Merge pull request #25110 from hashicorp/alisdair/credentials-source-nil-receiver

command: Fix panic for nil credentials source
This commit is contained in:
Alisdair McDiarmid 2020-06-03 11:51:49 -04:00 committed by GitHub
commit de0e67e5f6
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 10 additions and 4 deletions

14
main.go
View File

@ -154,18 +154,24 @@ func wrappedMain() int {
} }
// Get any configured credentials from the config and initialize // Get any configured credentials from the config and initialize
// a service discovery object. // a service discovery object. The slightly awkward predeclaration of
// disco is required to allow us to pass untyped nil as the creds source
// when creating the source fails. Otherwise we pass a typed nil which
// breaks the nil checks in the disco object
var services *disco.Disco
credsSrc, err := credentialsSource(config) credsSrc, err := credentialsSource(config)
if err != nil { if err == nil {
services = disco.NewWithCredentialsSource(credsSrc)
} else {
// Most commands don't actually need credentials, and most situations // Most commands don't actually need credentials, and most situations
// that would get us here would already have been reported by the config // that would get us here would already have been reported by the config
// loading above, so we'll just log this one as an aid to debugging // loading above, so we'll just log this one as an aid to debugging
// in the unlikely event that it _does_ arise. // in the unlikely event that it _does_ arise.
log.Printf("[WARN] Cannot initialize remote host credentials manager: %s", err) log.Printf("[WARN] Cannot initialize remote host credentials manager: %s", err)
// credsSrc may be nil in this case, but that's okay because the disco // passing (untyped) nil as the creds source is okay because the disco
// object checks that and just acts as though no credentials are present. // object checks that and just acts as though no credentials are present.
services = disco.NewWithCredentialsSource(nil)
} }
services := disco.NewWithCredentialsSource(credsSrc)
services.SetUserAgent(httpclient.TerraformUserAgent(version.String())) services.SetUserAgent(httpclient.TerraformUserAgent(version.String()))
providerSrc, diags := providerSource(config.ProviderInstallation, services) providerSrc, diags := providerSource(config.ProviderInstallation, services)