rscalr 0.0.5 → 0.0.7
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- data/lib/rscalr/api/scalr.rb +17 -1
- data/lib/rscalr/version.rb +1 -1
- data/test_integration/test_client_farms.rb +6 -1
- metadata +2 -2
data/lib/rscalr/api/scalr.rb
CHANGED
@@ -252,16 +252,19 @@ class Scalr
|
|
252
252
|
|
253
253
|
#=============== Helper methods ==================================
|
254
254
|
|
255
|
+
# Generates request signature based on config, action, timestamp
|
255
256
|
def generate_sig(action, timestamp)
|
256
257
|
message = action + ':' + @config[:key_id] + ':' + timestamp
|
257
258
|
hexdigest = OpenSSL::HMAC.hexdigest('sha256', @config[:key_secret], message)
|
258
259
|
[[hexdigest].pack("H*")].pack("m0")
|
259
260
|
end
|
260
261
|
|
262
|
+
# Generates a timestamp string based on a Time object
|
261
263
|
def generate_timestamp(time)
|
262
264
|
time.strftime("%Y-%m-%dT%H:%M:%SZ")
|
263
265
|
end
|
264
266
|
|
267
|
+
# Executes the specified API call, passing in the specified params
|
265
268
|
def execute_api_call(action, action_params=nil)
|
266
269
|
|
267
270
|
begin
|
@@ -272,6 +275,7 @@ class Scalr
|
|
272
275
|
params[:Version] = @config[:version]
|
273
276
|
params[:AuthVersion] = @config[:auth_version]
|
274
277
|
params[:KeyID] = @config[:key_id]
|
278
|
+
params[:EnvID] = @config[:env_id] unless @config[:env_id].nil?
|
275
279
|
|
276
280
|
uri = URI("https://api.scalr.net/?" + hash_to_querystring(params))
|
277
281
|
|
@@ -294,11 +298,12 @@ class Scalr
|
|
294
298
|
result
|
295
299
|
end
|
296
300
|
|
301
|
+
# Builds an ad hoc ScalrResponse to represent an unexpected error
|
297
302
|
def build_error_response(message, transaction_id)
|
298
303
|
result = ScalrResponse.new "<?xml version='1.0?>"
|
299
304
|
result.add_element("Error")
|
300
305
|
ele = REXML::Element.new "TransactionID"
|
301
|
-
ele.text = transaction_id
|
306
|
+
ele.text = "sig:#{transaction_id}"
|
302
307
|
result.root.elements << ele
|
303
308
|
ele = REXML::Element.new "Message"
|
304
309
|
ele.text = message
|
@@ -307,11 +312,18 @@ class Scalr
|
|
307
312
|
result
|
308
313
|
end
|
309
314
|
|
315
|
+
# Turns a hash of request parameter key/value pairs into an escaped request query string.
|
316
|
+
# Keys are expected to not require escaping.
|
310
317
|
def hash_to_querystring(h)
|
311
318
|
h.map{|k,v| "#{k.to_s}=#{CGI::escape(v.to_s)}"}.join('&')
|
312
319
|
end
|
320
|
+
|
321
|
+
def env_id= env_id
|
322
|
+
@config[:env_id] = env_id
|
323
|
+
end
|
313
324
|
end
|
314
325
|
|
326
|
+
# Represents a response from an API call. Thin wrapper around an REXML::Document of the parsed repsonse.
|
315
327
|
class ScalrResponse < REXML::Document
|
316
328
|
|
317
329
|
def initialize http_response_body=nil
|
@@ -322,10 +334,14 @@ class ScalrResponse < REXML::Document
|
|
322
334
|
end
|
323
335
|
end
|
324
336
|
|
337
|
+
# True iff the response indicates that the API call succeeded. This does not guarantee that
|
338
|
+
# the intent of the call succeeded of course (e.g. that a script executed successfully on the Scalr side),
|
339
|
+
# only that Scalr reported success for the call.
|
325
340
|
def success?
|
326
341
|
root.name != 'Error'
|
327
342
|
end
|
328
343
|
|
344
|
+
# If the API call was not successful, this returns the inner error message.
|
329
345
|
def error_message
|
330
346
|
if success?
|
331
347
|
nil
|
data/lib/rscalr/version.rb
CHANGED
@@ -4,7 +4,12 @@ require 'test/unit'
|
|
4
4
|
class TestClientFarms < Test::Unit::TestCase
|
5
5
|
|
6
6
|
def setup
|
7
|
-
@scalr = Scalr.new({
|
7
|
+
@scalr = Scalr.new({
|
8
|
+
:key_id => ENV['SCALR_TEST_API_KEY'],
|
9
|
+
:key_secret => ENV['SCALR_TEST_API_SECRET'],
|
10
|
+
:env_id => ENV['SCALR_TEST_ENV_ID']
|
11
|
+
})
|
12
|
+
|
8
13
|
@farm_test1_name = 'test1'
|
9
14
|
end
|
10
15
|
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: rscalr
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0.
|
4
|
+
version: 0.0.7
|
5
5
|
prerelease:
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
@@ -9,7 +9,7 @@ authors:
|
|
9
9
|
autorequire:
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
|
-
date: 2013-02-
|
12
|
+
date: 2013-02-05 00:00:00.000000000 Z
|
13
13
|
dependencies: []
|
14
14
|
description: Rscalr is a Ruby implementation of the Scalr API, written to interface
|
15
15
|
cleanly with Chef and other internal release management tasks.
|