Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Zedr wfjt inventories #8353

Merged
merged 2 commits into from
Oct 12, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions awx/api/serializers.py
Original file line number Diff line number Diff line change
Expand Up @@ -3438,6 +3438,12 @@ def get_related(self, obj):
res['organization'] = self.reverse('api:organization_detail', kwargs={'pk': obj.organization.pk})
if obj.webhook_credential_id:
res['webhook_credential'] = self.reverse('api:credential_detail', kwargs={'pk': obj.webhook_credential_id})
if obj.inventory_id:
res['inventory'] = self.reverse(
'api:inventory_detail', kwargs={
'pk': obj.inventory_id
}
)
return res

def validate_extra_vars(self, value):
Expand Down
17 changes: 14 additions & 3 deletions awxkit/awxkit/api/pages/api.py
Original file line number Diff line number Diff line change
Expand Up @@ -72,10 +72,21 @@ def _export(self, _page, post_fields):
}

for key in post_fields:
if key not in _page.related:
continue
if key in _page.related:
related = _page.related[key]
else:
if post_fields[key]['type'] == 'id' and _page.json.get(key) is not None:
log.warning("Related link %r missing from %s, attempting to reconstruct endpoint.",
key, _page.endpoint)
resource = getattr(self, key, None)
if resource is None:
log.error("Unable to infer endpoint for %r on %s.", key, _page.endpoint)
continue
related = self._filtered_list(resource, _page.json[key]).results[0]
else:
continue

rel_endpoint = self._cache.get_page(_page.related[key])
rel_endpoint = self._cache.get_page(related)
if rel_endpoint is None: # This foreign key is unreadable
if post_fields[key].get('required'):
log.error("Foreign key %r export failed for object %s.", key, _page.endpoint)
Expand Down