module Haipa::Client::Common::Configurable
The Haipa::Common::Configurable module provides basic configuration for Haipa
activities.
Attributes
client_id[RW]
@return [String] client id.
client_key[RW]
@return [String] client key
client_key_file[RW]
@return [String] path to client key file
credentials[RW]
@return [MsRest::ServiceClientCredentials] credentials to authorize HTTP requests made by the service client.
identity_endpoint[RW]
@return [String] url to identity endpoint.
Public Class Methods
keys()
click to toggle source
List of configurable keys for {Haipa::Client::Common::Client}. @return [Array] of option keys.
# File lib/haipa_rest/common/configurable.rb, line 31 def keys @keys ||= [:client_id, :client_key_file, :identity_endpoint ] end
Public Instance Methods
config()
click to toggle source
# File lib/haipa_rest/common/configurable.rb, line 75 def config self end
configure() { |self| ... }
click to toggle source
Set configuration options using a block.
# File lib/haipa_rest/common/configurable.rb, line 39 def configure yield self end
reset!(options = {})
click to toggle source
Resets the configurable options to provided options or defaults. This will also creates MsRest::TokenCredentials to be used for subsequent clients.
# File lib/haipa_rest/common/configurable.rb, line 47 def reset!(options = {}) Haipa::Client::Common::Configurable.keys.each do |key| default_value = Haipa::Client::Common::Default.options[key] instance_variable_set(:"@#{key}", options.fetch(key, default_value)) end if(options[:client_key].nil?) # The user has not passed in the client key. try to read it from client_key_file self.client_key = OpenSSL::PKey::RSA.new File.read self.client_key_file unless self.client_key_file.nil? end if(options[:credentials].nil?) # The user has not passed in the credentials. So, the api has to # build the credentials itself. fail ArgumentError, 'client_id is nil' if self.client_id.nil? fail ArgumentError, 'client_key is nil' if self.client_key.nil? fail ArgumentError, 'identity_endpoint is nil' if self.identity_endpoint.nil? self.credentials = MsRest::TokenCredentials.new( Haipa::Client::ApplicationTokenProvider.new( self.client_id, self.client_key, self.identity_endpoint)) else self.credentials = options[:credentials] end self end
Private Instance Methods
setup_default_options()
click to toggle source
configures configurable options to default values
# File lib/haipa_rest/common/configurable.rb, line 84 def setup_default_options opts = {} Haipa::Client::Common::Configurable.keys.map do |key| opts[key] = Haipa::Client::Common::Default.options[key] end opts end