Documentation ¶
Overview ¶
Package configv3 package contains everything related to the CF CLI Configuration.
Index ¶
- Constants
- func ConfigFilePath() string
- func WriteConfig(c *Config) error
- type ColorSetting
- type Config
- func (config *Config) APIVersion() string
- func (config *Config) AccessToken() string
- func (config *Config) AddPlugin(plugin Plugin)
- func (config *Config) AddPluginRepository(name string, url string)
- func (config *Config) BinaryName() string
- func (config *Config) BinaryVersion() string
- func (config *Config) CFPassword() string
- func (config *Config) CFUsername() string
- func (config *Config) ColorEnabled() ColorSetting
- func (config *Config) CreatePluginHome() error
- func (config *Config) CurrentUser() (User, error)
- func (config *Config) CurrentUserName() (string, error)
- func (config *Config) DialTimeout() time.Duration
- func (config *Config) DockerPassword() string
- func (config *Config) Experimental() bool
- func (config *Config) GetPlugin(pluginName string) (Plugin, bool)
- func (config *Config) GetPluginCaseInsensitive(pluginName string) (Plugin, bool)
- func (config *Config) HTTPSProxy() string
- func (config *Config) HasTargetedOrganization() bool
- func (config *Config) HasTargetedSpace() bool
- func (config *Config) IsTTY() bool
- func (config *Config) Locale() string
- func (config *Config) LogLevel() int
- func (config *Config) MinCLIVersion() string
- func (*Config) NOAARequestRetryCount() int
- func (config *Config) OverallPollingTimeout() time.Duration
- func (config *Config) PluginHome() string
- func (config *Config) PluginRepositories() []PluginRepository
- func (config *Config) Plugins() []Plugin
- func (config *Config) PollingInterval() time.Duration
- func (config *Config) RefreshToken() string
- func (config *Config) RemovePlugin(pluginName string)
- func (*Config) RequestRetryCount() int
- func (config *Config) RoutingEndpoint() string
- func (config *Config) SSHOAuthClient() string
- func (config *Config) SetAccessToken(accessToken string)
- func (config *Config) SetMinCLIVersion(minVersion string)
- func (config *Config) SetOrganizationInformation(guid string, name string)
- func (config *Config) SetRefreshToken(refreshToken string)
- func (config *Config) SetSpaceInformation(guid string, name string, allowSSH bool)
- func (config *Config) SetTargetInformation(api string, apiVersion string, auth string, minCLIVersion string, ...)
- func (config *Config) SetTokenInformation(accessToken string, refreshToken string, sshOAuthClient string)
- func (config *Config) SetUAAClientCredentials(client string, clientSecret string)
- func (config *Config) SetUAAEndpoint(uaaEndpoint string)
- func (config *Config) SetUAAGrantType(uaaGrantType string)
- func (config *Config) SkipSSLValidation() bool
- func (config *Config) StagingTimeout() time.Duration
- func (config *Config) StartupTimeout() time.Duration
- func (config *Config) Target() string
- func (config *Config) TargetedOrganization() Organization
- func (config *Config) TargetedOrganizationName() string
- func (config *Config) TargetedSpace() Space
- func (config *Config) TerminalWidth() int
- func (*Config) UAADisableKeepAlives() bool
- func (config *Config) UAAGrantType() string
- func (config *Config) UAAOAuthClient() string
- func (config *Config) UAAOAuthClientSecret() string
- func (config *Config) UnsetOrganizationAndSpaceInformation()
- func (config *Config) UnsetSpaceInformation()
- func (config *Config) UnsetUserInformation()
- func (config *Config) V7SetSpaceInformation(guid string, name string)
- func (config *Config) Verbose() (bool, []string)
- func (config *Config) WritePluginConfig() error
- type EnvOverride
- type FlagOverride
- type JSONConfig
- type Organization
- type Plugin
- type PluginCommand
- type PluginRepository
- type PluginUsageDetails
- type PluginVersion
- type PluginsConfig
- type QuotaDefinition
- type Space
- type User
Constants ¶
const ( // DefaultDialTimeout is the default timeout for the dail. DefaultDialTimeout = 5 * time.Second // DefaultNOAARetryCount is the default number of request retries. DefaultNOAARetryCount = 5 // DefaultOverallPollingTimeout is the default maximum time that the CLI will // poll a job running on the Cloud Controller. By default it's infinite, // which is represented by MaxInt64. DefaultOverallPollingTimeout = time.Duration(1 << 62) // DefaultPollingInterval is the time between consecutive polls of a status. DefaultPollingInterval = 3 * time.Second // DefaultStagingTimeout is the default timeout for application staging. DefaultStagingTimeout = 15 * time.Minute // DefaultStartupTimeout is the default timeout for application starting. DefaultStartupTimeout = 5 * time.Minute // DefaultTarget is the default CFConfig value for Target. DefaultTarget = "" // DefaultSSHOAuthClient is the default oauth client ID for SSHing into an // application/process container DefaultSSHOAuthClient = "ssh-proxy" // DefaultUAADisableKeepAlives is the default value that the UAA client will // use for Transport.DisableKeepAlives. UAA connections should always be // closed after every request because UAA communication is infrequent. DefaultUAADisableKeepAlives = true // DefaultUAAOAuthClient is the default client ID for the CLI when // communicating with the UAA. DefaultUAAOAuthClient = "cf" // DefaultUAAOAuthClientSecret is the default client secret for the CLI when // communicating with the UAA. DefaultUAAOAuthClientSecret = "" // DefaultRetryCount is the default number of request retries. DefaultRetryCount = 2 )
const ( // DefaultPluginRepoName is the name of the preinstalled plugin repository. DefaultPluginRepoName = "CF-Community" // DefaultPluginRepoURL is the URL of the preinstalled plugin repository. DefaultPluginRepoURL = "https://plugins.cloudfoundry.org" )
const (
// DefaultLocale is the default CFConfig value for Locale.
DefaultLocale = ""
)
Variables ¶
This section is empty.
Functions ¶
func ConfigFilePath ¶
func ConfigFilePath() string
ConfigFilePath returns the location of the config file
func WriteConfig ¶
WriteConfig creates the .cf directory and then writes the config.json. The location of .cf directory is written in the same way LoadConfig reads .cf directory.
Types ¶
type ColorSetting ¶
type ColorSetting int
ColorSetting is a trinary operator that represents if the display should have colors enabled, disabled, or automatically detected.
const ( // DefaultColorEnabled is the default CFConfig value for ColorEnabled. DefaultColorEnabled = "" // ColorDisabled means that no colors/bolding will be displayed. ColorDisabled ColorSetting = iota // ColorEnabled means colors/bolding will be displayed. ColorEnabled // ColorAuto means that the UI should decide if colors/bolding will be // enabled. ColorAuto )
type Config ¶
type Config struct { // ConfigFile stores the configuration from the .cf/config ConfigFile JSONConfig // ENV stores the configuration from os.ENV ENV EnvOverride // Flags stores the configuration from gobal flags Flags FlagOverride // contains filtered or unexported fields }
Config combines the settings taken from the .cf/config.json, os.ENV, and the plugin config.
func LoadConfig ¶
func LoadConfig(flags ...FlagOverride) (*Config, error)
LoadConfig loads the config from the .cf/config.json and os.ENV. If the config.json does not exists, it will use a default config in it's place. Takes in an optional FlagOverride, will only use the first one passed, that can override the given flag values.
The '.cf' directory will be read in one of the following locations on UNIX Systems:
- $CF_HOME/.cf if $CF_HOME is set
- $HOME/.cf as the default
The '.cf' directory will be read in one of the following locations on Windows Systems:
- CF_HOME\.cf if CF_HOME is set
- HOMEDRIVE\HOMEPATH\.cf if HOMEDRIVE or HOMEPATH is set
- USERPROFILE\.cf as the default
func (*Config) APIVersion ¶
APIVersion returns the CC API Version.
func (*Config) AccessToken ¶
AccessToken returns the access token for making authenticated API calls.
func (*Config) AddPluginRepository ¶
AddPluginRepository adds an new repository to the plugin config. It does not add duplicates to the config.
func (*Config) BinaryName ¶
BinaryName returns the running name of the CF CLI
func (*Config) BinaryVersion ¶
BinaryVersion is the current version of the CF binary.
func (*Config) CFPassword ¶
CFPassword returns the value of the "CF_PASSWORD" environment variable.
func (*Config) CFUsername ¶
CFUsername returns the value of the "CF_USERNAME" environment variable.
func (*Config) ColorEnabled ¶
func (config *Config) ColorEnabled() ColorSetting
ColorEnabled returns the color setting based off:
- The $CF_COLOR environment variable if set (0/1/t/f/true/false)
- The 'ColorEnabled' value in the .cf/config.json if set
- Defaults to ColorAuto if nothing is set
func (*Config) CreatePluginHome ¶
func (*Config) CurrentUser ¶
CurrentUser returns user information decoded from the JWT access token in .cf/config.json.
func (*Config) CurrentUserName ¶
CurrentUserName returns the name of a user as returned by CurrentUser()
func (*Config) DialTimeout ¶
DialTimeout returns the timeout to use when dialing. This is based off of:
- The $CF_DIAL_TIMEOUT environment variable if set
- Defaults to 5 seconds
func (*Config) DockerPassword ¶
DockerPassword returns the docker password from the environment.
func (*Config) Experimental ¶
Experimental returns whether or not to run experimental CLI commands. This is based on the following:
- The $CF_CLI_EXPERIMENTAL environment variable if set
- Defaults to false
func (*Config) GetPluginCaseInsensitive ¶
GetPluginCaseInsensitive finds the first matching plugin name case insensitive and returns true if it exists.
func (*Config) HTTPSProxy ¶
HTTPSProxy returns the proxy url that the CLI should use. The url is based off of:
- The $https_proxy environment variable if set
- Defaults to the empty string
func (*Config) HasTargetedOrganization ¶
HasTargetedOrganization returns true if the organization is set.
func (*Config) HasTargetedSpace ¶
HasTargetedSpace returns true if the space is set.
func (*Config) IsTTY ¶
IsTTY returns true based off of:
- The $FORCE_TTY is set to true/t/1
- Detected from the STDOUT stream
func (*Config) Locale ¶
Locale returns the locale/language the UI should be displayed in. This value is based off of:
- The 'Locale' setting in the .cf/config.json
- The $LC_ALL environment variable if set
- The $LANG environment variable if set
- Defaults to DefaultLocale
func (*Config) LogLevel ¶
LogLevel returns the global log level. The levels follow Logrus's log level scheme. This value is based off of:
- The $CF_LOG_LEVEL and an int/warn/info/etc...
- Defaults to PANIC/0 (ie no logging)
func (*Config) MinCLIVersion ¶
MinCLIVersion returns the minimum CLI version required by the CC.
func (*Config) NOAARequestRetryCount ¶
NOAARequestRetryCount returns the number of request retries.
func (*Config) OverallPollingTimeout ¶
OverallPollingTimeout returns the overall polling timeout for async operations. The time is based off of:
- The config file's AsyncTimeout value (integer) is > 0
- Defaults to the DefaultOverallPollingTimeout
func (*Config) PluginHome ¶
PluginHome returns the plugin configuration directory to:
- The $CF_PLUGIN_HOME/.cf/plugins environment variable if set
- Defaults to the home directory (outlined in LoadConfig)/.cf/plugins
func (*Config) PluginRepositories ¶
func (config *Config) PluginRepositories() []PluginRepository
PluginRepositories returns the currently configured plugin repositories from the .cf/config.json.
func (*Config) Plugins ¶
Plugins returns installed plugins from the config sorted by name (case-insensitive).
func (*Config) PollingInterval ¶
PollingInterval returns the time between polls.
func (*Config) RefreshToken ¶
RefreshToken returns the refresh token for getting a new access token.
func (*Config) RemovePlugin ¶
RemovePlugin removes the specified plugin from PluginsConfig idempotently
func (*Config) RequestRetryCount ¶
RequestRetryCount returns the number of request retries.
func (*Config) RoutingEndpoint ¶
RoutingEndpoint returns the endpoint for the router API
func (*Config) SSHOAuthClient ¶
SSHOAuthClient returns the OAuth client id used for SSHing into application/process containers.
func (*Config) SetAccessToken ¶
SetAccessToken sets the current access token.
func (*Config) SetMinCLIVersion ¶
SetMinCLIVersion sets the minimum CLI version required by the CC.
func (*Config) SetOrganizationInformation ¶
SetOrganizationInformation sets the currently targeted organization.
func (*Config) SetRefreshToken ¶
SetRefreshToken sets the current refresh token.
func (*Config) SetSpaceInformation ¶
SetSpaceInformation sets the currently targeted space. The "AllowSSH" field is not returned by v3, and is never read from the config. Persist `true` to maintain compatibility in the config file. TODO: this field should be removed entirely in v7
func (*Config) SetTargetInformation ¶
func (config *Config) SetTargetInformation(api string, apiVersion string, auth string, minCLIVersion string, doppler string, routing string, skipSSLValidation bool)
SetTargetInformation sets the currently targeted CC API and related other related API URLs.
func (*Config) SetTokenInformation ¶
func (config *Config) SetTokenInformation(accessToken string, refreshToken string, sshOAuthClient string)
SetTokenInformation sets the current token/user information.
func (*Config) SetUAAClientCredentials ¶
SetUAAClientCredentials sets the client credentials.
func (*Config) SetUAAEndpoint ¶
SetUAAEndpoint sets the UAA endpoint that is obtained from hitting <AuthorizationEndpoint>/login.
func (*Config) SetUAAGrantType ¶
SetUAAGrantType sets the UAA grant type for logging in and refreshing the token.
func (*Config) SkipSSLValidation ¶
SkipSSLValidation returns whether or not to skip SSL validation when targeting an API endpoint.
func (*Config) StagingTimeout ¶
StagingTimeout returns the max time an application staging should take. The time is based off of:
- The $CF_STAGING_TIMEOUT environment variable if set
- Defaults to the DefaultStagingTimeout
func (*Config) StartupTimeout ¶
StartupTimeout returns the max time an application should take to start. The time is based off of:
- The $CF_STARTUP_TIMEOUT environment variable if set
- Defaults to the DefaultStartupTimeout
func (*Config) TargetedOrganization ¶
func (config *Config) TargetedOrganization() Organization
TargetedOrganization returns the currently targeted organization.
func (*Config) TargetedOrganizationName ¶
TargetedOrganizationName returns the name of the targeted organization.
func (*Config) TargetedSpace ¶
TargetedSpace returns the currently targeted space.
func (*Config) TerminalWidth ¶
TerminalWidth returns the width of the terminal from when the config was loaded. If the terminal width has changed since the config has loaded, it will **not** return the new width.
func (*Config) UAADisableKeepAlives ¶
UAADisableKeepAlives returns true when TCP connections should not be reused for UAA.
func (*Config) UAAGrantType ¶
UAAGrantType returns the grant type of the supplied UAA credentials.
func (*Config) UAAOAuthClient ¶
UAAOAuthClient returns the CLI's UAA client ID.
func (*Config) UAAOAuthClientSecret ¶
UAAOAuthClientSecret returns the CLI's UAA client secret.
func (*Config) UnsetOrganizationAndSpaceInformation ¶
func (config *Config) UnsetOrganizationAndSpaceInformation()
UnsetOrganizationAndSpaceInformation resets the organization and space values to default.
func (*Config) UnsetSpaceInformation ¶
func (config *Config) UnsetSpaceInformation()
UnsetSpaceInformation resets the space values to default.
func (*Config) UnsetUserInformation ¶
func (config *Config) UnsetUserInformation()
UnsetUserInformation resets the access token, refresh token, UAA grant type, UAA client credentials, and targeted org/space information.
func (*Config) V7SetSpaceInformation ¶
V7SetSpaceInformation sets the currently targeted space.
func (*Config) Verbose ¶
Verbose returns true if verbose should be displayed to terminal, in addition a slice of absolute paths in which verbose text will appear. This is based off of:
- The config file's trace value (true/false/file path)
- The $CF_TRACE environment variable if set (true/false/file path)
- The '-v/--verbose' global flag
- Defaults to false
func (*Config) WritePluginConfig ¶
WritePluginConfig writes the plugin config to config.json in the plugin home directory.
type EnvOverride ¶
type EnvOverride struct { BinaryName string CFColor string CFDialTimeout string CFHome string CFLogLevel string CFPassword string CFPluginHome string CFStagingTimeout string CFStartupTimeout string CFTrace string CFUsername string DockerPassword string Experimental string ForceTTY string HTTPSProxy string Lang string LCAll string }
EnvOverride represents all the environment variables read by the CF CLI
type FlagOverride ¶
type FlagOverride struct {
Verbose bool
}
FlagOverride represents all the global flags passed to the CF CLI
type JSONConfig ¶
type JSONConfig struct { ConfigVersion int `json:"ConfigVersion"` Target string `json:"Target"` APIVersion string `json:"APIVersion"` AuthorizationEndpoint string `json:"AuthorizationEndpoint"` DopplerEndpoint string `json:"DopplerEndPoint"` UAAEndpoint string `json:"UaaEndpoint"` RoutingEndpoint string `json:"RoutingAPIEndpoint"` AccessToken string `json:"AccessToken"` SSHOAuthClient string `json:"SSHOAuthClient"` UAAOAuthClient string `json:"UAAOAuthClient"` UAAOAuthClientSecret string `json:"UAAOAuthClientSecret"` UAAGrantType string `json:"UAAGrantType"` RefreshToken string `json:"RefreshToken"` TargetedOrganization Organization `json:"OrganizationFields"` TargetedSpace Space `json:"SpaceFields"` SkipSSLValidation bool `json:"SSLDisabled"` AsyncTimeout int `json:"AsyncTimeout"` Trace string `json:"Trace"` ColorEnabled string `json:"ColorEnabled"` Locale string `json:"Locale"` PluginRepositories []PluginRepository `json:"PluginRepos"` MinCLIVersion string `json:"MinCLIVersion"` MinRecommendedCLIVersion string `json:"MinRecommendedCLIVersion"` }
JSONConfig represents .cf/config.json.
type Organization ¶
type Organization struct { GUID string `json:"GUID"` Name string `json:"Name"` QuotaDefinition QuotaDefinition `json:"QuotaDefinition"` }
Organization contains basic information about the targeted organization.
type Plugin ¶
type Plugin struct { Name string Location string `json:"Location"` Version PluginVersion `json:"Version"` Commands []PluginCommand `json:"Commands"` }
Plugin represents the plugin as a whole, not be confused with PluginCommand
func (Plugin) CalculateSHA1 ¶
CalculateSHA1 returns the SHA1 value of the plugin executable. If an error is encountered calculating SHA1, N/A is returned
func (Plugin) PluginCommands ¶
func (p Plugin) PluginCommands() []PluginCommand
PluginCommands returns the plugin's commands sorted by command name.
type PluginCommand ¶
type PluginCommand struct { Name string `json:"Name"` Alias string `json:"Alias"` HelpText string `json:"HelpText"` UsageDetails PluginUsageDetails `json:"UsageDetails"` }
PluginCommand represents an individual command inside a plugin
func (PluginCommand) CommandName ¶
func (c PluginCommand) CommandName() string
CommandName returns the name of the plugin. The name is concatenated with alias if alias is specified.
type PluginRepository ¶
PluginRepository is a saved plugin repository
type PluginUsageDetails ¶
type PluginUsageDetails struct { Usage string `json:"Usage"` Options map[string]string `json:"Options"` }
PluginUsageDetails contains the usage metadata provided by the plugin
type PluginVersion ¶
type PluginVersion struct { Major int `json:"Major"` Minor int `json:"Minor"` Build int `json:"Build"` }
PluginVersion is the plugin version information
func (PluginVersion) String ¶
func (v PluginVersion) String() string
String returns the plugin's version in the format x.y.z.
type PluginsConfig ¶
PluginsConfig represents the plugin configuration
type QuotaDefinition ¶
type QuotaDefinition struct { GUID string `json:"guid"` Name string `json:"name"` MemoryLimit int `json:"memory_limit"` InstanceMemoryLimit int `json:"instance_memory_limit"` TotalRoutes int `json:"total_routes"` TotalServices int `json:"total_services"` NonBasicServicesAllowed bool `json:"non_basic_services_allowed"` AppInstanceLimit int `json:"app_instance_limit"` TotalReservedRoutePorts int `json:"total_reserved_route_ports"` }
QuotaDefinition contains information about the organization's quota.