הגדרת כללי מדיניות

בדף הזה מוסבר בקצרה על תיקיות ואיך לנהל מסמכים באמצעות תיקיות.

מנוע המדיניות והכללים

במאגר המסמכים, Policy Engine מאפשר למשתמשים להגדיר ולבצע פעולות נפוצות במסמכים (לדוגמה, אימות או עדכון) במהלך יצירה או עדכון של מסמכים.

כללים וקבוצות כללים

כלל ברמה גבוהה הוא הגדרה שמוגדרת על ידי המשתמש ומציינת את הפרטים הבאים:

  • מה מפעיל את בדיקת הכללים,
  • איזה תנאי נבדק, ו
  • אילו פעולות מופעלות כשהתנאי מתקיים.

בנוסף למפרטים האלה, כל כלל כולל מידע על התיאור, המקור, היעד ותנאי ההפעלה.

אוסף לוגי של כללים נקרא RuleSet. לדוגמה, אפשר לקבץ כללים שפועלים על אותה סכימה ב-RuleSet אחד. הלקוחות יכולים להגדיר כמה קבוצות של כללים.

כללים שימושיים להפעלה אוטומטית של פעולות מוגדרות מראש, בזמן יצירה או עדכון של מסמכים.

כלל מורכב משלושה דברים עיקריים:

  • TriggerType: אירוע שבו צריך להתחיל את בדיקת הכלל. הסוגים הנתמכים של גורמים מפעילים הם Create (יצירה) ו-Update (עדכון).
  • תנאי הכלל: התנאי שנבדק אחרי שזוהה סוג טריגר מסוים. אפשר להגדיר תנאים באמצעות Common Expression Language ‏ (CEL). כל תנאי צריך להחזיר פלט בוליאני.
  • פעולות: קבוצת שלבים שמופעלים כשהתנאי של הכלל מתקיים. כשמתבצעת הערכה של תנאי של כלל מסוים והוא מתקיים, הפעולה התואמת (שמוגדרת בכלל) מבוצעת. אלה הפרטים הכלליים על פעולות ספציפיות שמוטמעות ב-Document Warehouse:
    • פעולת אימות נתונים: פעולה שמאפשרת לאמת שדות ספציפיים במסמך במהלך יצירה או עדכון של מסמך.
    • פעולת עדכון נתונים: פעולה שמאפשרת לעדכן שדות ספציפיים במסמך במהלך יצירה או עדכון של מסמך. עדכונים כאלה מופעלים כשהתנאי של הכלל מתקיים.
    • מחיקת פעולת מסמך: פעולה שמאפשרת למחוק את המסמך במהלך עדכון המסמך, אם שדות מסוימים עומדים בקריטריונים למחיקה שהוגדרו באמצעות תנאי הכלל.
    • פעולה להכללת תיקייה: פעולה שמוסיפה באופן אוטומטי מסמך חדש (או מסמך מעודכן) לתיקיות ספציפיות. אפשר לציין תיקיות כאלה ישירות באמצעות השם שלהן.
    • הפעולה 'הסרה מהתיקייה': פעולה שמסירה באופן אוטומטי מסמך חדש מתיקיות נתונות כשמתקיים תנאי ברמת הכלל.
    • פעולה של בקרת גישה: פעולה שמאפשרת לעדכן את הרשימות של בקרת הגישה (קבוצות וקישורי משתמשים) במהלך יצירת המסמך. עדכונים כאלה מופעלים כשהתנאי של הכלל מתקיים.
    • פעולת פרסום: פעולה שמפרסמת הודעות ספציפיות בערוץ Pub/Sub של המשתמש כשמתקיים תנאי ברמת הכלל.

ניהול של קבוצות כללים

‫Document Warehouse מספק ממשקי API לניהול של RuleSets (יצירה, אחזור, עדכון, מחיקה, רשימה). בקטע הזה מופיעות דוגמאות להגדרת סוגים שונים של כללים.

יצירת קבוצת כללים

כדי ליצור קבוצת כללים:

REST

בקשה:

# Create a RuleSet for data validation.
curl -X POST -H "Authorization: Bearer $(gcloud auth print-access-token)" \
-H "Content-Type: application/json; charset=utf-8" \
https://contentwarehouse.googleapis.com/v1/projects/PROJECT_NUMBER/locations/LOCATION/ruleSets \
-d '{
  "rules": [
    {
      "trigger_type": "ON_CREATE",
      "condition": "documentType == \'W9\' && STATE ==\'CA\'",
      "actions": {
        "data_validation": {
          "conditions": {
            "NAME": "NAME != \'\'",
            "FILING_COST": "FILING_COST > 10.0"
          }
        }
      },
      "enabled": true
    }
  ],
  "description": "W9: Basic validation check rules."
}'

