Class: Confidant::Client
- Inherits:
-
Object
- Object
- Confidant::Client
- Defined in:
- lib/confidant/client.rb
Overview
The Confidant Client implementation
Constant Summary collapse
- TOKEN_SKEW_SECONDS =
3 * 60
- TIME_FORMAT =
'%Y%m%dT%H%M%SZ'.freeze
Instance Attribute Summary collapse
-
#config ⇒ Object
Returns the value of attribute config.
Instance Method Summary collapse
-
#get_service(service = nil) ⇒ Object
Return a Hash of credentials from the confidant API for
service
, either explicitly-provided, or from config. -
#initialize(configurator) ⇒ Client
constructor
Initialize with a
configurator
, which is an instance of Confidant::Configurator. -
#suppress_errors(enable = true) ⇒ Object
The Python client suppresses API errors, returning { result: false } instead.
Constructor Details
#initialize(configurator) ⇒ Client
Initialize with a configurator
, which is an instance of Confidant::Configurator
18 19 20 21 22 |
# File 'lib/confidant/client.rb', line 18 def initialize(configurator) @config = configurator.config @kms = Aws::KMS::Client.new(region: config[:region]) @suppress_errors = false end |
Instance Attribute Details
#config ⇒ Object
Returns the value of attribute config.
14 15 16 |
# File 'lib/confidant/client.rb', line 14 def config @config end |
Instance Method Details
#get_service(service = nil) ⇒ Object
Return a Hash of credentials from the confidant API for service
, either explicitly-provided, or from config.
26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 |
# File 'lib/confidant/client.rb', line 26 def get_service(service = nil) log.debug "Requesting #{api_service_url(service_name(service))} " \ "as user #{api_user}" response = RestClient::Request.execute( method: :get, url: api_service_url(service_name(service)), user: api_user, password: generate_token, headers: { user_agent: RestClient::Platform.default_user_agent.prepend( "confidant-client/#{Confidant::VERSION} " ) } ) JSON.parse(response.body) rescue => ex Confidant.log_exception(self, ex) @suppress_errors ? api_error_response : raise end |
#suppress_errors(enable = true) ⇒ Object
The Python client suppresses API errors, returning { result: false } instead. Mimic this behavior based on the truthiness of enable
. This is generally only called from Confidant::CLI
51 52 53 54 |
# File 'lib/confidant/client.rb', line 51 def suppress_errors(enable = true) @suppress_errors = enable true end |