Path: blob/main/dev/preview/previewctl/cmd/credentials.go
2500 views
// Copyright (c) 2022 Gitpod GmbH. All rights reserved.1// Licensed under the GNU Affero General Public License (AGPL).2// See License.AGPL.txt in the project root for license information.34package cmd56import (7"context"8"path/filepath"910"github.com/cockroachdb/errors"11"github.com/sirupsen/logrus"12"github.com/spf13/viper"13"k8s.io/client-go/tools/clientcmd"14"k8s.io/client-go/util/homedir"1516kube "github.com/gitpod-io/gitpod/previewctl/pkg/k8s"17)1819var (20DefaultKubeConfigPath = filepath.Join(homedir.HomeDir(), clientcmd.RecommendedHomeDir, clientcmd.RecommendedFileName)21)2223func hasAccess(ctx context.Context, logger *logrus.Logger, contextName string) bool {24config, err := kube.NewFromDefaultConfigWithContext(logger, contextName)25if err != nil {26if errors.Is(err, kube.ErrContextNotExists) {27logger.Error(err)28return false29}3031logger.Fatal(err)32}3334return config.HasAccess(ctx)35}3637func getKubeConfigPath() string {38if v := viper.GetString("KUBECONFIG"); v != "" {39DefaultKubeConfigPath = v40}4142return DefaultKubeConfigPath43}444546