Class: RightScale::InfrastructureAuthClient

Inherits:
AuthClient
  • Object
show all
Includes:
InfrastructureHelpers
Defined in:
lib/right_infrastructure_agent/infrastructure_auth_client.rb

Overview

Authorization client for infrastructure agents

Instance Method Summary collapse

Methods included from InfrastructureHelpers

#constantize, #format_error, #render_nothing, #to_bool, #to_int_or_nil

Constructor Details

#initialize(client_name, router_url, config_dir, options = {}) ⇒ InfrastructureAuthClient

Initialized authorization client

Parameters:

  • client_name (String)

    of application using this client

  • router_url (String)

    including base path for accessing RightNet router

  • config_dir (String)

    path to global session configuration information



30
31
32
33
34
35
36
37
38
39
40
41
# File 'lib/right_infrastructure_agent/infrastructure_auth_client.rb', line 30

def initialize(client_name, router_url, config_dir, options = {})
  @client_name = client_name
  @router_url = router_url
  @agent_id = options[:agent_id]

  config = GlobalSession::Configuration.new(File.join(config_dir, "global_session.yml"), ENV["RAILS_ENV"])
  @global_session_dir = constantize(config["directory"]).new(config, File.join(config_dir, "authorities"))
  @global_session_timeout = (config["timeout"] * 8) / 10

  @state = :authorized
  reset_stats
end

Instance Method Details

#auth_headerHash

Headers to be added to HTTP request

Returns:

  • (Hash)

    headers to be added to request header

Raises:

  • (Exceptions::Unauthorized)

    not authorized

  • (Exceptions::RetryableError)

    authorization expired, but retry may succeed



61
62
63
64
# File 'lib/right_infrastructure_agent/infrastructure_auth_client.rb', line 61

def auth_header
  check_authorized
  {"Authorization" => "Bearer #{infrastructure_session}"}
end

#headersHash

Headers to be added to HTTP request Include authorization header by default

Returns:

  • (Hash)

    headers to be added to request header

Raises:

  • (Exceptions::Unauthorized)

    not authorized

  • (Exceptions::RetryableError)

    authorization expired, but retry may succeed



50
51
52
53
# File 'lib/right_infrastructure_agent/infrastructure_auth_client.rb', line 50

def headers
  check_authorized
  auth_header
end