Module: Legion::Extensions::Lakera::Runners::Policies

Extended by:
Helpers::Client
Includes:
Helpers::Lex
Included in:
Client
Defined in:
lib/legion/extensions/lakera/runners/policies.rb

Constant Summary

Constants included from Helpers::Client

Helpers::Client::DEFAULT_HOST, Helpers::Client::REGIONS

Instance Method Summary collapse

Methods included from Helpers::Client

client, self_hosted_client

Instance Method Details

#create_policy(name:, input_detectors:, output_detectors:, api_key:) ⇒ Object



13
14
15
16
17
# File 'lib/legion/extensions/lakera/runners/policies.rb', line 13

def create_policy(name:, input_detectors:, output_detectors:, api_key:, **)
  body = { name: name, input_detectors: input_detectors, output_detectors: output_detectors }
  response = client(api_key: api_key, **).post('/v2/policies', body)
  Helpers::Response.handle_response(response)
end

#delete_policy(policy_id:, api_key:) ⇒ Object



34
35
36
37
# File 'lib/legion/extensions/lakera/runners/policies.rb', line 34

def delete_policy(policy_id:, api_key:, **)
  response = client(api_key: api_key, **).delete("/v2/policies/#{policy_id}")
  Helpers::Response.handle_response(response)
end

#get_policy(policy_id:, api_key:) ⇒ Object



19
20
21
22
# File 'lib/legion/extensions/lakera/runners/policies.rb', line 19

def get_policy(policy_id:, api_key:, **)
  response = client(api_key: api_key, **).get("/v2/policies/#{policy_id}")
  Helpers::Response.handle_response(response)
end

#update_policy(policy_id:, api_key:, name: nil, input_detectors: nil, output_detectors: nil) ⇒ Object



24
25
26
27
28
29
30
31
32
# File 'lib/legion/extensions/lakera/runners/policies.rb', line 24

def update_policy(policy_id:, api_key:, name: nil, input_detectors: nil, output_detectors: nil, **)
  body = {}
  body[:name]             = name             if name
  body[:input_detectors]  = input_detectors  if input_detectors
  body[:output_detectors] = output_detectors if output_detectors

  response = client(api_key: api_key, **).put("/v2/policies/#{policy_id}", body)
  Helpers::Response.handle_response(response)
end