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:
Alisdair McDiarmid 2020-02-06 15:30:49 -05:00
parent 325f8a84f8
commit 7ff58780d4
2 changed files with 12 additions and 30 deletions

View File

@ -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")

View File

@ -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 {