// readHostsInCredentialsFile discovers which hosts have credentials configured
// in the credentials file specifically, as opposed to in any other CLI
// config file.
//
// If the credentials file isn't present or is unreadable for any reason then
// this returns an empty set, reflecting that effectively no credentials are
// stored there.
readHostsInCredentialsFile discovers which hosts have credentials configured
in the credentials file specifically, as opposed to in any other CLI
config file.

If the credentials file isn't present or is unreadable for any reason then
this returns an empty set, reflecting that effectively no credentials are
stored there.
// readHostsInCredentialsFile discovers which hosts have credentials configured // in the credentials file specifically as opposed to in any other CLI // config file . // // If the credentials file isn ' t present or is unreadable for any reason then // this returns an empty set reflecting that effectively no credentials are // stored there .
func readHostsInCredentialsFile(filename string) map[svchost.Hostname]struct{} {
	src, err := ioutil.ReadFile(filename)
	if err != nil {
		return nil
	}
	var raw map[string]interface{}
	err = json.Unmarshal(src, &raw)
	if err != nil {
		return nil
	}
	rawCredsI, ok := raw["credentials"]
	if !ok {
		return nil
	}
	rawCredsMap, ok := rawCredsI.(map[string]interface{})
	if !ok {
		return nil
	}
	ret := make(map[svchost.Hostname]struct{})
	for givenHost := range rawCredsMap {
		host, err := svchost.ForComparison(givenHost)
		if err != nil {
			continue
		}
		ret[host] = struct{}{}
	}
	return ret
}
func readHostsInCredentialsFile ( filename string ) map [ svchost . Hostname ] struct { } { src , err := ioutil . ReadFile ( filename ) if err != nil { return nil } var raw map [ string ] interface { } err = json . Unmarshal ( src , & raw ) if err != nil { return nil } rawCredsI , ok := raw [ " " ] if ! ok { return nil } rawCredsMap , ok := rawCredsI . ( map [ string ] interface { } ) if ! ok { return nil } ret := make ( map [ svchost . Hostname ] struct { } ) for givenHost := range rawCredsMap { host , err := svchost . ForComparison ( givenHost ) if err != nil { continue } ret [ host ] = struct { } { } } return ret }
readHostsInCredentialsFile discovers which hosts have credentials configured
in the credentials file specifically, as opposed to in any other CLI
config file.
readHostsInCredentialsFile discovers which hosts have credentials configured in the credentials file specifically as opposed to in any other CLI config file .
// We expect the config was already validated by the time we get // here, so we'll just ignore invalid hostnames.