-
Notifications
You must be signed in to change notification settings - Fork 32
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
Support default in addition to defaults #88
base: master
Are you sure you want to change the base?
Changes from 3 commits
df437a0
ff98348
1190f83
3fbefc1
37ea1f7
b8c01b6
39db094
10826cd
608cdc2
3a3d7f2
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -7,32 +7,49 @@ | |
class ConfigurationFile(configparser.ConfigParser): | ||
"""Represents a configuration ini file on disk""" | ||
|
||
DEFAULTS = dict(save_password=False) | ||
|
||
def __init__(self, config_file=None): | ||
super().__init__(default_section='defaults') | ||
|
||
self['defaults'] = dict(save_password=False) | ||
self[self.default_section] = dict(self.DEFAULTS) | ||
|
||
self.file = config_file | ||
|
||
if self.file is not None: | ||
self.load() | ||
|
||
@property | ||
def has_defaults(self) -> bool: | ||
"""True if the defaults section has settings beyond our defaults""" | ||
return len(self.defaults()) > len(self.DEFAULTS) | ||
|
||
@property | ||
def is_initialised(self) -> bool: | ||
"""True if there is at least one section""" | ||
"""True if there is at least one section or a defaults section""" | ||
return len( | ||
self.sections() | ||
) > 0 | ||
) > 0 or self.has_defaults | ||
|
||
def load(self): | ||
self.read_file(self.file) | ||
|
||
def initialise(self, config_name='default'): | ||
# For backwards compatibility, we check if they have a default | ||
# section instead of a defaults section and do a little switcheroo as | ||
# needed. | ||
if self.has_section('default') and not self.has_defaults: | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This might get a bit confusing.
If we say |
||
print("It looks like you're using a the deprecated 'default' " | ||
"section.\nConsider renaming the section to 'defaults'.") | ||
self.default_section = 'default' | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. In regards to whether this is still relevant, it depends on how we want to use There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Sure this was just in response to the reported issue; upon investigating I realized that until recently initialization was writing to a profile named 'default' so it seems like we should support it (or do a major version bump). There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Ah right. Your call. At the very least, I'll write details for the configuration behaviour. If you do close it, we can always come back to this branch. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Sounds good, thanks. I'll pull the default swizzling into a separate PR and we can discuss there. |
||
|
||
def initialise(self, config_name=None): | ||
""" | ||
Prompt the user for configurations, and save them to the | ||
onelogin-aws-cli config file | ||
""" | ||
print("Configure Onelogin and AWS\n\n") | ||
if not config_name: | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This will never be falsey unless calling functions pass a There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Oops, this got leftover from the merge. |
||
config_name = self.default_section | ||
|
||
config_section = self.section(config_name) | ||
|
||
config_section['base_uri'] = user_choice( | ||
|
@@ -68,7 +85,10 @@ def section(self, section_name: str): | |
:param section_name: Name of the section in the config file | ||
:return: | ||
""" | ||
if not self.has_section(section_name): | ||
if not section_name: | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. @drewsonne This is the check I was referring to in regards to default section handling |
||
section_name = self.default_section | ||
if section_name != self.default_section and \ | ||
not self.has_section(section_name): | ||
self.add_section(section_name) | ||
return Section(section_name, self) | ||
|
||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I... am confused...? what's the difference between the defaults section and the defaults?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I can clarify the comment, but I just meant that if it's properly initialized, they should have something beyond
save_password
(i.e., "our defaults") which we inject into the defaults section.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
"""True if the defaults section in the config file has key/values in addition to those defined in
onelogin_aws_cli.ConfigurationFile.DEFAULTS
"""am I understanding that right?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yep, that's much more eloquent (although it occurs to me I should make the check more accurate than it is now).