Skip to content
New issue

Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? # to your account

[WIP] Read YAML configuration settings #29

Closed
wants to merge 5 commits into from
Closed

[WIP] Read YAML configuration settings #29

wants to merge 5 commits into from

Conversation

Jos512
Copy link

@Jos512 Jos512 commented Jun 2, 2018

This is the first step for #23. It's my first Go pull request, so I'm also marking it as 'work in progress' to get feedback for what you'd like to see differently. I look forward to anything that makes it better. 🙂

Things that remain on my task list after this commit:

  • Add tests for the new function (I suppose that is needed).
  • Update README with this new feature, including a clear warning for storing AWS keys and secrets in .s3deploy.yml. (I thought about including such a warning in the code, but printing such a message each time feels inappropriate to users.)

I tested the code on go version go1.9 windows/amd64.

@codecov-io
Copy link

codecov-io commented Jun 2, 2018

Codecov Report

Merging #29 into master will decrease coverage by 1.07%.
The diff coverage is 35.71%.

Impacted file tree graph

@@            Coverage Diff             @@
##           master      #29      +/-   ##
==========================================
- Coverage   70.04%   68.97%   -1.08%     
==========================================
  Files           6        6              
  Lines         434      448      +14     
==========================================
+ Hits          304      309       +5     
- Misses        102      110       +8     
- Partials       28       29       +1
Impacted Files Coverage Δ
lib/config.go 73.17% <35.71%> (-19.43%) ⬇️

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update e1969a6...1d4c5d3. Read the comment docs.

lib/config.go Outdated
@@ -47,6 +50,15 @@ type Config struct {
baseStore remoteStore
}

// yamlConfig specifies the optional settings taken from `.s3deploy.yml`
type yamlConfig struct {
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The code in the PR looks correct, but since we already have a fileConfig struct and code that reads that from a YAML file, we should try to reuse that code. So I suggest that you just add these new fields to the same struct. And I suspect there should be some related tests you can expand on.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for the review, I'm working on implementing your suggestions. :)

Jos512 added 2 commits June 9, 2018 11:00
YAML file is now loaded into Config struct, unnecessary struct is removed, code for readSettings() simplified.

cfg, err := flagsToConfig(flags)
assert.NoError(err)
assert.NoError(flags.Parse([]string{"-source=testdata/.s3deploy.yml"}))
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is not a good location because 'testdata' contains the data used by deployer_test.go. Is there a location suited for the test file?

lib/config.go Outdated
}

// Load in settings, but only when the accompanying command flag hasn't been set
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The above sentence should be respected.

Copy link
Author

@Jos512 Jos512 Jun 16, 2018

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

So if the user choose to add his/her AWS key and secret to the config file, the general AWS credentials still take precedence?

I tried several times to program that situation this week, but it's unfortunately outside my current experience to implement. So just checking here if I actually understood correctly what you're saying.

Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If I say

s3deploy -source=dist/ -region=eu-west-1 -bucket=bepsays.com

I want those values to be used, watever values are stored in the config file for those settings.

Copy link
Author

@Jos512 Jos512 Jun 16, 2018

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ah I see, thanks for clarifying. I was looking in the wrong direction.

For what you ask, the code works like that for me. This is my test .s3deploy.yml file:

bucket: example.com
key: xcsds
secret: xdsfdsf
region: us-west
source: public

But I can override these settings with the command flags. When I use the latest commit above (18ac3a0) it goes like so.

Without command flags, it uses us-west as the region and example.com for the bucket name:

C:\Users\Jos\go\src\github.com\bep\s3deploy>go run main.go -try
s3deploy v2, commit none, built at unknown
This is a trial run, with no remote updates.

Total in 0.35 seconds
error: RequestError: send request failed
caused by: Get https://s3.us-west.amazonaws.com/example.com: dial tcp: lookup s3.us-west.amazonaws.com: no such host

But with command flags those settings are overruled:

C:\Users\Jos\go\src\github.com\bep\s3deploy>go run main.go -try -bucket=myexamplewebsite.com -region=europe-512
s3deploy v2, commit none, built at unknown
This is a trial run, with no remote updates.

Total in 0.37 seconds
error: RequestError: send request failed
caused by: Get https://s3.europe-512.amazonaws.com/myexamplewebsite.com: dial tcp: lookup s3.europe-512.amazonaws.com: no such host

Now it looked for the myexamplewebsite.com in the region europe-512, thereby overriding the settings specified in the s3deploy.yml file.


Edit

This behaviour seems to happen because of the unmarshal() function that yaml.Unmarshal() uses.

Jos512 added 2 commits June 16, 2018 07:03
Moved test of settings file in separate /lib/ subdirectory, fixed assert.Equal() function call
@Jos512
Copy link
Author

Jos512 commented Jun 20, 2018

With the latest commit I've moved the .s3deploy.yml test file into its own directory (/lib/testsettingsfile/). That way it doesn't conflict with the test_deployer.go file that reads the files from the /lib/testdata/ folder.

@Jos512 Jos512 closed this Jan 10, 2019
@Jos512 Jos512 deleted the yamlsettings branch January 10, 2019 15:44
# for free to join this conversation on GitHub. Already have an account? # to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants