mirror of
https://github.com/ansible/awx.git
synced 2026-03-25 04:45:03 -02:30
Merge pull request #4692 from ryanpetrello/cli-detail-options
cli: make "detail" actions actually respect Allow: headers Reviewed-by: https://github.com/apps/softwarefactory-project-zuul
This commit is contained in:
@@ -244,10 +244,11 @@ class CLI(object):
|
|||||||
# parse any action arguments
|
# parse any action arguments
|
||||||
if self.resource != 'settings':
|
if self.resource != 'settings':
|
||||||
for method in ('list', 'modify', 'create'):
|
for method in ('list', 'modify', 'create'):
|
||||||
parser.build_query_arguments(
|
if method in parser.parser.choices:
|
||||||
method,
|
parser.build_query_arguments(
|
||||||
'GET' if method == 'list' else 'POST'
|
method,
|
||||||
)
|
'GET' if method == 'list' else 'POST'
|
||||||
|
)
|
||||||
if from_sphinx:
|
if from_sphinx:
|
||||||
parsed, extra = self.parser.parse_known_args(self.argv)
|
parsed, extra = self.parser.parse_known_args(self.argv)
|
||||||
else:
|
else:
|
||||||
|
|||||||
@@ -83,6 +83,7 @@ class ResourceOptionsParser(object):
|
|||||||
self.options = getattr(
|
self.options = getattr(
|
||||||
self.page.options().json, 'actions', {'GET': {}}
|
self.page.options().json, 'actions', {'GET': {}}
|
||||||
)
|
)
|
||||||
|
self.get_allowed_options()
|
||||||
if self.resource != 'settings':
|
if self.resource != 'settings':
|
||||||
# /api/v2/settings is a special resource that doesn't have
|
# /api/v2/settings is a special resource that doesn't have
|
||||||
# traditional list/detail endpoints
|
# traditional list/detail endpoints
|
||||||
@@ -91,6 +92,11 @@ class ResourceOptionsParser(object):
|
|||||||
|
|
||||||
self.handle_custom_actions()
|
self.handle_custom_actions()
|
||||||
|
|
||||||
|
def get_allowed_options(self):
|
||||||
|
self.allowed_options = self.page.connection.options(
|
||||||
|
self.page.endpoint + '1'
|
||||||
|
).headers['Allow'].split(', ')
|
||||||
|
|
||||||
def build_list_actions(self):
|
def build_list_actions(self):
|
||||||
action_map = {
|
action_map = {
|
||||||
'GET': 'list',
|
'GET': 'list',
|
||||||
@@ -110,7 +116,12 @@ class ResourceOptionsParser(object):
|
|||||||
add_output_formatting_arguments(parser, {})
|
add_output_formatting_arguments(parser, {})
|
||||||
|
|
||||||
def build_detail_actions(self):
|
def build_detail_actions(self):
|
||||||
for method in ('get', 'modify', 'delete'):
|
allowed = ['get']
|
||||||
|
if 'PUT' in self.allowed_options:
|
||||||
|
allowed.append('modify')
|
||||||
|
if 'DELETE' in self.allowed_options:
|
||||||
|
allowed.append('delete')
|
||||||
|
for method in allowed:
|
||||||
parser = self.parser.add_parser(method, help='')
|
parser = self.parser.add_parser(method, help='')
|
||||||
self.parser.choices[method].add_argument(
|
self.parser.choices[method].add_argument(
|
||||||
'id',
|
'id',
|
||||||
|
|||||||
@@ -13,6 +13,12 @@ from awxkit.api.pages import Page
|
|||||||
from awxkit.cli.options import ResourceOptionsParser
|
from awxkit.cli.options import ResourceOptionsParser
|
||||||
|
|
||||||
|
|
||||||
|
class ResourceOptionsParser(ResourceOptionsParser):
|
||||||
|
|
||||||
|
def get_allowed_options(self):
|
||||||
|
self.allowed_options = ['GET', 'POST', 'PUT', 'PATCH', 'DELETE']
|
||||||
|
|
||||||
|
|
||||||
class OptionsPage(Page):
|
class OptionsPage(Page):
|
||||||
|
|
||||||
def options(self):
|
def options(self):
|
||||||
|
|||||||
Reference in New Issue
Block a user