Ensure credential paths are "Finalized" to their contents. #8048

Merged
merged 1 commit into from Nov 16, 2017

Conversation

Projects
None yet
3 participants
Member

ExternalReality commented Nov 10, 2017

Description of change

When bootstrapping a controller on GCE with JUJU_DATA set to the path of an empty directory, Juju will try to look for a path to a file holding GCE credentials in the environment variable GOOGLE_APPLICATION_CREDENTIALS. Juju incorrectly tries to use the file path itself as the credentials instead of using the contents of that file. This PR fixes that error.

Why is this change needed?

Fixes referenced bug.

QA steps

  1. set GOOGLE_APPLICATION_CREDENTIALS to the path of your application credentials.
  2. set JUJU_DATA to an empty directory (This way Juju ignores its current set of credentials.)
  3. You should see your controller successfully bootstrap on GCE whereas without this patch it would error expecting the file path string to be valid JSON.

Documentation changes

N/A

Does it affect current user workflow? CLI? API?

No

Bug reference

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

Contributor

jujubot commented Nov 10, 2017

Can one of the admins verify this patch?

@ExternalReality ExternalReality changed the title from Ensure credential filepaths are to their contents. to WIP: Ensure credential filepaths are to their contents. Nov 10, 2017

@ExternalReality ExternalReality changed the title from WIP: Ensure credential filepaths are to their contents. to WIP: Ensure credential paths are "Finalized" to their contents. Nov 10, 2017

@ExternalReality ExternalReality changed the title from WIP: Ensure credential paths are "Finalized" to their contents. to Ensure credential paths are "Finalized" to their contents. Nov 13, 2017

}
return credential, credentialName, regionName, nil
}
+// FinalizeFileContent replaces the path content of cloud credentials "file" attribute with its content.
+func FinalizeFileContent(credential *cloud.Credential, provider environs.EnvironProvider) (*cloud.Credential, error) {
@ExternalReality

ExternalReality Nov 13, 2017

Member

This function has been factored out of the existing code. Part of the reason for this bug is there is limited testing around this particular area of code. No test verifies that the variable storing the file path is actually converted to store its contents. Three things come to my mind here; we can either inject the readFile function into all relevant functions so that we can "mock" the file reading for test. Alternatively, we could use a file I/O mocking library. Lastly, we can make an actual temporary file for testing. I am aware of the fundamental Pros and Cons of each method. Is there an area of the code, that favors one approach over the other, which I can mimic here?

Another thing to do might be to relocate FinalizeFileContent so that it would live in Cloud, where it might be added to the interface, and stub the method altogether for testing. I welcome any feedback regarding this issue.

Member

ExternalReality commented Nov 15, 2017

!!build!!

I just realized I didn't comment on this.
I think its better than what we had, I was trying to find ways to help you work out tests for everything. We can try to talk it over tomorrow. Lets talk about it during standup.

Member

ExternalReality commented Nov 15, 2017

!!build!!

Member

ExternalReality commented Nov 16, 2017

$$MERGE$$

Contributor

jujubot commented Nov 16, 2017

Status: merge request accepted. Url: http://ci.jujucharms.com/job/github-merge-juju

@jujubot jujubot merged commit 73e9726 into juju:develop Nov 16, 2017

1 of 2 checks passed

github-check-merge-juju-pipeline Built PR, ran unit tests, and tested LXD deploy. Use !!.*!! to request another build. IE, !!build!!, !!retry!!
Details
continuous-integration/jenkins/pr-merge This commit looks good
Details

@ExternalReality ExternalReality deleted the ExternalReality:bug#1726226_rework branch Dec 20, 2017

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