Skip to content
This repository was archived by the owner on Sep 16, 2020. It is now read-only.

support listing, retrieving, and updating Configure Tower in Tower setting values#252

Merged
ryanpetrello merged 14 commits intoansible:masterfrom
ryanpetrello:settings-cli
Mar 6, 2017
Merged

support listing, retrieving, and updating Configure Tower in Tower setting values#252
ryanpetrello merged 14 commits intoansible:masterfrom
ryanpetrello:settings-cli

Conversation

@ryanpetrello
Copy link
Contributor

No description provided.

@jlaska jlaska added the review label Mar 1, 2017
@ryanpetrello ryanpetrello force-pushed the settings-cli branch 2 times, most recently from 031dfcf to c2d7a46 Compare March 1, 2017 22:57
# rather than URLs, since this endpoint just takes integers.
for key in ('next', 'previous'):
if not response[key]:
if not response.get(key):
Copy link
Contributor

Choose a reason for hiding this comment

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

This alone will not prevent AttributeError, response.get(key, None) will.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

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"

Copy link
Contributor

Choose a reason for hiding this comment

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

Indeed. I didn't try get without default value before, sorry.

@resources.command(ignore_defaults=True)
def modify(self, pk, value, **kwargs):
"""Modify an already existing object."""
prev_value = self.get(pk)['value']
Copy link
Member

Choose a reason for hiding this comment

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

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.

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 thought about this and one area that this falls apart is encrypted field values - we can't really tell if those changed :/

Copy link
Member

Choose a reason for hiding this comment

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

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).

raise exc.NotFound('The requested object could not be found.')

@resources.command(ignore_defaults=True)
def modify(self, pk, value, **kwargs):
Copy link
Member

Choose a reason for hiding this comment

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

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.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Don't we want use_fields_as_options so that the value can be specified via --value ?

Copy link
Member

Choose a reason for hiding this comment

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

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.

newattrs['endpoint'] = '/' + newattrs['endpoint']
if not newattrs['endpoint'].endswith('/'):
newattrs['endpoint'] += '/'
if isinstance(newattrs['endpoint'], basestring):
Copy link
Member

Choose a reason for hiding this comment

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

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.

Copy link
Contributor

Choose a reason for hiding this comment

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

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.

@AlanCoding AlanCoding added this to the release_3.1.0 milestone Mar 2, 2017
* 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)
@coveralls
Copy link

coveralls commented Mar 2, 2017

Coverage Status

Changes Unknown when pulling 75bbc93 on ryanpetrello:settings-cli into ** on ansible:master**.

@coveralls
Copy link

coveralls commented Mar 2, 2017

Coverage Status

Changes Unknown when pulling d33cec8 on ryanpetrello:settings-cli into ** on ansible:master**.

@coveralls
Copy link

coveralls commented Mar 2, 2017

Coverage Status

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
@coveralls
Copy link

coveralls commented Mar 2, 2017

Coverage Status

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()]
Copy link
Member

Choose a reason for hiding this comment

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

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.')
Copy link
Member

Choose a reason for hiding this comment

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

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.

@coveralls
Copy link

coveralls commented Mar 2, 2017

Coverage Status

Changes Unknown when pulling bed853f on ryanpetrello:settings-cli into ** on ansible:master**.

Copy link
Member

@AlanCoding AlanCoding left a comment

Choose a reason for hiding this comment

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

Tested, and the comments here are addressed sufficiently. Also consider issue 246, which could be added to this or implemented in a separate PR.

@AlanCoding
Copy link
Member

This is giving me trouble now:

$ tower-cli setting modify AUTH_LDAP_CONNECTION_OPTIONS '{"OPT_NETWORK_TIMEOUT": 40, "OPT_REFERRALS": 0}'
Error: The Tower server claims it was sent a bad request.

PATCH https://localhost:8043/api/v1/settings/all/
Params: None
Data: {"AUTH_LDAP_CONNECTION_OPTIONS": "{\"OPT_NETWORK_TIMEOUT\": 40, \"OPT_REFERRALS\": 0}"}

Response: {"AUTH_LDAP_CONNECTION_OPTIONS":["Expected a dictionary of items but got type \"unicode\"."]}

$ tower-cli setting modify AUTH_LDAP_CONNECTION_OPTIONS {"OPT_NETWORK_TIMEOUT": 40, "OPT_REFERRALS": 0}
Usage: tower-cli setting modify [OPTIONS] SETTING [VALUE]

Error: Got unexpected extra arguments (40, OPT_REFERRALS: 0})

How can we edit JSON settings?

Copy link
Member

@AlanCoding AlanCoding left a comment

Choose a reason for hiding this comment

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

I want to get JSON content working first, I might submit a patch

@coveralls
Copy link

coveralls commented Mar 6, 2017

Coverage Status

Changes Unknown when pulling 121d2a0 on ryanpetrello:settings-cli into ** on ansible:master**.

Copy link
Member

@AlanCoding AlanCoding left a comment

Choose a reason for hiding this comment

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

LGTM

@coveralls
Copy link

coveralls commented Mar 6, 2017

Coverage Status

Coverage increased (+0.1%) to 94.514% when pulling ecc9df2 on ryanpetrello:settings-cli into 4b88052 on ansible:master.

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

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants