Module: RightScale::Api
- Defined in:
- lib/rest_connection/rightscale/rightscale_api_base.rb,
lib/rest_connection/rightscale/rightscale_api_gateway.rb,
lib/rest_connection/rightscale/rightscale_api_internal.rb,
lib/rest_connection/rightscale/rightscale_api_mc_input.rb,
lib/rest_connection/rightscale/rightscale_api_taggable.rb,
lib/rest_connection/rightscale/rightscale_api_mc_taggable.rb
Defined Under Namespace
Modules: Base, BaseConnection, BaseExtend, Gateway, GatewayConnection, GatewayExtend, Internal, InternalConnection, InternalExtend, McInput, McTaggable, McTaggableExtend, Taggable, TaggableExtend
Constant Summary collapse
- DATETIME_FMT =
TODO: move this to McAuditEntry
"%Y/%m/%d %H:%M:%S +0000"
- AWS_CLOUDS =
Every supported AWS cloud must be hardcoded here. FIXME: Once this list exceeds 10 entries, must also update cloud_id logic elsewhere!
[ {"cloud_id" => 1, "name" => "AWS US-East"}, {"cloud_id" => 2, "name" => "AWS EU"}, {"cloud_id" => 3, "name" => "AWS US-West"}, {"cloud_id" => 4, "name" => "AWS AP-Singapore"}, {"cloud_id" => 5, "name" => "AWS AP-Tokyo"}, {"cloud_id" => 6, "name" => "AWS US-Oregon"}, {"cloud_id" => 7, "name" => "AWS SA-Sao Paulo"}, {"cloud_id" => 8, "name" => "AWS AP-Sydney"}, ]
- BASE_COOKIE_REFRESH =
proc do # Refresh cookie by logging in again def # login @cookie = nil ##################################################################### # HACK: Re-login with API version 1.0 when receiving an API 0.1 call # https://rightsite.gitsrc.com/trac/ticket/16404 if @settings[:common_headers]["X_API_VERSION"] == "0.1" @settings[:common_headers]["X_API_VERSION"] = "1.0" @__refreshing_cookie_for_api_0_1__ = true end ##################################################################### resp = get("login") unless resp.code == "302" || resp.code == "204" raise "ERROR: Login failed. #{resp.}. Code:#{resp.code}" end @cookie = resp.response['set-cookie'] ##################################################################### # HACK: Reset the API version header to 0.1 so subsequent calls work # https://rightsite.gitsrc.com/trac/ticket/16404 if @__refreshing_cookie_for_api_0_1__ @settings[:common_headers]["X_API_VERSION"] = "0.1" @__refreshing_cookie_for_api_0_1__ = false end ##################################################################### true end end
- GATEWAY_COOKIE_REFRESH =
Refresh cookie by logging in again
proc do def # login ignored, account = @settings[:api_url].split(/\/acct\//) if @settings[:api_url].include?("acct") params = { "email" => @settings[:user], "password" => @settings[:pass], "account_href" => "/api/accounts/#{account}" } @cookie = nil resp = post("session", params) unless resp.code == "302" || resp.code == "204" raise "ERROR: Login failed. #{resp.}. Code:#{resp.code}" end # TODO: handle 302 redirects @cookie = resp.response['set-cookie'] # test session resp = get("session") raise "ERROR: Invalid session. #{resp["message"]}." unless resp.is_a?(Hash) true end end
Class Method Summary collapse
-
.api0_1? ⇒ Boolean
Checks for API 0.1 access Requires an account with internal API access on a legacy cluster.
-
.api1_0? ⇒ Boolean
Checks for API 1.0 access Should always succeed.
-
.api1_5? ⇒ Boolean
Check for API 1.5 access Should always succeed.
-
.update_connection_settings(*settings) ⇒ Object
Pass no arguments to reset to the default configuration, pass a hash to update the settings for all API versions.
Class Method Details
.api0_1? ⇒ Boolean
Checks for API 0.1 access Requires an account with internal API access on a legacy cluster
100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 |
# File 'lib/rest_connection/rightscale/rightscale_api_base.rb', line 100 def self.api0_1? if class_variable_defined?("@@api0_1") return @@api0_1 unless @@api0_1.nil? end if RestConnection::Connection.new.settings[:legacy_shard] begin Ec2SshKeyInternal.find_all @@api0_1 = true rescue RestConnection::Errors::Forbidden @@api0_1 = false rescue RestConnection::Errors::UnprocessableEntity @@api0_1 = false end else @@api0_1 = false end end |
.api1_0? ⇒ Boolean
Checks for API 1.0 access Should always succeed
121 122 123 124 125 126 127 128 129 |
# File 'lib/rest_connection/rightscale/rightscale_api_base.rb', line 121 def self.api1_0? if class_variable_defined?("@@api1_0") return @@api1_0 unless @@api1_0.nil? end Ec2SecurityGroup.find_all @@api1_0 = true rescue RestConnection::Errors::Forbidden @@api1_0 = false end |
.api1_5? ⇒ Boolean
Check for API 1.5 access Should always succeed
133 134 135 136 137 138 139 140 141 |
# File 'lib/rest_connection/rightscale/rightscale_api_base.rb', line 133 def self.api1_5? if class_variable_defined?("@@api1_5") return @@api1_5 unless @@api1_5.nil? end Cloud.find_all @@api1_5 = true rescue RestConnection::Errors::Forbidden @@api1_5 = false end |
.update_connection_settings(*settings) ⇒ Object
Pass no arguments to reset to the default configuration, pass a hash to update the settings for all API versions
78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 |
# File 'lib/rest_connection/rightscale/rightscale_api_base.rb', line 78 def self.update_connection_settings(*settings) if settings.size > 1 raise ArgumentError.new("wrong number of arguments (#{settings.size} for 1)") end konstants = constants.map { |c| const_get(c) } konstants.reject! { |c| !(Module === c) } konstants.reject! { |c| !(c.instance_methods.include?("connection")) } konstants.each do |c| c.instance_exec(settings) do |opts| class_variable_set("@@connection", RestConnection::Connection.new(*opts)) end end @@api0_1, @@api1_0, @@api1_5 = nil, nil, nil true end |