Remove unnecessary type assertion checks
The type assertion checks on the credentials source are unnecessary, and the alternative code path they allow would panic.
This commit is contained in:
parent
325f8a84f8
commit
7ff58780d4
|
@ -105,21 +105,12 @@ func (c *LoginCommand) Run(args []string) int {
|
||||||
return 1
|
return 1
|
||||||
}
|
}
|
||||||
|
|
||||||
creds := c.Services.CredentialsSource()
|
creds := c.Services.CredentialsSource().(*cliconfig.CredentialsSource)
|
||||||
|
filename, _ := creds.CredentialsFilePath()
|
||||||
// In normal use (i.e. without test mocks/fakes) creds will be an instance
|
credsCtx := &loginCredentialsContext{
|
||||||
// of the command/cliconfig.CredentialsSource type, which has some extra
|
Location: creds.HostCredentialsLocation(hostname),
|
||||||
// methods we can use to give the user better feedback about what we're
|
LocalFilename: filename, // empty in the very unlikely event that we can't select a config directory for this user
|
||||||
// going to do. credsCtx will be nil if it's any other implementation,
|
HelperType: creds.CredentialsHelperType(),
|
||||||
// though.
|
|
||||||
var credsCtx *loginCredentialsContext
|
|
||||||
if c, ok := creds.(*cliconfig.CredentialsSource); ok {
|
|
||||||
filename, _ := c.CredentialsFilePath()
|
|
||||||
credsCtx = &loginCredentialsContext{
|
|
||||||
Location: c.HostCredentialsLocation(hostname),
|
|
||||||
LocalFilename: filename, // empty in the very unlikely event that we can't select a config directory for this user
|
|
||||||
HelperType: c.CredentialsHelperType(),
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
clientConfig, err := host.ServiceOAuthClient("login.v1")
|
clientConfig, err := host.ServiceOAuthClient("login.v1")
|
||||||
|
|
|
@ -61,21 +61,12 @@ func (c *LogoutCommand) Run(args []string) int {
|
||||||
// working as expected. (Perhaps the normalization is part of the cause.)
|
// working as expected. (Perhaps the normalization is part of the cause.)
|
||||||
dispHostname := hostname.ForDisplay()
|
dispHostname := hostname.ForDisplay()
|
||||||
|
|
||||||
creds := c.Services.CredentialsSource()
|
creds := c.Services.CredentialsSource().(*cliconfig.CredentialsSource)
|
||||||
|
filename, _ := creds.CredentialsFilePath()
|
||||||
// In normal use (i.e. without test mocks/fakes) creds will be an instance
|
credsCtx := &loginCredentialsContext{
|
||||||
// of the command/cliconfig.CredentialsSource type, which has some extra
|
Location: creds.HostCredentialsLocation(hostname),
|
||||||
// methods we can use to give the user better feedback about what we're
|
LocalFilename: filename, // empty in the very unlikely event that we can't select a config directory for this user
|
||||||
// going to do. credsCtx will be nil if it's any other implementation,
|
HelperType: creds.CredentialsHelperType(),
|
||||||
// though.
|
|
||||||
var credsCtx *loginCredentialsContext
|
|
||||||
if c, ok := creds.(*cliconfig.CredentialsSource); ok {
|
|
||||||
filename, _ := c.CredentialsFilePath()
|
|
||||||
credsCtx = &loginCredentialsContext{
|
|
||||||
Location: c.HostCredentialsLocation(hostname),
|
|
||||||
LocalFilename: filename, // empty in the very unlikely event that we can't select a config directory for this user
|
|
||||||
HelperType: c.CredentialsHelperType(),
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if credsCtx.Location == cliconfig.CredentialsInOtherFile {
|
if credsCtx.Location == cliconfig.CredentialsInOtherFile {
|
||||||
|
|
Loading…
Reference in New Issue