| 16 | 'use strict'; |
| 17 | |
| 18 | async function main( |
| 19 | projectId = 'YOUR_PROJECT_ID', |
| 20 | location = 'YOUR_PROJECT_LOCATION', |
| 21 | policyRole = 'YOUR_REQUESTED_ROLE', |
| 22 | policyMember = 'YOUR_REQUESTED_MEMBER', |
| 23 | userId = 'user:xxxx@example.com', |
| 24 | documentId = 'YOUR_DOCUMENT_ID' |
| 25 | ) { |
| 26 | // [START contentwarehouse_set_acl] |
| 27 | /** |
| 28 | * TODO(developer): Uncomment these variables before running the sample. |
| 29 | * project_id = 'YOUR_PROJECT_ID' |
| 30 | * location = 'YOUR_PROJECT_LOCATION' // Format is 'us' or 'eu' |
| 31 | * policyRole = 'YOUR_REQUESTED_ROLE', |
| 32 | * policyMember = 'YOUR_REQUESTED_MEMBER', |
| 33 | * user_id = 'user:YOUR_SERVICE_ACCOUNT_ID' # Format is "user:xxxx@example.com" |
| 34 | * document_id = 'YOUR_DOCUMENT_ID' |
| 35 | */ |
| 36 | |
| 37 | //Import service client from google cloud |
| 38 | const {DocumentServiceClient} = require('@google-cloud/contentwarehouse').v1; |
| 39 | |
| 40 | const apiEndpoint = |
| 41 | location === 'us' |
| 42 | ? 'contentwarehouse.googleapis.com' |
| 43 | : `${location}-contentwarehouse.googleapis.com`; |
| 44 | |
| 45 | // Create client |
| 46 | const serviceClient = new DocumentServiceClient({apiEndpoint: apiEndpoint}); |
| 47 | |
| 48 | // Set access control policies on project or document level. |
| 49 | async function setACL() { |
| 50 | //Initialize request argument(s) |
| 51 | const request = {}; |
| 52 | request.policy = { |
| 53 | bindings: [ |
| 54 | { |
| 55 | role: policyRole, |
| 56 | members: [policyMember], |
| 57 | }, |
| 58 | ], |
| 59 | }; |
| 60 | if (documentId !== 'YOUR_DOCUMENT_ID') { |
| 61 | // Full document resource name, e.g.: |
| 62 | // projects/{project_id}/locations/{location}/documents/{document_id} |
| 63 | request.resource = `projects/${projectId}/locations/${location}/documents/${documentId}`; |
| 64 | request.requestMetadata = {userInfo: {id: userId}}; |
| 65 | } else { |
| 66 | // Full document resource name, e.g.: projects/{project_id} |
| 67 | request.resource = `projects/${projectId}`; |
| 68 | request.projectOwner = true; |
| 69 | } |
| 70 | |
| 71 | // Make Request |
| 72 | const response = serviceClient.setAcl(request); |
| 73 | |
| 74 | // Print Response |
| 75 | response.then( |