config

package
v1.17.1 Latest Latest
Warning

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

Go to latest
Published: Sep 12, 2024 License: Apache-2.0 Imports: 7 Imported by: 0

Documentation

Overview

Package config manages the Crossplane CLI configuration.

Index

Constants

View Source
const (
	ConfigDir  = ".crossplane"
	ConfigFile = "config.json"
)

Location of crossplane CLI config file.

Variables

This section is empty.

Functions

func GetDefaultPath

func GetDefaultPath() (string, error)

GetDefaultPath returns the default config path or error.

Types

type Config

type Config struct {
	Upbound Upbound `json:"upbound"`
}

Config is format for the up configuration file.

func Extract

func Extract(src Source) (*Config, error)

Extract performs extraction of configuration from the provided source.

func (*Config) AddOrUpdateUpboundProfile

func (c *Config) AddOrUpdateUpboundProfile(name string, p Profile) error

AddOrUpdateUpboundProfile adds or updates an Upbound profile to the Config.

func (*Config) AddToBaseConfig

func (c *Config) AddToBaseConfig(name, key, value string) error

AddToBaseConfig adds the supplied key, value pair to the base config map of the profile that corresponds to the given name. If the supplied name does not match an existing Profile an error is returned. If the overrides map does not currently exist on the corresponding profile, a map is initialized.

func (*Config) BaseToJSON

func (c *Config) BaseToJSON(name string) (io.Reader, error)

BaseToJSON converts the base config of the given Profile to JSON. If the config couldn't be converted or if the supplied name does not correspond to an existing Profile, an error is returned.

func (*Config) GetBaseConfig

func (c *Config) GetBaseConfig(name string) (map[string]string, error)

GetBaseConfig returns the persisted base configuration associated with the provided Profile. If the supplied name does not match an existing Profile an error is returned.

func (*Config) GetDefaultUpboundProfile

func (c *Config) GetDefaultUpboundProfile() (string, Profile, error)

GetDefaultUpboundProfile gets the default Upbound profile or returns an error if default is not set or default profile does not exist.

func (*Config) GetUpboundProfile

func (c *Config) GetUpboundProfile(name string) (Profile, error)

GetUpboundProfile gets a profile with a given identifier. If a profile does not exist for the given identifier an error will be returned. Multiple profiles should never exist for the same identifier, but in the case that they do, the first will be returned.

func (*Config) GetUpboundProfiles

func (c *Config) GetUpboundProfiles() (map[string]Profile, error)

GetUpboundProfiles returns the list of existing profiles. If no profiles exist, then an error will be returned.

func (*Config) RemoveFromBaseConfig

func (c *Config) RemoveFromBaseConfig(name, key string) error

RemoveFromBaseConfig removes the supplied key from the base config map of the Profile that corresponds to the given name. If the supplied name does not match an existing Profile an error is returned. If the base config map does not currently exist on the corresponding profile, a no-op occurs.

func (*Config) SetDefaultUpboundProfile

func (c *Config) SetDefaultUpboundProfile(name string) error

SetDefaultUpboundProfile sets the default profile for communicating with Upbound. Setting a default profile that does not exist will return an error.

type FSSource

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

FSSource provides a filesystem source for interacting with a Config.

func NewFSSource

func NewFSSource(modifiers ...FSSourceModifier) *FSSource

NewFSSource constructs a new FSSource. Path must be supplied via modifier or Initialize must be called to use default. NOTE(hasheddan): using empty path by default is a bit of a footgun, so we should consider refactoring here. The motivation for the current design is to allow for flexibility in cases where the consumer does not want to create if the path does not exist, or they want to provide the FSSource as the default without handling an error in construction (see Docker credential helper for example).

func (*FSSource) GetConfig

func (src *FSSource) GetConfig() (*Config, error)

GetConfig fetches the config from a filesystem.

func (*FSSource) Initialize

func (src *FSSource) Initialize() error

Initialize creates a config in the filesystem if one does not exist. If path is not defined the default path is constructed.

func (*FSSource) UpdateConfig

func (src *FSSource) UpdateConfig(c *Config) error

UpdateConfig updates the Config in the filesystem.

type FSSourceModifier

type FSSourceModifier func(*FSSource)

FSSourceModifier modifies an FSSource.

func WithFS

func WithFS(fs afero.Fs) FSSourceModifier

WithFS overrides the FSSource filesystem with the given filesystem.

func WithPath

func WithPath(p string) FSSourceModifier

WithPath sets the config path for the filesystem source.

type MockSource

type MockSource struct {
	InitializeFn   func() error
	GetConfigFn    func() (*Config, error)
	UpdateConfigFn func(*Config) error
}

MockSource is a mock source.

func (*MockSource) GetConfig

func (m *MockSource) GetConfig() (*Config, error)

GetConfig calls the underlying get config function.

func (*MockSource) Initialize

func (m *MockSource) Initialize() error

Initialize calls the underlying initialize function.

func (*MockSource) UpdateConfig

func (m *MockSource) UpdateConfig(c *Config) error

UpdateConfig calls the underlying update config function.

type Profile

type Profile struct {
	// ID is either a username, email, or token.
	ID string `json:"id"`

	// Type is the type of the profile.
	Type ProfileType `json:"type"`

	// Session is a session token used to authenticate to Upbound.
	Session string `json:"session,omitempty"`

	// Account is the default account to use when this profile is selected.
	Account string `json:"account,omitempty"`

	// BaseConfig represent persisted settings for this profile.
	// For example:
	// * flags
	// * environment variables
	BaseConfig map[string]string `json:"base,omitempty"`
}

A Profile is a set of credentials.

type ProfileType

type ProfileType string

ProfileType is a type of Upbound profile.

const (
	UserProfileType  ProfileType = "user"
	TokenProfileType ProfileType = "token"
)

Types of profiles.

type RedactedProfile

type RedactedProfile struct {
	Profile
}

RedactedProfile embeds a Upbound Profile for the sole purpose of redacting sensitive information.

func (RedactedProfile) MarshalJSON

func (p RedactedProfile) MarshalJSON() ([]byte, error)

MarshalJSON overrides the session field with `REDACTED` so as not to leak sensitive information. We're using an explicit copy here instead of updating the underlying Profile struct so as to not modifying the internal state of the struct by accident.

type Source

type Source interface {
	Initialize() error
	GetConfig() (*Config, error)
	UpdateConfig(cfg *Config) error
}

Source is a source for interacting with a Config.

type Upbound

type Upbound struct {
	// Default indicates the default profile.
	Default string `json:"default"`

	// Profiles contain sets of credentials for communicating with Upbound. Key
	// is name of the profile.
	Profiles map[string]Profile `json:"profiles,omitempty"`
}

Upbound contains configuration information for Upbound.

Jump to

Keyboard shortcuts

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