maestrano 0.11.0 → 0.12.0

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/maestrano.rb CHANGED
@@ -9,6 +9,9 @@ require 'maestrano/open_struct'
9
9
  # Version
10
10
  require 'maestrano/version'
11
11
 
12
+ # Multiple providers support
13
+ require 'maestrano/preset'
14
+
12
15
  # XMLSecurity
13
16
  require 'maestrano/xml_security/signed_document'
14
17
 
@@ -58,16 +61,18 @@ require 'maestrano/account/recurring_bill'
58
61
  require 'maestrano/connec/client'
59
62
 
60
63
  module Maestrano
64
+ include Preset
61
65
 
62
66
  class << self
63
- attr_accessor :config
67
+ attr_accessor :configs
64
68
  end
65
69
 
66
70
  # Maestrano Configuration block
67
71
  def self.configure
68
- self.config ||= Configuration.new
69
- yield(config)
70
- self.config.post_initialize
72
+ self.configs ||= {}
73
+ self.configs[preset] ||= Configuration.new
74
+ yield(configs[preset])
75
+ self.configs[preset].post_initialize
71
76
  return self
72
77
  end
73
78
 
@@ -85,7 +90,7 @@ module Maestrano
85
90
  # 'virtual': then the virtual user uid is returned (usr-4d5sfd.cld-g4f5d)
86
91
  def self.mask_user(user_uid,group_uid)
87
92
  sanitized_user_uid = self.unmask_user(user_uid)
88
- if Maestrano.param('sso.creation_mode') == 'virtual'
93
+ if self.param('sso.creation_mode') == 'virtual'
89
94
  return "#{sanitized_user_uid}.#{group_uid}"
90
95
  else
91
96
  return sanitized_user_uid
@@ -102,8 +107,9 @@ module Maestrano
102
107
  # E.g:
103
108
  # Maestrano.param('api.key')
104
109
  # Maestrano.param(:api_key)
110
+ # Maestrano['preset'].param('api.key')
105
111
  def self.param(parameter)
106
- self.config.param(parameter)
112
+ (self.configs[preset] || Configuration.new).param(parameter)
107
113
  end
108
114
 
109
115
  # Return a hash describing the current
@@ -118,7 +124,7 @@ module Maestrano
118
124
  blacklist = ['api.key','api.token']
119
125
 
120
126
  config_groups.each do |cgroup_name|
121
- cgroup = self.config.send(cgroup_name)
127
+ cgroup = self.configs[preset].send(cgroup_name)
122
128
 
123
129
  attr_list = cgroup.attributes.map(&:to_s)
124
130
  attr_list += Configuration::EVT_CONFIG[hash['environment']].keys.select { |k| k =~ Regexp.new("^#{cgroup_name}\.") }.map { |k| k.gsub(Regexp.new("^#{cgroup_name}\."),'') }
@@ -149,7 +155,7 @@ module Maestrano
149
155
  end
150
156
 
151
157
  class Configuration
152
- attr_accessor :environment, :app, :sso, :api, :webhook
158
+ attr_accessor :environment, :app, :sso, :api, :webhook, :connec
153
159
 
154
160
  def initialize
155
161
  @environment = 'test'
@@ -191,6 +197,11 @@ module Maestrano
191
197
  subscriptions: {}
192
198
  })
193
199
  })
200
+
201
+ # Connec! Config
202
+ @connec = OpenStruct.new({
203
+ enabled: true
204
+ })
194
205
  end
195
206
 
196
207
  # Force or default certain parameters
@@ -259,9 +270,29 @@ module Maestrano
259
270
  end
260
271
 
