Remove cloud references from file if last credential is removed. #7025

Merged
merged 3 commits into from Feb 23, 2017

Conversation

Projects
None yet
3 participants
Member

anastasiamac commented Feb 23, 2017

Please provide the following details to expedite Pull Request review:


Description of change

When remove credential deletes last credential for a cloud, there is no need to keep reference for a cloud in credentials.yaml file.
In fact, it causes confusion as per the bug.

QA steps

  1. add cloud
  2. add credential for it
  3. remove cloud
  4. remove credential for the removed cloud
    Success criteria:
    a. listing credentials does not show message to re-run with --show-secrets flag
    b. listing credential with --show-secrets does not list the cloud
    c. credentials.yaml does not reference delete cloud

Documentation changes

No documentation changes are needed.

Bug reference

https://bugs.launchpad.net/juju/+bug/1590237

axw approved these changes Feb 23, 2017

LGTM with simplifications

jujuclient/credentials_test.go
+ c.Assert(err, jc.ErrorIsNil)
+
+ _, exists := creds[s.cloudName]
+ c.Assert(creds[s.cloudName].AuthCredentials, gc.HasLen, 0)
@axw

axw Feb 23, 2017

Member

this line is redundant. creds[s.cloudName] will have the zero value, as proven by c.Assert(exists, jc.IsFalse)

@anastasiamac

anastasiamac Feb 23, 2017

Member

Ooops, cut/paste :D thnx!

jujuclient/file.go
+
+ // If cloud has no credentials now, delete cloud references from
+ // credentials file as well.
+ if len(all[cloudName].AuthCredentials) == 0 {
@axw

axw Feb 23, 2017

Member

rather than assigning to all (above on line 631), then checking it and maybe deleting from it:

if len(details.AuthCredentials) > 0 {
    all[cloudName] = details
} else {
    delete(all, cloudName)
}
@anastasiamac

anastasiamac Feb 23, 2017

Member

yep, beautiful! tyvm

jujuclient/jujuclienttesting/mem.go
@@ -301,6 +301,11 @@ func (c *MemStore) RemoveAccount(controllerName string) error {
// UpdateCredential implements CredentialsUpdater.
func (c *MemStore) UpdateCredential(cloudName string, details cloud.CloudCredential) error {
c.Credentials[cloudName] = details
+ // If cloud has no credentials now, delete cloud references from
+ // credentials file as well.
+ if len(c.Credentials[cloudName]) == 0 {
Member

anastasiamac commented Feb 23, 2017

$$merge$$

Contributor

jujubot commented Feb 23, 2017

Status: merge request accepted. Url: http://juju-ci.vapour.ws:8080/job/github-merge-juju

Contributor

jujubot commented Feb 23, 2017

Build failed: Tests failed
build url: http://juju-ci.vapour.ws:8080/job/github-merge-juju/10348

Member

anastasiamac commented Feb 23, 2017

$$merge$$

Contributor

jujubot commented Feb 23, 2017

Status: merge request accepted. Url: http://juju-ci.vapour.ws:8080/job/github-merge-juju

@jujubot jujubot merged commit d7f0644 into juju:develop Feb 23, 2017

@anastasiamac anastasiamac deleted the anastasiamac:credential-delete-lp1590237 branch Feb 23, 2017

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment