cbtconfig

package
v0.44.0 Latest Latest
Warning

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

Go to latest
Published: Aug 9, 2019 License: Apache-2.0 Imports: 17 Imported by: 0

Documentation

Overview

Package cbtconfig encapsulates common code for reading configuration from .cbtrc and gcloud.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Filename

func Filename() string

Filename returns the filename consulted for standard configuration.

Types

type Config

type Config struct {
	Project, Instance string                           // required
	Creds             string                           // optional
	AdminEndpoint     string                           // optional
	DataEndpoint      string                           // optional
	CertFile          string                           // optional
	UserAgent         string                           // optional
	TokenSource       oauth2.TokenSource               // derived
	TLSCreds          credentials.TransportCredentials // derived
}

Config represents a configuration.

func Load

func Load() (*Config, error)

Load loads a .cbtrc file. If the file is not present, an empty config is returned.

func (*Config) CheckFlags

func (c *Config) CheckFlags(required RequiredFlags) error

CheckFlags checks that the required config values are set.

func (*Config) RegisterFlags

func (c *Config) RegisterFlags()

RegisterFlags registers a set of standard flags for this config. It should be called before flag.Parse.

func (*Config) SetFromGcloud

func (c *Config) SetFromGcloud() error

SetFromGcloud retrieves and sets any missing config values from the gcloud configuration if possible possible

type GcloudCmdTokenSource

type GcloudCmdTokenSource struct {
	Command string
	Args    []string
}

GcloudCmdTokenSource holds the comamnd arguments. It is only intended to be set by the program. TODO(deklerk): Can this be unexported?

func (*GcloudCmdTokenSource) Token

func (g *GcloudCmdTokenSource) Token() (*oauth2.Token, error)

Token implements the oauth2.TokenSource interface

type GcloudConfig

type GcloudConfig struct {
	Configuration struct {
		Properties struct {
			Core struct {
				Project string `json:"project"`
			} `json:"core"`
		} `json:"properties"`
	} `json:"configuration"`
	Credential GcloudCredential `json:"credential"`
}

GcloudConfig holds gcloud configuration values.

func LoadGcloudConfig

func LoadGcloudConfig(gcloudCmd string, gcloudCmdArgs []string) (*GcloudConfig, error)

LoadGcloudConfig retrieves the gcloud configuration values we need use via the 'config-helper' command

type GcloudCredential

type GcloudCredential struct {
	AccessToken string    `json:"access_token"`
	Expiry      time.Time `json:"token_expiry"`
}

GcloudCredential holds gcloud credential information.

func (*GcloudCredential) Token

func (cred *GcloudCredential) Token() *oauth2.Token

Token creates an oauth2 token using gcloud credentials.

type RequiredFlags

type RequiredFlags uint

RequiredFlags describes the flag requirements for a cbt command.

const (
	// NoneRequired specifies that not flags are required.
	NoneRequired RequiredFlags = 0
	// ProjectRequired specifies that the -project flag is required.
	ProjectRequired RequiredFlags = 1 << iota
	// InstanceRequired specifies that the -instance flag is required.
	InstanceRequired
	// ProjectAndInstanceRequired specifies that both -project and -instance is required.
	ProjectAndInstanceRequired = ProjectRequired | InstanceRequired
)

Jump to

Keyboard shortcuts

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