Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
gitpod-io
GitHub Repository: gitpod-io/gitpod
Path: blob/main/dev/preview/previewctl/cmd/credentials.go
2500 views
1
// Copyright (c) 2022 Gitpod GmbH. All rights reserved.
2
// Licensed under the GNU Affero General Public License (AGPL).
3
// See License.AGPL.txt in the project root for license information.
4
5
package cmd
6
7
import (
8
"context"
9
"path/filepath"
10
11
"github.com/cockroachdb/errors"
12
"github.com/sirupsen/logrus"
13
"github.com/spf13/viper"
14
"k8s.io/client-go/tools/clientcmd"
15
"k8s.io/client-go/util/homedir"
16
17
kube "github.com/gitpod-io/gitpod/previewctl/pkg/k8s"
18
)
19
20
var (
21
DefaultKubeConfigPath = filepath.Join(homedir.HomeDir(), clientcmd.RecommendedHomeDir, clientcmd.RecommendedFileName)
22
)
23
24
func hasAccess(ctx context.Context, logger *logrus.Logger, contextName string) bool {
25
config, err := kube.NewFromDefaultConfigWithContext(logger, contextName)
26
if err != nil {
27
if errors.Is(err, kube.ErrContextNotExists) {
28
logger.Error(err)
29
return false
30
}
31
32
logger.Fatal(err)
33
}
34
35
return config.HasAccess(ctx)
36
}
37
38
func getKubeConfigPath() string {
39
if v := viper.GetString("KUBECONFIG"); v != "" {
40
DefaultKubeConfigPath = v
41
}
42
43
return DefaultKubeConfigPath
44
}
45
46