config

package
v0.34.2 Latest Latest
Warning

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

Go to latest
Published: Oct 17, 2024 License: Apache-2.0 Imports: 8 Imported by: 0

Documentation

Index

Constants

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

Location of up config file.

Variables

This section is empty.

Functions

func GetDefaultPath added in v0.25.0

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 added in v0.5.0

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

Extract performs extraction of configuration from the provided source.

func (*Config) AddOrUpdateUpboundProfile added in v0.5.0

func (c *Config) AddOrUpdateUpboundProfile(name string, new profile.Profile) error

AddOrUpdateUpboundProfile adds or updates an Upbound profile to the Config.

func (*Config) AddToBaseConfig added in v0.25.0

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 added in v0.25.0

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 added in v0.25.0

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 added in v0.5.0

func (c *Config) GetDefaultUpboundProfile() (string, profile.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 added in v0.5.0

func (c *Config) GetUpboundProfile(name string) (profile.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 added in v0.25.0

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

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

func (*Config) RemoveFromBaseConfig added in v0.25.0

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 added in v0.5.0

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 added in v0.25.0

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 added in v0.25.0

func WithFS(fs afero.Fs) FSSourceModifier

WithFS overrides the FSSource filesystem with the given filesystem.

func WithPath added in v0.25.0

func WithPath(p string) FSSourceModifier

WithPath sets the config path for the filesystem source.

type Format added in v0.25.0

type Format string

Allowed values for the global format option

const (
	Default Format = "default"
	JSON    Format = "json"
	YAML    Format = "yaml"
)

type MockSource added in v0.25.0

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

MockSource is a mock source.

func (*MockSource) GetConfig added in v0.25.0

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

GetConfig calls the underlying get config function.

func (*MockSource) Initialize added in v0.25.0

func (m *MockSource) Initialize() error

Initialize calls the underlying initialize function.

func (*MockSource) UpdateConfig added in v0.25.0

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

UpdateConfig calls the underlying update config function.

type QuietFlag added in v0.25.0

type QuietFlag bool

QuietFlag provides a named boolean type for the QuietFlag.

type Source

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

Source is a source for interacting with a Config.

type Upbound added in v0.5.0

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.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