Module: Legion::Extensions::Lakera::Helpers::Client
- Included in:
- Runners::Guard, Runners::Health, Runners::Policies, Runners::Projects
- Defined in:
- lib/legion/extensions/lakera/helpers/client.rb
Constant Summary collapse
- DEFAULT_HOST =
'https://api.lakera.ai'- REGIONS =
{ us: 'https://us.api.lakera.ai', us_east_1: 'https://us-east-1.api.lakera.ai', us_west_2: 'https://us-west-2.api.lakera.ai', eu_west_1: 'https://eu-west-1.api.lakera.ai', ap_southeast_1: 'https://ap-southeast-1.api.lakera.ai' }.freeze
Class Method Summary collapse
- .client(api_key:, host: DEFAULT_HOST, region: nil, timeout: 30, open_timeout: 10, **_opts) ⇒ Object
- .self_hosted_client(host:, timeout: 30, open_timeout: 10, **_opts) ⇒ Object
Class Method Details
.client(api_key:, host: DEFAULT_HOST, region: nil, timeout: 30, open_timeout: 10, **_opts) ⇒ Object
23 24 25 26 27 28 29 30 31 32 33 34 |
# File 'lib/legion/extensions/lakera/helpers/client.rb', line 23 def client(api_key:, host: DEFAULT_HOST, region: nil, timeout: 30, open_timeout: 10, **_opts) resolved_host = region ? REGIONS.fetch(region, host) : host Faraday.new(url: resolved_host) do |conn| conn.request :json conn.response :json, content_type: /\bjson$/ conn.headers['Authorization'] = "Bearer #{api_key}" conn.headers['Content-Type'] = 'application/json' conn..timeout = timeout conn..open_timeout = open_timeout end end |
.self_hosted_client(host:, timeout: 30, open_timeout: 10, **_opts) ⇒ Object
36 37 38 39 40 41 42 43 44 |
# File 'lib/legion/extensions/lakera/helpers/client.rb', line 36 def self_hosted_client(host:, timeout: 30, open_timeout: 10, **_opts) Faraday.new(url: host) do |conn| conn.request :json conn.response :json, content_type: /\bjson$/ conn.headers['Content-Type'] = 'application/json' conn..timeout = timeout conn..open_timeout = open_timeout end end |