Class: RightScale::AuthClient
- Defined in:
- lib/right_agent/clients/auth_client.rb
Overview
Abstract base class for authorization client
Constant Summary collapse
- PERMITTED_STATE_TRANSITIONS =
{ :pending => [:pending, :authorized, :unauthorized, :failed, :closed], :authorized => [:authorized, :unauthorized, :expired, :failed, :closed], :unauthorized => [:authorized, :unauthorized, :failed, :closed], :expired => [:authorized, :unauthorized, :expired, :failed, :closed], :failed => [:failed, :closed], :closed => [:closed] }
Instance Attribute Summary collapse
-
#state ⇒ Object
readonly
State of authorization: :pending, :authorized, :unauthorized, :expired, :failed, :closed.
Instance Method Summary collapse
-
#account_id ⇒ Integer
Account if any to which agent using this client belongs.
-
#api_url ⇒ String
URL for accessing RightApi including base path.
-
#auth_header ⇒ Hash
Authorization header to be added to HTTP request.
-
#close ⇒ TrueClass
Take any actions necessary to quiesce client interaction in preparation for agent termination but allow any active requests to complete.
-
#communicated { ... } ⇒ TrueClass
Set callback for each successful communication excluding health checks Multiple callbacks are supported.
-
#expired ⇒ TrueClass
An HTTP request had an authorization expiration error Renew authorization.
-
#headers ⇒ Hash
Headers to be added to HTTP request Include authorization header by default.
-
#identity ⇒ String
Identity of agent using this client.
-
#initialize(options = {}) ⇒ AuthClient
constructor
Initialize client Derived classes need to call reset_stats.
-
#mode ⇒ Symbol
RightNet communication mode.
-
#redirect(location) ⇒ TrueClass
An HTTP request received a redirect response.
-
#router_url ⇒ String
URL for accessing RightNet router including base path.
-
#stats(reset = false) ⇒ Hash
Current statistics for this client.
-
#status {|type, status| ... } ⇒ Symbol
Record callback to be notified of authorization status changes Multiple callbacks are supported.
Constructor Details
#initialize(options = {}) ⇒ AuthClient
Initialize client Derived classes need to call reset_stats
42 43 44 |
# File 'lib/right_agent/clients/auth_client.rb', line 42 def initialize( = {}) raise NotImplementedError, "#{self.class.name} is an abstract class" end |
Instance Attribute Details
#state ⇒ Object
State of authorization: :pending, :authorized, :unauthorized, :expired, :failed, :closed
30 31 32 |
# File 'lib/right_agent/clients/auth_client.rb', line 30 def state @state end |
Instance Method Details
#account_id ⇒ Integer
Account if any to which agent using this client belongs
81 82 83 84 |
# File 'lib/right_agent/clients/auth_client.rb', line 81 def account_id @account_id end |
#api_url ⇒ String
URL for accessing RightApi including base path
92 93 94 95 |
# File 'lib/right_agent/clients/auth_client.rb', line 92 def api_url @api_url end |
#auth_header ⇒ Hash
Authorization header to be added to HTTP request
71 72 73 74 |
# File 'lib/right_agent/clients/auth_client.rb', line 71 def auth_header {"Authorization" => "Bearer #{@access_token}"} end |
#close ⇒ TrueClass
Take any actions necessary to quiesce client interaction in preparation for agent termination but allow any active requests to complete
139 140 141 142 |
# File 'lib/right_agent/clients/auth_client.rb', line 139 def close self.state = :closed true end |
#communicated { ... } ⇒ TrueClass
Set callback for each successful communication excluding health checks Multiple callbacks are supported
165 166 167 168 169 170 |
# File 'lib/right_agent/clients/auth_client.rb', line 165 def communicated(&callback) raise ArgumentError, "Block missing" unless callback @communicated_callbacks ||= [] @communicated_callbacks << callback true end |
#expired ⇒ TrueClass
An HTTP request had an authorization expiration error Renew authorization
119 120 121 122 123 124 |
# File 'lib/right_agent/clients/auth_client.rb', line 119 def expired Log.info("Renewing authorization for #{identity} because request failed due to expiration") self.state = :expired true end |
#headers ⇒ Hash
Headers to be added to HTTP request Include authorization header by default
60 61 62 63 |
# File 'lib/right_agent/clients/auth_client.rb', line 60 def headers auth_header end |
#identity ⇒ String
Identity of agent using this client
49 50 51 |
# File 'lib/right_agent/clients/auth_client.rb', line 49 def identity @identity end |
#mode ⇒ Symbol
RightNet communication mode
111 112 113 |
# File 'lib/right_agent/clients/auth_client.rb', line 111 def mode @mode end |
#redirect(location) ⇒ TrueClass
An HTTP request received a redirect response
131 132 133 |
# File 'lib/right_agent/clients/auth_client.rb', line 131 def redirect(location) true end |
#router_url ⇒ String
URL for accessing RightNet router including base path
103 104 105 106 |
# File 'lib/right_agent/clients/auth_client.rb', line 103 def router_url @router_url end |
#stats(reset = false) ⇒ Hash
Current statistics for this client
178 179 180 181 182 183 |
# File 'lib/right_agent/clients/auth_client.rb', line 178 def stats(reset = false) stats = {} @stats.each { |k, v| stats[k] = v.all } reset_stats if reset stats end |
#status {|type, status| ... } ⇒ Symbol
Record callback to be notified of authorization status changes Multiple callbacks are supported
152 153 154 155 |
# File 'lib/right_agent/clients/auth_client.rb', line 152 def status(&callback) @status_callbacks = (@status_callbacks || []) << callback if callback state end |