diff --git a/src/contactdelegation-v1.json b/src/contactdelegation-v1.json new file mode 100644 index 00000000..7f554ed6 --- /dev/null +++ b/src/contactdelegation-v1.json @@ -0,0 +1,237 @@ +{ + "basePath": "", + "baseUrl": "https://admin.googleapis.com/admin/contacts/v1/", + "batchPath": "batch", + "canonicalName": "contactdelegation", + "description": "The Contact Delegation API allows Admins to delegate access of one user's, called the delegator, contacts to another user, called the delegate.", + "discoveryVersion": "v1", + "documentationLink": "https://developers.google.com/admin-sdk/contact-delegation", + "fullyEncodeReservedExpansion": true, + "icons": { + "x16": "http://www.google.com/images/icons/product/search-16.gif", + "x32": "http://www.google.com/images/icons/product/search-32.gif" + }, + "id": "contactdelegation:v1", + "kind": "discovery#restDescription", + "name": "contactdelegation", + "ownerDomain": "google.com", + "ownerName": "Google", + "packagePath": "admin", + "parameters": { + "$.xgafv": { + "description": "V1 error format.", + "enum": [ + "1", + "2" + ], + "enumDescriptions": [ + "v1 error format", + "v2 error format" + ], + "location": "query", + "type": "string" + }, + "access_token": { + "description": "OAuth access token.", + "location": "query", + "type": "string" + }, + "alt": { + "default": "json", + "description": "Data format for response.", + "enum": [ + "json", + "media", + "proto" + ], + "enumDescriptions": [ + "Responses with Content-Type of application/json", + "Media download with context-dependent Content-Type", + "Responses with Content-Type of application/x-protobuf" + ], + "location": "query", + "type": "string" + }, + "callback": { + "description": "JSONP", + "location": "query", + "type": "string" + }, + "fields": { + "description": "Selector specifying which fields to include in a partial response.", + "location": "query", + "type": "string" + }, + "key": { + "description": "API key. Your API key identifies your project and provides you with API access, quota, and reports. Required unless you provide an OAuth 2.0 token.", + "location": "query", + "type": "string" + }, + "oauth_token": { + "description": "OAuth 2.0 token for the current user.", + "location": "query", + "type": "string" + }, + "prettyPrint": { + "default": "true", + "description": "Returns response with indentations and line breaks.", + "location": "query", + "type": "boolean" + }, + "quotaUser": { + "description": "Available to use for quota purposes for server-side applications. Can be any arbitrary string assigned to a user, but should not exceed 40 characters.", + "location": "query", + "type": "string" + }, + "uploadType": { + "description": "Legacy upload protocol for media (e.g. \"media\", \"multipart\").", + "location": "query", + "type": "string" + }, + "upload_protocol": { + "description": "Upload protocol for media (e.g. \"raw\", \"multipart\").", + "location": "query", + "type": "string" + } + }, + "protocol": "rest", + "resources": { + "delegates": { + "methods": { + "create": { + "description": "Creates a contact delegations", + "flatPath": "users/{user}/delegates", + "httpMethod": "POST", + "id": "contactdelegations.delegates.create", + "parameterOrder": [ + "user" + ], + "parameters": { + "user": { + "description": "Email address of the delegator.", + "location": "path", + "required": true, + "type": "string" + } + }, + "path": "users/{user}/delegates/{delegate}", + "request": { + "$ref": "Delegate" + }, + "scopes": [ + "https://www.googleapis.com/auth/admin.contact.delegation" + ] + }, + "delete": { + "description": "Deletes a contact delegation.", + "flatPath": "users/{user}/delegates/{delegate}", + "httpMethod": "DELETE", + "id": "contactdelegations.delegates.delete", + "parameterOrder": [ + "user", + "delegate" + ], + "parameters": { + "delegate": { + "description": "Email address of the delegate", + "location": "path", + "required": true, + "type": "string" + }, + "user": { + "description": "Email address of the delegator.", + "location": "path", + "required": true, + "type": "string" + } + }, + "path": "users/{user}/delegates/{delegate}", + "scopes": [ + "https://www.googleapis.com/auth/admin.contact.delegation" + ] + }, + "list": { + "description": "Lists contact delegates for a user", + "flatPath": "users/{user}/delegates", + "httpMethod": "GET", + "id": "contactdelegations.delegates.list", + "parameterOrder": [ + "user" + ], + "parameters": { + "pageSize": { + "description": "Determines how many delegates are returned in each response. ", + "format": "int32", + "location": "query", + "minimum": "1", + "type": "integer" + }, + "pageToken": { + "description": "Token to specify the next page in the list.", + "location": "query", + "type": "string" + }, + "user": { + "description": "Email address of the delegator.", + "location": "path", + "required": true, + "type": "string" + } + }, + "path": "users/{user}/delegates", + "response": { + "$ref": "Delegates" + }, + "scopes": [ + "https://www.googleapis.com/auth/admin.contact.delegation", + "https://www.googleapis.com/auth/admin.contact.delegation.readonly" + ] + } + } + } + }, + "rootUrl": "https://admin.googleapis.com/admin/contacts/v1/", + "schemas": { + "Delegate": { + "description": "JSON template for a delegate.", + "id": "Delegate", + "properties": { + "email": { + "description": "Email of the delegate.", + "type": "string" + } + }, + "type": "object" + }, + "Delegates": { + "id": "Delegates", + "properties": { + "delegates": { + "description": "List of delegates.", + "items": { + "$ref": "Delegate" + }, + "type": "array" + }, + "etag": { + "description": "ETag of the resource.", + "type": "string" + }, + "kind": { + "default": "", + "description": "Kind of resource this is.", + "type": "string" + }, + "nextPageToken": { + "description": "Token used to access the next page of this result. To access the next page, use this token's value in the `pageToken` query string of this request.", + "type": "string" + } + }, + "type": "object" + } + }, + "servicePath": "", + "title": "Contact Delegation API", + "version": "v1", + "version_module": true +} diff --git a/src/gam/__init__.py b/src/gam/__init__.py index 1ece8a89..9f383fb6 100755 --- a/src/gam/__init__.py +++ b/src/gam/__init__.py @@ -53,6 +53,7 @@ from gam.gapi import cloudidentity as gapi_cloudidentity from gam.gapi import cbcm as gapi_cbcm from gam.gapi.cloudidentity import devices as gapi_cloudidentity_devices from gam.gapi.cloudidentity import groups as gapi_cloudidentity_groups +from gam.gapi import contactdelegation as gapi_contactdelegation from gam.gapi.directory import asps as gapi_directory_asps from gam.gapi.directory import cros as gapi_directory_cros from gam.gapi.directory import customer as gapi_directory_customer @@ -10215,14 +10216,18 @@ OAUTH2_SCOPES = [ 'subscopes': ['readonly'], 'scopes': 'https://www.googleapis.com/auth/cloud-identity.groups' }, + { + 'name': 'Contact Delegation', + 'subscopes': ['readonly'], + 'scopes': 'https://www.googleapis.com/auth/admin.contact.delegation' + }, { 'name': 'Data Transfer API', 'subscopes': ['readonly'], 'scopes': 'https://www.googleapis.com/auth/admin.datatransfer' }, { - 'name': - 'Directory API - Chrome OS Devices', + 'name': 'Directory API - Chrome OS Devices', 'subscopes': ['readonly'], 'scopes': 'https://www.googleapis.com/auth/admin.directory.device.chromeos' @@ -11597,6 +11602,8 @@ def ProcessGAMCommand(args): printShowTeamDrives(users, False) elif showWhat in ['teamdriveinfo']: doGetTeamDriveInfo(users) + elif showWhat in ['contactdelegation']: + gapi_contactdelegation.print_(users) else: controlflow.invalid_argument_exit(showWhat, 'gam show') elif command == 'print': @@ -11625,6 +11632,8 @@ def ProcessGAMCommand(args): printShowTokens(5, 'users', users, True) elif printWhat in ['teamdrive', 'teamdrives']: printShowTeamDrives(users, True) + elif printWhat in ['contactdelegation']: + gapi_contactdelegation.print_(users) else: controlflow.invalid_argument_exit(printWhat, 'gam print') @@ -11705,6 +11714,8 @@ def ProcessGAMCommand(args): deleteSmime(users) elif delWhat == 'teamdrive': doDeleteTeamDrive(users) + elif delWhat == 'contactdelegate': + gapi_contactdelegation.delete(users) else: controlflow.invalid_argument_exit(delWhat, 'gam delete') elif command in ['add', 'create']: @@ -11737,6 +11748,8 @@ def ProcessGAMCommand(args): addSmime(users) elif addWhat == 'teamdrive': doCreateTeamDrive(users) + elif addWhat == 'contactdelegation': + gapi_contactdelegation.create(users) else: controlflow.invalid_argument_exit(addWhat, f'gam {command}') diff --git a/src/gam/gapi/contactdelegation.py b/src/gam/gapi/contactdelegation.py new file mode 100644 index 00000000..912c4e8c --- /dev/null +++ b/src/gam/gapi/contactdelegation.py @@ -0,0 +1,75 @@ +"""Contact Delegation API calls""" + +import csv +import os.path +import sys + +import gam +from gam import controlflow +from gam import display +from gam import gapi + + +def build(): + return gam.buildGAPIObject('contactdelegation') + + +def create(users): + condel = build() + delegate = gam.normalizeEmailAddressOrUID(sys.argv[5], noUid=True) + body = {'email': delegate} + i = 0 + count = len(users) + for user in users: + i += 1 + print( + f'Granting {delegate} contact delegate access to {user}{gam.currentCount(i, count)}' + ) + body + gapi.call(condel.delegates(), + 'create', + soft_errors=True, + user=user, + body=body) + + +def delete(users): + condel = build() + delegate = gam.normalizeEmailAddressOrUID(sys.argv[5], noUid=True) + i = 0 + count = len(users) + for user in users: + i += 1 + print( + f'Deleting {delegate} contact delegate access to {user}{gam.currentCount(i, count)}' + ) + gapi.call(condel.delegates(), + 'delete', + soft_errors=True, + user=user, + delegate=delegate) + + +def print_(users): + condel = build() + titles = ['user', 'delegate'] + csv_rows = [] + todrive = False + i = 5 + while i < len(sys.argv): + myarg = sys.argv[i].lower().replace('_', '') + if myarg == 'todrive': + todrive = True + i += 1 + else: + controlflow.invalid_argument_exit(sys.argv[i], + 'gam print browsers') + page_message = gapi.got_total_items_msg('Contact Delegates', '...\n') + for user in users: + delegates = gapi.get_all_pages(condel.delegates(), 'list', + 'delegates', + page_message=page_message, + user=user) + for delegate in delegates: + csv_rows.append({'user': user, 'delegate': delegate.get('email')}) + display.write_csv_file(csv_rows, titles, 'Contact Delegates', todrive) diff --git a/src/gam/var.py b/src/gam/var.py index acfe81ba..6f6c49c2 100644 --- a/src/gam/var.py +++ b/src/gam/var.py @@ -266,6 +266,7 @@ API_VER_MAPPING = { 'cloudidentity_beta': 'v1beta1', 'cloudresourcemanager': 'v2', 'cloudresourcemanagerv1': 'v1', + 'contactdelegation': 'v1', 'datatransfer': 'datatransfer_v1', 'directory': 'directory_v1', 'drive': 'v2',