gcloud

package
v0.19.0 Latest Latest
Warning

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

Go to latest
Published: Sep 19, 2024 License: MIT Imports: 21 Imported by: 0

README

POSH gcloud provider

Usage

Plugin

func New(l log.Logger) (plugin.Plugin, error) {
  inst := &Plugin{}

	// ...

  // create provider
  provider, err := gcloud.New(l, inst.cache)
  if err != nil {
    return nil
  }

  // add command
  inst.commands.Add(
    gcloud.NewCommand(l, provider, inst.kubectl),
	)

	// ...
}

Using service account access tokens retrieved by OnePassword:

func New(l log.Logger) (plugin.Plugin, error) {
  inst := &Plugin{}

  // ...

  // create provider
  provider, err := gcloud.New(l, inst.cache)
  if err != nil {
    return nil
  }

  // add command
  inst.commands.Add(
    gcloud.NewCommand(l, provider, inst.kubectl, gcloud.CommandWithOnePassword(inst.op)),
	)

	// ...
}
Config
gcloud:
  configPath: .posh/config/gcloud
  clusters:
    prod:
      name: default
      project: myproject-123456
      region: europe-west6

Using service account access tokens:

gcloud:
  configPath: .posh/config/gcloud
  accounts:
    prod:
      name: user@account.iam.gserviceaccount.com
    admin@prod:
      name: admin@account.iam.gserviceaccount.com
  clusters:
    prod:
      name: default
      project: myproject-123456
      region: europe-west6
      account: prod
    admin@prod:
      name: default
      project: myproject-123456
      region: europe-west6
      account: admin@prod

NOTE: Servce account keys can optionally be retrieved by OnePassword.

gcloud:
  configPath: .posh/config/gcloud
  accounts:
    prod:
      name: user@account.iam.gserviceaccount.com
      key:
        field: 1234564dxtuty3vaaxezex4c7ey
        item: 1234564dxtuty3vaaxezex4c7ey
        vault: 1234564dxtuty3vaaxezex4c7ey
        account: foomo
Ownbrew
require:
  packages:
    - name: gcloud
      version: '>=409'
      command: gcloud --version 2>&1 | grep "Google Cloud SDK" | awk '{print $4}'
      help: |
        Please ensure you have 'gcloud' installed in a recent version: %s!

          $ brew update
          $ brew install google-cloud-sdk

Documentation

Index

Constants

View Source
const (
	ClusterNameDefault string = "default"
)

Variables

This section is empty.

Functions

func AuthChecker added in v0.3.0

func AuthChecker(p *GCloud) check.Checker

Types

type Account added in v0.1.0

type Account struct {
	Name  string              `json:"name" yaml:"name"`
	Email string              `json:"email" yaml:"email"`
	Key   *onepassword.Secret `json:"key" yaml:"key"`
}

type Cluster

type Cluster struct {
	Name    string `json:"name" yaml:"name"`
	Project string `json:"project" yaml:"project"`
	Region  string `json:"region" yaml:"region"`
	Account string `json:"account" yaml:"account"`
}

type ClusterNameFn added in v0.1.0

type ClusterNameFn func(name string, cluster Cluster) string

type Command

type Command struct {
	// contains filtered or unexported fields
}

func NewCommand

func NewCommand(l log.Logger, gcloud *GCloud, kubectl *kubectl.Kubectl, opts ...CommandOption) *Command

func (*Command) Complete

func (c *Command) Complete(ctx context.Context, r *readline.Readline) []goprompt.Suggest

func (*Command) Description

func (c *Command) Description() string

func (*Command) Execute

func (c *Command) Execute(ctx context.Context, r *readline.Readline) error

func (*Command) Help

func (c *Command) Help(ctx context.Context, r *readline.Readline) string

func (*Command) Name

func (c *Command) Name() string

type CommandOption added in v0.1.0

type CommandOption func(command *Command)

func CommandWithClusterNameFn added in v0.1.0

func CommandWithClusterNameFn(v ClusterNameFn) CommandOption

func CommandWithName added in v0.1.0

func CommandWithName(v string) CommandOption

func CommandWithOnePassword added in v0.1.0

func CommandWithOnePassword(v *onepassword.OnePassword) CommandOption

type Config

type Config struct {
	ConfigPath string             `json:"configPath" yaml:"configPath"`
	Accounts   map[string]Account `json:"accounts" yaml:"accounts"`
	Clusters   map[string]Cluster `json:"clusters" yaml:"clusters"`
}

func (Config) Account added in v0.1.0

func (c Config) Account(name string) (Account, error)

func (Config) AccountNames added in v0.1.0

func (c Config) AccountNames() []string

func (Config) Cluster added in v0.1.0

func (c Config) Cluster(name string) (Cluster, error)

func (Config) ClusterNames

func (c Config) ClusterNames() []string

type GCloud

type GCloud struct {
	// contains filtered or unexported fields
}

func New

func New(l log.Logger, cache cache.Cache, opts ...Option) (*GCloud, error)

func (*GCloud) ActiveAccount added in v0.1.0

func (p *GCloud) ActiveAccount(ctx context.Context, l log.Logger) (string, error)

ActiveAccount returns the active account email

func (*GCloud) ServiceAccountKeysPath added in v0.1.0

func (p *GCloud) ServiceAccountKeysPath() string

type Option

type Option func(*GCloud)

func WithAccountFileNameRegex added in v0.1.0

func WithAccountFileNameRegex(v *regexp.Regexp) Option

func WithConfig added in v0.1.0

func WithConfig(v *Config) Option

func WithConfigKey added in v0.1.0

func WithConfigKey(v string) Option

Jump to

Keyboard shortcuts

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