gcloudconfig

package module
v0.1.5 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: May 6, 2020 License: Apache-2.0 Imports: 7 Imported by: 8

README

gcloud-config-helper

Google Cloud SDK Credentials helper

The standard Google Cloud Platform SDK for Go ignores the gcloud configuration for default project and account to use the authentication with.

The function GetCredentials returns a google.Credentials object based upon the active configuration. This allows you to create utilities that will work in the same context as gcloud.

The function GetConfig will return the properties of the active configuration in gcloud.

The implementation entirely depends on the output of gcloud config config-helper, which is intended to utilities to use the gcloud configuration. Oddly enough, Google also promises it to be a volatile and unstable interface. So if Google broke it or changed it, let me know perhaps we can fix the implementation of this library :-)

read the blog How to authenticate to Google Cloud Platform using the active gcloud configuration

Documentation

Overview

Wrapper around the Google Cloud SDK configuration * * the standard Google Cloud SDK go library does not support * to use the project and account specified by the current * gcloud configuration. * * this package wrap the `gcloud config config-helper` * and returns the google.Credentials of the current or desired * gcloud configuration

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func GetCredentials added in v0.1.4

func GetCredentials(name string) (*google.Credentials, error)

* get the credentials associated with the specified gcloud * configuration. If the name is "", than the current active * configuration is used.

func IsGCloudOnPath

func IsGCloudOnPath() bool

returns true if gcloud is on the path, otherwise false.

Types

type Config

type Config struct {
	Configuration struct {
		ActiveConfiguration *string `json:"active_configuration"`
		Properties          struct {
			Core struct {
				Project                       *string `json:"project"`
				Account                       *string `json:"account"`
				CustomCaCertsFile             *string `json:"custom_ca_certs_file"`
				DefaultRegionalBackendService *string `json:"default_regional_backend_service"`
				DisableColor                  *string `json:"disable_color"`
				DisableFileLogging            *string `json:"disable_file_logging"`
				DisableUsageReporting         *string `json:"disable_usage_reporting"`
				LogHttp                       *string `json:"log_http"`
				MaxLogDays                    *string `json:"MaxLogDays"`
				PassCredentialsToGsutil       *string `json:"pass_credentials_to_gsutil"`
				ShowStructuredLogs            *string `json:"show_structured_logs"`
				TraceToken                    *string `json:"trace_token"`
				UserOutputEnabled             *string `json:"user_output_enabled"`
				Verbosity                     *string `json:"verbosity"`
			} `json:"core"`
			Accessibility struct {
				ScreenReader *string `json:"screen_reader"`
			} `json:"accessibility"`
			App struct {
				CloudBuildTimeout   *string `json:"cloud_build_timeout"`
				PromoteByDefault    *string `json:"promote_by_default"`
				StopPreviousVersion *string `json:"stop_previous_version"`
				UseRuntimeBuilders  *string `json:"use_runtime_builders"`
			} `json:"app"`
			Artifacts struct {
				DisableCredentials        *string `json:"disable_credentials"`
				ImpersonateServiceAccount *string `json:"impersonate_service_account"`
			} `json:"artifacts"`
			Auth struct {
				Location   *string `json:"location"`
				Repository *string `json:"repository"`
			} `json:"auth"`
			Billing struct {
				QuotaProject *string `json:"quota_project"`
			} `json:"billing"`
			Builds struct {
				UseKaniko      *string `json:"use_kaniko"`
				KanikoCacheTTL *string `json:"kaniko_cache_ttl"`
				Timeout        *string `json:"timeout"`
			} `json:"builds"`
			ComponentManager struct {
				AdditionalRepositories *string `json:"additional_repositories"`
				DisableUpdateCheck     *string `json:"disable_update_check"`
			} `json:"component_manager"`
			Composer struct {
				Location           *string `json:"location"`
				DisableUpdateCheck *string `json:"disable_update_check"`
			} `json:"composer"`
			Compute struct {
				Region                     *string `json:"region"`
				Zone                       *string `json:"zone"`
				UseNewListUsableSubnetsAPI *string `json:"use_new_list_usable_subnets_api"`
			} `json:"compute"`
			Container struct {
				BuildTimeout                     *string `json:"build_timeout"`
				Cluster                          *string `json:"cluster"`
				UseApplicationDefaultCredentials *string `json:"use_application_default_credentials"`
				UseClientCertificate             *string `json:"use_client_certificate"`
			} `json:"container"`
			ContextAware struct {
				UseClientCertificate *string `json:"use_client_certificate"`
			} `json:"context_aware"`
			Dataflow struct {
				DisablePublicIPs *string `json:"disable_public_ips"`
				PrintOnly        *string `json:"print_only"`
			} `json:"dataflow"`
			Datafusion struct {
				Location *string `json:"location"`
			} `json:"datafusion"`
			Dataproc struct {
				Region *string `json:"region"`
			} `json:"dataproc"`
			DeploymentManager struct {
				GlobImports *string `json:"glob_imports"`
			} `json:"deployment_manager"`
			Filestore struct {
				Zone *string `json:"zone"`
			} `json:"filestore"`
			Functions struct {
				Region *string `json:"region"`
			} `json:"functions"`
			GameServices struct {
				DefaultDeployment *string `json:"default_deployment"`
				DefaultRealm      *string `json:"default_realm"`
				Location          *string `json:"location"`
			} `json:"game_services"`
			GCloudignore struct {
				Enabled *string `json:"enabled"`
			} `json:"functions"`
			Healthcare struct {
				Dataset  *string `json:"dataset"`
				Location *string `json:"location"`
			} `json:"healthcare"`
			Lifesciences struct {
				Location *string `json:"location"`
			} `json:"lifesciences"`
			MLEngine struct {
				LocalPython     *string `json:"local_python"`
				PollingInterval *string `json:"polling_interval"`
			} `json:"ml_engine"`
			Proxy struct {
				Address  *string `json:"address"`
				Password *string `json:"password"`
				Port     *string `json:"port"`
				Rdns     *string `json:"rdns"`
				Type     *string `json:"type"`
				Username *string `json:"username"`
			} `json:"proxy"`
			Redis struct {
				Region *string `json:"region"`
			} `json:"redis"`
			Run struct {
				Cluster         *string `json:"cluster"`
				ClusterLocation *string `json:"cluster_location"`
				Platform        *string `json:"platform"`
				Region          *string `json:"region"`
			} `json:"run"`
			SCC struct {
				Organization *string `json:"organization"`
			} `json:"scc"`
			Secrets struct {
				Locations         *string `json:"locations"`
				ReplicationPolicy *string `json:"replication-policy"`
			} `json:"secrets"`
			Spanner struct {
				Instance *string `json:"instance"`
			} `json:"spanner"`
			Survey struct {
				DisablePrompts *string `json:"disable_prompts"`
			} `json:"survey"`
		} `json:"properties"`
	} `json:"configuration"`
	Credential struct {
		AccessToken string    `json:"access_token"`
		IDToken     string    `json:"id_token"`
		TokenExpiry time.Time `json:"token_expiry"`
	} `json:"credential"`
	Sentinels struct {
		ConfigSentinel *string `json:"config_sentinel"`
	} `json:"sentinels"`
}

*

  • the unmarshaled output of `gcloud config config-helper` with all of the
  • documented properties.

func GetConfig added in v0.1.4

func GetConfig(name string) (*Config, error)

returns the parsed output of the gcloud config config-helper command.

func (*Config) Token

func (c *Config) Token() (*oauth2.Token, error)

returns the OAuth2 token if the current configuration. If it * expired, GetCloudSDKConfig() will be used to refresh the token.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL