config

package
v0.0.0-...-9df870d Latest Latest
Warning

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

Go to latest
Published: Jan 15, 2025 License: MIT Imports: 7 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func LoadYAML

func LoadYAML() ([]byte, error)

LoadYAML reads the configuration file from the environment if specified, falling back to the embedded file.

func ToContext

func ToContext(ctx context.Context, cnf *Config) context.Context

ToContext adds configuration to a context so it can be later fetched using FromContext.

Types

type Config

type Config struct {
	// Fields only used by to the Go wrapper.
	Wrapper struct {
		HomebrewTap string `yaml:"homebrew_tap"` // e.g. "platformsh/tap/platformsh-cli"
		GitHubRepo  string `yaml:"github_repo"`  // e.g. "platformsh/cli"
	}

	Application struct {
		// Fields required for both the PHP and Go applications.
		Name            string `validate:"required"`                           // e.g. "Platform.sh CLI"
		EnvPrefix       string `validate:"required" yaml:"env_prefix"`         // e.g. "PLATFORMSH_CLI_"
		Executable      string `validate:"required"`                           // e.g. "platform"
		Slug            string `validate:"required,ascii"`                     // e.g. "platformsh-cli"
		UserConfigDir   string `validate:"required" yaml:"user_config_dir"`    // e.g. ".platformsh"
		UserStateFile   string `validate:"omitempty" yaml:"user_state_file"`   // defaults to "state.json"
		WritableUserDir string `validate:"omitempty" yaml:"writable_user_dir"` // defaults to UserConfigDir
		TempSubDir      string `validate:"omitempty" yaml:"tmp_sub_dir"`       // defaults to Slug+"-tmp"
	} `validate:"required"`
	Updates struct {
		Check         bool `validate:"omitempty"`                       // defaults to true
		CheckInterval int  `validate:"omitempty" yaml:"check_interval"` // seconds, defaults to 3600
	} `validate:"omitempty"`

	// Fields only needed by the PHP (legacy) CLI, at least for now.
	API struct {
		BaseURL string `validate:"required,url" yaml:"base_url"`  // e.g. "https://api.platform.sh"
		AuthURL string `validate:"omitempty,url" yaml:"auth_url"` // e.g. "https://auth.api.platform.sh"

		OAuth2AuthorizeURL string `validate:"required_without=AuthURL,omitempty,url" yaml:"oauth2_auth_url"`   // e.g. "https://auth.api.platform.sh/oauth2/authorize"
		OAuth2RevokeURL    string `validate:"required_without=AuthURL,omitempty,url" yaml:"oauth2_revoke_url"` // e.g. "https://auth.api.platform.sh/oauth2/revoke"
		OAuth2TokenURL     string `validate:"required_without=AuthURL,omitempty,url" yaml:"oauth2_token_url"`  // e.g. "https://auth.api.platform.sh/oauth2/token"
		CertifierURL       string `validate:"required_without=AuthURL,omitempty,url" yaml:"certifier_url"`     // e.g. "https://ssh.api.platform.sh"
	} `validate:"required"`
	Detection struct {
		GitRemoteName string   `validate:"required" yaml:"git_remote_name"` // e.g. "platform"
		SiteDomains   []string `validate:"required" yaml:"site_domains"`    // e.g. ["platformsh.site", "tst.site"]
	} `validate:"required"`
	Service struct {
		Name                string `validate:"required"`                               // e.g. "Platform.sh"
		EnvPrefix           string `validate:"required" yaml:"env_prefix"`             // e.g. "PLATFORM_"
		ProjectConfigDir    string `validate:"required" yaml:"project_config_dir"`     // e.g. ".platform"
		ProjectConfigFlavor string `validate:"omitempty" yaml:"project_config_flavor"` // default: "platform"
		ConsoleURL          string `validate:"omitempty,url" yaml:"console_url"`       // e.g. "https://console.platform.sh"
		DocsURL             string `validate:"omitempty,url" yaml:"docs_url"`          // e.g. "https://docs.platform.sh"
	} `validate:"required"`
	SSH struct {
		DomainWildcards []string `validate:"required" yaml:"domain_wildcards"` // e.g. ["*.platform.sh"]
	} `validate:"required"`
}

Config provides YAML configuration for the CLI. This includes some translation strings for vendorization or white-label needs.

It is able to parse some of the keys in the legacy CLI's config.yaml file. See: https://github.com/platformsh/legacy-cli/blob/main/config.yaml

func FromContext

func FromContext(ctx context.Context) *Config

FromContext loads configuration that was set using ToContext, and panics if it is not set.

func FromYAML

func FromYAML(b []byte) (*Config, error)

FromYAML parses YAML configuration.

func (*Config) WritableUserDir

func (c *Config) WritableUserDir() (string, error)

WritableUserDir returns the path to a writable user-level directory.

Jump to

Keyboard shortcuts

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