Skip to content

Commit

Permalink
Added Customer name and ID to reports
Browse files Browse the repository at this point in the history
  • Loading branch information
k-winters committed Jan 22, 2025
1 parent 90564ff commit 66ba7cd
Show file tree
Hide file tree
Showing 5 changed files with 43 additions and 13 deletions.
1 change: 1 addition & 0 deletions scubagoggles/auth.py
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ class GwsAuth:
f'{_base_auth_url}/admin.directory.orgunit.readonly',
f'{_base_auth_url}/admin.directory.user.readonly',
f'{_base_auth_url}/admin.directory.group.readonly',
f'{_base_auth_url}/admin.directory.customer.readonly',
f'{_base_auth_url}/apps.groups.settings',
f'{_base_auth_url}/cloud-identity.policies.readonly')

Expand Down
8 changes: 6 additions & 2 deletions scubagoggles/orchestrator.py
Original file line number Diff line number Diff line change
Expand Up @@ -232,6 +232,8 @@ def _run_reporter(self):
settings_data = json.load(file)
tenant_info = settings_data['tenant_info']
tenant_domain = tenant_info['domain']
tenant_ID = tenant_info['ID']
tenant_name = tenant_info['topLevelOU']
successful_calls = set(settings_data['successful_calls'])
unsuccessful_calls = set(settings_data['unsuccessful_calls'])

Expand Down Expand Up @@ -275,8 +277,8 @@ def _run_reporter(self):
timestamp_zulu = timestamp_utc.strftime('%Y-%m-%dT%H:%M:%S.%f')[:-3] + 'Z'

report_metadata = {
'TenantId': None,
'DisplayName': None,
'TenantId': tenant_ID,
'DisplayName': tenant_name,
'DomainName': tenant_domain,
'ProductSuite': 'GWS',
'ProductsAssessed': products_assessed,
Expand All @@ -294,6 +296,8 @@ def _run_reporter(self):
products_bar.set_description('Creating the HTML and JSON Report '
f'for {product}...')
reporter = Reporter(product,
tenant_ID,
tenant_name,
tenant_domain,
main_report_name,
prod_to_fullname,
Expand Down
31 changes: 24 additions & 7 deletions scubagoggles/provider.py
Original file line number Diff line number Diff line change
Expand Up @@ -416,13 +416,30 @@ def get_tenant_info(self) -> dict:
"""
Gets the high-level tenant info using the directory API
"""
primary_domain = 'Error Retrieving'
for domain in self.list_domains():
if domain['isPrimary']:
primary_domain = domain['domainName']
return {
'domain': primary_domain,
'topLevelOU': self._top_ou
tenantID = ''
try:
response = self._services['directory'].customers().get(customerKey = self._customer_id).execute()
tenant_ID = response.get('id')

primary_domain = 'Error Retrieving'
for domain in self.list_domains():
if domain['isPrimary']:
primary_domain = domain['domainName']
return {
'ID' : tenant_ID,
'domain': primary_domain,
'topLevelOU': self._top_ou
}
except Exception as exc:
warnings.warn(
f'Exception thrown while customer list: {exc}',
RuntimeWarning
)
self._unsuccessful_calls.add(ApiReference.LIST_CUSTOMERS.value)
return {
'ID': "",
'domain': primary_domain,
'topLevelOU': self._top_ou
}

def get_gws_logs(self, products: list, event: str) -> dict:
Expand Down
14 changes: 10 additions & 4 deletions scubagoggles/reporter/reporter.py
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,8 @@ class Reporter:
# pylint: disable-next=too-many-positional-arguments
def __init__(self,
product: str,
tenant_ID: str,
tenant_name: str,
tenant_domain: str,
main_report_name: str,
prod_to_fullname: dict,
Expand All @@ -44,6 +46,8 @@ def __init__(self,
"""Reporter class initialization
:param product: name of product being tested
:param tenant_ID: Unique ID of GWS Customer
:param tenant_name: Customer name
:param tenant_domain: The primary domain of the GWS org
:param main_report_name: Name of the main report HTML file.
:param prod_to_fullname: mapping of the product full names
Expand All @@ -59,6 +63,8 @@ def __init__(self,
"""

self._product = product
self._tenant_ID = tenant_ID
self._tenant_name = tenant_name
self._tenant_domain = tenant_domain
self._main_report_name = main_report_name
self._product_policies = product_policies
Expand Down Expand Up @@ -180,8 +186,8 @@ def build_front_page_html(cls, fragments: list, tenant_info: dict) -> str:
+ ' ' + time.tzname[time.daylight])

meta_data = ('<table style = "text-align:center;">'
'<tr><th>Customer Domain</th><th>Report Date</th></tr>'
f'<tr><td>{tenant_info["domain"]}</td><td>{report_date}'
'<tr><th>Customer Name</th><th>Customer Domain</th><th>Customer ID</th><th>Report Date</th></tr>'
f'<tr><td>{tenant_info["topLevelOU"]}</td><td>{tenant_info["domain"]}</td><td>{tenant_info["ID"]}</td><td>{report_date}'
'</td></tr></table>')

html = html.replace('{{TENANT_DETAILS}}', meta_data)
Expand Down Expand Up @@ -305,9 +311,9 @@ def _build_report_html(self, fragments: list) -> str:
report_date = (now.strftime('%m/%d/%Y %H:%M:%S')
+ ' ' + time.tzname[time.daylight])
meta_data = (f'<table style = "text-align:center;">'
'<tr><th>Customer Domain</th><th>Report Date</th>'
'<tr><th>Customer Name</th><th>Customer Domain</th><th>Cusomter ID</th><th>Report Date</th>'
'<th>Baseline Version</th><th>Tool Version</th></tr>'
f'<tr><td>{self._tenant_domain}</td><td>{report_date}</td>'
f'<tr><td>{self._tenant_name}</td><td>{self._tenant_domain}</td><td>{self._tenant_ID}</td><td>{report_date}</td>'
f'<td>{Version.suffix}</td><td>{Version.current}</td></tr>'
'</table>')

Expand Down
2 changes: 2 additions & 0 deletions scubagoggles/scuba_constants.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ class ApiReference(Enum):
LIST_OUS = 'directory/v1/orgunits/list'
LIST_DOMAINS = 'directory/v1/domains/list'
LIST_GROUPS = 'directory/v1/groups/list'
LIST_CUSTOMERS = 'directory/v1/customer/get'
LIST_ACTIVITIES = 'reports/v1/activities/list'
GET_GROUP = 'groups-settings/v1/groups/get'

Expand All @@ -26,6 +27,7 @@ class ApiUrl(Enum):
LIST_OUS = f'{BASE_URL}/directory/reference/rest/v1/orgunits/list'
LIST_DOMAINS = f'{BASE_URL}/directory/reference/rest/v1/domains/list'
LIST_GROUPS = f'{BASE_URL}/directory/reference/rest/v1/groups/list'
LIST_CUSTOMERS = f'{BASE_URL}/directory/v1/customer/get'
LIST_ACTIVITIES = f'{BASE_URL}/reports/reference/rest/v1/activities/list'
GET_GROUP = f'{BASE_URL}/groups-settings/v1/reference/groups/get'

Expand Down

0 comments on commit 66ba7cd

Please sign in to comment.