// FinalizeCredential is part of the environs.ProviderCredentials interface. func (c environProviderCredentials) FinalizeCredential( ctx environs.FinalizeCredentialContext, args environs.FinalizeCredentialParams, ) (*cloud.Credential, error) { switch authType := args.Credential.AuthType(); authType { case deviceCodeAuthType: subscriptionId := args.Credential.Attributes()[credAttrSubscriptionId] applicationId, password, err := c.interactiveCreateServicePrincipal( ctx.GetStderr(), c.sender, c.requestInspector, args.CloudEndpoint, args.CloudIdentityEndpoint, subscriptionId, clock.WallClock, utils.NewUUID, ) if err != nil { return nil, errors.Trace(err) } out := cloud.NewCredential(clientCredentialsAuthType, map[string]string{ credAttrSubscriptionId: subscriptionId, credAttrAppId: applicationId, credAttrAppPassword: password, }) out.Label = args.Credential.Label return &out, nil case clientCredentialsAuthType: return &args.Credential, nil default: return nil, errors.NotSupportedf("%q auth-type", authType) } }
// FinalizeCredential is part of the environs.ProviderCredentials interface. func (c environProviderCredentials) FinalizeCredential( ctx environs.FinalizeCredentialContext, args environs.FinalizeCredentialParams, ) (*cloud.Credential, error) { switch authType := args.Credential.AuthType(); authType { case cloud.UserPassAuthType: fmt.Fprintf(ctx.GetStderr(), ` WARNING: The %q auth-type is deprecated, and will be removed soon. Please update the credential in ~/.local/share/juju/credentials.yaml, changing auth-type to %q, and dropping the tenant-id field. `[1:], authType, clientCredentialsAuthType, ) attrs := args.Credential.Attributes() delete(attrs, credAttrTenantId) out := cloud.NewCredential(clientCredentialsAuthType, attrs) out.Label = args.Credential.Label return &out, nil case deviceCodeAuthType: subscriptionId := args.Credential.Attributes()[credAttrSubscriptionId] applicationId, password, err := c.interactiveCreateServicePrincipal( ctx.GetStderr(), c.sender, c.requestInspector, args.CloudEndpoint, args.CloudIdentityEndpoint, subscriptionId, clock.WallClock, utils.NewUUID, ) if err != nil { return nil, errors.Trace(err) } out := cloud.NewCredential(clientCredentialsAuthType, map[string]string{ credAttrSubscriptionId: subscriptionId, credAttrAppId: applicationId, credAttrAppPassword: password, }) out.Label = args.Credential.Label return &out, nil case clientCredentialsAuthType: return &args.Credential, nil default: return nil, errors.NotSupportedf("%q auth-type", authType) } }
func (p *mockProvider) FinalizeCredential( ctx environs.FinalizeCredentialContext, args environs.FinalizeCredentialParams, ) (*jujucloud.Credential, error) { if args.Credential.AuthType() == "interactive" { fmt.Fprintln(ctx.GetStderr(), "generating userpass credential") out := jujucloud.NewCredential(jujucloud.UserPassAuthType, map[string]string{ "username": args.Credential.Attributes()["username"], "password": args.CloudEndpoint, "application-password": args.CloudIdentityEndpoint, }) return &out, nil } return &args.Credential, nil }
func (mockProvider) FinalizeCredential( ctx environs.FinalizeCredentialContext, args environs.FinalizeCredentialParams, ) (*cloud.Credential, error) { if args.Credential.AuthType() == "interactive" { username := args.Credential.Attributes()["username"] fmt.Fprintf(ctx.GetStderr(), "generating credential for %q\n", username) out := cloud.NewCredential(cloud.UserPassAuthType, map[string]string{ "username": username, "password": "******", "key": "value", }) return &out, nil } return &args.Credential, nil }