Merge pull request #5018 from ryanpetrello/cli-deprecation-warnings

warn about endpoint deprecation in the CLI

Reviewed-by: https://github.com/apps/softwarefactory-project-zuul
This commit is contained in:
softwarefactory-project-zuul[bot]
2019-10-16 20:37:29 +00:00
committed by GitHub
3 changed files with 18 additions and 3 deletions

View File

@@ -205,6 +205,9 @@ class APIView(views.APIView):
response['X-API-Query-Count'] = len(q_times) response['X-API-Query-Count'] = len(q_times)
response['X-API-Query-Time'] = '%0.3fs' % sum(q_times) response['X-API-Query-Time'] = '%0.3fs' % sum(q_times)
if getattr(self, 'deprecated', False):
response['Warning'] = '299 awx "This resource has been deprecated and will be removed in a future release."' # noqa
return response return response
def get_authenticate_header(self, request): def get_authenticate_header(self, request):

View File

@@ -15,7 +15,7 @@ from .format import (add_authentication_arguments,
from .options import ResourceOptionsParser, UNIQUENESS_RULES from .options import ResourceOptionsParser, UNIQUENESS_RULES
from .resource import parse_resource, is_control_resource from .resource import parse_resource, is_control_resource
from awxkit import api, config, utils, exceptions, WSClient # noqa 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 from awxkit.awx.utils import uses_sessions # noqa
@@ -233,6 +233,12 @@ class CLI(object):
# parse the action from OPTIONS # parse the action from OPTIONS
parser = ResourceOptionsParser(self.v2, page, self.resource, subparsers) 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: if from_sphinx:
# Our Sphinx plugin runs `parse_action` for *every* available # Our Sphinx plugin runs `parse_action` for *every* available
# resource + action in the API so that it can generate usage # resource + action in the API so that it can generate usage

View File

@@ -68,6 +68,8 @@ def pk_or_name(v2, model_name, value, page=None):
class ResourceOptionsParser(object): class ResourceOptionsParser(object):
deprecated = False
def __init__(self, v2, page, resource, parser): def __init__(self, v2, page, resource, parser):
"""Used to submit an OPTIONS request to the appropriate endpoint """Used to submit an OPTIONS request to the appropriate endpoint
and apply the appropriate argparse arguments and apply the appropriate argparse arguments
@@ -94,9 +96,13 @@ class ResourceOptionsParser(object):
self.handle_custom_actions() self.handle_custom_actions()
def get_allowed_options(self): def get_allowed_options(self):
self.allowed_options = self.page.connection.options( options = self.page.connection.options(
self.page.endpoint + '1/' 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): def build_list_actions(self):
action_map = { action_map = {