config

package
v0.8.0-alpha.2 Latest Latest
Warning

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

Go to latest
Published: Feb 1, 2019 License: Apache-2.0 Imports: 10 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	// ConfigFileName is the name of the config files (home / project)
	ConfigFileName = "config"
	// ConfigFileType is the config file extension
	ConfigFileType = "yaml"
	// ConfigFileNameWithExt is the config filename with extension
	ConfigFileNameWithExt = fmt.Sprintf("%s.%s", ConfigFileName, ConfigFileType)
	// ConfigDir is the directory for astro files
	ConfigDir = ".astro"

	// HomePath is the path to a users home directory
	HomePath, _ = fileutil.GetHomeDir()
	// HomeConfigPath is the path to the users global config directory
	HomeConfigPath = filepath.Join(HomePath, ConfigDir)
	// HomeConfigFile is the global config file
	HomeConfigFile = filepath.Join(HomeConfigPath, ConfigFileNameWithExt)

	// WorkingPath is the path to the working directory
	WorkingPath, _ = fileutil.GetWorkingDir()

	// CFGStrMap maintains string to cfg mapping
	CFGStrMap = make(map[string]cfg)

	// CFG Houses configuration meta
	CFG = cfgs{
		CloudAPIProtocol:  newCfg("cloud.api.protocol", "https"),
		CloudAPIPort:      newCfg("cloud.api.port", "443"),
		CloudAPIToken:     newCfg("cloud.api.token", ""),
		Context:           newCfg("context", ""),
		Contexts:          newCfg("contexts", ""),
		LocalHouston:      newCfg("local.houston", ""),
		LocalOrbit:        newCfg("local.orbit", ""),
		PostgresUser:      newCfg("postgres.user", "postgres"),
		PostgresPassword:  newCfg("postgres.password", "postgres"),
		PostgresHost:      newCfg("postgres.host", "postgres"),
		PostgresPort:      newCfg("postgres.port", "5432"),
		ProjectDeployment: newCfg("project.deployment", ""),
		ProjectName:       newCfg("project.name", ""),
		ProjectWorkspace:  newCfg("project.workspace", ""),
		WebserverPort:     newCfg("webserver.port", "8080"),
	}
)

Functions

func CreateConfig

func CreateConfig(v *viper.Viper, path, file string) error

CreateConfig creates a config file in the given directory

func CreateProjectConfig

func CreateProjectConfig(projectPath string)

CreateProjectConfig creates a project config file

func InitConfig

func InitConfig()

InitConfig initializes the config files

func IsProjectDir added in v0.2.2

func IsProjectDir(path string) (bool, error)

IsProjectDir returns a boolean depending on if path is a valid project dir

func PrintCurrentContext added in v0.2.2

func PrintCurrentContext() error

PrintCurrentContext prints the current config context

func ProjectConfigExists

func ProjectConfigExists() bool

ProjectConfigExists returns a boolean indicating if a project config file exists

func ProjectRoot

func ProjectRoot() (string, error)

ProjectRoot returns the path to the nearest project root TODO Deprecate if remains unused, removed due to https://github.com/astronomer/astro-cli/issues/103

Types

type Context added in v0.2.2

type Context struct {
	Domain    string `mapstructure:"domain"`
	Workspace string `mapstructure:"workspace"`
	Token     string `mapstructure:"token"`
}

Context represents a single cluster context

func GetCurrentContext added in v0.2.2

func GetCurrentContext() (Context, error)

GetCurrentContext looks up current context and gets cooresponding Context struct

func (Context) ContextExists added in v0.2.2

func (c Context) ContextExists() bool

ContextExists checks if a cluster struct exists in config based on Cluster.Domain Returns a boolean indicating whether or not cluster exists

func (Context) GetAPIURL added in v0.2.2

func (c Context) GetAPIURL() string

GetAPIURL returns full Houston API Url for the provided Context

func (Context) GetAppURL added in v0.4.0

func (c Context) GetAppURL() string

GetAppURL returns full Houston API Url for the provided Context

func (Context) GetContext added in v0.2.2

func (c Context) GetContext() (Context, error)

GetContext gets the full context from the specified Context receiver struct Returns based on Domain prop

func (Context) GetContextKey added in v0.2.2

func (c Context) GetContextKey() (string, error)

GetContextKey allows a cluster domain to be used without interfering with viper's dot (.) notation for fetching configs by replacing with underscores (_)

func (Context) PrintContext added in v0.2.2

func (c Context) PrintContext() error

PrintContext prints current context to stdOut

func (Context) SetContext added in v0.2.2

func (c Context) SetContext() error

SetContext saves Context to the config

func (Context) SetContextKey added in v0.2.2

func (c Context) SetContextKey(key, value string) error

SetContextKey saves a single context key value pair

func (Context) SwitchContext added in v0.2.2

func (c Context) SwitchContext() error

SwitchContext sets the current config context to the one matching the provided Context struct

type Contexts added in v0.2.2

type Contexts struct {
	Contexts map[string]Context `mapstructure:"contexts"`
}

Contexts holds all available Context structs in a map

func (Contexts) GetContexts added in v0.2.2

func (c Contexts) GetContexts() (Contexts, error)

GetContexts gets all contexts currently configured in the global config Returns a Contexts struct containing a map of all Context structs

Jump to

Keyboard shortcuts

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