support listing, retrieving, and updating Configure Tower in Tower setting values#252
Conversation
031dfcf to
c2d7a46
Compare
c2d7a46 to
9d47e83
Compare
| # rather than URLs, since this endpoint just takes integers. | ||
| for key in ('next', 'previous'): | ||
| if not response[key]: | ||
| if not response.get(key): |
There was a problem hiding this comment.
This alone will not prevent AttributeError, response.get(key, None) will.
There was a problem hiding this comment.
response is a dict, so it would be a KeyError. dict.get falls back to None, so I think this should work: https://docs.python.org/2/library/stdtypes.html#dict.get
python -c "print {}.get('missing') is None"
There was a problem hiding this comment.
Indeed. I didn't try get without default value before, sorry.
tower_cli/resources/setting.py
Outdated
| @resources.command(ignore_defaults=True) | ||
| def modify(self, pk, value, **kwargs): | ||
| """Modify an already existing object.""" | ||
| prev_value = self.get(pk)['value'] |
There was a problem hiding this comment.
If this were to behave like other tower-cli modify commands, I think that it would write a debug statement if prev_value==value, and avoid doing the patch.
There was a problem hiding this comment.
I thought about this and one area that this falls apart is encrypted field values - we can't really tell if those changed :/
There was a problem hiding this comment.
That's true. My personal vote is a no-op in these cases unless it is encrypted (I want to favor fewer database changes with logging settings in mind).
tower_cli/resources/setting.py
Outdated
| raise exc.NotFound('The requested object could not be found.') | ||
|
|
||
| @resources.command(ignore_defaults=True) | ||
| def modify(self, pk, value, **kwargs): |
There was a problem hiding this comment.
I take it that the pk is the string representing the key here. Given this code, I don't think the category will be relevant, so my gut tells me that use_fields_as_options should be set to False and that **kwargs could be safely removed. We also want to advertise that there's just one specific use-case we want to support for the command.
There was a problem hiding this comment.
Don't we want use_fields_as_options so that the value can be specified via --value ?
There was a problem hiding this comment.
Here you have value as an argument, and if it were an option (of the command like --value) I would expected it to be a keyword argument to the function. On the other hand, if you wanted to keep it as an argument you might consider decorating with @click.argument.
Also, use_fields_as_options can take a list, putting value into that would be one possibility.
tower_cli/models/base.py
Outdated
| newattrs['endpoint'] = '/' + newattrs['endpoint'] | ||
| if not newattrs['endpoint'].endswith('/'): | ||
| newattrs['endpoint'] += '/' | ||
| if isinstance(newattrs['endpoint'], basestring): |
There was a problem hiding this comment.
It looks like some python environment hit ./tower_cli/models/base.py:118:45: F821 undefined name 'basestring'. I think that jangsutsr was working on a solution to that problem, and he's probably figured it out by now.
There was a problem hiding this comment.
That's true. It will fail python3, where basestring is removed. This is also the reason for travis test failures. Try using six.text_type or whatever is suitable.
* if a setting is modified, but the provided value isn't different than the current setting, don't actually PATCH * if an encrypted setting is modified, *always* PATCH (and show the value as changed, because there's really no way to tell for sure)
|
Changes Unknown when pulling 75bbc93 on ryanpetrello:settings-cli into ** on ansible:master**. |
|
Changes Unknown when pulling d33cec8 on ryanpetrello:settings-cli into ** on ansible:master**. |
|
Changes Unknown when pulling 966c4e8 on ryanpetrello:settings-cli into ** on ansible:master**. |
this changes from the invocation from: $ tower-cli setting modify SETTING_NAME --value=1812 to: $ tower-cli setting modify SETTING_NAME 1812
|
Changes Unknown when pulling 73d1473 on ryanpetrello:settings-cli into ** on ansible:master**. |
| finally: | ||
| self.custom_category = None | ||
| return { | ||
| 'results': [{'id': k, 'value': v} for k, v in result.items()] |
There was a problem hiding this comment.
this also affects just doing tower-cli setting list
| try: | ||
| return next(s for s in self.list()['results'] if s['id'] == pk) | ||
| except StopIteration: | ||
| raise exc.NotFound('The requested object could not be found.') |
There was a problem hiding this comment.
I checked out your branch and this works:
tower-cli setting get SOCIAL_AUTH_SAML_ORGANIZATION_MAP
This does not work:
tower-cli setting get --value=SOCIAL_AUTH_SAML_ORGANIZATION_MAP
That's fine, I somewhat prefer the one that works, but the help text:
$ tower-cli setting get
Usage: tower-cli setting get [OPTIONS] [ID]
Return one and exactly one setting
Options:
--value TEXT [REQUIRED] The value field.
-h, --tower-host TEXT The location of the Ansible Tower host.
HTTPS is assumed as the protocol unless
"http://" is explicitly provided. This will
take precedence over a host provided to
`tower config`, if any.
-u, --tower-username TEXT Username to use to authenticate to Ansible
Tower. This will take precedence over a
username provided to `tower config`, if any.
-p, --tower-password TEXT Password to use to authenticate to Ansible
Tower. This will take precedence over a
password provided to `tower config`, if any.
-f, --format [human|json|yaml] Output format. The "human" format is
intended for humans reading output on the
CLI; the "json" and "yaml" formats provide
more data.
-v, --verbose Show information about requests being made.
--description-on Show description in human-formatted output.
--insecure Turn off insecure connection warnings. Set
config verify_ssl to make this permanent.
--certificate TEXT Path to a custom certificate file that will
be used throughout the command. Overwritten
by --insecure flag if set.
--help Show this message and exit.
I have a sense of what your edits to base.py did, and since the other standard use still works I'm fine with that, but you'll see that the help text points us to the --value usage. Because of that, use_fields_as_options may need to be revisited.
|
Changes Unknown when pulling bed853f on ryanpetrello:settings-cli into ** on ansible:master**. |
AlanCoding
left a comment
There was a problem hiding this comment.
Tested, and the comments here are addressed sufficiently. Also consider issue 246, which could be added to this or implemented in a separate PR.
|
This is giving me trouble now: How can we edit JSON settings? |
AlanCoding
left a comment
There was a problem hiding this comment.
I want to get JSON content working first, I might submit a patch
|
Changes Unknown when pulling 121d2a0 on ryanpetrello:settings-cli into ** on ansible:master**. |
e54578f to
ecc9df2
Compare
No description provided.