Skip to content
New issue

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

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

Already on GitHub? Sign in to your account

Fixes incorrect handling of cli and config file parameter merging #87

Merged
merged 11 commits into from
Apr 21, 2018

Conversation

drewsonne
Copy link
Contributor

Not sure when this was lost. This addresses #84 .

@codecov-io
Copy link

codecov-io commented Apr 19, 2018

Codecov Report

Merging #87 into master will decrease coverage by 0.37%.
The diff coverage is 80%.

Impacted file tree graph

@@            Coverage Diff             @@
##           master      #87      +/-   ##
==========================================
- Coverage   73.18%   72.81%   -0.38%     
==========================================
  Files           6        6              
  Lines         317      320       +3     
==========================================
+ Hits          232      233       +1     
- Misses         85       87       +2
Impacted Files Coverage Δ
onelogin_aws_cli/argparse.py 100% <ø> (ø) ⬆️
onelogin_aws_cli/__init__.py 64.04% <66.66%> (-0.33%) ⬇️
onelogin_aws_cli/configuration.py 93.1% <85.71%> (-1.64%) ⬇️

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 90131ed...1802298. Read the comment docs.

@drewsonne drewsonne changed the title The config value should always fall back to default The config value should always fall back to defaults Apr 19, 2018
@@ -17,7 +17,7 @@ def __init__(self):
self.add_argument(
'-C', '--config-name',
action=EnvDefault, required=False,
dest='config_name',
dest='config_name', default='defaults',
Copy link
Contributor

Choose a reason for hiding this comment

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

The stumbling block I ran into is that when you do it this way, and you try to retrieve the section, per configparser, the default section is not acknowledged by has_section so we'll try to add it. However, adding a section with the name of the default section throws an exception.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

We can change it so it errors or returns None or something if there's no section. It doesn't need to be that smart.

If no section exists, we can make it explicit that a section would need to be added. Would that fix it?

Copy link
Contributor

Choose a reason for hiding this comment

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

That would but then it just moves a check somewhere else (see line 88 of my PR)

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Can you link to it? I can not see a line 88 in the diffs.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Maybe moving the check is a good thing.

I propose we should only create a section when we run the --configure option. Any other time we should (gracefully) fail and say we don't have the section.

That is, only create a section when we explicitly want to create a new one. Any other time, say we don't have one.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

See #89

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I think I've got this working now.

@slycoder
Copy link
Contributor

Ok, I think this change is good although one thing comes to mind --- does is_initialized work for defaults (since we automatically populate it with save_password we need to also check has_defaults)?

@drewsonne drewsonne changed the title The config value should always fall back to defaults Fixes incorrect handling of cli and config file parameter merging Apr 21, 2018
@@ -34,7 +34,7 @@ def __init__(self):
)

self.add_argument(
'-d', '--duration-seconds', type=int, default=3600,
'-d', '--duration-seconds', type=int,
Copy link
Contributor

Choose a reason for hiding this comment

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

What are the pros/cons of setting defaults via the config as you have versus just putting defaults here?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

If (as an example), a user were to have the duration_seconds value in the config file, and not provide it via the cli, as the cli has precedence to overwrite values in the config file, when we parse the args, this default value of 3600 will always take precedence over the values in the config file.

If the config precedence chain has the cli options higher than the config file, then defaults must be set at the bottom level of the chain (in this case, the config file).

Copy link
Contributor

Choose a reason for hiding this comment

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

Ah, that makes sense. In that case maybe the fallbackiest of defaults should go into overrides (so as to not be written into the config)?


self.file = config_file

if self.file is not None:
self.load()

@property
Copy link
Contributor

Choose a reason for hiding this comment

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

All this jazz is no longer needed since we're never updating defaults with the fallbacks.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants