summaryrefslogtreecommitdiffstats
path: root/awxkit
diff options
context:
space:
mode:
authorJeff Bradberry <jeff.bradberry@gmail.com>2020-04-02 21:20:43 +0200
committerJeff Bradberry <jeff.bradberry@gmail.com>2020-06-09 19:54:05 +0200
commita5fa34bd3bd3c04436e8602bfe64e49eef2bd3ce (patch)
tree3ee2758c26416668975977006683fbc93ca5d428 /awxkit
parentDrop objects that cannot be read or do not have a natural key (diff)
downloadawx-a5fa34bd3bd3c04436e8602bfe64e49eef2bd3ce.tar.xz
awx-a5fa34bd3bd3c04436e8602bfe64e49eef2bd3ce.zip
Fall back to parsing the OPTIONS description
to determine the needed fields for constructing an object.
Diffstat (limited to 'awxkit')
-rw-r--r--awxkit/awxkit/api/pages/api.py20
1 files changed, 17 insertions, 3 deletions
diff --git a/awxkit/awxkit/api/pages/api.py b/awxkit/awxkit/api/pages/api.py
index 5e1a91c49c..27d39968d2 100644
--- a/awxkit/awxkit/api/pages/api.py
+++ b/awxkit/awxkit/api/pages/api.py
@@ -1,5 +1,6 @@
import itertools
import logging
+import re
from awxkit.api.resources import resources
import awxkit.exceptions as exc
@@ -7,6 +8,7 @@ from . import base
from . import page
from ..mixins import has_create
+descRE = re.compile('^[*] `(\w+)`: [^(]*\((\w+), ([^)]+)\)')
log = logging.getLogger(__name__)
@@ -54,6 +56,17 @@ class Api(base.Base):
page.register_page(resources.api, Api)
+def parse_description(desc):
+ options = {}
+ for line in desc[desc.index('POST'):].splitlines():
+ match = descRE.match(line)
+ if not match:
+ continue
+ options[match.group(1)] = {'type': match.group(2),
+ 'required': match.group(3) == 'required'}
+ return options
+
+
class ApiV2(base.Base):
# Common import/export methods
@@ -77,9 +90,10 @@ class ApiV2(base.Base):
if 'POST' not in options.r.headers.get('Allow', ''):
return self._options.setdefault(url, None)
- # FIXME: if POST isn't in the actions, this is a view where we
- # don't have write permissions. Try to do something anyway.
- return self._options.setdefault(url, options.json['actions'].get('POST', {}))
+ if 'POST' in options.json['actions']:
+ return self._options.setdefault(url, options.json['actions']['POST'])
+ else:
+ return self._options.setdefault(url, parse_description(options.json['description']))
# Export methods