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