base

package
v0.2.3 Latest Latest
Warning

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

Go to latest
Published: May 21, 2021 License: MPL-2.0 Imports: 70 Imported by: 0

Documentation

Index

Constants

View Source
const (
	CommandSuccess int = iota
	CommandApiError
	CommandCliError
	CommandUserError
)
View Source
const (
	EnvTokenName   = "BOUNDARY_TOKEN_NAME"
	EnvKeyringType = "BOUNDARY_KEYRING_TYPE"

	StoredTokenName = "HashiCorp Boundary Auth Token"
)
View Source
const (
	// FlagNameAddr is the flag used in the base command to read in the
	// address of the Boundary server.
	FlagNameAddr = "addr"
	// FlagnameCACert is the flag used in the base command to read in the CA
	// cert.
	FlagNameCACert = "ca-cert"
	// FlagnameCAPath is the flag used in the base command to read in the CA
	// cert path.
	FlagNameCAPath = "ca-path"
	// FlagNameClientCert is the flag used in the base command to read in the
	// client key
	FlagNameClientKey = "client-key"
	// FlagNameClientCert is the flag used in the base command to read in the
	// client cert
	FlagNameClientCert = "client-cert"
	// FlagNameTLSInsecure is the flag used in the base command to read in
	// the option to ignore TLS certificate verification.
	FlagNameTLSInsecure = "tls-insecure"
	// FlagTLSServerName is the flag used in the base command to read in
	// the TLS server name.
	FlagTLSServerName = "tls-server-name"
)
View Source
const (
	EnvBoundaryCLINoColor = `BOUNDARY_CLI_NO_COLOR`
	EnvBoundaryCLIFormat  = `BOUNDARY_CLI_FORMAT`
)
View Source
const (
	NoneKeyring          = "none"
	AutoKeyring          = "auto"
	WincredKeyring       = "wincred"
	PassKeyring          = "pass"
	KeychainKeyring      = "keychain"
	SecretServiceKeyring = "secret-service"

	DefaultTokenName = "default"
	LoginCollection  = "login"
	PassPrefix       = "HashiCorp_Boundary"
)

Variables

View Source
var BuiltinListeners = map[string]ListenerFactory{
	"tcp":  tcpListenerFactory,
	"unix": unixListenerFactory,
}

BuiltinListeners is the list of built-in listener types.

View Source
var DevOnlyControllerFlags = func(*Command, *FlagSet) {}
View Source
var TermWidth uint = 80

Functions

func Format

func Format(ui cli.Ui) string

func MakeShutdownCh

func MakeShutdownCh() chan struct{}

MakeShutdownCh returns a channel that can be used for shutdown notifications for commands. This channel will send a message for every SIGINT or SIGTERM received.

func MakeSighupCh added in v0.1.8

func MakeSighupCh() chan struct{}

MakeSighupCh returns a channel that can be used for SIGHUP reloading. This channel will send a message for every SIGHUP received.

func MaxAttributesLength

func MaxAttributesLength(nonAttributesMap, attributesMap map[string]interface{}, keySubstMap map[string]string) int

func NewListener

func NewListener(l *configutil.Listener, logger hclog.Logger, ui cli.Ui) (*alpnmux.ALPNMux, map[string]string, reloadutil.ReloadFunc, error)

New creates a new listener of the given type with the given configuration. The type is looked up in the BuiltinListeners map.

func ProcessLogLevelAndFormat

func ProcessLogLevelAndFormat(flagLogLevel, flagLogFormat, configLogLevel, configLogFormat string) (hclog.Level, logging.LogFormat, error)

func ScopeInfoForOutput

func ScopeInfoForOutput(scp *scopes.ScopeInfo, maxLength int) string

func StartMemProfiler

func StartMemProfiler(_ hclog.Logger)

func TokenIdFromToken added in v0.2.1

func TokenIdFromToken(token string) (string, error)

func WrapAtLength

func WrapAtLength(s string) string

WrapAtLength wraps the given text to maxLineLength.

func WrapAtLengthWithPadding

func WrapAtLengthWithPadding(s string, pad int) string

WrapAtLengthWithPadding wraps the given text at the maxLineLength, taking into account any provided left padding.

