mirror of
https://github.com/ansible/awx.git
synced 2026-01-11 01:57:35 -03:30
warn about endpoint deprecation in the CLI
This commit is contained in:
parent
1376b8a149
commit
c8a29bac66
@ -205,6 +205,9 @@ class APIView(views.APIView):
|
||||
response['X-API-Query-Count'] = len(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
|
||||
|
||||
def get_authenticate_header(self, request):
|
||||
|
||||
@ -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
|
||||
|
||||
@ -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 = {
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user