תשובה

{
  "description": "W9: Basic validation check rules.",
  "name": "RULE_SET_NAME",
  "rules": [
    {
      "actions": [
        {
          "actionId": "de0e6b84-106b-44ba-b1c4-0b3ad6ddc719",
          "dataValidation": {
            "conditions": {
              "FILING_COST": "FILING_COST > 10.0",
              "NAME": "NAME != ''"
            }
          }
        }
      ],
      "condition": "documentType == 'W9' && STATE =='CA'",
      "enabled": true,
      "triggerType": "ON_CREATE"
    }
  ]
}

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 = "us" # Format is 'us' or 'eu'


def create_rule_set(project_number: str, location: str) -> None:
    # Create a client
    client = contentwarehouse.RuleSetServiceClient()

    # The full resource name of the location, e.g.:
    # projects/{project_number}/locations/{location}
    parent = client.common_location_path(project=project_number, location=location)

    actions = contentwarehouse.Action(
        delete_document_action=contentwarehouse.DeleteDocumentAction(
            enable_hard_delete=True
        )
    )

    rules = contentwarehouse.Rule(
        trigger_type="ON_CREATE",
        condition="documentType == 'W9' && STATE =='CA'",
        actions=[actions],
    )

    rule_set = contentwarehouse.RuleSet(
        description="W9: Basic validation check rules.",
        source="My Organization",
        rules=[rules],
    )

    # Initialize request argument(s)
    request = contentwarehouse.CreateRuleSetRequest(parent=parent, rule_set=rule_set)

    # Make the request
    response = client.create_rule_set(request=request)

    # Handle the response
    print(f"Rule Set Created: {response}")

    # Initialize request argument(s)
    request = contentwarehouse.ListRuleSetsRequest(
        parent=parent,
    )

    # Make the request
    page_result = client.list_rule_sets(request=request)

    # Handle the response
    for response in page_result:
        print(f"Rule Sets: {response}")

Java

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

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

import com.google.cloud.contentwarehouse.v1.Action;
import com.google.cloud.contentwarehouse.v1.ActionOrBuilder;
import com.google.cloud.contentwarehouse.v1.CreateRuleSetRequest;
import com.google.cloud.contentwarehouse.v1.CreateRuleSetRequestOrBuilder;
import com.google.cloud.contentwarehouse.v1.DeleteDocumentAction;
import com.google.cloud.contentwarehouse.v1.DeleteDocumentActionOrBuilder;
import com.google.cloud.contentwarehouse.v1.ListRuleSetsRequest;
import com.google.cloud.contentwarehouse.v1.ListRuleSetsRequestOrBuilder;
import com.google.cloud.contentwarehouse.v1.LocationName;
import com.google.cloud.contentwarehouse.v1.Rule;
import com.google.cloud.contentwarehouse.v1.Rule.TriggerType;
import com.google.cloud.contentwarehouse.v1.RuleOrBuilder;
import com.google.cloud.contentwarehouse.v1.RuleSet;
import com.google.cloud.contentwarehouse.v1.RuleSetOrBuilder;
import com.google.cloud.contentwarehouse.v1.RuleSetServiceClient;
import com.google.cloud.contentwarehouse.v1.RuleSetServiceClient.ListRuleSetsPagedResponse;
import com.google.cloud.contentwarehouse.v1.RuleSetServiceSettings;
import com.google.cloud.resourcemanager.v3.Project;
import com.google.cloud.resourcemanager.v3.ProjectName;
import com.google.cloud.resourcemanager.v3.ProjectsClient;
import java.io.IOException;
import java.util.concurrent.ExecutionException;
import java.util.concurrent.TimeoutException;


public class CreateRuleSet {

  public static void createRuleSet() throws IOException, 
        InterruptedException, ExecutionException, TimeoutException { 
    // TODO(developer): Replace these variables before running the sample.
    String projectId = "your-project-id";
    String location = "your-region"; // Format is "us" or "eu".
    createRuleSet(projectId, location);
  }

