Module: Haipa::Client::Common::Configurable
- Defined in:
- lib/haipa_rest/common/configurable.rb,
lib/haipa_rest.rb
Overview
The Haipa::Common::Configurable module provides basic configuration for Haipa activities.
Instance Attribute Summary collapse
-
#client_id ⇒ String
Client id.
-
#client_key ⇒ String
Client key.
-
#client_key_file ⇒ String
Path to client key file.
-
#credentials ⇒ MsRest::ServiceClientCredentials
Credentials to authorize HTTP requests made by the service client.
-
#identity_endpoint ⇒ String
Url to identity endpoint.
Class Method Summary collapse
-
.keys ⇒ Array
List of configurable keys for Client.
Instance Method Summary collapse
- #config ⇒ Object
-
#configure {|_self| ... } ⇒ Object
Set configuration options using a block.
-
#reset!(options = {}) ⇒ Object
Resets the configurable options to provided options or defaults.
Instance Attribute Details
#client_id ⇒ String
Returns client id.
15 16 17 |
# File 'lib/haipa_rest/common/configurable.rb', line 15 def client_id @client_id end |
#client_key ⇒ String
Returns client key.
21 22 23 |
# File 'lib/haipa_rest/common/configurable.rb', line 21 def client_key @client_key end |
#client_key_file ⇒ String
Returns path to client key file.
18 19 20 |
# File 'lib/haipa_rest/common/configurable.rb', line 18 def client_key_file @client_key_file end |
#credentials ⇒ MsRest::ServiceClientCredentials
Returns credentials to authorize HTTP requests made by the service client.
12 13 14 |
# File 'lib/haipa_rest/common/configurable.rb', line 12 def credentials @credentials end |
#identity_endpoint ⇒ String
Returns url to identity endpoint.
24 25 26 |
# File 'lib/haipa_rest/common/configurable.rb', line 24 def identity_endpoint @identity_endpoint end |
Class Method Details
.keys ⇒ Array
List of configurable keys for Haipa::Client::Common::Client.
31 32 33 |
# File 'lib/haipa_rest/common/configurable.rb', line 31 def keys @keys ||= [:client_id, :client_key_file, :identity_endpoint ] end |
Instance Method Details
#config ⇒ Object
75 76 77 |
# File 'lib/haipa_rest/common/configurable.rb', line 75 def config self end |
#configure {|_self| ... } ⇒ Object
Set configuration options using a block.
39 40 41 |
# File 'lib/haipa_rest/common/configurable.rb', line 39 def configure yield self end |
#reset!(options = {}) ⇒ Object
Resets the configurable options to provided options or defaults. This will also creates MsRest::TokenCredentials to be used for subsequent clients.
47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 |
# File 'lib/haipa_rest/common/configurable.rb', line 47 def reset!( = {}) Haipa::Client::Common::Configurable.keys.each do |key| default_value = Haipa::Client::Common::Default.[key] instance_variable_set(:"@#{key}", .fetch(key, default_value)) end if([: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([: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 = [:credentials] end self end |