func WrapForHelpText

func WrapForHelpText(lines []string) string

func WrapMap

func WrapMap(prefixSpaces, maxLengthOverride int, input map[string]interface{}) string

func WrapSlice

func WrapSlice(prefixSpaces int, input []string) string

Types

type BoolVar

type BoolVar struct {
	Name       string
	Aliases    []string
	Usage      string
	Default    bool
	Hidden     bool
	EnvVar     string
	Target     *bool
	Completion complete.Predictor
}

-- BoolVar and boolValue

type BoundaryUI

type BoundaryUI struct {
	cli.Ui
	Format string
}

type Command

type Command struct {
	Context    context.Context
	UI         cli.Ui
	ShutdownCh chan struct{}

	FlagToken          string
	FlagTokenName      string
	FlagKeyringType    string
	FlagRecoveryConfig string

	FlagScopeId       string
	FlagScopeName     string
	FlagId            string
	FlagName          string
	FlagDescription   string
	FlagAuthMethodId  string
	FlagHostCatalogId string
	FlagVersion       int
	FlagRecursive     bool
	FlagFilter        string
	// contains filtered or unexported fields
}

func NewCommand

func NewCommand(ui cli.Ui) *Command

New returns a new instance of a base.Command type

func (*Command) Client

func (c *Command) Client(opt ...Option) (*api.Client, error)

Client returns the HTTP API client. The client is cached on the command to save performance on future calls.

func (*Command) DiscoverKeyringTokenInfo added in v0.1.1

func (c *Command) DiscoverKeyringTokenInfo() (string, string, error)

func (*Command) FlagSet

func (c *Command) FlagSet(bit FlagSetBit) *FlagSets

FlagSet creates the flags for this command. The result is cached on the command to save performance on future calls.

func (*Command) PrintApiError added in v0.1.8

func (c *Command) PrintApiError(in *api.Error, contextStr string)

PrintApiError prints the given API error, optionally with context information, to the UI in the appropriate format

func (*Command) PrintCliError added in v0.1.8

func (c *Command) PrintCliError(err error)

PrintCliError prints the given CLI error to the UI in the appropriate format

func (*Command) PrintJsonItem added in v0.1.8

func (c *Command) PrintJsonItem(result api.GenericResult) bool

PrintJsonItem prints the given item to the UI in JSON format

func (*Command) PrintJsonItems added in v0.1.8

func (c *Command) PrintJsonItems(result api.GenericListResult) bool

PrintJsonItems prints the given items to the UI in JSON format

func (*Command) ReadTokenFromKeyring

func (c *Command) ReadTokenFromKeyring(keyringType, tokenName string) *authtokens.AuthToken

type DurationVar

type DurationVar struct {
	Name       string
	Aliases    []string
	Usage      string
	Default    time.Duration
	Hidden     bool
	EnvVar     string
	Target     *time.Duration
	Completion complete.Predictor
}

-- DurationVar and durationValue

type FlagBool

type FlagBool interface {
	IsBoolFlag() bool
}

FlagBool is an interface which boolean flags implement.

type FlagExample

type FlagExample interface {
	Example() string
}

FlagExample is an interface which declares an example value.

type FlagSet

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

FlagSet is a grouped wrapper around a real flag set and a grouped flag set.

func NewFlagSet

func NewFlagSet(name string) *FlagSet

NewFlagSet creates a new flag set.

func (*FlagSet) BoolVar

func (f *FlagSet) BoolVar(i *BoolVar)

func (*FlagSet) DurationVar

func (f *FlagSet) DurationVar(i *DurationVar)

func (*FlagSet) Float64Var

func (f *FlagSet) Float64Var(i *Float64Var)

func (*FlagSet) Int64Var

func (f *FlagSet) Int64Var(i *Int64Var)

func (*FlagSet) IntVar

func (f *FlagSet) IntVar(i *IntVar)

func (*FlagSet) Name

func (f *FlagSet) Name() string

Name returns the name of this flag set.

func (*FlagSet) StringMapVar

func (f *FlagSet) StringMapVar(i *StringMapVar)

func (*FlagSet) StringSliceVar

