func (c *listCredentialsCommand) Run(ctxt *cmd.Context) error { var credentials map[string]jujucloud.CloudCredential credentials, err := c.store.AllCredentials() if err != nil && !errors.IsNotFound(err) { return err } if c.cloudName != "" { for cloudName := range credentials { if cloudName != c.cloudName { delete(credentials, cloudName) } } } // Find local cloud names. personalClouds, err := c.personalClouds() if err != nil { return err } var personalCloudNames []string for name := range personalClouds { personalCloudNames = append(personalCloudNames, name) } displayCredentials := make(map[string]CloudCredential) var missingClouds []string for cloudName, cred := range credentials { if !c.showSecrets { if err := c.removeSecrets(cloudName, &cred); err != nil { if errors.IsNotValid(err) { missingClouds = append(missingClouds, cloudName) continue } return errors.Annotatef(err, "removing secrets from credentials for cloud %v", cloudName) } } displayCredential := CloudCredential{ DefaultCredential: cred.DefaultCredential, DefaultRegion: cred.DefaultRegion, } if len(cred.AuthCredentials) != 0 { displayCredential.Credentials = make(map[string]Credential, len(cred.AuthCredentials)) for credName, credDetails := range cred.AuthCredentials { displayCredential.Credentials[credName] = Credential{ string(credDetails.AuthType()), credDetails.Attributes(), credDetails.Revoked, credDetails.Label, } } } displayCredentials[cloudName] = displayCredential } if c.out.Name() == "tabular" && len(missingClouds) > 0 { fmt.Fprintf(ctxt.GetStdout(), "The following clouds have been removed and are omitted from the results to avoid leaking secrets.\n"+ "Run with --show-secrets to display these clouds' credentials: %v\n\n", strings.Join(missingClouds, ", ")) } return c.out.Write(ctxt, credentialsMap{displayCredentials}) }
// Run implements Command.Run. func (c *listRegionsCommand) Run(ctxt *cmd.Context) error { cloud, err := cloud.CloudByName(c.cloudName) if err != nil { return err } if len(cloud.Regions) == 0 { fmt.Fprintf(ctxt.GetStdout(), "Cloud %q has no regions defined.\n", c.cloudName) return nil } var regions interface{} if c.out.Name() == "json" { details := make(map[string]regionDetails) for _, r := range cloud.Regions { details[r.Name] = regionDetails{ Endpoint: r.Endpoint, IdentityEndpoint: r.IdentityEndpoint, StorageEndpoint: r.StorageEndpoint, } } regions = details } else { details := make(yaml.MapSlice, len(cloud.Regions)) for i, r := range cloud.Regions { details[i] = yaml.MapItem{r.Name, regionDetails{ Name: r.Name, Endpoint: r.Endpoint, IdentityEndpoint: r.IdentityEndpoint, StorageEndpoint: r.StorageEndpoint, }} } regions = details } err = c.out.Write(ctxt, regions) if err != nil { return err } return nil }