  public static void createRuleSet(String projectId, String location)
      throws IOException, InterruptedException, ExecutionException, TimeoutException {
    String projectNumber = getProjectNumber(projectId);

    String endpoint = "contentwarehouse.googleapis.com:443";
    if (!"us".equals(location)) {
      endpoint = String.format("%s-%s", location, endpoint);
    }
    RuleSetServiceSettings ruleSetServiceSettings =
        RuleSetServiceSettings.newBuilder().setEndpoint(endpoint).build();

    // Create a Rule Set Service Client 
    try (RuleSetServiceClient ruleSetServiceClient = 
        RuleSetServiceClient.create(ruleSetServiceSettings)) {
      /*  The full resource name of the location, e.g.:
      projects/{project_number}/locations/{location} */
      String parent = LocationName.format(projectNumber, location); 

      // Create a Delete Document Action to be added to the Rule Set 
      DeleteDocumentActionOrBuilder deleteDocumentAction = 
          DeleteDocumentAction.newBuilder().setEnableHardDelete(true).build();

      // Add Delete Document Action to Action Object 
      ActionOrBuilder action = Action.newBuilder()
            .setDeleteDocumentAction((DeleteDocumentAction) deleteDocumentAction).build();

      // Create rule to add to rule set 
      RuleOrBuilder rule = Rule.newBuilder()
          .setTriggerType(TriggerType.ON_CREATE)
          .setCondition("documentType == 'W9' && STATE =='CA' ")
          .addActions(0, (Action) action).build();

      // Create rule set and add rule to it
      RuleSetOrBuilder ruleSetOrBuilder = RuleSet.newBuilder()
          .setDescription("W9: Basic validation check rules.")
          .setSource("My Organization")
          .addRules((Rule) rule).build();

      // Create and prepare rule set request to client
      CreateRuleSetRequestOrBuilder createRuleSetRequest = 
          CreateRuleSetRequest.newBuilder()
              .setParent(parent)
              .setRuleSet((RuleSet) ruleSetOrBuilder).build();

      RuleSet response = ruleSetServiceClient.createRuleSet(
          (CreateRuleSetRequest) createRuleSetRequest);

      System.out.println("Rule set created: " + response.toString());

      ListRuleSetsRequestOrBuilder listRuleSetsRequest = 
          ListRuleSetsRequest.newBuilder()
              .setParent(parent).build();

      ListRuleSetsPagedResponse listRuleSetsPagedResponse = 
          ruleSetServiceClient.listRuleSets((ListRuleSetsRequest) listRuleSetsRequest);

      listRuleSetsPagedResponse.iterateAll().forEach(
          (ruleSet -> System.out.print(ruleSet))
      );
    }
  }

  private static String getProjectNumber(String projectId) throws IOException { 
    try (ProjectsClient projectsClient = ProjectsClient.create()) { 
      ProjectName projectName = ProjectName.of(projectId); 
      Project project = projectsClient.getProject(projectName);
      String projectNumber = project.getName(); // Format returned is projects/xxxxxx
      return projectNumber.substring(projectNumber.lastIndexOf("/") + 1);
    } 
  }
}

List RuleSets

כדי להציג את קבוצות הכללים בפרויקט:

REST

בקשה:

# List all rule-sets for a project.
curl -X GET -H "Authorization: Bearer $(gcloud auth print-access-token)" \
-H "Content-Type: application/json; charset=utf-8" \
https://contentwarehouse.googleapis.com/v1/projects/PROJECT_NUMBER/locations/LOCATION/ruleSets

תשובה

{
  "ruleSets": [
    {
      "description": "W9: Basic validation check rules.",
      "rules": [
        {
          "triggerType": "ON_CREATE",
          "condition": "documentType == 'W9' && STATE =='CA'",
          "actions": [
            {
              "actionId": "fcf79ae8-9a1f-4462-9262-eb2e7161350c",
              "dataValidation": {
                "conditions": {
                  "NAME": "NAME != ''",
                  "FILING_COST": "FILING_COST > 10.0"
                }
              }
            }
          ],
          "enabled": true
        }
      ],
      "name": "RULE_SET_NAME"
    }
  ]
}

קבלת RuleSet

כדי לקבל קבוצת כללים באמצעות השם שלה:

REST

בקשה:

# Get a rule-set using rule-set ID.
curl -X GET -H "Authorization: Bearer $(gcloud auth print-access-token)" \
-H "Content-Type: application/json; charset=utf-8" \
https://contentwarehouse.googleapis.com/v1/projects/PROJECT_NUMBER/locations/LOCATION/ruleSets/RULE_SET

תשובה