func (f *FlagSet) StringSliceVar(i *StringSliceVar)

func (*FlagSet) StringVar

func (f *FlagSet) StringVar(i *StringVar)

func (*FlagSet) Uint64Var

func (f *FlagSet) Uint64Var(i *Uint64Var)

func (*FlagSet) UintVar

func (f *FlagSet) UintVar(i *UintVar)

func (*FlagSet) Var

func (f *FlagSet) Var(value flag.Value, name, usage string)

Var is a lower-level API for adding something to the flags. It should be used with caution, since it bypasses all validation. Consider VarFlag instead.

func (*FlagSet) VarFlag

func (f *FlagSet) VarFlag(i *VarFlag)

func (*FlagSet) Visit

func (f *FlagSet) Visit(fn func(*flag.Flag))

func (*FlagSet) VisitAll

func (f *FlagSet) VisitAll(fn func(*flag.Flag))

type FlagSetBit

type FlagSetBit uint
const (
	FlagSetNone FlagSetBit = 1 << iota
	FlagSetHTTP
	FlagSetClient
	FlagSetOutputFormat
)

type FlagSets

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

FlagSets is a group of flag sets.

func NewFlagSets

func NewFlagSets(ui cli.Ui) *FlagSets

NewFlagSets creates a new flag sets.

func (*FlagSets) Args

func (f *FlagSets) Args() []string

Args returns the remaining args after parsing.

func (*FlagSets) Completions

func (f *FlagSets) Completions() complete.Flags

Completions returns the completions for this flag set.

func (*FlagSets) Help

func (fs *FlagSets) Help() string

Help builds custom help for this command, grouping by flag set.

func (*FlagSets) NewFlagSet

func (f *FlagSets) NewFlagSet(name string) *FlagSet

NewFlagSet creates a new flag set from the given flag sets.

func (*FlagSets) Parse

func (f *FlagSets) Parse(args []string) error

Parse parses the given flags, returning any errors.

func (*FlagSets) Parsed

func (f *FlagSets) Parsed() bool

Parsed reports whether the command-line flags have been parsed.

func (*FlagSets) Visit

func (f *FlagSets) Visit(fn func(*flag.Flag))

Visit visits the flags in lexicographical order, calling fn for each. It visits only those flags that have been set.

type FlagVisibility

type FlagVisibility interface {
	Hidden() bool
}

FlagVisibility is an interface which declares whether a flag should be hidden from help and completions. This is usually used for deprecations on "internal-only" flags.

type Float64Var

type Float64Var struct {
	Name       string
	Aliases    []string
	Usage      string
	Default    float64
	Hidden     bool
	EnvVar     string
	Target     *float64
	Completion complete.Predictor
}

-- Float64Var and float64Value

type GRPCLogFaker

type GRPCLogFaker struct {
	Logger hclog.Logger
	Log    bool
}

func (*GRPCLogFaker) Fatal

func (g *GRPCLogFaker) Fatal(args ...interface{})

func (*GRPCLogFaker) Fatalf

func (g *GRPCLogFaker) Fatalf(format string, args ...interface{})

func (*GRPCLogFaker) Fatalln

func (g *GRPCLogFaker) Fatalln(args ...interface{})

func (*GRPCLogFaker) Print

func (g *GRPCLogFaker) Print(args ...interface{})

func (*GRPCLogFaker) Printf

func (g *GRPCLogFaker) Printf(format string, args ...interface{})

func (*GRPCLogFaker) Println

func (g *GRPCLogFaker) Println(args ...interface{})

type Int64Var

type Int64Var struct {
	Name       string
	Aliases    []string
	Usage      string
	Default    int64
	Hidden     bool
	EnvVar     string
	Target     *int64
	Completion complete.Predictor
}

-- Int64Var and int64Value

type IntVar

type IntVar struct {
	Name       string
	Aliases    []string
	Usage      string
	Default    int
	Hidden     bool
	EnvVar     string
	Target     *int
	Completion complete.Predictor
}

-- IntVar and intValue

type JsonFormatter

type JsonFormatter struct{}

An output formatter for json output of an object

func (JsonFormatter) Format

func (j JsonFormatter) Format(data interface{}) ([]byte, error)

