undo overzealous find/replace
This commit is contained in:
parent
56522f9f14
commit
0a619d422a
18 changed files with 39 additions and 32 deletions
|
|
@ -22,10 +22,10 @@ hosts:
|
||||||
`, "")()
|
`, "")()
|
||||||
config, err := parseConfig("config.yml")
|
config, err := parseConfig("config.yml")
|
||||||
assert.NoError(t, err)
|
assert.NoError(t, err)
|
||||||
user, err := config.GetOrDefault("github.com", "user")
|
user, err := config.Get("github.com", "user")
|
||||||
assert.NoError(t, err)
|
assert.NoError(t, err)
|
||||||
assert.Equal(t, "monalisa", user)
|
assert.Equal(t, "monalisa", user)
|
||||||
token, err := config.GetOrDefault("github.com", "oauth_token")
|
token, err := config.Get("github.com", "oauth_token")
|
||||||
assert.NoError(t, err)
|
assert.NoError(t, err)
|
||||||
assert.Equal(t, "OTOKEN", token)
|
assert.Equal(t, "OTOKEN", token)
|
||||||
}
|
}
|
||||||
|
|
@ -42,10 +42,10 @@ hosts:
|
||||||
`, "")()
|
`, "")()
|
||||||
config, err := parseConfig("config.yml")
|
config, err := parseConfig("config.yml")
|
||||||
assert.NoError(t, err)
|
assert.NoError(t, err)
|
||||||
user, err := config.GetOrDefault("github.com", "user")
|
user, err := config.Get("github.com", "user")
|
||||||
assert.NoError(t, err)
|
assert.NoError(t, err)
|
||||||
assert.Equal(t, "monalisa", user)
|
assert.Equal(t, "monalisa", user)
|
||||||
token, err := config.GetOrDefault("github.com", "oauth_token")
|
token, err := config.Get("github.com", "oauth_token")
|
||||||
assert.NoError(t, err)
|
assert.NoError(t, err)
|
||||||
assert.Equal(t, "OTOKEN", token)
|
assert.Equal(t, "OTOKEN", token)
|
||||||
}
|
}
|
||||||
|
|
@ -58,10 +58,10 @@ github.com:
|
||||||
`)()
|
`)()
|
||||||
config, err := parseConfig("config.yml")
|
config, err := parseConfig("config.yml")
|
||||||
assert.NoError(t, err)
|
assert.NoError(t, err)
|
||||||
user, err := config.GetOrDefault("github.com", "user")
|
user, err := config.Get("github.com", "user")
|
||||||
assert.NoError(t, err)
|
assert.NoError(t, err)
|
||||||
assert.Equal(t, "monalisa", user)
|
assert.Equal(t, "monalisa", user)
|
||||||
token, err := config.GetOrDefault("github.com", "oauth_token")
|
token, err := config.Get("github.com", "oauth_token")
|
||||||
assert.NoError(t, err)
|
assert.NoError(t, err)
|
||||||
assert.Equal(t, "OTOKEN", token)
|
assert.Equal(t, "OTOKEN", token)
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -62,7 +62,7 @@ func Test_defaultConfig(t *testing.T) {
|
||||||
assert.NoError(t, err)
|
assert.NoError(t, err)
|
||||||
assert.Equal(t, "https", proto)
|
assert.Equal(t, "https", proto)
|
||||||
|
|
||||||
editor, err := cfg.GetOrDefault("", "editor")
|
editor, err := cfg.Get("", "editor")
|
||||||
assert.NoError(t, err)
|
assert.NoError(t, err)
|
||||||
assert.Equal(t, "", editor)
|
assert.Equal(t, "", editor)
|
||||||
|
|
||||||
|
|
@ -72,7 +72,7 @@ func Test_defaultConfig(t *testing.T) {
|
||||||
expansion, _ := aliases.Get("co")
|
expansion, _ := aliases.Get("co")
|
||||||
assert.Equal(t, expansion, "pr checkout")
|
assert.Equal(t, expansion, "pr checkout")
|
||||||
|
|
||||||
browser, err := cfg.GetOrDefault("", "browser")
|
browser, err := cfg.Get("", "browser")
|
||||||
assert.NoError(t, err)
|
assert.NoError(t, err)
|
||||||
assert.Equal(t, "", browser)
|
assert.Equal(t, "", browser)
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -301,11 +301,11 @@ func TestInheritEnv(t *testing.T) {
|
||||||
hosts, _ := cfg.Hosts()
|
hosts, _ := cfg.Hosts()
|
||||||
assert.Equal(t, tt.wants.hosts, hosts)
|
assert.Equal(t, tt.wants.hosts, hosts)
|
||||||
|
|
||||||
val, source, _ := cfg.GetOrDefaultWithSource(tt.hostname, "oauth_token")
|
val, source, _ := cfg.GetWithSource(tt.hostname, "oauth_token")
|
||||||
assert.Equal(t, tt.wants.token, val)
|
assert.Equal(t, tt.wants.token, val)
|
||||||
assert.Regexp(t, tt.wants.source, source)
|
assert.Regexp(t, tt.wants.source, source)
|
||||||
|
|
||||||
val, _ = cfg.GetOrDefault(tt.hostname, "oauth_token")
|
val, _ = cfg.Get(tt.hostname, "oauth_token")
|
||||||
assert.Equal(t, tt.wants.token, val)
|
assert.Equal(t, tt.wants.token, val)
|
||||||
|
|
||||||
err := cfg.CheckWriteable(tt.hostname, "oauth_token")
|
err := cfg.CheckWriteable(tt.hostname, "oauth_token")
|
||||||
|
|
|
||||||
|
|
@ -14,7 +14,7 @@ import (
|
||||||
const tokenUser = "x-access-token"
|
const tokenUser = "x-access-token"
|
||||||
|
|
||||||
type config interface {
|
type config interface {
|
||||||
GetOrDefaultWithSource(string, string) (string, string, error)
|
GetWithSource(string, string) (string, string, error)
|
||||||
}
|
}
|
||||||
|
|
||||||
type CredentialOptions struct {
|
type CredentialOptions struct {
|
||||||
|
|
@ -101,11 +101,11 @@ func helperRun(opts *CredentialOptions) error {
|
||||||
}
|
}
|
||||||
|
|
||||||
var gotUser string
|
var gotUser string
|
||||||
gotToken, source, _ := cfg.GetOrDefaultWithSource(wants["host"], "oauth_token")
|
gotToken, source, _ := cfg.GetWithSource(wants["host"], "oauth_token")
|
||||||
if strings.HasSuffix(source, "_TOKEN") {
|
if strings.HasSuffix(source, "_TOKEN") {
|
||||||
gotUser = tokenUser
|
gotUser = tokenUser
|
||||||
} else {
|
} else {
|
||||||
gotUser, _, _ = cfg.GetOrDefaultWithSource(wants["host"], "user")
|
gotUser, _, _ = cfg.GetWithSource(wants["host"], "user")
|
||||||
}
|
}
|
||||||
|
|
||||||
if gotUser == "" || gotToken == "" {
|
if gotUser == "" || gotToken == "" {
|
||||||
|
|
|
||||||
|
|
@ -11,12 +11,12 @@ import (
|
||||||
// why not just use the config stub argh
|
// why not just use the config stub argh
|
||||||
type tinyConfig map[string]string
|
type tinyConfig map[string]string
|
||||||
|
|
||||||
func (c tinyConfig) GetOrDefaultWithSource(host, key string) (string, string, error) {
|
func (c tinyConfig) GetWithSource(host, key string) (string, string, error) {
|
||||||
return c[fmt.Sprintf("%s:%s", host, key)], c["_source"], nil
|
return c[fmt.Sprintf("%s:%s", host, key)], c["_source"], nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func (c tinyConfig) GetOrDefault(host, key string) (val string, err error) {
|
func (c tinyConfig) Get(host, key string) (val string, err error) {
|
||||||
val, _, err = c.GetOrDefaultWithSource(host, key)
|
val, _, err = c.GetWithSource(host, key)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -165,7 +165,7 @@ func loginRun(opts *LoginOptions) error {
|
||||||
return cfg.Write()
|
return cfg.Write()
|
||||||
}
|
}
|
||||||
|
|
||||||
existingToken, _ := cfg.GetOrDefault(hostname, "oauth_token")
|
existingToken, _ := cfg.Get(hostname, "oauth_token")
|
||||||
if existingToken != "" && opts.Interactive {
|
if existingToken != "" && opts.Interactive {
|
||||||
if err := shared.HasMinimumScopes(httpClient, hostname, existingToken); err == nil {
|
if err := shared.HasMinimumScopes(httpClient, hostname, existingToken); err == nil {
|
||||||
var keepGoing bool
|
var keepGoing bool
|
||||||
|
|
|
||||||
|
|
@ -127,7 +127,7 @@ func logoutRun(opts *LogoutOptions) error {
|
||||||
if err != nil {
|
if err != nil {
|
||||||
// suppressing; the user is trying to delete this token and it might be bad.
|
// suppressing; the user is trying to delete this token and it might be bad.
|
||||||
// we'll see if the username is in the config and fall back to that.
|
// we'll see if the username is in the config and fall back to that.
|
||||||
username, _ = cfg.GetOrDefault(hostname, "user")
|
username, _ = cfg.Get(hostname, "user")
|
||||||
}
|
}
|
||||||
|
|
||||||
usernameStr := ""
|
usernameStr := ""
|
||||||
|
|
|
||||||
|
|
@ -132,7 +132,7 @@ func refreshRun(opts *RefreshOptions) error {
|
||||||
}
|
}
|
||||||
|
|
||||||
var additionalScopes []string
|
var additionalScopes []string
|
||||||
if oldToken, _ := cfg.GetOrDefault(hostname, "oauth_token"); oldToken != "" {
|
if oldToken, _ := cfg.Get(hostname, "oauth_token"); oldToken != "" {
|
||||||
if oldScopes, err := shared.GetScopes(opts.httpClient, hostname, oldToken); err == nil {
|
if oldScopes, err := shared.GetScopes(opts.httpClient, hostname, oldToken); err == nil {
|
||||||
for _, s := range strings.Split(oldScopes, ",") {
|
for _, s := range strings.Split(oldScopes, ",") {
|
||||||
s = strings.TrimSpace(s)
|
s = strings.TrimSpace(s)
|
||||||
|
|
@ -159,8 +159,8 @@ func refreshRun(opts *RefreshOptions) error {
|
||||||
}
|
}
|
||||||
|
|
||||||
if credentialFlow.ShouldSetup() {
|
if credentialFlow.ShouldSetup() {
|
||||||
username, _ := cfg.GetOrDefault(hostname, "user")
|
username, _ := cfg.Get(hostname, "user")
|
||||||
password, _ := cfg.GetOrDefault(hostname, "oauth_token")
|
password, _ := cfg.Get(hostname, "oauth_token")
|
||||||
if err := credentialFlow.Setup(hostname, username, password); err != nil {
|
if err := credentialFlow.Setup(hostname, username, password); err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -15,7 +15,7 @@ import (
|
||||||
)
|
)
|
||||||
|
|
||||||
type iconfig interface {
|
type iconfig interface {
|
||||||
GetOrDefault(string, string) (string, error)
|
Get(string, string) (string, error)
|
||||||
Set(string, string, string) error
|
Set(string, string, string) error
|
||||||
Write() error
|
Write() error
|
||||||
}
|
}
|
||||||
|
|
@ -147,7 +147,7 @@ func Login(opts *LoginOptions) error {
|
||||||
|
|
||||||
var username string
|
var username string
|
||||||
if userValidated {
|
if userValidated {
|
||||||
username, _ = cfg.GetOrDefault(hostname, "user")
|
username, _ = cfg.Get(hostname, "user")
|
||||||
} else {
|
} else {
|
||||||
apiClient := api.NewClientFromHTTP(httpClient)
|
apiClient := api.NewClientFromHTTP(httpClient)
|
||||||
var err error
|
var err error
|
||||||
|
|
|
||||||
|
|
@ -17,7 +17,7 @@ import (
|
||||||
|
|
||||||
type tinyConfig map[string]string
|
type tinyConfig map[string]string
|
||||||
|
|
||||||
func (c tinyConfig) GetOrDefault(host, key string) (string, error) {
|
func (c tinyConfig) Get(host, key string) (string, error) {
|
||||||
return c[fmt.Sprintf("%s:%s", host, key)], nil
|
return c[fmt.Sprintf("%s:%s", host, key)], nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -92,7 +92,7 @@ func statusRun(opts *StatusOptions) error {
|
||||||
}
|
}
|
||||||
isHostnameFound = true
|
isHostnameFound = true
|
||||||
|
|
||||||
token, tokenSource, _ := cfg.GetOrDefaultWithSource(hostname, "oauth_token")
|
token, tokenSource, _ := cfg.GetWithSource(hostname, "oauth_token")
|
||||||
tokenIsWriteable := cfg.CheckWriteable(hostname, "oauth_token") == nil
|
tokenIsWriteable := cfg.CheckWriteable(hostname, "oauth_token") == nil
|
||||||
|
|
||||||
statusInfo[hostname] = []string{}
|
statusInfo[hostname] = []string{}
|
||||||
|
|
|
||||||
|
|
@ -117,6 +117,8 @@ func Test_getRun(t *testing.T) {
|
||||||
assert.Equal(t, tt.stderr, stderr.String())
|
assert.Equal(t, tt.stderr, stderr.String())
|
||||||
_, err = tt.input.Config.GetOrDefault("", "_written")
|
_, err = tt.input.Config.GetOrDefault("", "_written")
|
||||||
assert.Error(t, err)
|
assert.Error(t, err)
|
||||||
|
_, err = tt.input.Config.Get("", "_written")
|
||||||
|
assert.Error(t, err)
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -113,7 +113,7 @@ func browserLauncher(f *cmdutil.Factory) string {
|
||||||
|
|
||||||
cfg, err := f.Config()
|
cfg, err := f.Config()
|
||||||
if err == nil {
|
if err == nil {
|
||||||
if cfgBrowser, _ := cfg.GetOrDefault("", "browser"); cfgBrowser != "" {
|
if cfgBrowser, _ := cfg.Get("", "browser"); cfgBrowser != "" {
|
||||||
return cfgBrowser
|
return cfgBrowser
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
@ -230,7 +230,7 @@ func ioStreams(f *cmdutil.Factory) *iostreams.IOStreams {
|
||||||
// 3. PAGER
|
// 3. PAGER
|
||||||
if ghPager, ghPagerExists := os.LookupEnv("GH_PAGER"); ghPagerExists {
|
if ghPager, ghPagerExists := os.LookupEnv("GH_PAGER"); ghPagerExists {
|
||||||
io.SetPager(ghPager)
|
io.SetPager(ghPager)
|
||||||
} else if pager, _ := cfg.GetOrDefault("", "pager"); pager != "" {
|
} else if pager, _ := cfg.Get("", "pager"); pager != "" {
|
||||||
io.SetPager(pager)
|
io.SetPager(pager)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -55,6 +55,7 @@ var timezoneNames = map[int]string{
|
||||||
|
|
||||||
type configGetter interface {
|
type configGetter interface {
|
||||||
GetOrDefault(string, string) (string, error)
|
GetOrDefault(string, string) (string, error)
|
||||||
|
Get(string, string) (string, error)
|
||||||
}
|
}
|
||||||
|
|
||||||
// generic authenticated HTTP client for commands
|
// generic authenticated HTTP client for commands
|
||||||
|
|
@ -73,7 +74,7 @@ func NewHTTPClient(io *iostreams.IOStreams, cfg configGetter, appVersion string,
|
||||||
// which would use that non-default behavior is right here, and it doesn't
|
// which would use that non-default behavior is right here, and it doesn't
|
||||||
// seem worth the cognitive overhead everywhere else just to serve this one
|
// seem worth the cognitive overhead everywhere else just to serve this one
|
||||||
// use case.
|
// use case.
|
||||||
unixSocket, err := cfg.GetOrDefault("", "http_unix_socket")
|
unixSocket, err := cfg.Get("", "http_unix_socket")
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
|
|
@ -92,7 +93,7 @@ func NewHTTPClient(io *iostreams.IOStreams, cfg configGetter, appVersion string,
|
||||||
api.AddHeader("User-Agent", fmt.Sprintf("GitHub CLI %s", appVersion)),
|
api.AddHeader("User-Agent", fmt.Sprintf("GitHub CLI %s", appVersion)),
|
||||||
api.AddHeaderFunc("Authorization", func(req *http.Request) (string, error) {
|
api.AddHeaderFunc("Authorization", func(req *http.Request) (string, error) {
|
||||||
hostname := ghinstance.NormalizeHostname(getHost(req))
|
hostname := ghinstance.NormalizeHostname(getHost(req))
|
||||||
if token, err := cfg.GetOrDefault(hostname, "oauth_token"); err == nil && token != "" {
|
if token, err := cfg.Get(hostname, "oauth_token"); err == nil && token != "" {
|
||||||
return fmt.Sprintf("token %s", token), nil
|
return fmt.Sprintf("token %s", token), nil
|
||||||
}
|
}
|
||||||
return "", nil
|
return "", nil
|
||||||
|
|
|
||||||
|
|
@ -161,6 +161,10 @@ func (c tinyConfig) GetOrDefault(host, key string) (string, error) {
|
||||||
return c[fmt.Sprintf("%s:%s", host, key)], nil
|
return c[fmt.Sprintf("%s:%s", host, key)], nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func (c tinyConfig) Get(host, key string) (string, error) {
|
||||||
|
return c[fmt.Sprintf("%s:%s", host, key)], nil
|
||||||
|
}
|
||||||
|
|
||||||
var requestAtRE = regexp.MustCompile(`(?m)^\* Request at .+`)
|
var requestAtRE = regexp.MustCompile(`(?m)^\* Request at .+`)
|
||||||
var dateRE = regexp.MustCompile(`(?m)^< Date: .+`)
|
var dateRE = regexp.MustCompile(`(?m)^< Date: .+`)
|
||||||
var hostWithPortRE = regexp.MustCompile(`127\.0\.0\.1:\d+`)
|
var hostWithPortRE = regexp.MustCompile(`127\.0\.0\.1:\d+`)
|
||||||
|
|
|
||||||
|
|
@ -83,7 +83,7 @@ func (rr *remoteResolver) Resolver() func() (context.Remotes, error) {
|
||||||
dummyHostname := "example.com" // any non-github.com hostname is fine here
|
dummyHostname := "example.com" // any non-github.com hostname is fine here
|
||||||
if config.IsHostEnv(src) {
|
if config.IsHostEnv(src) {
|
||||||
return nil, fmt.Errorf("none of the git remotes configured for this repository correspond to the %s environment variable. Try adding a matching remote or unsetting the variable.", src)
|
return nil, fmt.Errorf("none of the git remotes configured for this repository correspond to the %s environment variable. Try adding a matching remote or unsetting the variable.", src)
|
||||||
} else if v, src, _ := cfg.GetOrDefaultWithSource(dummyHostname, "oauth_token"); v != "" && config.IsEnterpriseEnv(src) {
|
} else if v, src, _ := cfg.GetWithSource(dummyHostname, "oauth_token"); v != "" && config.IsEnterpriseEnv(src) {
|
||||||
return nil, errors.New("set the GH_HOST environment variable to specify which GitHub host to use")
|
return nil, errors.New("set the GH_HOST environment variable to specify which GitHub host to use")
|
||||||
}
|
}
|
||||||
return nil, errors.New("none of the git remotes configured for this repository point to a known GitHub host. To tell gh about a new GitHub host, please use `gh auth login`")
|
return nil, errors.New("none of the git remotes configured for this repository point to a known GitHub host. To tell gh about a new GitHub host, please use `gh auth login`")
|
||||||
|
|
|
||||||
|
|
@ -24,7 +24,7 @@ func CheckAuth(cfg config.Config) bool {
|
||||||
}
|
}
|
||||||
|
|
||||||
for _, hostname := range hosts {
|
for _, hostname := range hosts {
|
||||||
token, _ := cfg.GetOrDefault(hostname, "oauth_token")
|
token, _ := cfg.Get(hostname, "oauth_token")
|
||||||
if token != "" {
|
if token != "" {
|
||||||
return true
|
return true
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -16,7 +16,7 @@ func DetermineEditor(cf func() (config.Config, error)) (string, error) {
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return "", fmt.Errorf("could not read config: %w", err)
|
return "", fmt.Errorf("could not read config: %w", err)
|
||||||
}
|
}
|
||||||
editorCommand, _ = cfg.GetOrDefault("", "editor")
|
editorCommand, _ = cfg.Get("", "editor")
|
||||||
}
|
}
|
||||||
|
|
||||||
return editorCommand, nil
|
return editorCommand, nil
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue