summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorJeff Bradberry <jeff.bradberry@gmail.com>2023-08-15 20:00:11 +0200
committerJeff Bradberry <jeff.bradberry@gmail.com>2023-08-15 21:55:10 +0200
commit4822dd79fcdfb0f046c62b41f013eeebb25fef97 (patch)
treed143117c8f990f9192b8c1cfb603d9f3f64da906
parentmake the default JOB_EVENT_BUFFER_SECONDS 1 seconds (#14335) (diff)
downloadawx-4822dd79fcdfb0f046c62b41f013eeebb25fef97.tar.xz
awx-4822dd79fcdfb0f046c62b41f013eeebb25fef97.zip
Revert "Improve performance for awx cli export (#13182)"
-rw-r--r--awxkit/awxkit/api/pages/api.py6
-rw-r--r--awxkit/awxkit/api/pages/page.py24
-rw-r--r--awxkit/awxkit/api/utils.py15
3 files changed, 18 insertions, 27 deletions
diff --git a/awxkit/awxkit/api/pages/api.py b/awxkit/awxkit/api/pages/api.py
index 7bcbb8a814..5b001ae560 100644
--- a/awxkit/awxkit/api/pages/api.py
+++ b/awxkit/awxkit/api/pages/api.py
@@ -162,7 +162,7 @@ class ApiV2(base.Base):
export_key = 'create_approval_template'
rel_option_endpoint = _page.related.get('create_approval_template')
- rel_post_fields = self._cache.get_post_fields(rel_option_endpoint)
+ rel_post_fields = utils.get_post_fields(rel_option_endpoint, self._cache)
if rel_post_fields is None:
log.debug("%s is a read-only endpoint.", rel_endpoint)
continue
@@ -202,7 +202,7 @@ class ApiV2(base.Base):
return utils.remove_encrypted(fields)
def _export_list(self, endpoint):
- post_fields = self._cache.get_post_fields(endpoint)
+ post_fields = utils.get_post_fields(endpoint, self._cache)
if post_fields is None:
return None
@@ -267,7 +267,7 @@ class ApiV2(base.Base):
def _import_list(self, endpoint, assets):
log.debug("_import_list -- endpoint: %s, assets: %s", endpoint.endpoint, repr(assets))
- post_fields = self._cache.get_post_fields(endpoint)
+ post_fields = utils.get_post_fields(endpoint, self._cache)
changed = False
diff --git a/awxkit/awxkit/api/pages/page.py b/awxkit/awxkit/api/pages/page.py
index c47ff20a08..4c26fd5314 100644
--- a/awxkit/awxkit/api/pages/page.py
+++ b/awxkit/awxkit/api/pages/page.py
@@ -495,7 +495,6 @@ class TentativePage(str):
class PageCache(object):
def __init__(self):
self.options = {}
- self.post_fields = {}
self.pages_by_url = {}
self.pages_by_natural_key = {}
@@ -517,29 +516,6 @@ class PageCache(object):
return self.options.setdefault(url, options)
- def get_post_fields(self, page):
- url = page.endpoint if isinstance(page, Page) else str(page)
- key = get_registered_page(url)
- if key in self.post_fields:
- return self.post_fields[key]
-
- options_page = self.get_options(page)
-
- if options_page is None:
- return None
-
- if 'POST' not in options_page.r.headers.get('Allow', ''):
- return None
-
- if 'POST' in options_page.json['actions']:
- post_fields = options_page.json['actions']['POST']
- else:
- log.warning("Insufficient privileges on %s, inferring POST fields from description.", options_page.endpoint)
- post_fields = utils.parse_description(options_page.json['description'])
- self.post_fields[key] = post_fields
-
- return post_fields
-
def set_page(self, page):
log.debug("set_page: %s %s", type(page), page.endpoint)
self.pages_by_url[page.endpoint] = page
diff --git a/awxkit/awxkit/api/utils.py b/awxkit/awxkit/api/utils.py
index 68ecc43b6f..119d68aa41 100644
--- a/awxkit/awxkit/api/utils.py
+++ b/awxkit/awxkit/api/utils.py
@@ -31,3 +31,18 @@ def remove_encrypted(value):
if isinstance(value, dict):
return {k: remove_encrypted(v) for k, v in value.items()}
return value
+
+
+def get_post_fields(page, cache):
+ options_page = cache.get_options(page)
+ if options_page is None:
+ return None
+
+ if 'POST' not in options_page.r.headers.get('Allow', ''):
+ return None
+
+ if 'POST' in options_page.json['actions']:
+ return options_page.json['actions']['POST']
+ else:
+ log.warning("Insufficient privileges on %s, inferring POST fields from description.", options_page.endpoint)
+ return parse_description(options_page.json['description'])