Deal with exports involving foreign keys where you don't have permission

This commit is contained in:
Jeff Bradberry
2020-04-28 13:50:12 -04:00
parent a531b85b31
commit 76fb605dcd

View File

@@ -61,6 +61,7 @@ class ApiV2(base.Base):
if _page.json.get('managed_by_tower'): if _page.json.get('managed_by_tower'):
return None return None
if post_fields is None: # Deprecated endpoint or insufficient permissions if post_fields is None: # Deprecated endpoint or insufficient permissions
log.error("Object export failed: %s", _page.endpoint)
return None return None
# Note: doing _page[key] automatically parses json blob strings, which can be a problem. # Note: doing _page[key] automatically parses json blob strings, which can be a problem.
@@ -74,8 +75,12 @@ class ApiV2(base.Base):
continue continue
rel_endpoint = self._cache.get_page(_page.related[key]) rel_endpoint = self._cache.get_page(_page.related[key])
if rel_endpoint is None: if rel_endpoint is None: # This foreign key is unreadable
return None # This foreign key is unreadable if post_fields[key].get('required'):
log.error("Foreign key export failed: %s", _page.related[key])
return None
log.error("Foreign key export failed, setting to null: %s", _page.related[key])
continue
natural_key = rel_endpoint.get_natural_key(self._cache) natural_key = rel_endpoint.get_natural_key(self._cache)
if natural_key is None: if natural_key is None:
return None # This foreign key has unresolvable dependencies return None # This foreign key has unresolvable dependencies