summaryrefslogtreecommitdiffstats
path: root/awxkit
diff options
context:
space:
mode:
authorArtsiom Musin <artyom.musin@gmail.com>2023-06-21 16:49:22 +0200
committerGitHub <noreply@github.com>2023-06-21 16:49:22 +0200
commit4bae961b5ffb3df7a68bd76cff84ea90f7d59d61 (patch)
treedc9e9e58ac159b9b409cf5e726b6cb523b0c8ca3 /awxkit
parentRename work signing private key filename (#14151) (diff)
downloadawx-4bae961b5ffb3df7a68bd76cff84ea90f7d59d61.tar.xz
awx-4bae961b5ffb3df7a68bd76cff84ea90f7d59d61.zip
Improve performance for awx cli export (#13182)
Co-authored-by: Jesse Wattenbarger <jwattenb@redhat.com>
Diffstat (limited to 'awxkit')
-rw-r--r--awxkit/awxkit/api/pages/api.py6
-rw-r--r--awxkit/awxkit/api/pages/page.py21
-rw-r--r--awxkit/awxkit/api/utils.py15
3 files changed, 24 insertions, 18 deletions
diff --git a/awxkit/awxkit/api/pages/api.py b/awxkit/awxkit/api/pages/api.py
index 5b001ae560..7bcbb8a814 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 = utils.get_post_fields(rel_option_endpoint, self._cache)
+ rel_post_fields = self._cache.get_post_fields(rel_option_endpoint)
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 = utils.get_post_fields(endpoint, self._cache)
+ post_fields = self._cache.get_post_fields(endpoint)
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 = utils.get_post_fields(endpoint, self._cache)
+ post_fields = self._cache.get_post_fields(endpoint)
changed = False
diff --git a/awxkit/awxkit/api/pages/page.py b/awxkit/awxkit/api/pages/page.py
index 4c26fd5314..d43840e536 100644
--- a/awxkit/awxkit/api/pages/page.py
+++ b/awxkit/awxkit/api/pages/page.py
@@ -495,6 +495,7 @@ class TentativePage(str):
class PageCache(object):
def __init__(self):
self.options = {}
+ self.post_fields = {}
self.pages_by_url = {}
self.pages_by_natural_key = {}
@@ -516,6 +517,26 @@ 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 '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 119d68aa41..68ecc43b6f 100644
--- a/awxkit/awxkit/api/utils.py
+++ b/awxkit/awxkit/api/utils.py
@@ -31,18 +31,3 @@ 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'])