אחזור רשימה של בקרת גישה (ACL)

קבלת רשימה של בקרת גישה (ACL) למסמך או לפרויקט.

דוגמת קוד

Node.js

מידע נוסף מופיע במאמרי העזרה של Document AI Warehouse Node.js API.

כדי לבצע אימות ב-Document AI Warehouse, צריך להגדיר את Application Default Credentials. מידע נוסף זמין במאמר הגדרת אימות לסביבת פיתוח מקומית.


/**
 * TODO(developer): Uncomment these variables before running the sample.
 * const projectId = 'YOUR_PROJECT_ID';
 * const location = 'YOUR_PROJECT_LOCATION'; // Format is 'us' or 'eu'
 * const documentId = 'YOUR_DOCUMENT_ID',
 * const userId = "user:xxxx@example.com" // Format is "user:xxxx@example.com"
 */

// Import from google cloud
const {DocumentServiceClient} = require('@google-cloud/contentwarehouse').v1;

const apiEndpoint =
  location === 'us'
    ? 'contentwarehouse.googleapis.com'
    : `${location}-contentwarehouse.googleapis.com`;

// Create service client
const serviceClient = new DocumentServiceClient({apiEndpoint: apiEndpoint});

// Fetches access control policies on project or document level.
async function fetchACL() {
  // Initialize request argument(s)
  const request = {};
  if (documentId !== 'YOUR_DOCUMENT_ID') {
    // Full document resource name, e.g.:
    // projects/{project_id}/locations/{location}/documents/{document_id}
    request.resource = `projects/${projectId}/locations/${location}/documents/${documentId}`;
    request.requestMetadata = {userInfo: {id: userId}};
  } else {
    // Full document resource name, e.g.: projects/{project_id}
    request.resource = `projects/${projectId}`;
    request.projectOwner = true;
  }

  // Make Request
  const response = serviceClient.fetchAcl(request);

  // Print out response
  response.then(
    result => console.log(`Success! Response: \n${JSON.stringify(result)}`),
    error => console.log(`Failed! Response: \n${error}`)
  );
}

Python

מידע נוסף מופיע במאמרי העזרה של Document AI Warehouse Python API.

כדי לבצע אימות ב-Document AI Warehouse, צריך להגדיר את Application Default Credentials. מידע נוסף זמין במאמר הגדרת אימות לסביבת פיתוח מקומית.


from google.cloud import contentwarehouse

# TODO(developer): Uncomment these variables before running the sample.
# project_number = 'YOUR_PROJECT_NUMBER'
# location = 'YOUR_PROJECT_LOCATION' # Format is 'us' or 'eu'
# document_id = 'YOUR_DOCUMENT_ID'
# user_id = 'user:YOUR_SERVICE_ACCOUNT_ID' # Format is "user:xxxx@example.com"


def fetch_acl(
    project_number: str, location: str, user_id: str, document_id: str = ""
) -> None:
    """Fetches access control policies on project or document level.

    Args:
        project_number: Google Cloud project number.
        location: Google Cloud project location.
        user_id: user:YOUR_SERVICE_ACCOUNT_ID.
        document_id: Record id in Document AI Warehouse.
    """
    # Create a client
    client = contentwarehouse.DocumentServiceClient()

    # Initialize request argument(s)
    # Fetch document acl if document id is specified
    # else fetch acl on project level
    if document_id:
        request = contentwarehouse.FetchAclRequest(
            # The full resource name of the document, e.g.:
            # projects/{project_number}/locations/{location}/documents/{document_id}
            resource=client.document_path(project_number, location, document_id),
            request_metadata=contentwarehouse.RequestMetadata(
                user_info=contentwarehouse.UserInfo(id=user_id)
            ),
        )
    else:
        request = contentwarehouse.FetchAclRequest(
            # The full resource name of the project, e.g.:
            # projects/{project_number}
            resource=client.common_project_path(project_number),
            project_owner=True,
        )

    # Make Request
    response = client.fetch_acl(request)
    print(response)

המאמרים הבאים

כדי לחפש ולסנן דוגמאות קוד למוצרים אחרים של Google Cloud , אפשר להיעזר בGoogle Cloud דפדפן לדוגמה.