From c1a07ff00b08ad35674e979b3f6f675e1a8f34bf Mon Sep 17 00:00:00 2001 From: Jeff Bradberry Date: Wed, 29 Jan 2020 13:21:13 -0500 Subject: [PATCH] Limit export output to only those fields needed to create the resource --- awxkit/awxkit/cli/resource.py | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/awxkit/awxkit/cli/resource.py b/awxkit/awxkit/cli/resource.py index 5629742511..c899126f96 100644 --- a/awxkit/awxkit/cli/resource.py +++ b/awxkit/awxkit/cli/resource.py @@ -133,13 +133,16 @@ class Export(CustomCommand): def get_resources(self, client, resource, value): api_resource = getattr(client.v2, resource) + post_fields = api_resource.options().json['actions']['POST'] if value: from .options import pk_or_name pk = pk_or_name(client.v2, resource, value) - return api_resource.get(id=pk).json['results'] + results = api_resource.get(id=pk).json['results'] else: - return api_resource.get(all_pages=True).json['results'] + results = api_resource.get(all_pages=True).json['results'] + + return [{key: r[key] for key in post_fields if key in r} for r in results] def handle(self, client, parser): self.extend_parser(parser) @@ -156,7 +159,7 @@ class Export(CustomCommand): value = getattr(parsed, resource, None) if value is None: continue - resources = self.get_resources(client, resource, value) or [] + resources = self.get_resources(client, resource, value) data[resource] = resources