Class: Cerbos::Hub::Stores::Client
- Inherits:
-
Object
- Object
- Cerbos::Hub::Stores::Client
- Defined in:
- lib/cerbos/hub/stores/client.rb
Overview
A client for interacting with policy stores in Cerbos Hub.
Instance Method Summary collapse
-
#get_files(store_id:, files:, grpc_metadata: {}) ⇒ Output::GetFiles
Get file contents from a policy store.
-
#initialize(client_id:, client_secret:, target: "api.cerbos.cloud:443", grpc_channel_args: {}, grpc_metadata: {}, timeout: nil) ⇒ Client
constructor
Create a client for interacting with policy stores in Cerbos Hub.
-
#list_files(store_id:, filter: nil, grpc_metadata: {}) ⇒ Output::ListFiles
List file paths in a policy store.
-
#modify_files(store_id:, operations:, condition: nil, change_details: nil, allow_unchanged: false, grpc_metadata: {}) ⇒ Output::ModifyFiles
Modify files in a policy store.
-
#replace_files(store_id:, files: nil, zipped_contents: nil, condition: nil, change_details: nil, allow_unchanged: false, grpc_metadata: {}) ⇒ Output::ReplaceFiles
Replace files in a policy store.
Constructor Details
#initialize(client_id:, client_secret:, target: "api.cerbos.cloud:443", grpc_channel_args: {}, grpc_metadata: {}, timeout: nil) ⇒ Client
Create a client for interacting with policy stores in Cerbos Hub.
16 17 18 19 20 21 22 23 24 25 26 |
# File 'lib/cerbos/hub/stores/client.rb', line 16 def initialize(client_id:, client_secret:, target: "api.cerbos.cloud:443", grpc_channel_args: {}, grpc_metadata: {}, timeout: nil) @service = Service.new( client_id:, client_secret:, stub: Protobuf::Cerbos::Cloud::Store::V1::CerbosStoreService::Stub, target:, grpc_channel_args:, grpc_metadata:, timeout: ) end |
Instance Method Details
#get_files(store_id:, files:, grpc_metadata: {}) ⇒ Output::GetFiles
Get file contents from a policy store.
38 39 40 41 42 43 44 45 46 |
# File 'lib/cerbos/hub/stores/client.rb', line 38 def get_files(store_id:, files:, grpc_metadata: {}) Error.handle do request = Protobuf::Cerbos::Cloud::Store::V1::GetFilesRequest.new(store_id:, files:) response = @service.call(:get_files, request, ) Output::GetFiles.from_protobuf(response) end end |
#list_files(store_id:, filter: nil, grpc_metadata: {}) ⇒ Output::ListFiles
List file paths in a policy store.
58 59 60 61 62 63 64 65 66 67 68 69 |
# File 'lib/cerbos/hub/stores/client.rb', line 58 def list_files(store_id:, filter: nil, grpc_metadata: {}) Error.handle do request = Protobuf::Cerbos::Cloud::Store::V1::ListFilesRequest.new( store_id:, filter: Cerbos::Input.coerce_optional(filter, Input::FileFilter)&.to_protobuf ) response = @service.call(:list_files, request, ) Output::ListFiles.from_protobuf(response) end end |
#modify_files(store_id:, operations:, condition: nil, change_details: nil, allow_unchanged: false, grpc_metadata: {}) ⇒ Output::ModifyFiles
Modify files in a policy store.
This is a "patch" operation; files that aren't included in the request won't be modified.
89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 |
# File 'lib/cerbos/hub/stores/client.rb', line 89 def modify_files(store_id:, operations:, condition: nil, change_details: nil, allow_unchanged: false, grpc_metadata: {}) Error.handle do request = Protobuf::Cerbos::Cloud::Store::V1::ModifyFilesRequest.new( store_id:, operations: Cerbos::Input.coerce_array(operations, Input::FileOperation).map(&:to_protobuf), condition: Cerbos::Input.coerce_optional(condition, Input::FileModificationCondition)&.to_protobuf_modify_files, change_details: Cerbos::Input.coerce_optional(change_details, Input::ChangeDetails)&.to_protobuf ) response = @service.call(:modify_files, request, ) Output::ModifyFiles.from_protobuf(response) end rescue Error::OperationDiscarded => error raise unless allow_unchanged Output::ModifyFiles.new( new_store_version: error.current_store_version, changed: false ) end |
#replace_files(store_id:, files: nil, zipped_contents: nil, condition: nil, change_details: nil, allow_unchanged: false, grpc_metadata: {}) ⇒ Output::ReplaceFiles
Replace files in a policy store.
This is a "put" operation; files that aren't included in the request will be removed from the store.
136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 |
# File 'lib/cerbos/hub/stores/client.rb', line 136 def replace_files(store_id:, files: nil, zipped_contents: nil, condition: nil, change_details: nil, allow_unchanged: false, grpc_metadata: {}) Error.handle do request = Protobuf::Cerbos::Cloud::Store::V1::ReplaceFilesRequest.new( store_id:, files: files && Protobuf::Cerbos::Cloud::Store::V1::ReplaceFilesRequest::Files.new(files: files.map { |file| Cerbos::Input.coerce_required(file, File).to_protobuf }), zipped_contents:, condition: Cerbos::Input.coerce_optional(condition, Input::FileModificationCondition)&.to_protobuf_replace_files, change_details: Cerbos::Input.coerce_optional(change_details, Input::ChangeDetails)&.to_protobuf ) response = @service.call(:replace_files, request, ) Output::ReplaceFiles.from_protobuf(response) end rescue Error::OperationDiscarded => error raise unless allow_unchanged Output::ReplaceFiles.new( new_store_version: error.current_store_version, ignored_files: error.ignored_files, changed: false ) end |