type ListenerFactory

type ListenerFactory func(string, *configutil.Listener, hclog.Logger, cli.Ui) (string, net.Listener, error)

Factory is the factory function to create a listener.

type Option

type Option func(*Options)

Option - how Options are passed as arguments.

func WithContainerImage added in v0.2.1

func WithContainerImage(name string) Option

WithContainerImage tells the command which container image to start a dev database with

func WithNoTokenScope

func WithNoTokenScope() Option

WithNoTokenScope tells the client not to set a scope for the client from a saved token's scope, as this can cause confusing behavior at authentication time.

func WithNoTokenValue

func WithNoTokenValue() Option

WithNoTokenValue tells the client not to set a token for the client from a saved token's value, as this can cause confusing behavior at authentication time.

func WithSkipAuthMethodCreation

func WithSkipAuthMethodCreation() Option

WithSkipAuthMethodCreation tells the command not to instantiate an auth method on first run.

func WithSkipDatabaseDestruction

func WithSkipDatabaseDestruction() Option

WithSkipDatabaseDestruction tells the command not to destroy the database even on error.

func WithSkipHostResourcesCreation

func WithSkipHostResourcesCreation() Option

WithSkipHostResourcesCreation tells the command not to instantiate a host catalog and related resources on first run.

func WithSkipScopesCreation

func WithSkipScopesCreation() Option

WithSkipScopesCreation tells the command not to instantiate scopes on first run.

func WithSkipTargetCreation

func WithSkipTargetCreation() Option

WithSkipTargetCreation tells the command not to instantiate a target on first run.

type Options

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

Options - how Options are represented.

type Server

type Server struct {
	*Command

	InfoKeys []string
	Info     map[string]string

	GatedWriter *gatedwriter.Writer
	Logger      hclog.Logger
	CombineLogs bool
	LogLevel    hclog.Level

	RootKms            wrapping.Wrapper
	WorkerAuthKms      wrapping.Wrapper
	RecoveryKms        wrapping.Wrapper
	Kms                *kms.Kms
	SecureRandomReader io.Reader

	InmemSink         *metrics.InmemSink
	PrometheusEnabled bool

	ReloadFuncsLock *sync.RWMutex
	ReloadFuncs     map[string][]reloadutil.ReloadFunc

	ShutdownFuncs []func() error

	Listeners []*ServerListener

	DevPasswordAuthMethodId         string
	DevOidcAuthMethodId             string
	DevLoginName                    string
	DevPassword                     string
	DevUserId                       string
	DevUnprivilegedLoginName        string
	DevUnprivilegedPassword         string
	DevUnprivilegedUserId           string
	DevOrgId                        string
	DevProjectId                    string
	DevHostCatalogId                string
	DevHostSetId                    string
	DevHostId                       string
	DevTargetId                     string
	DevHostAddress                  string
	DevTargetDefaultPort            int
	DevTargetSessionMaxSeconds      int
	DevTargetSessionConnectionLimit int

	DatabaseUrl                string
	DatabaseMaxOpenConnections int
	DevDatabaseCleanupFunc     func() error

	Database *gorm.DB
	// contains filtered or unexported fields
}

func NewServer

func NewServer(cmd *Command) *Server

func (*Server) ConnectToDatabase

func (b *Server) ConnectToDatabase(dialect string) error

func (*Server) CreateDevDatabase

func (b *Server) CreateDevDatabase(ctx context.Context, opt ...Option) error

func (*Server) CreateGlobalKmsKeys

func (b *Server) CreateGlobalKmsKeys(ctx context.Context) error

func (*Server) CreateInitialHostResources

func (b *Server) CreateInitialHostResources(ctx context.Context) (*static.HostCatalog, *static.HostSet, *static.Host, error)

func (*Server) CreateInitialLoginRole

func (b *Server) CreateInitialLoginRole(ctx context.Context) (*iam.Role, error)

func (*Server) CreateInitialPasswordAuthMethod added in v0.2.0

func (b *Server) CreateInitialPasswordAuthMethod(ctx context.Context) (*password.AuthMethod, *iam.User, error)

func (*Server) CreateInitialScopes

