Class: Round::Client::Context
- Inherits:
-
Object
- Object
- Round::Client::Context
- Defined in:
- lib/round/client.rb
Defined Under Namespace
Modules: Scheme
Constant Summary collapse
Instance Attribute Summary collapse
-
#mfa_token ⇒ Object
Returns the value of attribute mfa_token.
-
#schemes ⇒ Object
Returns the value of attribute schemes.
Instance Method Summary collapse
-
#authorize(scheme, params) ⇒ Object
Is there a list of accepted params somewhere?.
- #authorizer(schemes: [], action: 'NULL ACTION', **kwargs) ⇒ Object
- #compile_params(params) ⇒ Object
-
#initialize ⇒ Context
constructor
A new instance of Context.
- #inspect ⇒ Object
Constructor Details
#initialize ⇒ Context
Returns a new instance of Context.
81 82 83 |
# File 'lib/round/client.rb', line 81 def initialize @schemes = {} end |
Instance Attribute Details
#mfa_token ⇒ Object
Returns the value of attribute mfa_token.
79 80 81 |
# File 'lib/round/client.rb', line 79 def mfa_token @mfa_token end |
#schemes ⇒ Object
Returns the value of attribute schemes.
79 80 81 |
# File 'lib/round/client.rb', line 79 def schemes @schemes end |
Instance Method Details
#authorize(scheme, params) ⇒ Object
Is there a list of accepted params somewhere?
86 87 88 89 90 |
# File 'lib/round/client.rb', line 86 def (scheme, params) raise ArgumentError, 'Params cannot be empty.' if params.empty? raise ArgumentError, 'Unknown auth scheme' unless SCHEMES.include?(scheme) @schemes[scheme] = params end |
#authorizer(schemes: [], action: 'NULL ACTION', **kwargs) ⇒ Object
100 101 102 103 104 105 106 107 108 |
# File 'lib/round/client.rb', line 100 def (schemes: [], action: 'NULL ACTION', **kwargs) schemes.each do |scheme| if (params = @schemes[scheme]) credential = compile_params(params) return [scheme, credential] end end raise "Action: #{action}. No authorization available for '#{schemes}'" end |
#compile_params(params) ⇒ Object
92 93 94 95 96 97 98 |
# File 'lib/round/client.rb', line 92 def compile_params(params) compiled = params.map do |key, value| %Q(#{key}="#{value}") end.join(', ') compiled << ", mfa_token=#{@mfa_token}" if @mfa_token compiled end |
#inspect ⇒ Object
110 111 112 113 114 |
# File 'lib/round/client.rb', line 110 def inspect # Hide the secret token when printed id = "%x" % (self.object_id << 1) %Q(#<#{self.class}:0x#{id}) end |