From e1fb26de94e6c7353ead0d76eb68a86cc225470e Mon Sep 17 00:00:00 2001 From: Martin Atkins Date: Wed, 7 Aug 2019 16:32:23 -0700 Subject: [PATCH] svchost/disco: Disco.CredentialsSource Previously we allowed access to the credentials store only indirectly through the Disco object, and that's fine for callers that only need to _read_ credentials, but more specialized callers like "terraform login" and "terraform logout" need more information in order to be transparent to the user about what they are going to do and where the credentials are going to be stored. --- svchost/disco/disco.go | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/svchost/disco/disco.go b/svchost/disco/disco.go index 1963cbd18a..5d8e469347 100644 --- a/svchost/disco/disco.go +++ b/svchost/disco/disco.go @@ -75,6 +75,18 @@ func (d *Disco) SetCredentialsSource(src auth.CredentialsSource) { d.credsSrc = src } +// CredentialsSource returns the credentials source associated with the receiver, +// or an empty credentials source if none is associated. +func (d *Disco) CredentialsSource() auth.CredentialsSource { + if d.credsSrc == nil { + // We'll return an empty one just to save the caller from having to + // protect against the nil case, since this interface already allows + // for the possibility of there being no credentials at all. + return auth.StaticCredentialsSource(nil) + } + return d.credsSrc +} + // CredentialsForHost returns a non-nil HostCredentials if the embedded source has // credentials available for the host, and a nil HostCredentials if it does not. func (d *Disco) CredentialsForHost(hostname svchost.Hostname) (auth.HostCredentials, error) {