{
  "description": "W9: Basic validation check rules.",
  "rules": [
    {
      "triggerType": "ON_CREATE",
      "condition": "documentType == 'W9' && STATE =='CA'",
      "actions": [
        {
          "actionId": "7559346b-ec9f-4143-ab1c-1912f5588807",
          "dataValidation": {
            "conditions": {
              "NAME": "NAME != ''",
              "FILING_COST": "FILING_COST > 10.0"
            }
          }
        }
      ],
      "enabled": true
    }
  ],
  "name": "RULE_SET_NAME"
}

מחיקת קבוצת כללים

כדי למחוק קבוצת כללים באמצעות השם שלה:

REST

בקשה:

# Get a rule-set using rule-set ID.
curl -X DELETE -H "Authorization: Bearer $(gcloud auth print-access-token)" \
-H "Content-Type: application/json; charset=utf-8" \
https://contentwarehouse.googleapis.com/v1/projects/PROJECT_NUMBER/locations/LOCATION/ruleSets/RULE_SET

פעולות של כללים

בקטע הזה נסביר על ביטויי הכללים ועל דוגמאות לכל פעולת כלל.

תנאים לדוגמה

תנאי הוא הביטוי שצוין באמצעות Common Expression Language.

דוגמאות:

  • ביטוי של שדה מחרוזת
    • STATE == \'CA\'. בדיקה אם הערך של השדה STATE שווה ל-CA
    • NAME != \'\'. מוודאים שהערך של השדה NAME לא ריק.
  • ביטוי של שדה מספרי
    • FILING_COST > 10.0. בודקים אם הערך של השדה FILING_COST (מוגדר כערך צף) גדול מ-10.0.

איך בודקים אם מסמך שייך לסכימה ספציפית

כדי להתייחס לסוג סכימה ספציפי, משתמשים בשם השדה המיוחד documentType (זו מילה שמורה). הוא מוערך בהשוואה לשדה DisplayName ב-DocumentSchema.

דוגמה:

  • documentType == \'W9\'

התנאי הקודם בודק אם לסכימה של המסמך (באמצעות מילת המפתח documentType) יש שם תצוגה W9.

איך מתייחסים לערכים של מאפייני מסמך קיימים ולערכים של מאפייני מסמך חדשים

כדי לתמוך בתנאים שכוללים מאפיינים קיימים ומאפיינים חדשים, משתמשים בשני הקידומות הבאות עם אופרטור נקודה כדי לגשת לגרסה הספציפית של המאפיין:

  • OLD_ כדי להפנות למאפיינים קיימים של המסמך.
  • NEW_ כדי להתייחס למאפיינים חדשים של המסמך בבקשה.

דוגמה:

  • OLD_.state == \'TX\' && NEW_.state == \'CA\' בודקת שהערך הקיים של מאפיין המצב הוא TX והערך החדש שצוין הוא CA.

טיפול בשדות תאריך

במסמך DriverLicense, אם EXPIRATION_DATE הוא לפני תאריך מסוים

  • מעדכנים את הערך של EXPIRATION_STATUS (שדה enum) (או מוסיפים ערך חדש אם אין ערך) כך שיהיה שווה ל-EXPIRING_BEFORE_CLOSING_DATE.

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

REST

בקשה:

# Check if document expires before a date and update the status field
curl -X POST -H "Authorization: Bearer $(gcloud auth print-access-token)" \
-H "Content-Type: application/json; charset=utf-8" \
https://contentwarehouse.googleapis.com/v1/projects/PROJECT_NUMBER/locations/LOCATION/ruleSets \
-d '{
  "rules":[
    {
      "trigger_type": "ON_CREATE",
      "description": "Expiration date check rule",
      "condition": "documentType==\'DriverLicense\' && EXPIRATION_DATE  < timestamp(\'2021-08-01T00:00:00Z\')",
      "actions": {
        "data_update": {
          "entries": {
            "EXPIRATION_STATUS": "EXPIRING_BEFORE_CLOSING_DATE"
          }
        }
      }
    }
  ]
}'

כלל לאימות נתונים

אימות מסמך W9 עבור STATE (שדה טקסט) בקליפורניה:

  • בודקים שהשדה NAME (שדה טקסט) לא ריק.
  • בודקים שהערך של FILING_COST (שדה מסוג float) גדול מ-10.0.

REST

בקשה:

