From 7ff58780d49f72f1d93a63ac06d8185741d260c2 Mon Sep 17 00:00:00 2001 From: Alisdair McDiarmid Date: Thu, 6 Feb 2020 15:30:49 -0500 Subject: [PATCH] Remove unnecessary type assertion checks The type assertion checks on the credentials source are unnecessary, and the alternative code path they allow would panic. --- command/login.go | 21 ++++++--------------- command/logout.go | 21 ++++++--------------- 2 files changed, 12 insertions(+), 30 deletions(-) diff --git a/command/login.go b/command/login.go index a53071226..be2d79c93 100644 --- a/command/login.go +++ b/command/login.go @@ -105,21 +105,12 @@ func (c *LoginCommand) Run(args []string) int { return 1 } - creds := c.Services.CredentialsSource() - - // In normal use (i.e. without test mocks/fakes) creds will be an instance - // of the command/cliconfig.CredentialsSource type, which has some extra - // methods we can use to give the user better feedback about what we're - // going to do. credsCtx will be nil if it's any other implementation, - // 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(), - } + creds := c.Services.CredentialsSource().(*cliconfig.CredentialsSource) + filename, _ := creds.CredentialsFilePath() + credsCtx := &loginCredentialsContext{ + Location: creds.HostCredentialsLocation(hostname), + LocalFilename: filename, // empty in the very unlikely event that we can't select a config directory for this user + HelperType: creds.CredentialsHelperType(), } clientConfig, err := host.ServiceOAuthClient("login.v1") diff --git a/command/logout.go b/command/logout.go index 489877a8b..1ecaf3b47 100644 --- a/command/logout.go +++ b/command/logout.go @@ -61,21 +61,12 @@ func (c *LogoutCommand) Run(args []string) int { // working as expected. (Perhaps the normalization is part of the cause.) dispHostname := hostname.ForDisplay() - creds := c.Services.CredentialsSource() - - // In normal use (i.e. without test mocks/fakes) creds will be an instance - // of the command/cliconfig.CredentialsSource type, which has some extra - // methods we can use to give the user better feedback about what we're - // going to do. credsCtx will be nil if it's any other implementation, - // 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(), - } + creds := c.Services.CredentialsSource().(*cliconfig.CredentialsSource) + filename, _ := creds.CredentialsFilePath() + credsCtx := &loginCredentialsContext{ + Location: creds.HostCredentialsLocation(hostname), + LocalFilename: filename, // empty in the very unlikely event that we can't select a config directory for this user + HelperType: creds.CredentialsHelperType(), } if credsCtx.Location == cliconfig.CredentialsInOtherFile {