func (b *Server) CreateInitialScopes(ctx context.Context) (*iam.Scope, *iam.Scope, error)

func (*Server) CreateInitialTarget

func (b *Server) CreateInitialTarget(ctx context.Context) (target.Target, error)

func (*Server) DestroyDevDatabase

func (b *Server) DestroyDevDatabase() error

func (*Server) PrintInfo

func (b *Server) PrintInfo(ui cli.Ui)

func (*Server) ReleaseLogGate

func (b *Server) ReleaseLogGate()

func (*Server) RemovePidFile

func (b *Server) RemovePidFile(pidPath string) error

func (*Server) RunShutdownFuncs

func (b *Server) RunShutdownFuncs() error

func (*Server) SetupControllerPublicClusterAddress added in v0.1.2

func (b *Server) SetupControllerPublicClusterAddress(conf *config.Config, flagValue string) error

func (*Server) SetupKMSes

func (b *Server) SetupKMSes(ui cli.Ui, config *config.Config) error

func (*Server) SetupListeners

func (b *Server) SetupListeners(ui cli.Ui, config *configutil.SharedConfig, allowedPurposes []string) error

func (*Server) SetupLogging

func (b *Server) SetupLogging(flagLogLevel, flagLogFormat, configLogLevel, configLogFormat string) error

func (*Server) SetupMetrics

func (b *Server) SetupMetrics(ui cli.Ui, telemetry *configutil.Telemetry) error

func (*Server) SetupWorkerPublicAddress

func (b *Server) SetupWorkerPublicAddress(conf *config.Config, flagValue string) error

func (*Server) StorePidFile

func (b *Server) StorePidFile(pidPath string) error

type ServerListener

type ServerListener struct {
	Mux          *alpnmux.ALPNMux
	Config       *configutil.Listener
	HTTPServer   *http.Server
	GrpcServer   *grpc.Server
	ALPNListener net.Listener
}

type StringMapVar

type StringMapVar struct {
	Name       string
	Aliases    []string
	Usage      string
	Default    map[string]string
	Hidden     bool
	Target     *map[string]string
	Completion complete.Predictor
}

-- StringMapVar and stringMapValue

type StringSliceVar

type StringSliceVar struct {
	Name       string
	Aliases    []string
	Usage      string
	Default    []string
	Hidden     bool
	EnvVar     string
	Target     *[]string
	Completion complete.Predictor
}

-- StringSliceVar and stringSliceValue

type StringVar

type StringVar struct {
	Name       string
	Aliases    []string
	Usage      string
	Default    string
	Hidden     bool
	EnvVar     string
	Target     *string
	Completion complete.Predictor
}

-- StringVar and stringValue

type TCPKeepAliveListener

type TCPKeepAliveListener struct {
	*net.TCPListener
}

TCPKeepAliveListener sets TCP keep-alive timeouts on accepted connections. It's used by ListenAndServe and ListenAndServeTLS so dead TCP connections (e.g. closing laptop mid-download) eventually go away.

This is copied directly from the Go source code.

func (TCPKeepAliveListener) Accept

func (ln TCPKeepAliveListener) Accept() (net.Conn, error)

type Uint64Var

type Uint64Var struct {
	Name       string
	Aliases    []string
	Usage      string
	Default    uint64
	Hidden     bool
	EnvVar     string
	Target     *uint64
	Completion complete.Predictor
}

-- Uint64Var and uint64Value

type UintVar

type UintVar struct {
	Name       string
	Aliases    []string
	Usage      string
	Default    uint
	Hidden     bool
	EnvVar     string
	Target     *uint
	Completion complete.Predictor
}

-- UintVar && uintValue

type VarFlag

type VarFlag struct {
	Name       string
	Aliases    []string
	Usage      string
	Default    string
	EnvVar     string
	Value      flag.Value
	Completion complete.Predictor
}

-- VarFlag

type WorkerAuthInfo

type WorkerAuthInfo struct {
	CertPEM         []byte `json:"cert"`
	KeyPEM          []byte `json:"key"`
	Name            string `json:"name"`
	Description     string `json:"description"`
	ConnectionNonce string `json:"connection_nonce"`
}

Jump to

Keyboard shortcuts

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