rscalr 0.0.15 → 0.0.16

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.
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: c1d09e3277034b6fff104dd498bc8c7280fa4f4a
4
+ data.tar.gz: f037ab7e67e26247eebcb2885efe0db9aca164e5
5
+ SHA512:
6
+ metadata.gz: c628603cf19d159730791913700b7ee5a1fcdd2024f69eaf11ca8fa10c4183950b2a79debd2d0abc83ea9d7b41e6fcb3d5c6278c9b4904d201723374117e4033
7
+ data.tar.gz: 899109fde0145cc322eba14e37604ab7fb472958d8f6465eb43666f10281b13b75df46ea8a1c9a0d8d8dd417e5fd562cfea0168b819717e310dfe74da29c8ee2
data/README.md CHANGED
@@ -50,6 +50,7 @@ If you use this tool a lot from the command line, you can set environment variab
50
50
  ```bash
51
51
  export SCALR_API_KEY=your-api-key
52
52
  export SCALR_API_SECRET=your-api-secret
53
+ export SCALR_URL=scalr-api-url, optional, default=https://api.scalr.net
53
54
  export SCALR_ENV_ID=id-of-desired-environment # optional
54
55
  export SCALR_CLIENT_VERBOSE=true # Print API calls/responses to stdout, optional, default=false
55
56
  ```
@@ -0,0 +1,8 @@
1
+ require 'rake/testtask'
2
+
3
+ Rake::TestTask.new do |t|
4
+ t.libs << 'test'
5
+ end
6
+
7
+ desc "Run tests"
8
+ task :default => :test
@@ -12,9 +12,10 @@ require 'rexml/document'
12
12
  class Scalr
13
13
  attr_accessor :config
14
14
 
15
- # Default versions
15
+ # Default values
16
16
  $DEFAULT_VERSION = '2.3.0'
17
17
  $DEFAULT_AUTH_VERSION = '3'
18
+ $DEFAULT_URL = 'https://api.scalr.net'
18
19
 
19
20
  def initialize(config=nil)
20
21
  if (config.nil?)
@@ -25,6 +26,7 @@ class Scalr
25
26
 
26
27
  @config[:version] = $DEFAULT_VERSION if @config[:version].nil?
27
28
  @config[:auth_version] = $DEFAULT_AUTH_VERSION if @config[:auth_version].nil?
29
+ @config[:url] = $DEFAULT_URL if @config[:url].nil?
28
30
  end
29
31
 
30
32
  #=================== API Section ===================================
@@ -263,6 +265,7 @@ class Scalr
263
265
  config = {}
264
266
  config[:key_id] = ENV['SCALR_API_KEY'] unless ENV['SCALR_API_KEY'].nil?
265
267
  config[:key_secret] = ENV['SCALR_API_SECRET'] unless ENV['SCALR_API_SECRET'].nil?
268
+ config[:url] = ENV['SCALR_URL'] unless ENV['SCALR_URL'].nil?
266
269
  config[:env_id] = ENV['SCALR_ENV_ID'] unless ENV['SCALR_ENV_ID'].nil?
267
270
  config[:version] = ENV['SCALR_API_VERSION'] unless ENV['SCALR_API_VERSION'].nil?
268
271
  config[:auth_version] = ENV['SCALR_API_AUTH_VERSION'] unless ENV['SCALR_API_AUTH_VERSION'].nil?
@@ -294,8 +297,8 @@ class Scalr
294
297
  params[:AuthVersion] = @config[:auth_version]
295
298
  params[:KeyID] = @config[:key_id]
296
299
  params[:EnvID] = @config[:env_id] unless @config[:env_id].nil?
297
-
298
- uri = URI("https://api.scalr.net/?" + hash_to_querystring(params))
300
+
301
+ uri = URI(url + "?" + hash_to_querystring(params))
299
302
  $stdout.puts(uri) if @config[:verbose]
300
303
 
301
304
  response = Net::HTTP.start(uri.host, uri.port, :use_ssl => true) do |http|
@@ -350,6 +353,22 @@ class Scalr
350
353
  @config[:env_id]
351
354
  end
352
355
 
356
+ # Changes the configured API endpoint for this instance
357
+ def url= url
358
+ @config[:url] = url
359
+ end
360
+
361
+ # Get the current environment value. A nil response means the "first" environment will be assumed for API calls,
362
+ # per the Scalr API docs.
363
+ def url
364
+ @config[:url]
365
+ end
366
+
367
+ def verbose= setting
368
+ if !!setting == setting
369
+ @config[:verbose] = !!setting
370
+ end
371
+ end
353
372
  end
354
373
 
355
374
  # Represents a response from an API call. Thin wrapper around an REXML::Document of the parsed repsonse.
@@ -110,6 +110,33 @@ class Dashboard
110
110
  @environments
111
111
  end
112
112
 
113
+ def get_role(name)
114
+ if @roles.nil?
115
+ load_roles
116
+ end
117
+ @roles[name]
118
+ end
119
+
120
+ def load_roles
121
+ @roles = {}
122
+
123
+ scalr_response = @client.roles_list
124
+ scalr_response.root.each_element('RoleSet/Item') { |row|
125
+ role = Role.new
126
+
127
+ row.each_element { |prop|
128
+ if "ID" == prop.name
129
+ role.id = prop.text
130
+ elsif "Name" == prop.name
131
+ role.name = prop.text
132
+ end
133
+ }
134
+ @roles[role.name] = role
135
+ }
136
+
137
+ @roles
138
+ end
139
+
113
140
  # Blocks up to timeout seconds waiting on log response(s) of script execution. Returns true iff
114
141
  # script executed successfully (returned) exit_value on all servers.
115
142
  def verify_script_success(script_execution, exit_value=0, timeout_sec=60)