261
272
  EVT_CONFIG = {
273
+ 'local' => {
274
+ 'api.host' => 'http://application.maestrano.io',
275
+ 'api.base' => '/api/v1/',
276
+ 'connec.enabled' => true,
277
+ 'connec.host' => 'http://connec.maestrano.io',
278
+ 'connec.base_path' => '/api',
279
+ 'connec.v2_path' => '/v2',
280
+ 'connec.reports_path' => '/reports',
281
+ 'connec.timeout' => 60,
282
+ 'sso.idp' => 'http://application.maestrano.io',
283
+ 'sso.name_id_format' => Maestrano::Saml::Settings::NAMEID_PERSISTENT,
284
+ 'sso.x509_fingerprint' => '01:06:15:89:25:7d:78:12:28:a6:69:c7:de:63:ed:74:21:f9:f5:36',
285
+ 'sso.x509_certificate' => "-----BEGIN CERTIFICATE-----\nMIIDezCCAuSgAwIBAgIJAOehBr+YIrhjMA0GCSqGSIb3DQEBBQUAMIGGMQswCQYD\nVQQGEwJBVTEMMAoGA1UECBMDTlNXMQ8wDQYDVQQHEwZTeWRuZXkxGjAYBgNVBAoT\nEU1hZXN0cmFubyBQdHkgTHRkMRYwFAYDVQQDEw1tYWVzdHJh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"
286
+ },
262
287
  'test' => {
263
288
  'api.host' => 'http://api-sandbox.maestrano.io',
264
289
  'api.base' => '/api/v1/',
290
+ 'connec.enabled' => true,
291
+ 'connec.host' => 'http://api-sandbox.maestrano.io',
292
+ 'connec.base_path' => '/connec/api',
293
+ 'connec.v2_path' => '/v2',
294
+ 'connec.reports_path' => '/reports',
295
+ 'connec.timeout' => 60,
265
296
  'sso.idp' => 'https://maestrano.com',
266
297
  'sso.name_id_format' => Maestrano::Saml::Settings::NAMEID_PERSISTENT,
267
298
  'sso.x509_fingerprint' => '01:06:15:89:25:7d:78:12:28:a6:69:c7:de:63:ed:74:21:f9:f5:36',
@@ -269,9 +300,29 @@ module Maestrano
269
300
  'connec.host' => 'http://api-sandbox.maestrano.io',
270
301
  'connec.base_path' => '/connec/api/v2'
271
302
  },
303
+ 'uat' => {
304
+ 'api.host' => 'https://uat.maestrano.io',
305
+ 'api.base' => '/api/v1/',
306
+ 'connec.enabled' => true,
307
+ 'connec.host' => 'https://api-connec-uat.maestrano.io',
308
+ 'connec.base_path' => '/api',
309
+ 'connec.v2_path' => '/v2',
310
+ 'connec.reports_path' => '/reports',
311
+ 'connec.timeout' => 180,
312
+ 'sso.idp' => 'https://uat.maestrano.io',
313
+ 'sso.name_id_format' => Maestrano::Saml::Settings::NAMEID_PERSISTENT,
314
+ 'sso.x509_fingerprint' => '8a:1e:2e:76:c4:67:80:68:6c:81:18:f7:d3:29:5d:77:f8:79:54:2f',
315
+ 'sso.x509_certificate' => "-----BEGIN CERTIFICATE-----\nMIIDezCCAuSgAwIBAgIJAMzy+weDPp7qMA0GCSqGSIb3DQEBBQUAMIGGMQswCQYD\nVQQGEwJBVTEMMAoGA1UECBMDTlNXMQ8wDQYDVQQHEwZTeWRuZXkxGjAYBgNVBAoT\nEU1hZXN0cmFubyBQdHkgTHRkMRYwFAYDVQQDEw1tYWVzdHJhbm8uY29tMSQwIgYJ\nKoZIhvcNAQkBFhVzdXBwb3J0QG1hZXN0cmFuby5jb20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' => '/api/v1/',
320
+ 'connec.enabled' => true,
321
+ 'connec.host' => 'https://api-connec.maestrano.io',
322
+ 'connec.base_path' => '/api',
323
+ 'connec.v2_path' => '/v2',
324
+ 'connec.reports_path' => '/reports',
325
+ 'connec.timeout' => 180,
275
326
  'sso.idp' => 'https://maestrano.com',
276
327
  'sso.name_id_format' => Maestrano::Saml::Settings::NAMEID_PERSISTENT,
277
328
  'sso.x509_fingerprint' => '2f:57:71:e4:40:19:57:37:a6:2c:f0:c5:82:52:2f:2e:41:b7:9d:7e',
@@ -28,20 +28,61 @@ module Maestrano
28
28
  end
29
29
  end
30
30
 
31
+ context 'without presets' do
32
+ should "should successfully create a remote bill when passed correct parameters" do
33
+ @api_mock.expects(:post).with do |url, api_token, params|
34
+ url == "#{Maestrano.param('api.host')}#{Maestrano.param('api.base')}account/bills" && api_token.nil? &&
35
+ CGI.parse(params) == {"group_id"=>["cld-1"], "price_cents"=>["23000"], "currency"=>["AUD"], "description"=>["Some bill"]}
36
+ end.once.returns(test_response(test_account_bill))
31
37
 
32
- should "should successfully create a remote bill when passed correct parameters" do
33
- @api_mock.expects(:post).with do |url, api_token, params|
34
- url == "#{Maestrano.param('api_host')}#{Maestrano.param('api_base')}account/bills" && api_token.nil? &&
35
- CGI.parse(params) == {"group_id"=>["cld-1"], "price_cents"=>["23000"], "currency"=>["AUD"], "description"=>["Some bill"]}
36
- end.once.returns(test_response(test_account_bill))
37
-
38
- bill = Maestrano::Account::Bill.create({
39
- group_id: 'cld-1',
40
- price_cents: 23000,
41
- currency: 'AUD',
42
- description: 'Some bill'
43
- })
44
- assert bill.id
38
+ bill = Maestrano::Account::Bill.create({
39
+ group_id: 'cld-1',
40
+ price_cents: 23000,
41
+ currency: 'AUD',
42
+ description: 'Some bill'
43
+ })
44
+ assert bill.id
45
+ end
46
+ end
47
+
48
+ context 'with presets' do
49
+ setup do
50
+ @preset = 'mypreset'
51
+ Maestrano.configure do |config|
52
+ config.environment = 'production'
53
+ config.api.host = 'https://maestrano.com'
54
+ config.api.base = '/api'
55
+ end
56
+ Maestrano[@preset].configure do |config|
57
+ config.environment = 'production'
58
+ config.api.host = 'https://myprovider.com'
59
+ config.api.base = '/myapi'
60
+ end
61
+ end
62
+
63
+ should "should successfully create a remote bill when passed correct parameters" do
64
+ @api_mock.expects(:post).with do |url, api_token, params|
65
+ url == "#{Maestrano[@preset].param('api.host')}#{Maestrano[@preset].param('api.base')}account/bills" && api_token.nil? &&
66
+ CGI.parse(params) == {"group_id"=>["cld-1"], "price_cents"=>["23000"], "currency"=>["AUD"], "description"=>["Some bill"]}
67
+ end.once.returns(test_response(test_account_bill))
68
+
69
+ bill = Maestrano::Account::Bill[@preset].create({
70
+ group_id: 'cld-1',
71
+ price_cents: 23000,
72
+ currency: 'AUD',
73
+ description: 'Some bill'
74
+ })
75
+ assert bill.id
76
+ end
77
+
78
+ should "should successfully list remote bills" do
79
+ @api_mock.expects(:get).with do |url, api_token|
80
+ url == "#{Maestrano[@preset].param('api.host')}#{Maestrano[@preset].param('api.base')}account/bills" && api_token.nil?
81
+ end.once.returns(test_response(test_account_bill_array))
82
+
83
+ bills = Maestrano::Account::Bill[@preset].all
84
+ assert bills
85
+ end
45
86
  end
46
87
  end
47
88
  end
@@ -28,6 +28,26 @@ module Maestrano
28
28
  c = Maestrano::Account::User.create({name: "Bla"})
29
29
  end
30
30
  end
31
+
32
+ context 'with presets' do
33
+ setup do
34
+ @preset = 'mypreset'
35
+ Maestrano[@preset].configure do |config|
36
+ config.environment = 'production'
37
+ config.api.host = 'https://myprovider.com'
38
+ config.api.base = '/myapi'
39
+ end
40
+ end
41
+
42
+ should "should successfully list remote users" do
43
+ @api_mock.expects(:get).with do |url, api_token|
44
+ url == "#{Maestrano[@preset].param('api.host')}#{Maestrano[@preset].param('api.base')}account/users" && api_token.nil?
45
+ end.once.returns(test_response(test_account_user_array))
46
+
47
+ bills = Maestrano::Account::User[@preset].all
48
+ assert bills
49
+ end
50
+ end
31
51
  end
32
52
  end
33
53
  end
@@ -4,89 +4,233 @@ module Maestrano
4
4
  module Connec
5
5
  class ClientTest < Test::Unit::TestCase
6
6
 
7
- context 'initializer' do
8
- context '.base_uri' do
9
- context 'in test' do
10
- setup { Maestrano.configure { |config| config.environment = 'test' } }
11
- setup { @client = Maestrano::Connec::Client.new("cld-123") }
12
-
13
- should "return the right uri" do
14
- assert_equal "http://api-sandbox.maestrano.io/connec/api/v2", Maestrano::Connec::Client.base_uri
7
+ context 'without preset' do
8
+ context 'initializer' do
9
+ context '.base_uri' do
10
+ context 'in test' do
11
+ setup { Maestrano.configs = {}; Maestrano.configure { |config| config.environment = 'test' } }
12
+ setup { @client = Maestrano::Connec::Client.new("cld-123") }
13
+
14
+ should "return the right uri" do
15
+ assert_equal "http://api-sandbox.maestrano.io/connec/api/v2", Maestrano::Connec::Client.base_uri
16
+ end
17
+ end
18
+
19
+ context 'in production' do
20
+ setup { Maestrano.configs = {}; Maestrano.configure { |config| config.environment = 'production' } }
21
+ setup { @client = Maestrano::Connec::Client.new("cld-123") }
22
+
23
+ should "return the right uri" do
24
+ assert_equal "https://api-connec.maestrano.com/api/v2", Maestrano::Connec::Client.base_uri
25
+ end
15
26
  end
16
27
  end
28
+ end
17
29
 
18
- context 'in production' do
19
- setup { Maestrano.configure { |config| config.environment = 'production' } }
20
- setup { @client = Maestrano::Connec::Client.new("cld-123") }
21
-
22
- should "return the right uri" do
23
- assert_equal "https://api-connec.maestrano.com/api/v2", Maestrano::Connec::Client.base_uri
24
- end
30
+ context 'scoped_path' do
31
+ setup { @client = Maestrano::Connec::Client.new("cld-123") }
32
+
33
+ should "return the right scoped path" do
34
+ assert_equal "/cld-123/people", @client.scoped_path('/people')
35
+ end
36
+
37
+ should "remove any leading or trailing slash" do
38
+ assert_equal "/cld-123/people", @client.scoped_path('/people/')
25
39
  end
26
40
  end
27
- end
28
-
29
- context 'scoped_path' do
30
- setup { @client = Maestrano::Connec::Client.new("cld-123") }
31
41
 
32
- should "return the right scoped path" do
33
- assert_equal "/cld-123/people", @client.scoped_path('/people')
42
+ context 'default_options' do
43
+ setup { @client = Maestrano::Connec::Client.new("cld-123") }
44
+
45
+ should "return the right authentication options" do
46
+ expected_opts = {
47
+ basic_auth: {
48
+ username: Maestrano.param('api.id'),
49
+ password: Maestrano.param('api.key')
50
+ },
51
+ timeout: Maestrano.param('connec.timeout')
52
+ }
53
+ assert_equal expected_opts, @client.default_options
54
+ end
34
55
  end
35
56
 
36
- should "remove any leading or trailing slash" do
37
- assert_equal "/cld-123/people", @client.scoped_path('/people/')
57
+ context 'get' do
58
+ setup { @client = Maestrano::Connec::Client.new("cld-123") }
59
+
60
+ should "perform the right query" do
61
+ path = '/people'
62
+ opts = { foo: 'bar' }
63
+ resp = mock('resp')
64
+ Maestrano::Connec::Client.expects(:get).with(@client.scoped_path(path),@client.default_options.merge(opts)).returns(resp)
65
+ assert_equal resp, @client.get(path,opts)
66
+ end
38
67
  end
39
- end
40
-
41
- context 'default_options' do
42
- setup { @client = Maestrano::Connec::Client.new("cld-123") }
43
68
 
44
- should "return the right authentication options" do
45
- expected_opts = {
46
- basic_auth: {
47
- username: Maestrano.param('api.id'),
48
- password: Maestrano.param('api.key')
49
- }
50
- }
51
- assert_equal expected_opts, @client.default_options
69
+ context 'post' do
70
+ setup { @client = Maestrano::Connec::Client.new("cld-123") }
71
+
72
+ should "perform the right query" do
73
+ path = '/people'
74
+ body = { some: 'data'}
75
+ opts = { foo: 'bar' }
76
+ resp = mock('resp')
77
+ Maestrano::Connec::Client.expects(:post).with(@client.scoped_path(path),@client.default_options.merge(body: body.to_json).merge(opts)).returns(resp)
78
+ assert_equal resp, @client.post(path,body,opts)
79
+ end
52
80
  end
53
- end
54
-
55
- context 'get' do
56
- setup { @client = Maestrano::Connec::Client.new("cld-123") }
57
81
 
58
- should "perform the right query" do
59
- path = '/people'
60
- opts = { foo: 'bar' }
61
- resp = mock('resp')
62
- Maestrano::Connec::Client.expects(:get).with(@client.scoped_path(path),@client.default_options.merge(opts)).returns(resp)
63
- assert_equal resp, @client.get(path,opts)
82
+ context 'put' do
83
+ setup { @client = Maestrano::Connec::Client.new("cld-123") }
84
+
85
+ should "perform the right query" do
86
+ path = '/people/123'
87
+ body = { some: 'data'}
88
+ opts = { foo: 'bar' }
89
+ resp = mock('resp')
90
+ Maestrano::Connec::Client.expects(:put).with(@client.scoped_path(path),@client.default_options.merge(body: body.to_json).merge(opts)).returns(resp)
91
+ assert_equal resp, @client.put(path,body,opts)
92
+ end
64
93
  end
65
94
  end
66
-
67
- context 'post' do
68
- setup { @client = Maestrano::Connec::Client.new("cld-123") }
95
+
96
+ context 'with preset' do
97
+ setup do
98
+ @preset = 'mypreset'
99
+
100
+ @config = {
101
+ 'environment' => 'production',
102
+ 'app.host' => 'http://mysuperapp.com',
103
+
104
+ 'api.id' => 'app-f54ds4f8',
105
+ 'api.key' => 'someapikey',
106
+
107
+ 'connec.enabled' => true,
108
+ 'connec.host' => 'https://connec-api.com',
109
+ 'connec.base_path' => '/api'
110
+ }
111
+
112
+ @preset_config = {
113
+ 'environment' => 'production',
114
+ 'app.host' => 'http://myotherapp.com',
115
+
116
+ 'api.id' => 'app-553941',
117
+ 'api.key' => 'otherapikey',
118
+
119
+ 'connec.enabled' => true,
120
+ 'connec.host' => 'https://other-provider.com',
121
+ 'connec.base_path' => '/data'
122
+ }
123
+
124
+ Maestrano.configure do |config|
125
+ config.environment = @config['environment']
126
+ config.app.host = @config['app.host']
127
+
128
+ config.api.id = @config['api.id']
129
+ config.api.key = @config['api.key']
130
+
131
+ config.connec.enabled = @config['connec.enabled']
132
+ config.connec.host = @config['connec.host']
133
+ config.connec.base_path = @config['connec.base_path']
134
+ end
69
135
 
70
- should "perform the right query" do
71
- path = '/people'
72
- body = { some: 'data'}
73
- opts = { foo: 'bar' }
74
- resp = mock('resp')
75
- Maestrano::Connec::Client.expects(:post).with(@client.scoped_path(path),@client.default_options.merge(body: body.to_json).merge(opts)).returns(resp)
76
- assert_equal resp, @client.post(path,body,opts)
136
+ Maestrano[@preset].configure do |config|
137
+ config.environment = @preset_config['environment']
138
+ config.app.host = @preset_config['app.host']
139
+
140
+ config.api.id = @preset_config['api.id']
141
+ config.api.key = @preset_config['api.key']
142
+
143
+ config.connec.enabled = @preset_config['connec.enabled']
144
+ config.connec.host = @preset_config['connec.host']
145
+ config.connec.base_path = @preset_config['connec.base_path']
146
+ end
147
+ end
148
+
149
+ context 'initializer' do
150
+ context '.base_uri' do
151
+ context 'in test' do
152
+ setup { Maestrano[@preset].configure { |config| config.environment = 'test' } }
153
+ setup { @client = Maestrano::Connec::Client[@preset].new("cld-123") }
154
+
155
+ should "return the right uri" do
156
+ assert_equal "https://other-provider.com/data", Maestrano::Connec::Client[@preset].base_uri
157
+ end
158
+ end
159
+
160
+ context 'in production' do
161
+ setup { Maestrano[@preset].configure { |config| config.environment = 'production' } }
162
+ setup { @client = Maestrano::Connec::Client[@preset].new("cld-123") }
163
+
164
+ should "return the right uri" do
165
+ assert_equal "https://other-provider.com/data", Maestrano::Connec::Client[@preset].base_uri
166
+ end
167
+ end
168
+ end
77
169
  end
78
- end
79
-
80
- context 'put' do
81
- setup { @client = Maestrano::Connec::Client.new("cld-123") }
82
170
 
83
- should "perform the right query" do
84
- path = '/people/123'
85
- body = { some: 'data'}
86
- opts = { foo: 'bar' }
87
- resp = mock('resp')
88
- Maestrano::Connec::Client.expects(:put).with(@client.scoped_path(path),@client.default_options.merge(body: body.to_json).merge(opts)).returns(resp)
89
- assert_equal resp, @client.put(path,body,opts)
171
+ context 'scoped_path' do
172
+ setup { @client = Maestrano::Connec::Client[@preset].new("cld-123") }
173
+
174
+ should "return the right scoped path" do
175
+ assert_equal "/cld-123/people", @client.scoped_path('/people')
176
+ end
177
+
178
+ should "remove any leading or trailing slash" do
179
+ assert_equal "/cld-123/people", @client.scoped_path('/people/')
180
+ end
181
+ end
182
+
183
+ context 'default_options' do
184
+ setup { @client = Maestrano::Connec::Client[@preset].new("cld-123") }
185
+
186
+ should "return the right authentication options" do
187
+ expected_opts = {
188
+ basic_auth: {
189
+ username: Maestrano[@preset].param('api.id'),
190
+ password: Maestrano[@preset].param('api.key')
191
+ },
192
+ timeout: Maestrano[@preset].param('connec.timeout')
193
+ }
194
+ assert_equal expected_opts, @client.default_options
195
+ end
196
+ end
197
+
198
+ context 'get' do
199
+ setup { @client = Maestrano::Connec::Client[@preset].new("cld-123") }
200
+
201
+ should "perform the right query" do
202
+ path = '/people'
203
+ opts = { foo: 'bar' }
204
+ resp = mock('resp')
205
+ Maestrano::Connec::Client[@preset].expects(:get).with(@client.scoped_path(path),@client.default_options.merge(opts)).returns(resp)
206
+ assert_equal resp, @client.get(path,opts)
207
+ end
208
+ end
209
+
210
+ context 'post' do
211
+ setup { @client = Maestrano::Connec::Client[@preset].new("cld-123") }
212
+
213
+ should "perform the right query" do
214
+ path = '/people'
215
+ body = { some: 'data'}
216
+ opts = { foo: 'bar' }
217
+ resp = mock('resp')
218
+ Maestrano::Connec::Client[@preset].expects(:post).with(@client.scoped_path(path),@client.default_options.merge(body: body.to_json).merge(opts)).returns(resp)
219
+ assert_equal resp, @client.post(path,body,opts)
220
+ end
221
+ end
222
+
223
+ context 'put' do
224
+ setup { @client = Maestrano::Connec::Client[@preset].new("cld-123") }
225
+
226
+ should "perform the right query" do
227
+ path = '/people/123'
228
+ body = { some: 'data'}
229
+ opts = { foo: 'bar' }
230
+ resp = mock('resp')
231
+ Maestrano::Connec::Client[@preset].expects(:put).with(@client.scoped_path(path),@client.default_options.merge(body: body.to_json).merge(opts)).returns(resp)
232
+ assert_equal resp, @client.put(path,body,opts)
233
+ end
90
234
  end
91
235
  end
92
236
  end