# Rules for data validation.
curl -X POST -H "Authorization: Bearer $(gcloud auth print-access-token)" \
-H "Content-Type: application/json; charset=utf-8" \
https://contentwarehouse.googleapis.com/v1/projects/PROJECT_NUMBER/locations/LOCATION/ruleSets \
-d '{
  "rules": [
    {
      "trigger_type": "ON_CREATE",
      "condition": "documentType == \'W9\' && STATE ==\'CA\'",
      "actions": {
        "data_validation": {
          "conditions": {
            "NAME": "NAME != \'\'",
            "FILING_COST": "FILING_COST > 10.0"
          }
        }
      },
      "enabled": true
    }
  ],
  "description": "W9: Basic validation check rules."
}'

כלל לעדכון נתונים

במסמך W9, אם השדה BUSINESS_NAME הוא Google:

  • מעדכנים (או מוסיפים חדש אם הוא לא קיים) שדה Address ששווה ל-1600 Amphitheatre Pkwy.
  • מעדכנים (או מוסיפים חדש אם הוא לא קיים) שדה EIN ששווה ל-77666666.

REST

בקשה:

# Rule for data update.
curl -X POST -H "Authorization: Bearer $(gcloud auth print-access-token)" \
-H "Content-Type: application/json; charset=utf-8" \
https://contentwarehouse.googleapis.com/v1/projects/PROJECT_NUMBER/locations/LOCATION/ruleSets \
-d '{
  "rules":[
    {
      "description": "W9: Rule to update address data and EIN.",
      "trigger_type": "ON_CREATE",
      "condition": "documentType==\'W9\' && BUSINESS_NAME == \'Google\'",
      "actions": {
        "data_update": {
          "entries": {
            "Address": "1600 Amphitheatre Pkwy",
            "EIN": "776666666"
          }
        }
      }
    }
  ]
}'

כלל למחיקת מסמכים

במהלך עדכון המסמך W9, אם השדה BUSINESS_NAME משתנה ל-Google, המסמך יימחק.

REST

בקשה:

# Rule for deleting the document
curl -X POST -H "Authorization: Bearer $(gcloud auth print-access-token)" \
-H "Content-Type: application/json; charset=utf-8" \
https://contentwarehouse.googleapis.com/v1/projects/PROJECT_NUMBER/locations/LOCATION/ruleSets \
-d '{
  "rules": [
    {
      "description": "W9: Rule to delete the document during update.",
      "trigger_type": "ON_UPDATE",
      "condition": "documentType == \'W9\' && BUSINESS_NAME == \'Google\'",
      "actions": {
        "delete_document_action": {
          "enable_hard_delete": true
        }
      }
    }
  ]
}'

כלל בקרת גישה

במהלך העדכון של המסמך W9, אם השדה BUSINESS_NAME הוא Google, צריך לעדכן את קשרי המדיניות ששולטים בגישה למסמך

הוספת קישור חדש

כשמסמך עומד בתנאי של הכלל:

  • הוספת הרשאת עריכה ל-user:a@example.com ול-group:xxx@example.com
  • הוספת התפקיד 'צפייה' ל-user:b@example.com ול-group:yyy@example.com

REST

בקשה:

# Rule for adding new policy binding while creating the document.
curl -X POST -H "Authorization: Bearer $(gcloud auth print-access-token)" \
-H "Content-Type: application/json; charset=utf-8" \
https://contentwarehouse.googleapis.com/v1/projects/PROJECT_NUMBER/locations/LOCATION/ruleSets \
-d '{
  "rules": [
    {
      "description": "W9: Rule to add new policy binding."
      "trigger_type": "ON_CREATE",
      "condition": "documentType == \'aca13aa9-6d0d-4b6b-a1eb-315dcb876bd1\' && BUSINESS_NAME == \'Google\'",
      "actions": {
        "access_control": {
          "operation_type": "ADD_POLICY_BINDING",
          "policy": {
            "bindings": [
              {
                "role": "roles/contentwarehouse.documentEditor",
                "members": ["user:a@example.com", "group:xxx@example.com"]
              },
              {
                "role": "roles/contentwarehouse.documentViewer",
                "members": ["user:b@example.com", "group:yyy@example.com"]
              }
            ]
          }
        }
      }
    }
  ]
}'

החלפת קישור קיים

אם מסמך עומד בתנאי הכלל, מחליפים את הקישור הקיים כך שיכלול רק את תפקיד העריכה עבור user:a@example.com ו-group:xxx@example.com.

REST

בקשה:

