Documentation
¶
Index ¶
- func ConfigDir() string
- func DataDir() string
- func HomeDirPath(subdir string) (string, error)
- func StateDir() string
- func StubWriteConfig(t *testing.T) func(io.Writer, io.Writer)
- type AliasConfig
- type AuthConfig
- func (c *AuthConfig) DefaultHost() (string, string)
- func (c *AuthConfig) GitProtocol(hostname string) (string, error)
- func (c *AuthConfig) HasEnvToken() bool
- func (c *AuthConfig) Hosts() []string
- func (c *AuthConfig) Login(hostname, username, token, gitProtocol string, secureStorage bool) error
- func (c *AuthConfig) Logout(hostname string) error
- func (c *AuthConfig) SetDefaultHost(host, source string)
- func (c *AuthConfig) SetHosts(hosts []string)
- func (c *AuthConfig) SetToken(token, source string)
- func (c *AuthConfig) Token(hostname string) (string, string)
- func (c *AuthConfig) TokenFromKeyring(hostname string) (string, error)
- func (c *AuthConfig) User(hostname string) (string, error)
- type Config
- type ConfigMock
- func (mock *ConfigMock) Aliases() *AliasConfig
- func (mock *ConfigMock) AliasesCalls() []struct{}
- func (mock *ConfigMock) Authentication() *AuthConfig
- func (mock *ConfigMock) AuthenticationCalls() []struct{}
- func (mock *ConfigMock) Get(s1 string, s2 string) (string, error)
- func (mock *ConfigMock) GetCalls() []struct{ ... }
- func (mock *ConfigMock) GetOrDefault(s1 string, s2 string) (string, error)
- func (mock *ConfigMock) GetOrDefaultCalls() []struct{ ... }
- func (mock *ConfigMock) Set(s1 string, s2 string, s3 string)
- func (mock *ConfigMock) SetCalls() []struct{ ... }
- func (mock *ConfigMock) Write() error
- func (mock *ConfigMock) WriteCalls() []struct{}
- type ConfigOption
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func HomeDirPath ¶
func StubWriteConfig ¶
StubWriteConfig stubs out the filesystem where config file are written. It then returns a function that will read in the config files into io.Writers. It automatically cleans up environment variables and written files.
Types ¶
type AliasConfig ¶
type AliasConfig struct {
// contains filtered or unexported fields
}
func (*AliasConfig) Add ¶
func (a *AliasConfig) Add(alias, expansion string)
func (*AliasConfig) All ¶
func (a *AliasConfig) All() map[string]string
func (*AliasConfig) Delete ¶
func (a *AliasConfig) Delete(alias string) error
type AuthConfig ¶ added in v2.24.0
type AuthConfig struct {
// contains filtered or unexported fields
}
AuthConfig is used for interacting with some persistent configuration for gh, with knowledge on how to access encrypted storage when neccesarry. Behavior is scoped to authentication specific tasks.
func (*AuthConfig) DefaultHost ¶ added in v2.24.0
func (c *AuthConfig) DefaultHost() (string, string)
func (*AuthConfig) GitProtocol ¶ added in v2.24.0
func (c *AuthConfig) GitProtocol(hostname string) (string, error)
GitProtocol will retrieve the git protocol for the logged in user at the given hostname. If none is set it will return the default value.
func (*AuthConfig) HasEnvToken ¶ added in v2.25.0
func (c *AuthConfig) HasEnvToken() bool
HasEnvToken returns true when a token has been specified in an environment variable, else returns false.
func (*AuthConfig) Hosts ¶ added in v2.24.0
func (c *AuthConfig) Hosts() []string
func (*AuthConfig) Login ¶ added in v2.24.0
func (c *AuthConfig) Login(hostname, username, token, gitProtocol string, secureStorage bool) error
Login will set user, git protocol, and auth token for the given hostname. If the encrypt option is specified it will first try to store the auth token in encrypted storage and will fall back to the plain text config file.
func (*AuthConfig) Logout ¶ added in v2.24.0
func (c *AuthConfig) Logout(hostname string) error
Logout will remove user, git protocol, and auth token for the given hostname. It will remove the auth token from the encrypted storage if it exists there.
func (*AuthConfig) SetDefaultHost ¶ added in v2.24.0
func (c *AuthConfig) SetDefaultHost(host, source string)
SetDefaultHost will override any host resolution and return the given host and source for all calls to DefaultHost. Use for testing purposes only.
func (*AuthConfig) SetHosts ¶ added in v2.24.0
func (c *AuthConfig) SetHosts(hosts []string)
SetHosts will override any hosts resolution and return the given hosts for all calls to Hosts. Use for testing purposes only.
func (*AuthConfig) SetToken ¶ added in v2.24.0
func (c *AuthConfig) SetToken(token, source string)
SetToken will override any token resolution and return the given token and source for all calls to Token. Use for testing purposes only.
func (*AuthConfig) Token ¶ added in v2.24.0
func (c *AuthConfig) Token(hostname string) (string, string)
Token will retrieve the auth token for the given hostname, searching environment variables, plain text config, and lastly encrypted storage.
func (*AuthConfig) TokenFromKeyring ¶ added in v2.24.0
func (c *AuthConfig) TokenFromKeyring(hostname string) (string, error)
TokenFromKeyring will retrieve the auth token for the given hostname, only searching in encrypted storage.
type Config ¶
type Config interface { Get(string, string) (string, error) GetOrDefault(string, string) (string, error) Set(string, string, string) Write() error Aliases() *AliasConfig Authentication() *AuthConfig }
This interface describes interacting with some persistent configuration for gh.
type ConfigMock ¶ added in v2.14.0
type ConfigMock struct { // AliasesFunc mocks the Aliases method. AliasesFunc func() *AliasConfig // AuthenticationFunc mocks the Authentication method. AuthenticationFunc func() *AuthConfig // GetFunc mocks the Get method. GetFunc func(s1 string, s2 string) (string, error) // GetOrDefaultFunc mocks the GetOrDefault method. GetOrDefaultFunc func(s1 string, s2 string) (string, error) // SetFunc mocks the Set method. SetFunc func(s1 string, s2 string, s3 string) // WriteFunc mocks the Write method. WriteFunc func() error // contains filtered or unexported fields }
ConfigMock is a mock implementation of Config.
func TestSomethingThatUsesConfig(t *testing.T) { // make and configure a mocked Config mockedConfig := &ConfigMock{ AliasesFunc: func() *AliasConfig { panic("mock out the Aliases method") }, AuthenticationFunc: func() *AuthConfig { panic("mock out the Authentication method") }, GetFunc: func(s1 string, s2 string) (string, error) { panic("mock out the Get method") }, GetOrDefaultFunc: func(s1 string, s2 string) (string, error) { panic("mock out the GetOrDefault method") }, SetFunc: func(s1 string, s2 string, s3 string) { panic("mock out the Set method") }, WriteFunc: func() error { panic("mock out the Write method") }, } // use mockedConfig in code that requires Config // and then make assertions. }
func NewBlankConfig ¶
func NewBlankConfig() *ConfigMock
func NewFromString ¶
func NewFromString(cfgStr string) *ConfigMock
func (*ConfigMock) Aliases ¶ added in v2.14.0
func (mock *ConfigMock) Aliases() *AliasConfig
Aliases calls AliasesFunc.
func (*ConfigMock) AliasesCalls ¶ added in v2.14.0
func (mock *ConfigMock) AliasesCalls() []struct { }
AliasesCalls gets all the calls that were made to Aliases. Check the length with:
len(mockedConfig.AliasesCalls())
func (*ConfigMock) Authentication ¶ added in v2.24.0
func (mock *ConfigMock) Authentication() *AuthConfig
Authentication calls AuthenticationFunc.
func (*ConfigMock) AuthenticationCalls ¶ added in v2.24.0
func (mock *ConfigMock) AuthenticationCalls() []struct { }
AuthenticationCalls gets all the calls that were made to Authentication. Check the length with:
len(mockedConfig.AuthenticationCalls())
func (*ConfigMock) Get ¶ added in v2.14.0
func (mock *ConfigMock) Get(s1 string, s2 string) (string, error)
Get calls GetFunc.
func (*ConfigMock) GetCalls ¶ added in v2.14.0
func (mock *ConfigMock) GetCalls() []struct { S1 string S2 string }
GetCalls gets all the calls that were made to Get. Check the length with:
len(mockedConfig.GetCalls())
func (*ConfigMock) GetOrDefault ¶ added in v2.14.0
func (mock *ConfigMock) GetOrDefault(s1 string, s2 string) (string, error)
GetOrDefault calls GetOrDefaultFunc.
func (*ConfigMock) GetOrDefaultCalls ¶ added in v2.14.0
func (mock *ConfigMock) GetOrDefaultCalls() []struct { S1 string S2 string }
GetOrDefaultCalls gets all the calls that were made to GetOrDefault. Check the length with:
len(mockedConfig.GetOrDefaultCalls())
func (*ConfigMock) Set ¶ added in v2.14.0
func (mock *ConfigMock) Set(s1 string, s2 string, s3 string)
Set calls SetFunc.
func (*ConfigMock) SetCalls ¶ added in v2.14.0
func (mock *ConfigMock) SetCalls() []struct { S1 string S2 string S3 string }
SetCalls gets all the calls that were made to Set. Check the length with:
len(mockedConfig.SetCalls())
func (*ConfigMock) Write ¶ added in v2.14.0
func (mock *ConfigMock) Write() error
Write calls WriteFunc.
func (*ConfigMock) WriteCalls ¶ added in v2.14.0
func (mock *ConfigMock) WriteCalls() []struct { }
WriteCalls gets all the calls that were made to Write. Check the length with:
len(mockedConfig.WriteCalls())
type ConfigOption ¶
type ConfigOption struct { Key string Description string DefaultValue string AllowedValues []string }
func ConfigOptions ¶
func ConfigOptions() []ConfigOption