1// Copyright 2023 Google LLC 2// 3// Licensed under the Apache License, Version 2.0 (the "License"); 4// you may not use this file except in compliance with the License. 5// You may obtain a copy of the License at 6// 7// http://www.apache.org/licenses/LICENSE-2.0 8// 9// Unless required by applicable law or agreed to in writing, software 10// distributed under the License is distributed on an "AS IS" BASIS, 11// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12// See the License for the specific language governing permissions and 13// limitations under the License. 14 15syntax = "proto3"; 16 17package google.cloud.contentwarehouse.v1; 18 19import "google/api/field_behavior.proto"; 20import "google/api/resource.proto"; 21import "google/iam/v1/policy.proto"; 22 23option csharp_namespace = "Google.Cloud.ContentWarehouse.V1"; 24option go_package = "cloud.google.com/go/contentwarehouse/apiv1/contentwarehousepb;contentwarehousepb"; 25option java_multiple_files = true; 26option java_outer_classname = "RuleEngineProto"; 27option java_package = "com.google.cloud.contentwarehouse.v1"; 28option php_namespace = "Google\\Cloud\\ContentWarehouse\\V1"; 29option ruby_package = "Google::Cloud::ContentWarehouse::V1"; 30 31// Represents a set of rules from a single customer. 32message RuleSet { 33 option (google.api.resource) = { 34 type: "contentwarehouse.googleapis.com/RuleSet" 35 pattern: "projects/{project}/locations/{location}/ruleSets/{rule_set}" 36 }; 37 38 // The resource name of the rule set. Managed internally. 39 // Format: 40 // projects/{project_number}/locations/{location}/ruleSet/{rule_set_id}. 41 // 42 // The name is ignored when creating a rule set. 43 string name = 6; 44 45 // Short description of the rule-set. 46 string description = 1; 47 48 // Source of the rules i.e., customer name. 49 string source = 2; 50 51 // List of rules given by the customer. 52 repeated Rule rules = 3; 53} 54 55// Represents the rule for a content warehouse trigger. 56message Rule { 57 // The trigger types for actions. 58 enum TriggerType { 59 // Trigger for unknown action. 60 UNKNOWN = 0; 61 62 // Trigger for create document action. 63 ON_CREATE = 1; 64 65 // Trigger for update document action. 66 ON_UPDATE = 4; 67 68 // Trigger for create link action. 69 ON_CREATE_LINK = 7; 70 71 // Trigger for delete link action. 72 ON_DELETE_LINK = 8; 73 } 74 75 // Short description of the rule and its context. 76 string description = 1; 77 78 // ID of the rule. It has to be unique across all the examples. 79 // This is managed internally. 80 string rule_id = 2; 81 82 // Identifies the trigger type for running the policy. 83 TriggerType trigger_type = 3; 84 85 // Represents the conditional expression to be evaluated. 86 // Expression should evaluate to a boolean result. 87 // When the condition is true actions are executed. 88 // Example: user_role = "hsbc_role_1" AND doc.salary > 20000 89 string condition = 4; 90 91 // List of actions that are executed when the rule is satisfied. 92 repeated Action actions = 5; 93} 94 95// Represents the action triggered by Rule Engine when the rule is true. 96message Action { 97 // ID of the action. Managed internally. 98 string action_id = 1; 99 100 oneof action { 101 // Action triggering access control operations. 102 AccessControlAction access_control = 2; 103 104 // Action triggering data validation operations. 105 DataValidationAction data_validation = 3; 106 107 // Action triggering data update operations. 108 DataUpdateAction data_update = 4; 109 110 // Action triggering create document link operation. 111 AddToFolderAction add_to_folder = 5; 112 113 // Action publish to Pub/Sub operation. 114 PublishAction publish_to_pub_sub = 6; 115 116 // Action removing a document from a folder. 117 RemoveFromFolderAction remove_from_folder_action = 9; 118 119 // Action deleting the document. 120 DeleteDocumentAction delete_document_action = 10; 121 } 122} 123 124// Represents the action responsible for access control list management 125// operations. 126message AccessControlAction { 127 // Type of ACL modification operation. 128 enum OperationType { 129 // The unknown operation type. 130 UNKNOWN = 0; 131 132 // Adds newly given policy bindings in the existing bindings list. 133 ADD_POLICY_BINDING = 1; 134 135 // Removes newly given policy bindings from the existing bindings list. 136 REMOVE_POLICY_BINDING = 2; 137 138 // Replaces existing policy bindings with the given policy binding list 139 REPLACE_POLICY_BINDING = 3; 140 } 141 142 // Identifies the type of operation. 143 OperationType operation_type = 1; 144 145 // Represents the new policy from which bindings are added, removed or 146 // replaced based on the type of the operation. the policy is limited to a few 147 // 10s of KB. 148 google.iam.v1.Policy policy = 2; 149} 150 151// Represents the action responsible for data validation operations. 152message DataValidationAction { 153 // Map of (K, V) -> (field, string condition to be evaluated on the field) 154 // E.g., ("age", "age > 18 && age < 60") entry triggers validation of field 155 // age with the given condition. Map entries will be ANDed during validation. 156 map<string, string> conditions = 1; 157} 158 159// Represents the action responsible for properties update operations. 160message DataUpdateAction { 161 // Map of (K, V) -> (valid name of the field, new value of the field) 162 // E.g., ("age", "60") entry triggers update of field age with a value of 60. 163 // If the field is not present then new entry is added. 164 // During update action execution, value strings will be casted to 165 // appropriate types. 166 map<string, string> entries = 1; 167} 168 169// Represents the action responsible for adding document under a folder. 170message AddToFolderAction { 171 // Names of the folder under which new document is to be added. 172 // Format: 173 // projects/{project_number}/locations/{location}/documents/{document_id}. 174 repeated string folders = 1 [(google.api.resource_reference) = { 175 type: "contentwarehouse.googleapis.com/Document" 176 }]; 177} 178 179// Represents the action responsible for remove a document from a specific 180// folder. 181message RemoveFromFolderAction { 182 // Condition of the action to be executed. 183 string condition = 1; 184 185 // Name of the folder under which new document is to be added. 186 // Format: 187 // projects/{project_number}/locations/{location}/documents/{document_id}. 188 string folder = 2 [(google.api.resource_reference) = { 189 type: "contentwarehouse.googleapis.com/Document" 190 }]; 191} 192 193// Represents the action responsible for publishing messages to a Pub/Sub topic. 194message PublishAction { 195 // The topic id in the Pub/Sub service for which messages will be published 196 // to. 197 string topic_id = 1; 198 199 // Messages to be published. 200 repeated string messages = 2; 201} 202 203// Represents the action responsible for deleting the document. 204message DeleteDocumentAction { 205 // Boolean field to select between hard vs soft delete options. 206 // Set 'true' for 'hard delete' and 'false' for 'soft delete'. 207 bool enable_hard_delete = 1; 208} 209 210// Records the output of Rule Engine including rule evaluation and actions 211// result. 212message RuleEngineOutput { 213 // Name of the document against which the rules and actions were evaluated. 214 string document_name = 3; 215 216 // Output from Rule Evaluator containing matched, unmatched and invalid rules. 217 RuleEvaluatorOutput rule_evaluator_output = 1; 218 219 // Output from Action Executor containing rule and corresponding actions 220 // execution result. 221 ActionExecutorOutput action_executor_output = 2; 222} 223 224// Represents the output of the Rule Evaluator. 225message RuleEvaluatorOutput { 226 // List of rules fetched from database for the given request trigger type. 227 repeated Rule triggered_rules = 1; 228 229 // A subset of triggered rules that are evaluated true for a given request. 230 repeated Rule matched_rules = 2; 231 232 // A subset of triggered rules that failed the validation check(s) after 233 // parsing. 234 repeated InvalidRule invalid_rules = 3; 235} 236 237// A triggered rule that failed the validation check(s) after parsing. 238message InvalidRule { 239 // Triggered rule. 240 Rule rule = 1; 241 242 // Validation error on a parsed expression. 243 string error = 2; 244} 245 246// Represents the output of the Action Executor. 247message ActionExecutorOutput { 248 // List of rule and corresponding actions result. 249 repeated RuleActionsPair rule_actions_pairs = 1; 250} 251 252// Represents a rule and outputs of associated actions. 253message RuleActionsPair { 254 // Represents the rule. 255 Rule rule = 1; 256 257 // Outputs of executing the actions associated with the above rule. 258 repeated ActionOutput action_outputs = 2; 259} 260 261// Represents the result of executing an action. 262message ActionOutput { 263 // Represents execution state of the action. 264 enum State { 265 // The unknown state. 266 UNKNOWN = 0; 267 268 // State indicating action executed successfully. 269 ACTION_SUCCEEDED = 1; 270 271 // State indicating action failed. 272 ACTION_FAILED = 2; 273 274 // State indicating action timed out. 275 ACTION_TIMED_OUT = 3; 276 277 // State indicating action is pending. 278 ACTION_PENDING = 4; 279 } 280 281 // ID of the action. 282 string action_id = 1; 283 284 // State of an action. 285 State action_state = 2; 286 287 // Action execution output message. 288 string output_message = 3; 289} 290