@@ -162,4 +189,8 @@ class Dashboard
162
189
 
163
190
  success
164
191
  end
192
+
193
+ def verbose= setting
194
+ @client.verbose = setting
195
+ end
165
196
  end
@@ -1,3 +1,3 @@
1
1
  module Rscalr
2
- VERSION = "0.0.15"
2
+ VERSION = "0.0.16"
3
3
  end
@@ -0,0 +1,22 @@
1
+ require 'rscalr'
2
+ require 'test/unit'
3
+
4
+ class TestObjRoles < Test::Unit::TestCase
5
+
6
+ def setup
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
+
13
+ @dashboard = Dashboard.new @scalr
14
+ end
15
+
16
+ def test_get_role_by_name
17
+ role = @dashboard.get_role(ENV['SCALR_TEST_ROLE_NAME'])
18
+
19
+ assert_not_nil(role, "Test role not found by name")
20
+ end
21
+
22
+ end
@@ -0,0 +1,20 @@
1
+ require 'rscalr'
2
+ require 'test/unit'
3
+
4
+ class TestUrl < Test::Unit::TestCase
5
+
6
+ def test_set_and_get_url
7
+ scalr = Scalr.new({ :key_id => '123', :key_secret => '123abc' })
8
+
9
+ assert_equal('https://api.scalr.net', scalr.url, "url should default to api.scalr.net if not specified")
10
+
11
+ scalr = Scalr.new({ :key_id => '123', :key_secret => '123abc', :url => 'https://scalr.example.com/api/api.php' })
12
+
13
+ assert_equal('https://scalr.example.com/api/api.php', scalr.url, "url not set correctly from config in ctor")
14
+
15
+ scalr.url = 'http://api.scalr.example.net'
16
+
17
+ assert_equal('http://api.scalr.example.net', scalr.url, "url not set correctly from setter")
18
+ end
19
+
20
+ end
metadata CHANGED
@@ -1,30 +1,26 @@
1
- --- !ruby/object:Gem::Specification
1
+ --- !ruby/object:Gem::Specification
2
2
  name: rscalr
3
- version: !ruby/object:Gem::Version
4
- prerelease:
5
- version: 0.0.15
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.16
6
5
  platform: ruby
7
- authors:
6
+ authors:
8
7
  - Nathan Smith
9
8
  autorequire:
10
9
  bindir: bin
11
10
  cert_chain: []
12
-
13
- date: 2013-03-14 00:00:00 Z
11
+ date: 2014-02-09 00:00:00.000000000 Z
14
12
  dependencies: []
15
-
16
- description: Rscalr is a Ruby implementation of the Scalr API, written to interface cleanly with Chef and other internal release management tasks.
17
- email:
13
+ description: Rscalr is a Ruby implementation of the Scalr API, written to interface
14
+ cleanly with Chef and other internal release management tasks.
15
+ email:
18
16
  - nate@branchout.com
19
17
  executables: []
20
-
21
18
  extensions: []
22
-
23
19
  extra_rdoc_files: []
24
-
25
- files:
20
+ files:
26
21
  - .gitignore
27
22
  - README.md
23
+ - Rakefile
28
24
  - lib/rscalr.rb
29
25
  - lib/rscalr/api/scalr.rb
30
26
  - lib/rscalr/model/dashboard.rb
@@ -41,41 +37,41 @@ files:
41
37
  - lib/rscalr/model/server_log.rb
42
38
  - lib/rscalr/version.rb
43
39
  - rscalr.gemspec
40
+ - test/test_client_farms.rb
44
41
  - test/test_env_id.rb
42
+ - test/test_obj_environments.rb
43
+ - test/test_obj_logs.rb
44
+ - test/test_obj_roles.rb
45
45
  - test/test_sig.rb
46
- - test_integration/test_client_farms.rb
47
- - test_integration/test_obj_environments.rb
48
- - test_integration/test_obj_logs.rb
46
+ - test/test_url.rb
49
47
  homepage:
50
48
  licenses: []
51
-
49
+ metadata: {}
52
50
  post_install_message:
53
51
  rdoc_options: []
54
-
55
- require_paths:
52
+ require_paths:
56
53
  - lib
57
- required_ruby_version: !ruby/object:Gem::Requirement
58
- none: false
59
- requirements:
60
- - - ">="
61
- - !ruby/object:Gem::Version
62
- version: "0"
63
- required_rubygems_version: !ruby/object:Gem::Requirement
64
- none: false
65
- requirements:
66
- - - ">="
67
- - !ruby/object:Gem::Version
68
- version: "0"
54
+ required_ruby_version: !ruby/object:Gem::Requirement
55
+ requirements:
56
+ - - '>='
57
+ - !ruby/object:Gem::Version
58
+ version: '0'
59
+ required_rubygems_version: !ruby/object:Gem::Requirement
60
+ requirements:
61
+ - - '>='
62
+ - !ruby/object:Gem::Version
63
+ version: '0'
69
64
  requirements: []
70
-
71
65
  rubyforge_project:
72
- rubygems_version: 1.8.25
66
+ rubygems_version: 2.0.5
73
67
  signing_key:
74
- specification_version: 3
68
+ specification_version: 4
75
69
  summary: Ruby implementation of the Scalr API
76
- test_files:
70
+ test_files:
71
+ - test/test_client_farms.rb
77
72
  - test/test_env_id.rb
73
+ - test/test_obj_environments.rb
74
+ - test/test_obj_logs.rb
75
+ - test/test_obj_roles.rb
78
76
  - test/test_sig.rb
79
- - test_integration/test_client_farms.rb
80
- - test_integration/test_obj_environments.rb
81
- - test_integration/test_obj_logs.rb
77
+ - test/test_url.rb