# Rule for replacing existing policy bindings with newly given bindings.
curl -X POST -H "Authorization: Bearer $(gcloud auth print-access-token)" \
-H "Content-Type: application/json; charset=utf-8" \
https://contentwarehouse.googleapis.com/v1/projects/PROJECT_NUMBER/locations/LOCATION/ruleSets \
-d '{
  "rules": [
    {
      "description": "W9: Rule to replace policy binding."
      "trigger_type": "ON_CREATE",
      "condition": "documentType == \'a9e37d07-9cfa-4b4d-b372-53162e3b8bd9\' && BUSINESS_NAME == \'Google\'",
      "actions": {
        "access_control": {
          "operation_type": "REPLACE_POLICY_BINDING",
          "policy": {
            "bindings": [
              {
                "role": "roles/contentwarehouse.documentEditor",
                "members": ["user:a@example.com", "group:xxx@example.com"]
              }
            ]
          }
        }
      }
    }
  ]
}'

הוספת כלל לתיקייה

כשיוצרים או מעדכנים תיקייה, אפשר להוסיף אותה לתיקיות סטטיות מוגדרות מראש או לתיקיות שתואמות לקריטריונים מסוימים לחיפוש.

הגדרת תיקיות סטטיות

כשיוצרים DriverLicense חדש, מוסיפים אותו לתיקייה שכבר נוצרה.

REST

בקשה:

curl -X POST -H "Authorization: Bearer $(gcloud auth print-access-token)" \
-H "Content-Type: application/json; charset=utf-8" \
https://contentwarehouse.googleapis.com/v1/projects/PROJECT_NUMBER/locations/LOCATION/ruleSets \
-d '{
  "rules": [
    {
      "trigger_type": "ON_CREATE",
      "condition": "documentType == \'DriverLicense\'",
      "actions": {
        "add_to_folder": {
          "folders": ["projects/821411934445/locations/us/documents/445en119hqp70"]
        }
      }
    }
  ]
}'

פרסום ב-Pub/Sub

כשמסמך נוצר או מתעדכן, או כשקישור נוצר או נמחק, אפשר לשלוח הודעת התראה לערוץ Pub/Sub.

שלבים לשימוש

  • יוצרים נושא Pub/Sub בפרויקט של הלקוח.
  • יוצרים כלל להפעלת פעולת הפרסום ב-Pub/Sub באמצעות הבקשה הבאה. (ראו את הדוגמה הבאה.)
  • מפעילים את ממשקי Document AI Warehouse API.
  • מוודאים שההודעות מתפרסמות בערוץ Pub/Sub.

דוגמה לכלל

כשמוסיפים מסמך לתיקייה (מופעל CreateLink API), אפשר להשתמש בכלל הבא כדי לשלוח הודעות התראה לנושא Pub/Sub.

REST

בקשה:

curl -X POST -H "Authorization: Bearer $(gcloud auth print-access-token)" \
-H "Content-Type: application/json; charset=utf-8" \
https://contentwarehouse.googleapis.com/v1/projects/PROJECT_NUMBER/locations/LOCATION/ruleSets \
-d '{
  "rules": [
    {
      "trigger_type": "ON_CREATE_LINK",
      "condition": "documentType == \'DriverLicenseFolder\'",
      "actions": {
        "publish_to_pub_sub": {
          "topic_id": "<topic_name>"
          "messages": "Added document under a folder."
        }
      }
    }
  ]
}'

פרטי הכלל

  • הפעולה הזו נתמכת בסוגי הטריגרים הבאים:

    • ON_CRATE: כשנוצר מסמך חדש.
    • ON_UPDATE: כשהמסמך מתעדכן.
    • ON_CRATE_LINK: כשנוצר קישור חדש.
    • ON_DELETE_LINK: כשקישור נמחק.
  • בטריגרים של יצירה ועדכון מסמכים, התנאי יכול לכלול מאפיינים של המסמך שנוצר או מתעדכן.

  • בטריגרים של יצירת קישור ומחיקת קישור, התנאי יכול לכלול רק מאפיינים של מסמך התיקייה שממנו המסמך מתווסף או מוסר.

  • אפשר להשתמש בשדהmessages כדי לשלוח רשימה של הודעות לערוץ Pub/Sub. שימו לב: בנוסף להודעות האלה, כברירת מחדל מתפרסמים גם השדות הבאים:

    • שם הסכימה, שם המסמך, סוג הטריגר, שם קבוצת הכללים, מזהה הכלל, מזהה הפעולה.
    • בטריגרים של יצירה ומחיקה של קישורים, ההתראות כוללות את פרטי הקישור הרלוונטיים שנוספו או נמחקו.