Skip to content
This repository has been archived by the owner on Jun 5, 2023. It is now read-only.

Add appengine services and versions to Inventory. #646

Merged
merged 7 commits into from
Sep 19, 2017
Merged

Conversation

blueandgold
Copy link
Contributor

@blueandgold blueandgold commented Sep 15, 2017

After looking at the data in the responses, it seems the best way to incorporate the services/versions data is to associate the versions to each service, and then put the whole services payload into a json column named services. Of course the services payload is part of the raw json column.

I will add testing if this approach is good. Otherwise, please let me know what else might work.

@@ -30,6 +30,7 @@
`default_bucket` varchar(255) DEFAULT NULL,
`iap` json DEFAULT NULL,
`gcr_domain` varchar(255) DEFAULT NULL,
`services` json DEFAULT NULL,
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'd prefer to see an APPENGINE_SERVICES, APPENGINE_VERSIONS and APPENGINE_INSTANCES tables added, with just json columns for the main data, and the required keys:

CREATE_APPENGINE_SERVICES_TABLE = """
CREATE TABLE {0} (
id bigint(20) unsigned NOT NULL AUTO_INCREMENT,
project_id varchar(255) DEFAULT NULL,
app_id varchar(255) DEFAULT NULL,
service_id varchar(255) DEFAULT NULL,
service json DEFAULT NULL,
PRIMARY KEY (id),
UNIQUE KEY service_key (app_id, service_id)
) ENGINE=InnoDB DEFAULT CHARSET=utf8;
"""

CREATE_APPENGINE_VERSIONS_TABLE = """
CREATE TABLE {0} (
id bigint(20) unsigned NOT NULL AUTO_INCREMENT,
project_id varchar(255) DEFAULT NULL,
app_id varchar(255) DEFAULT NULL,
service_id varchar(255) DEFAULT NULL,
version_id varchar(255) DEFAULT NULL,
version json DEFAULT NULL,
PRIMARY KEY (id),
UNIQUE KEY version_key (app_id, service_id, version_id)
) ENGINE=InnoDB DEFAULT CHARSET=utf8;
"""

CREATE_APPENGINE_INSTANCES_TABLE = """
CREATE TABLE {0} (
id bigint(20) unsigned NOT NULL AUTO_INCREMENT,
project_id varchar(255) DEFAULT NULL,
app_id varchar(255) DEFAULT NULL,
service_id varchar(255) DEFAULT NULL,
version_id varchar(255) DEFAULT NULL,
instance_id varchar(255) DEFAULT NULL,
instance json DEFAULT NULL,
PRIMARY KEY (id),
UNIQUE KEY instance_key (app_id, service_id, version_id, instance_id)
) ENGINE=InnoDB DEFAULT CHARSET=utf8;
"""
Then the pipeline can output the correct data to each table. That will be closer to the one row per resource that the new inventory will output.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Got it, will work on this!

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done. The only oddity is that it's easier to return the services, versions, instances data from retrieve() in loadable form. Versus forcing them into the app data, and then parse them out again in transform().

@codecov
Copy link

codecov bot commented Sep 19, 2017

Codecov Report

Merging #646 into dev will increase coverage by 0.06%.
The diff coverage is 100%.

@@            Coverage Diff            @@
##              dev    #646      +/-   ##
=========================================
+ Coverage   83.64%   83.7%   +0.06%     
=========================================
  Files         165     165              
  Lines        8321    8354      +33     
=========================================
+ Hits         6960    6993      +33     
  Misses       1361    1361
Impacted Files Coverage Δ
google/cloud/security/common/data_access/dao.py 61.29% <ø> (ø) ⬆️
...ity/inventory/pipelines/load_appengine_pipeline.py 100% <100%> (ø) ⬆️
...le/cloud/security/common/data_access/csv_writer.py 92.3% <100%> (+0.47%) ⬆️
...ty/common/data_access/sql_queries/create_tables.py 100% <100%> (ø) ⬆️

Copy link
Collaborator

@ahoying ahoying left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nice! This should be really useful.

self._get_loaded_count()

# TODO: Make _get_loaded_count() support multiple resources in a single
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nit: You could put this under the if apps: since if there are no apps there won't be any other resources either.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done!

@blueandgold blueandgold merged commit 3a4ad58 into dev Sep 19, 2017
@blueandgold blueandgold deleted the appengine branch September 19, 2017 18:46
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants