Skip to content

Commit

Permalink
changed find_parent_ou function to find_ou function (#26)
Browse files Browse the repository at this point in the history
* Add BlockExtensionBasedOnRiskScore

* Add BlockExtensionBasedOnRiskScore

* Update README.md

* Add BlockExtensionBasedOnRiskScore

* Add BlockExtensionBasedOnRiskScore

* Add BlockExtensionBasedOnRiskScore

* Update BlockExtensionBasedOnRiskScore.py

fix for Spin AI Risk Score

* Add files via upload

401 Login Error at find_parent_org_unit_id Function fix.

* Add files via upload
  • Loading branch information
dymzd authored May 13, 2024
1 parent d602fb0 commit c5a85a3
Showing 1 changed file with 11 additions and 7 deletions.
18 changes: 11 additions & 7 deletions Python/BlockExtensionBasedOnRiskScore.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,6 @@
EXCEPTION_EXTENSION_IDs = ['callobklhcbilhphinckomhgkigmfocg']
# #/******* END: Customer to modify this section *******/


SCOPES = [
'https://www.googleapis.com/auth/admin.directory.device.chromebrowsers',
'https://www.googleapis.com/auth/chrome.management.reports.readonly',
Expand Down Expand Up @@ -196,17 +195,18 @@ def get_risk_score(extension_id, version):
return crxcavator_score, spin_score


def find_parent_org_unit_id(session, customer_id, ou_name):
def find_org_unit_id(session, customer_id, ou_name):

"""
Find the parent organization unit ID for a given organization unit name in Google Workspace.
Find the organization unit ID for a given organization unit name in Google Workspace.
Args:
session (AuthorizedSession): The authorized session for making API requests.
customer_id (str): The customer ID of the Google Workspace account.
ou_name (str): The name of the organization unit.
Returns:
str: The parent organization unit ID of the specified organization unit, or None if not found.
str: The organization unit ID of the specified organization unit, or None if not found.
"""
# Define the API URL
api_url = f'https://admin.googleapis.com/admin/directory/v1/customer/{customer_id}/orgunits?type=all'
Expand All @@ -216,10 +216,12 @@ def find_parent_org_unit_id(session, customer_id, ou_name):
response.raise_for_status() # Raises an HTTPError for bad responses
org_units = response.json().get('organizationUnits', [])

# Extract parentOrgUnitId for the specified OU name

# Extract OrgUnitId for the specified OU name
for org_unit in org_units:
if org_unit.get('name') == ou_name:
targetouid = org_unit.get('parentOrgUnitId')
targetouid = org_unit.get('orgUnitId')

targetouid = targetouid.replace('id:','')
return targetouid
return None
Expand All @@ -236,7 +238,9 @@ def main():
# This session will be used to make authenticated API requests.
session = AuthorizedSession(credentials)

TARGET_OU_ID = find_parent_org_unit_id(session, CUSTOMER_ID,TARGET_OU)

TARGET_OU_ID = find_org_unit_id(session, CUSTOMER_ID,TARGET_OU)


if TARGET_OU_ID == None:
print(f"Please check if Target OU name is correct: {TARGET_OU}")
Expand Down

0 comments on commit c5a85a3

Please sign in to comment.