// Copyright 2023 Styra, Inc. // // Licensed under the Apache License, Version 2.0 (the "License"); // you may not use this file except in compliance with the License. // You may obtain a copy of the License at // // https://www.apache.org/licenses/LICENSE-2.0 // // Unless required by applicable law or agreed to in writing, software // distributed under the License is distributed on an "AS IS" BASIS, // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. // See the License for the specific language governing permissions and // limitations under the License. syntax = "proto3"; package eopa.data.v1; import "google/protobuf/struct.proto"; import "google/protobuf/any.proto"; // DataDocument is a thin wrapper type around a JSON value located at a // particular path in the virtual document store. message DataDocument { string path = 1; google.protobuf.Value document = 2; // json value, like {"foo":true} or [1, 2, 3] } // InputDocument is a thin wrapper type around OPA inputs, which are always // JSON object types. message InputDocument { google.protobuf.Struct document = 1; // json object, like {"foo":true} } // PatchOp allows specifying a subset of JSON-Patch operations, namely // "add", "remove", and "replace". enum PatchOp { PATCH_OP_UNSPECIFIED = 0; PATCH_OP_ADD = 1; PATCH_OP_REMOVE = 2; PATCH_OP_REPLACE = 3; } // CreateDataRequest provides a document and the path to insert it at. message CreateDataRequest { DataDocument data = 1; } // CreateDataResponse is an empty confirmation message type. message CreateDataResponse { } // GetDataRequest queries the virtual document store at the specified path. // This path can target a rule, or any value under the `data` document. // // Input to a query can also be provided, as a key-value mapping that will // appear under the `input` document at runtime. For example, the following // input mapping: // ```json // { // "a": 2, // "b": "example", // "c": true // } // ```` // would map to `input.a`, `input.b`, and `input.c`, where `input.a` has // the value `2`, and so forth in a Rego policy. message GetDataRequest { string path = 1; InputDocument input = 2; } // GetDataResponse is the query result returned from a GetData operation. message GetDataResponse { DataDocument result = 1; } // UpdateDataRequest provides an optional document to patch in, and the // patch operation specifying whether it's a create/update/delete operation // to be performed. message UpdateDataRequest { DataDocument data = 1; // JSON value to be patched in, like {"foo":true} PatchOp op = 2; // If unspecified, defaults to "overwrite/replace". } // UpdateDataResponse is an empty confirmation message type. message UpdateDataResponse { } // DeleteDataRequest provides the path of a document to delete from the // document store. message DeleteDataRequest { string path = 1; } // DeleteDataResponse is an empty confirmation message type. message DeleteDataResponse { } // StreamingDataRequest provides a way to send DataService requests over // gRPC streams. Limited batching support is provided via the // `writes`/`reads` fields. As in the BulkRW API, if a write operation // fails, the entire request will be aborted. Writes are done as a single // transaction, reads are done in parallel. message StreamingDataRWRequest { // WriteDataRequest provides a union of possible Data request types. // This allows creating arbitrary sequences of data store operations. message WriteRequest { oneof req { CreateDataRequest create = 1; UpdateDataRequest update = 2; DeleteDataRequest delete = 3; } } // ReadRequest is currently a simple wrapper over the GetData // request type. message ReadRequest { GetDataRequest get = 1; } // writes provides a sequence of WriteData requests. repeated WriteRequest writes = 1; // reads provides a sequence of ReadData requests. repeated ReadRequest reads = 2; } // StreamingDataRWResponse contains lists of the appropriate response types // for each operation in the StreamingDataRWRequest. message StreamingDataRWResponse { // WriteResponse provides a union of possible Data request types. // This allows creating arbitrary sequences of data store operations. message WriteResponse { oneof resp { CreateDataResponse create = 1; UpdateDataResponse update = 2; DeleteDataResponse delete = 3; } } // ReadResponse is currently a simple wrapper over the GetData // request type. message ReadResponse { GetDataResponse get = 1; ErrorList errors = 2; } // writes provides a sequence of WriteData results. repeated WriteResponse writes = 1; // reads provides a sequence of ReadData results or errors. repeated ReadResponse reads = 2; } // Context-dependent error messages. message ErrorList { // The errors in the list. repeated google.protobuf.Any errors = 1; } service DataService { // CreateData looks up the document by path, and inserts a new JSON value // at the end of the path. // // This is equivalent in functionality to OPA's // [Data REST API Create/Overwrite method](https://www.openpolicyagent.org/docs/latest/rest-api/#create-or-overwrite-a-document). rpc CreateData(CreateDataRequest) returns (CreateDataResponse); // GetData looks up the document by path. This can be either a plain JSON // value (a "Base" document in OPA parlance), or a rule head (a // "Virtual"/computed document). // // This is equivalent in functionality to OPA's // [Data REST API Get with Input method](https://www.openpolicyagent.org/docs/latest/rest-api/#get-a-document-with-input). // // Note that the input field should not be wrapped with // `{ "input": }`, you can simply put the JSON serialized `` // in the input field directly. rpc GetData(GetDataRequest) returns (GetDataResponse); // UpdateData looks up the document by path, and then attempts to perform // one of three patching operations at that location: add, remove, or // replace. // // This is roughly equivalent in functionality to OPA's // [Data REST API Patch method](https://www.openpolicyagent.org/docs/latest/rest-api/#patch-a-document) rpc UpdateData(UpdateDataRequest) returns (UpdateDataResponse); // DeleteData looks up the document by path, and then attempts to remove // it from the store. // // This is equivalent in functionality to OPA's // [Data REST API Delete method](https://www.openpolicyagent.org/docs/latest/rest-api/#delete-a-document). rpc DeleteData(DeleteDataRequest) returns (DeleteDataResponse); // StreamingDataRW specifies a stream of fixed-structure, batched // read/write operations. // // WriteData operations are executed sequentially, aborting the entire // gRPC call if any operations fail. // // The ReadData operations are then executed in parallel, but will report // errors inline in their responses, instead of aborting the entire gRPC // call. rpc StreamingDataRW(stream StreamingDataRWRequest) returns (stream StreamingDataRWResponse); }