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

Condition on value not index when checking for lastModifiedTime. #454

Merged
merged 2 commits into from
Apr 28, 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
2 changes: 1 addition & 1 deletion tools/asset-inventory/asset_inventory/api_schema.py
Original file line number Diff line number Diff line change
Expand Up @@ -285,7 +285,7 @@ def _add_asset_export_fields(cls,
}]
if include_resource:
resource_schema = list(schema)
last_modified, _ = bigquery_schema.get_field_by_name(
_, last_modified = bigquery_schema.get_field_by_name(
resource_schema,
'lastModifiedTime')
if not last_modified:
Expand Down
30 changes: 30 additions & 0 deletions tools/asset-inventory/tests/test_api_schema.py
Original file line number Diff line number Diff line change
Expand Up @@ -201,6 +201,36 @@ def test_for_for_asset_type(self):
# name, asset_type, timestamp, resource, iam_policy
self.assertEqual(len(schema), 5)

def test_resource_last_modified(self):
# Test that resource lastModifiedTime takes precedence.
APISchema._discovery_document_cache = {
'https://www.googleapis.com/discovery/v1/apis/compute/v1/rest': {
'id': 'compute.v1',
'schemas': {
'Machine': {
'properties': {
'lastModifiedTime': {
'type': 'string',
'description': 'Track time of last change.'
}}}}},
'https://content.googleapis.com/discovery/v1/apis': {
'items': [{
'name': 'compute',
'version': 'v1',
'discoveryRestUrl': 'https://www.googleapis.com/discovery/v1/apis/compute/v1/rest'}]}}
schema = APISchema.bigquery_schema_for_resource(
'google.compute.Machine',
'Machine',
'https://www.googleapis.com/discovery/v1/apis/compute/v1/rest',
True, True)
data_fields = self.get_schema_data_field(schema)
self.assertEqual(
[{'field_type': 'STRING',
'name': 'lastModifiedTime',
'description': 'Track time of last change.',
'mode': 'NULLABLE'}],
data_fields)

def test_self_recursive_properties(self):
discovery_doc = {
'id': 'recursive#api',
Expand Down