rule_engine.proto 8.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276
  1. // Copyright 2022 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. syntax = "proto3";
  15. package google.cloud.contentwarehouse.v1;
  16. import "google/api/field_behavior.proto";
  17. import "google/api/resource.proto";
  18. import "google/iam/v1/policy.proto";
  19. option go_package = "google.golang.org/genproto/googleapis/cloud/contentwarehouse/v1;contentwarehouse";
  20. option java_multiple_files = true;
  21. option java_outer_classname = "RuleEngineProto";
  22. option java_package = "com.google.cloud.contentwarehouse.v1";
  23. // Represents a set of rules from a single customer.
  24. message RuleSet {
  25. option (google.api.resource) = {
  26. type: "contentwarehouse.googleapis.com/RuleSet"
  27. pattern: "projects/{project}/locations/{location}/ruleSets/{rule_set}"
  28. };
  29. // The resource name of the rule set. Managed internally.
  30. // Format:
  31. // projects/{project_number}/locations/{location}/ruleSet/{rule_set_id}.
  32. //
  33. // The name is ignored when creating a rule set.
  34. string name = 6;
  35. // Short description of the rule-set.
  36. string description = 1;
  37. // Source of the rules i.e., customer name.
  38. string source = 2;
  39. // List of rules given by the customer.
  40. repeated Rule rules = 3;
  41. }
  42. // Represents the rule for a content warehouse trigger.
  43. message Rule {
  44. enum TriggerType {
  45. UNKNOWN = 0;
  46. // Trigger for create document action.
  47. ON_CREATE = 1;
  48. // Trigger for update document action.
  49. ON_UPDATE = 4;
  50. }
  51. // Short description of the rule and its context.
  52. string description = 1;
  53. // ID of the rule. It has to be unique across all the examples.
  54. // This is managed internally.
  55. string rule_id = 2;
  56. // Identifies the trigger type for running the policy.
  57. TriggerType trigger_type = 3;
  58. // Represents the conditional expression to be evaluated.
  59. // Expression should evaluate to a boolean result.
  60. // When the condition is true actions are executed.
  61. // Example: user_role = "hsbc_role_1" AND doc.salary > 20000
  62. string condition = 4;
  63. // List of actions that are executed when the rule is satisfied.
  64. repeated Action actions = 5;
  65. }
  66. // Represents the action triggered by Rule Engine when the rule is true.
  67. message Action {
  68. // ID of the action. Managed internally.
  69. string action_id = 1;
  70. oneof action {
  71. // Action triggering access control operations.
  72. AccessControlAction access_control = 2;
  73. // Action triggering data validation operations.
  74. DataValidationAction data_validation = 3;
  75. // Action triggering data update operations.
  76. DataUpdateAction data_update = 4;
  77. // Action triggering create document link operation.
  78. AddToFolderAction add_to_folder = 5;
  79. // Action publish to Pub/Sub operation.
  80. PublishAction publish_to_pub_sub = 6;
  81. // Action removing a document from a folder.
  82. RemoveFromFolderAction remove_from_folder_action = 9;
  83. // Action deleting the document.
  84. DeleteDocumentAction delete_document_action = 10;
  85. }
  86. }
  87. // Represents the action responsible for access control list management
  88. // operations.
  89. message AccessControlAction {
  90. // Type of ACL modification operation.
  91. enum OperationType {
  92. UNKNOWN = 0;
  93. // Adds newly given policy bindings in the existing bindings list.
  94. ADD_POLICY_BINDING = 1;
  95. // Removes newly given policy bindings from the existing bindings list.
  96. REMOVE_POLICY_BINDING = 2;
  97. // Replaces existing policy bindings with the given policy binding list
  98. REPLACE_POLICY_BINDING = 3;
  99. }
  100. // Identifies the type of operation.
  101. OperationType operation_type = 1;
  102. // Represents the new policy from which bindings are added, removed or
  103. // replaced based on the type of the operation. the policy is limited to a few
  104. // 10s of KB.
  105. google.iam.v1.Policy policy = 2;
  106. }
  107. // Represents the action responsible for data validation operations.
  108. message DataValidationAction {
  109. // Map of (K, V) -> (field, string condition to be evaluated on the field)
  110. // E.g., ("age", "age > 18 && age < 60") entry triggers validation of field
  111. // age with the given condition. Map entries will be ANDed during validation.
  112. map<string, string> conditions = 1;
  113. }
  114. // Represents the action responsible for properties update operations.
  115. message DataUpdateAction {
  116. // Map of (K, V) -> (valid name of the field, new value of the field)
  117. // E.g., ("age", "60") entry triggers update of field age with a value of 60.
  118. // If the field is not present then new entry is added.
  119. // During update action execution, value strings will be casted to
  120. // appropriate types.
  121. map<string, string> entries = 1;
  122. }
  123. // Represents the action responsible for adding document under a folder.
  124. message AddToFolderAction {
  125. // Names of the folder under which new document is to be added.
  126. // Format:
  127. // projects/{project_number}/locations/{location}/documents/{document_id}.
  128. repeated string folders = 1 [(google.api.resource_reference) = {
  129. type: "contentwarehouse.googleapis.com/Document"
  130. }];
  131. }
  132. // Represents the action responsible for remove a document from a specific
  133. // folder.
  134. message RemoveFromFolderAction {
  135. // Condition of the action to be executed.
  136. string condition = 1;
  137. // Name of the folder under which new document is to be added.
  138. // Format:
  139. // projects/{project_number}/locations/{location}/documents/{document_id}.
  140. string folder = 2 [(google.api.resource_reference) = {
  141. type: "contentwarehouse.googleapis.com/Document"
  142. }];
  143. }
  144. // Represents the action responsible for publishing messages to a Pub/Sub topic.
  145. message PublishAction {
  146. // The topic id in the Pub/Sub service for which messages will be published
  147. // to.
  148. string topic_id = 1;
  149. // Messages to be published.
  150. repeated string messages = 2;
  151. }
  152. // Represents the action responsible for deleting the document.
  153. message DeleteDocumentAction {
  154. // Boolean field to select between hard vs soft delete options.
  155. // Set 'true' for 'hard delete' and 'false' for 'soft delete'.
  156. bool enable_hard_delete = 1;
  157. }
  158. // Records the output of Rule Engine including rule evaluation and actions
  159. // result.
  160. message RuleEngineOutput {
  161. // Name of the document against which the rules and actions were evaluated.
  162. string document_name = 3;
  163. // Output from Rule Evaluator containing matched, unmatched and invalid rules.
  164. RuleEvaluatorOutput rule_evaluator_output = 1;
  165. // Output from Action Executor containing rule and corresponding actions
  166. // execution result.
  167. ActionExecutorOutput action_executor_output = 2;
  168. }
  169. // Represents the output of the Rule Evaluator.
  170. message RuleEvaluatorOutput {
  171. // List of rules fetched from database for the given request trigger type.
  172. repeated Rule triggered_rules = 1;
  173. // A subset of triggered rules that are evaluated true for a given request.
  174. repeated Rule matched_rules = 2;
  175. // A subset of triggered rules that failed the validation check(s) after
  176. // parsing.
  177. repeated InvalidRule invalid_rules = 3;
  178. }
  179. // A triggered rule that failed the validation check(s) after parsing.
  180. message InvalidRule {
  181. // Triggered rule.
  182. Rule rule = 1;
  183. // Validation error on a parsed expression.
  184. string error = 2;
  185. }
  186. // Represents the output of the Action Executor.
  187. message ActionExecutorOutput {
  188. // List of rule and corresponding actions result.
  189. repeated RuleActionsPair rule_actions_pairs = 1;
  190. }
  191. // Represents a rule and outputs of associated actions.
  192. message RuleActionsPair {
  193. // Represents the rule.
  194. Rule rule = 1;
  195. // Outputs of executing the actions associated with the above rule.
  196. repeated ActionOutput action_outputs = 2;
  197. }
  198. // Represents the result of executing an action.
  199. message ActionOutput {
  200. // Represents execution state of the action.
  201. enum State {
  202. UNKNOWN = 0;
  203. // State indicating action executed successfully.
  204. ACTION_SUCCEEDED = 1;
  205. // State indicating action failed.
  206. ACTION_FAILED = 2;
  207. // State indicating action timed out.
  208. ACTION_TIMED_OUT = 3;
  209. // State indicating action is pending.
  210. ACTION_PENDING = 4;
  211. }
  212. // ID of the action.
  213. string action_id = 1;
  214. // State of an action.
  215. State action_state = 2;
  216. // Action execution output message.
  217. string output_message = 3;
  218. }