Created
May 30, 2025 14:39
-
-
Save annextuckner/fe5d9ade573797e72b6cd77d90738473 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| from google.oauth2 import service_account | |
| from googleapiclient.discovery import build | |
| import json | |
| def main(): | |
| # Authenticate the service account | |
| scopes = ['https://www.googleapis.com/auth/chrome.management.policy'] | |
| admin_to_impersonate = '' | |
| credentials = service_account.Credentials.from_service_account_file( | |
| 'acsa.json', scopes=scopes, subject=admin_to_impersonate | |
| ) | |
| # Build the service for Chrome Policy API | |
| service = build('chromepolicy', 'v1', credentials=credentials) | |
| customer_id = 'my_customer' # Or your actual customer ID | |
| org_unit_id = '' # Replace with your org unit ID | |
| extension_id = 'kbfnbcaeplbcioakkpcpgfkobkghlhen' # Replace with your extension ID | |
| body = { | |
| "requests": [ | |
| { | |
| "policyTargetKey": { | |
| "targetResource": f"orgunits/{org_unit_id}", | |
| "additionalTargetKeys": { | |
| "app_id": f"chrome:{extension_id}" | |
| } | |
| }, | |
| "policyValue": { | |
| "policySchema": "chrome.users.apps.InstallType", | |
| "value": { | |
| "appInstallType": "ALLOWED" | |
| } | |
| }, | |
| "updateMask": "appInstallType" | |
| } | |
| ] | |
| } | |
| response = service.customers().policies().orgunits().batchModify( | |
| customer=f"customers/{customer_id}", | |
| body=body | |
| ).execute() | |
| print(json.dumps(response, indent=2)) | |
| if __name__ == '__main__': | |
| main() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment