From c8a29bac66b292abaa144f5a1b92bd10fdef8ee5 Mon Sep 17 00:00:00 2001 From: Ryan Petrello Date: Wed, 16 Oct 2019 12:03:16 -0400 Subject: warn about endpoint deprecation in the CLI --- awxkit/awxkit/cli/client.py | 8 +++++++- awxkit/awxkit/cli/options.py | 10 ++++++++-- 2 files changed, 15 insertions(+), 3 deletions(-) (limited to 'awxkit') diff --git a/awxkit/awxkit/cli/client.py b/awxkit/awxkit/cli/client.py index ed7408f177..6ccef0f12f 100755 --- a/awxkit/awxkit/cli/client.py +++ b/awxkit/awxkit/cli/client.py @@ -15,7 +15,7 @@ from .format import (add_authentication_arguments, from .options import ResourceOptionsParser, UNIQUENESS_RULES from .resource import parse_resource, is_control_resource from awxkit import api, config, utils, exceptions, WSClient # noqa -from awxkit.cli.utils import HelpfulArgumentParser, cprint, disable_color +from awxkit.cli.utils import HelpfulArgumentParser, cprint, disable_color, colored from awxkit.awx.utils import uses_sessions # noqa @@ -233,6 +233,12 @@ class CLI(object): # parse the action from OPTIONS parser = ResourceOptionsParser(self.v2, page, self.resource, subparsers) + if parser.deprecated: + description = 'This resource has been deprecated and will be removed in a future release.' + if not from_sphinx: + description = colored(description, 'yellow') + self.subparsers[self.resource].description = description + if from_sphinx: # Our Sphinx plugin runs `parse_action` for *every* available # resource + action in the API so that it can generate usage diff --git a/awxkit/awxkit/cli/options.py b/awxkit/awxkit/cli/options.py index 5156482df9..c303154827 100644 --- a/awxkit/awxkit/cli/options.py +++ b/awxkit/awxkit/cli/options.py @@ -68,6 +68,8 @@ def pk_or_name(v2, model_name, value, page=None): class ResourceOptionsParser(object): + deprecated = False + def __init__(self, v2, page, resource, parser): """Used to submit an OPTIONS request to the appropriate endpoint and apply the appropriate argparse arguments @@ -94,9 +96,13 @@ class ResourceOptionsParser(object): self.handle_custom_actions() def get_allowed_options(self): - self.allowed_options = self.page.connection.options( + options = self.page.connection.options( self.page.endpoint + '1/' - ).headers.get('Allow', '').split(', ') + ) + warning = options.headers.get('Warning', '') + if '299' in warning and 'deprecated' in warning: + self.deprecated = True + self.allowed_options = options.headers.get('Allow', '').split(', ') def build_list_actions(self): action_map = { -- cgit v1.2.3