// credentialsSource is an internal factory for the credentials source which
// allows overriding the credentials file path, which allows setting it to
// a temporary file location when testing.
credentialsSource is an internal factory for the credentials source which
allows overriding the credentials file path, which allows setting it to
a temporary file location when testing.
// credentialsSource is an internal factory for the credentials source which // allows overriding the credentials file path which allows setting it to // a temporary file location when testing .
func (c *Config) credentialsSource(helperType string, helper svcauth.CredentialsSource, credentialsFilePath string) *CredentialsSource {
	configured := map[svchost.Hostname]cty.Value{}
	for userHost, creds := range c.Credentials {
		host, err := svchost.ForComparison(userHost)
		if err != nil {
			continue
		}
		credsV := hcl2shim.HCL2ValueFromConfigValue(creds)
		configured[host] = credsV
	}
	writableLocal := readHostsInCredentialsFile(credentialsFilePath)
	unwritableLocal := map[svchost.Hostname]cty.Value{}
	for host, v := range configured {
		if _, exists := writableLocal[host]; !exists {
			unwritableLocal[host] = v
		}
	}
	return &CredentialsSource{
		configured:          configured,
		unwritable:          unwritableLocal,
		credentialsFilePath: credentialsFilePath,
		helper:              helper,
		helperType:          helperType,
	}
}
func ( c * Config ) credentialsSource ( helperType string , helper svcauth . CredentialsSource , credentialsFilePath string ) * CredentialsSource { configured := map [ svchost . Hostname ] cty . Value { } for userHost , creds := range c . Credentials { host , err := svchost . ForComparison ( userHost ) if err != nil { continue } credsV := hcl2shim . HCL2ValueFromConfigValue ( creds ) configured [ host ] = credsV } writableLocal := readHostsInCredentialsFile ( credentialsFilePath ) unwritableLocal := map [ svchost . Hostname ] cty . Value { } for host , v := range configured { if _ , exists := writableLocal [ host ] ; ! exists { unwritableLocal [ host ] = v } } return & CredentialsSource { configured : configured , unwritable : unwritableLocal , credentialsFilePath : credentialsFilePath , helper : helper , helperType : helperType , } }
credentialsSource is an internal factory for the credentials source which
allows overriding the credentials file path, which allows setting it to
a temporary file location when testing.
credentialsSource is an internal factory for the credentials source which allows overriding the credentials file path which allows setting it to a temporary file location when testing .
// We expect the config was already validated by the time we get // here, so we'll just ignore invalid hostnames. // For now our CLI config continues to use HCL 1.0, so we'll shim it // over to HCL 2.0 types. In future we will hopefully migrate it to // HCL 2.0 instead, and so it'll be a cty.Value already.