maestrano 0.12.5 → 1.0.0.pre.RC1
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.
- checksums.yaml +4 -4
- data/.gitignore +2 -2
- data/.travis.yml +1 -2
- data/README.md +42 -1
- data/lib/maestrano.rb +69 -25
- data/lib/maestrano/auto_configure.rb +52 -0
- data/lib/maestrano/open_struct.rb +5 -1
- data/lib/maestrano/version.rb +1 -1
- data/maestrano.gemspec +9 -8
- data/test/maestrano/maestrano_test.rb +173 -66
- data/test/support/yml/dev_platform.yml +8 -0
- data/test/support/yml/wrong_dev_platform.yml +8 -0
- metadata +34 -15
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 7dc88705517a1e58d2c51c43f136064b54ebae69
|
4
|
+
data.tar.gz: 1cf04674d0747ab9186de44f8c4919edcc58b47e
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 5eb450cf434d00e7e68e82918e37cd0eb57b11746b6d840fbdebd6d29a29c571063f50b1551306615dd4cbd65d3ad343c2ef3fb41fc289e95bfff1253534d5ed
|
7
|
+
data.tar.gz: f8cbd89e3c370038d06f54b54e4faae37c8290311f890077bd580a9e63cddc37eeced2c6ae6c81665f621f6c8034006498471318a35512a43b3614eae50d8b5f
|
data/.gitignore
CHANGED
@@ -27,8 +27,8 @@ build/
|
|
27
27
|
# for a library or gem, you might want to ignore these files since the code is
|
28
28
|
# intended to run in multiple environments; otherwise, check them in:
|
29
29
|
Gemfile.lock
|
30
|
-
|
31
|
-
|
30
|
+
.ruby-version
|
31
|
+
.ruby-gemset
|
32
32
|
|
33
33
|
# unless supporting rvm < 1.11.0 or doing something fancy, ignore this:
|
34
34
|
.rvmrc
|
data/.travis.yml
CHANGED
data/README.md
CHANGED
@@ -67,7 +67,48 @@ gem 'maestrano'
|
|
67
67
|
|
68
68
|
|
69
69
|
### Configuration
|
70
|
-
Once installed the first step is to create an initializer to configure the behaviour of the Maestrano gem
|
70
|
+
Once installed the first step is to create an initializer to configure the behaviour of the Maestrano gem
|
71
|
+
|
72
|
+
#### Configuration based of the Developer Platform
|
73
|
+
Your environment configuration is retrieved from the developer platform where your different environments are registered.
|
74
|
+
In your initializer add the following configuration:
|
75
|
+
|
76
|
+
`config/initializers/maestrano.rb`
|
77
|
+
```ruby
|
78
|
+
Maestrano.auto_configure('config/dev_platform.yml')
|
79
|
+
```
|
80
|
+
|
81
|
+
`dev_platform.yml`
|
82
|
+
```yml
|
83
|
+
dev_platform:
|
84
|
+
host: 'https://dev-platform.maestrano.com'
|
85
|
+
api_path: '/api/config/v1/marketplaces'
|
86
|
+
|
87
|
+
environment:
|
88
|
+
name: 'my-environment'
|
89
|
+
api_key: 'your-environment-api-key'
|
90
|
+
api_secret: 'your-environment-api-secret'
|
91
|
+
```
|
92
|
+
|
93
|
+
The API keys can be found under your Environment settings on the developer platform.
|
94
|
+
|
95
|
+
Note that the configuration can also be set from environment variables:
|
96
|
+
|
97
|
+
```bash
|
98
|
+
export MNO_DEVPL_HOST=<developer platform host>
|
99
|
+
export MNO_DEVPL_API_PATH=<developer platform path>
|
100
|
+
export MNO_DEVPL_ENV_NAME=<your environment nid>
|
101
|
+
export MNO_DEVPL_ENV_KEY=<your environment key>
|
102
|
+
export MNO_DEVPL_ENV_SECRET=<your environment secret>
|
103
|
+
```
|
104
|
+
|
105
|
+
`config/initializers/maestrano.rb`
|
106
|
+
```ruby
|
107
|
+
Maestrano.auto_configure
|
108
|
+
```
|
109
|
+
|
110
|
+
#### Configure environments manually - Deprecated
|
111
|
+
Environments configuration should be driven from the developer platform configuration. For backward compatibility purpose, environments can still be defined manually.
|
71
112
|
|
72
113
|
You can add configuration presets by putting additional configuration blocks in your maestrano.rb initializer. These additional presets can then be specified when doing particular action, such as initializing a Connec!™ client or triggering a SSO handshake. These presets are particularly useful if you are dealing with multiple Maestrano-style marketplaces (multi-enterprise integration).
|
73
114
|
|
data/lib/maestrano.rb
CHANGED
@@ -1,6 +1,6 @@
|
|
1
1
|
# libs
|
2
|
-
require 'rest_client'
|
3
2
|
require 'json'
|
3
|
+
require 'rest-client'
|
4
4
|
|
5
5
|
# OpenStruct (Extended)
|
6
6
|
require 'ostruct'
|
@@ -60,13 +60,23 @@ require 'maestrano/account/recurring_bill'
|
|
60
60
|
# Connec
|
61
61
|
require 'maestrano/connec/client'
|
62
62
|
|
63
|
+
# Dev platform
|
64
|
+
require 'maestrano/auto_configure'
|
65
|
+
|
66
|
+
|
63
67
|
module Maestrano
|
64
68
|
include Preset
|
65
|
-
|
69
|
+
|
66
70
|
class << self
|
67
71
|
attr_accessor :configs
|
68
72
|
end
|
69
|
-
|
73
|
+
|
74
|
+
# Reset Maesrtano configuration
|
75
|
+
def self.reset!
|
76
|
+
self.configs = {}
|
77
|
+
return self
|
78
|
+
end
|
79
|
+
|
70
80
|
# Maestrano Configuration block
|
71
81
|
def self.configure
|
72
82
|
self.configs ||= {}
|
@@ -75,13 +85,13 @@ module Maestrano
|
|
75
85
|
self.configs[preset].post_initialize
|
76
86
|
return self
|
77
87
|
end
|
78
|
-
|
88
|
+
|
79
89
|
# Check that app_id and api_key passed
|
80
90
|
# in argument match
|
81
91
|
def self.authenticate(app_id,api_key)
|
82
92
|
self.param(:app_id) == app_id && self.param(:api_key) == api_key
|
83
93
|
end
|
84
|
-
|
94
|
+
|
85
95
|
# Take a user uid (either real or virtual)
|
86
96
|
# and a group id and return the user uid that should
|
87
97
|
# be used within the app based on the user_creation_mode
|
@@ -96,13 +106,13 @@ module Maestrano
|
|
96
106
|
return sanitized_user_uid
|
97
107
|
end
|
98
108
|
end
|
99
|
-
|
109
|
+
|
100
110
|
# Take a user uid (either real or virtual)
|
101
111
|
# and return the real uid part
|
102
112
|
def self.unmask_user(user_uid)
|
103
113
|
user_uid.split(".").first
|
104
114
|
end
|
105
|
-
|
115
|
+
|
106
116
|
# Get configuration parameter value
|
107
117
|
# E.g:
|
108
118
|
# Maestrano.param('api.key')
|
@@ -111,7 +121,7 @@ module Maestrano
|
|
111
121
|
def self.param(parameter)
|
112
122
|
(self.configs[preset] || Configuration.new).param(parameter)
|
113
123
|
end
|
114
|
-
|
124
|
+
|
115
125
|
# Return a hash describing the current
|
116
126
|
# Maestrano configuration. The metadata
|
117
127
|
# will be remotely fetched by Maestrano
|
@@ -119,17 +129,17 @@ module Maestrano
|
|
119
129
|
def self.to_metadata
|
120
130
|
hash = {}
|
121
131
|
hash['environment'] = self.param('environment')
|
122
|
-
|
132
|
+
|
123
133
|
config_groups = ['app','api','sso','webhook']
|
124
134
|
blacklist = ['api.key','api.token']
|
125
|
-
|
135
|
+
|
126
136
|
config_groups.each do |cgroup_name|
|
127
137
|
cgroup = self.configs[preset].send(cgroup_name)
|
128
|
-
|
138
|
+
|
129
139
|
attr_list = cgroup.attributes.map(&:to_s)
|
130
140
|
attr_list += Configuration::EVT_CONFIG[hash['environment']].keys.select { |k| k =~ Regexp.new("^#{cgroup_name}\.") }.map { |k| k.gsub(Regexp.new("^#{cgroup_name}\."),'') }
|
131
141
|
attr_list.uniq!
|
132
|
-
|
142
|
+
|
133
143
|
attr_list.each do |first_lvl|
|
134
144
|
if cgroup.send(first_lvl).is_a?(OpenStruct)
|
135
145
|
c2group = cgroup.send(first_lvl)
|
@@ -150,21 +160,27 @@ module Maestrano
|
|
150
160
|
end
|
151
161
|
end
|
152
162
|
end
|
153
|
-
|
163
|
+
|
154
164
|
return hash
|
155
165
|
end
|
156
166
|
|
167
|
+
def self.auto_configure(config_file_path = nil)
|
168
|
+
AutoConfigure.get_marketplace_configurations(config_file_path)
|
169
|
+
rescue => e
|
170
|
+
raise "Error while fetching dynamic configuration: #{e}. Backtrace: #{e.backtrace}"
|
171
|
+
end
|
172
|
+
|
157
173
|
class Configuration
|
158
174
|
attr_accessor :environment, :app, :sso, :api, :webhook, :connec
|
159
175
|
|
160
176
|
def initialize
|
161
177
|
@environment = 'test'
|
162
|
-
|
178
|
+
|
163
179
|
# App config
|
164
180
|
@app = OpenStruct.new({
|
165
181
|
host: 'http://localhost:3000'
|
166
182
|
})
|
167
|
-
|
183
|
+
|
168
184
|
# API Config
|
169
185
|
@api = OpenStruct.new({
|
170
186
|
id: nil,
|
@@ -175,7 +191,7 @@ module Maestrano
|
|
175
191
|
lang: nil, #set in post_initialize
|
176
192
|
lang_version: nil #set in post_initialize
|
177
193
|
})
|
178
|
-
|
194
|
+
|
179
195
|
# SSO Config
|
180
196
|
@sso = OpenStruct.new({
|
181
197
|
enabled: true,
|
@@ -185,7 +201,7 @@ module Maestrano
|
|
185
201
|
consume_path: '/maestrano/auth/saml/consume',
|
186
202
|
idm: nil
|
187
203
|
})
|
188
|
-
|
204
|
+
|
189
205
|
# WebHooks Config
|
190
206
|
@webhook = OpenStruct.new({
|
191
207
|
account: OpenStruct.new({
|
@@ -203,7 +219,7 @@ module Maestrano
|
|
203
219
|
enabled: true
|
204
220
|
})
|
205
221
|
end
|
206
|
-
|
222
|
+
|
207
223
|
# Force or default certain parameters
|
208
224
|
# Used after configure block
|
209
225
|
def post_initialize
|
@@ -214,7 +230,7 @@ module Maestrano
|
|
214
230
|
self.sso.idm ||= self.app.host
|
215
231
|
self.sso.slo_enabled &&= self.sso.enabled
|
216
232
|
end
|
217
|
-
|
233
|
+
|
218
234
|
# Transform legacy parameters into new parameter
|
219
235
|
# style
|
220
236
|
# Dummy mapping
|
@@ -238,7 +254,7 @@ module Maestrano
|
|
238
254
|
return parameter.to_s
|
239
255
|
end
|
240
256
|
end
|
241
|
-
|
257
|
+
|
242
258
|
# Handle legacy parameter assignment
|
243
259
|
def method_missing(meth, *args, &block)
|
244
260
|
if meth.to_s =~ /^((?:sso|app|api|user)_.*)=$/
|
@@ -251,12 +267,12 @@ module Maestrano
|
|
251
267
|
super
|
252
268
|
end
|
253
269
|
end
|
254
|
-
|
270
|
+
|
255
271
|
# Get configuration parameter value
|
256
272
|
def param(parameter)
|
257
273
|
real_param = self.legacy_param_to_new(parameter)
|
258
274
|
props = real_param.split('.')
|
259
|
-
|
275
|
+
|
260
276
|
# Either respond to param directly or via properties chaining (e.g: webhook.account.groups_path)
|
261
277
|
if self.respond_to?(real_param) || props.inject(self) { |result,elem| result && result.respond_to?(elem) ? result.send(elem) || elem : false }
|
262
278
|
last_prop = props.pop
|
@@ -268,8 +284,8 @@ module Maestrano
|
|
268
284
|
raise ArgumentError, "No such configuration parameter: '#{parameter}'"
|
269
285
|
end
|
270
286
|
end
|
271
|
-
|
272
|
-
EVT_CONFIG
|
287
|
+
|
288
|
+
EVT_CONFIG ||= {
|
273
289
|
'local' => {
|
274
290
|
'api.host' => 'http://application.maestrano.io',
|
275
291
|
'api.base' => '/api/v1/',
|
@@ -325,7 +341,35 @@ module Maestrano
|
|
325
341
|
'sso.name_id_format' => Maestrano::Saml::Settings::NAMEID_PERSISTENT,
|
326
342
|
'sso.x509_fingerprint' => '2f:57:71:e4:40:19:57:37:a6:2c:f0:c5:82:52:2f:2e:41:b7:9d:7e',
|
327
343
|
'sso.x509_certificate' => "-----BEGIN CERTIFICATE-----\nMIIDezCCAuSgAwIBAgIJAPFpcH2rW0pyMA0GCSqGSIb3DQEBBQUAMIGGMQswCQYD\nVQQGEwJBVTEMMAoGA1UECBMDTlNXMQ8wDQYDVQQHEwZTeWRuZXkxGjAYBgNVBAoT\nEU1hZXN0cmFubyBQdHkgTHRkMRYwFAYDVQQDEw1tYWVzdHJhbm8uY29tMSQwIgYJ\nKoZIhvcNAQkBFhVzdXBwb3J0QG1hZXN0cmFuby5jb20wHhcNMTQwMTA0MDUyNDEw\nWhcNMzMxMjMwMDUyNDEwWjCBhjELMAkGA1UEBhMCQVUxDDAKBgNVBAgTA05TVzEP\nMA0GA1UEBxMGU3lkbmV5MRowGAYDVQQKExFNYWVzdHJhbm8gUHR5IEx0ZDEWMBQG\nA1UEAxMNbWFlc3RyYW5vLmNvbTEkMCIGCSqGSIb3DQEJARYVc3VwcG9ydEBtYWVz\ndHJhbm8uY29tMIGfMA0GCSqGSIb3DQEBAQUAA4GNADCBiQKBgQD3feNNn2xfEz5/\nQvkBIu2keh9NNhobpre8U4r1qC7h7OeInTldmxGL4cLHw4ZAqKbJVrlFWqNevM5V\nZBkDe4mjuVkK6rYK1ZK7eVk59BicRksVKRmdhXbANk/C5sESUsQv1wLZyrF5Iq8m\na9Oy4oYrIsEF2uHzCouTKM5n+O4DkwIDAQABo4HuMIHrMB0GA1UdDgQWBBSd/X0L\n/Pq+ZkHvItMtLnxMCAMdhjCBuwYDVR0jBIGzMIGwgBSd/X0L/Pq+ZkHvItMtLnxM\nCAMdhqGBjKSBiTCBhjELMAkGA1UEBhMCQVUxDDAKBgNVBAgTA05TVzEPMA0GA1UE\nBxMGU3lkbmV5MRowGAYDVQQKExFNYWVzdHJhbm8gUHR5IEx0ZDEWMBQGA1UEAxMN\nbWFlc3RyYW5vLmNvbTEkMCIGCSqGSIb3DQEJARYVc3VwcG9ydEBtYWVzdHJhbm8u\nY29tggkA8WlwfatbSnIwDAYDVR0TBAUwAwEB/zANBgkqhkiG9w0BAQUFAAOBgQDE\nhe/18oRh8EqIhOl0bPk6BG49AkjhZZezrRJkCFp4dZxaBjwZTddwo8O5KHwkFGdy\nyLiPV326dtvXoKa9RFJvoJiSTQLEn5mO1NzWYnBMLtrDWojOe6Ltvn3x0HVo/iHh\nJShjAn6ZYX43Tjl1YXDd1H9O+7/VgEWAQQ32v8p5lA==\n-----END CERTIFICATE-----",
|
344
|
+
},
|
345
|
+
'maestrano-uat' => {
|
346
|
+
'api.host' => 'https://uat.maestrano.io',
|
347
|
+
'api.base' => '/api/v1/',
|
348
|
+
'connec.enabled' => true,
|
349
|
+
'connec.host' => 'https://api-connec-uat.maestrano.io',
|
350
|
+
'connec.base_path' => '/api/v2',
|
351
|
+
'connec.v2_path' => '/v2',
|
352
|
+
'connec.reports_path' => '/reports',
|
353
|
+
'connec.timeout' => 180,
|
354
|
+
'sso.idp' => 'https://uat.maestrano.io',
|
355
|
+
'sso.name_id_format' => Maestrano::Saml::Settings::NAMEID_PERSISTENT,
|
356
|
+
'sso.x509_fingerprint' => '8a:1e:2e:76:c4:67:80:68:6c:81:18:f7:d3:29:5d:77:f8:79:54:2f',
|
357
|
+
'sso.x509_certificate' => "-----BEGIN CERTIFICATE-----\nMIIDezCCAuSgAwIBAgIJAMzy+weDPp7qMA0GCSqGSIb3DQEBBQUAMIGGMQswCQYD\nVQQGEwJBVTEMMAoGA1UECBMDTlNXMQ8wDQYDVQQHEwZTeWRuZXkxGjAYBgNVBAoT\nEU1hZXN0cmFubyBQdHkgTHRkMRYwFAYDVQQDEw1tYWVzdHJhbm8uY29tMSQwIgYJ\nKoZIhvcNAQkBFhVzdXBwb3J0QG1hZXN0cmFuby5jb20wHhcNMTQwMTA0MDUyMzE0\nWhcNMzMxMjMwMDUyMzE0WjCBhjELMAkGA1UEBhMCQVUxDDAKBgNVBAgTA05TVzEP\nMA0GA1UEBxMGU3lkbmV5MRowGAYDVQQKExFNYWVzdHJhbm8gUHR5IEx0ZDEWMBQG\nA1UEAxMNbWFlc3RyYW5vLmNvbTEkMCIGCSqGSIb3DQEJARYVc3VwcG9ydEBtYWVz\ndHJhbm8uY29tMIGfMA0GCSqGSIb3DQEBAQUAA4GNADCBiQKBgQC+2uyQeAOc/iro\nhCyT33RkkWfTGeJ8E/mu9F5ORWoCZ/h2J+QDuzuc69Rf1LoO4wZVQ8LBeWOqMBYz\notYFUIPlPfIBXDNL/stHkpg28WLDpoJM+46WpTAgp89YKgwdAoYODHiUOcO/uXOO\n2i9Ekoa+kxbvBzDJf7uuR/io6GERXwIDAQABo4HuMIHrMB0GA1UdDgQWBBTGRDBT\nie5+fHkB0+SZ5g3WY/D2RTCBuwYDVR0jBIGzMIGwgBTGRDBTie5+fHkB0+SZ5g3W\nY/D2RaGBjKSBiTCBhjELMAkGA1UEBhMCQVUxDDAKBgNVBAgTA05TVzEPMA0GA1UE\nBxMGU3lkbmV5MRowGAYDVQQKExFNYWVzdHJhbm8gUHR5IEx0ZDEWMBQGA1UEAxMN\nbWFlc3RyYW5vLmNvbTEkMCIGCSqGSIb3DQEJARYVc3VwcG9ydEBtYWVzdHJhbm8u\nY29tggkAzPL7B4M+nuowDAYDVR0TBAUwAwEB/zANBgkqhkiG9w0BAQUFAAOBgQAw\nRxg3rZrML//xbsS3FFXguzXiiNQAvA4KrMWhGh3jVrtzAlN1/okFNy6zuN8gzdKD\nYw2n0c/u3cSpUutIVZOkwQuPCMC1hoP7Ilat6icVewNcHayLBxKgRxpBhr5Sc4av\n3HOW5Bi/eyC7IjeBTbTnpziApEC7uUsBou2rlKmTGw==\n-----END CERTIFICATE-----"
|
358
|
+
},
|
359
|
+
'maestrano-production' => {
|
360
|
+
'api.host' => 'https://maestrano.com',
|
361
|
+
'api.base' => '/api/v1/',
|
362
|
+
'connec.enabled' => true,
|
363
|
+
'connec.host' => 'https://api-connec.maestrano.com',
|
364
|
+
'connec.base_path' => '/api/v2',
|
365
|
+
'connec.v2_path' => '/v2',
|
366
|
+
'connec.reports_path' => '/reports',
|
367
|
+
'connec.timeout' => 180,
|
368
|
+
'sso.idp' => 'https://maestrano.com',
|
369
|
+
'sso.name_id_format' => Maestrano::Saml::Settings::NAMEID_PERSISTENT,
|
370
|
+
'sso.x509_fingerprint' => '2f:57:71:e4:40:19:57:37:a6:2c:f0:c5:82:52:2f:2e:41:b7:9d:7e',
|
371
|
+
'sso.x509_certificate' => "-----BEGIN CERTIFICATE-----\nMIIDezCCAuSgAwIBAgIJAPFpcH2rW0pyMA0GCSqGSIb3DQEBBQUAMIGGMQswCQYD\nVQQGEwJBVTEMMAoGA1UECBMDTlNXMQ8wDQYDVQQHEwZTeWRuZXkxGjAYBgNVBAoT\nEU1hZXN0cmFubyBQdHkgTHRkMRYwFAYDVQQDEw1tYWVzdHJhbm8uY29tMSQwIgYJ\nKoZIhvcNAQkBFhVzdXBwb3J0QG1hZXN0cmFuby5jb20wHhcNMTQwMTA0MDUyNDEw\nWhcNMzMxMjMwMDUyNDEwWjCBhjELMAkGA1UEBhMCQVUxDDAKBgNVBAgTA05TVzEP\nMA0GA1UEBxMGU3lkbmV5MRowGAYDVQQKExFNYWVzdHJhbm8gUHR5IEx0ZDEWMBQG\nA1UEAxMNbWFlc3RyYW5vLmNvbTEkMCIGCSqGSIb3DQEJARYVc3VwcG9ydEBtYWVz\ndHJhbm8uY29tMIGfMA0GCSqGSIb3DQEBAQUAA4GNADCBiQKBgQD3feNNn2xfEz5/\nQvkBIu2keh9NNhobpre8U4r1qC7h7OeInTldmxGL4cLHw4ZAqKbJVrlFWqNevM5V\nZBkDe4mjuVkK6rYK1ZK7eVk59BicRksVKRmdhXbANk/C5sESUsQv1wLZyrF5Iq8m\na9Oy4oYrIsEF2uHzCouTKM5n+O4DkwIDAQABo4HuMIHrMB0GA1UdDgQWBBSd/X0L\n/Pq+ZkHvItMtLnxMCAMdhjCBuwYDVR0jBIGzMIGwgBSd/X0L/Pq+ZkHvItMtLnxM\nCAMdhqGBjKSBiTCBhjELMAkGA1UEBhMCQVUxDDAKBgNVBAgTA05TVzEPMA0GA1UE\nBxMGU3lkbmV5MRowGAYDVQQKExFNYWVzdHJhbm8gUHR5IEx0ZDEWMBQGA1UEAxMN\nbWFlc3RyYW5vLmNvbTEkMCIGCSqGSIb3DQEJARYVc3VwcG9ydEBtYWVzdHJhbm8u\nY29tggkA8WlwfatbSnIwDAYDVR0TBAUwAwEB/zANBgkqhkiG9w0BAQUFAAOBgQDE\nhe/18oRh8EqIhOl0bPk6BG49AkjhZZezrRJkCFp4dZxaBjwZTddwo8O5KHwkFGdy\nyLiPV326dtvXoKa9RFJvoJiSTQLEn5mO1NzWYnBMLtrDWojOe6Ltvn3x0HVo/iHh\nJShjAn6ZYX43Tjl1YXDd1H9O+7/VgEWAQQ32v8p5lA==\n-----END CERTIFICATE-----",
|
328
372
|
}
|
329
373
|
}
|
330
374
|
end
|
331
|
-
end
|
375
|
+
end
|
@@ -0,0 +1,52 @@
|
|
1
|
+
module Maestrano
|
2
|
+
module AutoConfigure
|
3
|
+
def self.get_marketplace_configurations(config_file_path = nil)
|
4
|
+
devpl_config = dev_platform_config(config_file_path)
|
5
|
+
begin
|
6
|
+
request = RestClient::Request.new(
|
7
|
+
method: :get,
|
8
|
+
url: "#{devpl_config[:host]}#{devpl_config[:v1_path]}",
|
9
|
+
user: devpl_config[:env_api_key],
|
10
|
+
password: devpl_config[:env_api_secret],
|
11
|
+
headers: {accept: :json, content_type: :json}
|
12
|
+
)
|
13
|
+
response = request.execute
|
14
|
+
hash = JSON.parse(response.to_s)
|
15
|
+
rescue => e
|
16
|
+
raise "No or bad response received from dev platform: #{e}"
|
17
|
+
end
|
18
|
+
|
19
|
+
hash['marketplaces'].each do |marketplace|
|
20
|
+
Maestrano[marketplace['marketplace']].configure do |config|
|
21
|
+
config.environment = marketplace['marketplace']
|
22
|
+
|
23
|
+
[:app, :sso, :api, :webhook, :connec].each do |s|
|
24
|
+
(marketplace[s.to_s] || {}).each do |k, v|
|
25
|
+
config.send(s).send("#{k}=", v)
|
26
|
+
end
|
27
|
+
end
|
28
|
+
end
|
29
|
+
end
|
30
|
+
end
|
31
|
+
|
32
|
+
def self.dev_platform_config(config_file_path = nil)
|
33
|
+
begin
|
34
|
+
yaml_config = YAML.load_file("#{Dir.pwd}/#{config_file_path}")
|
35
|
+
rescue
|
36
|
+
yaml_config = {'dev_platform' => {}, 'environment' => {}}
|
37
|
+
end
|
38
|
+
|
39
|
+
devpl_config = {}
|
40
|
+
devpl_config[:host] = ENV['MNO_DEVPL_HOST'] || yaml_config['dev_platform']['host']
|
41
|
+
devpl_config[:api_path] = ENV['MNO_DEVPL_API_PATH'] || yaml_config['dev_platform']['api_path']
|
42
|
+
|
43
|
+
devpl_config[:env_name] = ENV['MNO_DEVPL_ENV_NAME'] || yaml_config['environment']['name']
|
44
|
+
devpl_config[:env_api_key] = ENV['MNO_DEVPL_ENV_KEY'] || yaml_config['environment']['api_key']
|
45
|
+
devpl_config[:env_api_secret] = ENV['MNO_DEVPL_ENV_SECRET'] || yaml_config['environment']['api_secret']
|
46
|
+
|
47
|
+
raise 'Missing configuration' if devpl_config.values.any? { |v| v.nil? || v.empty? }
|
48
|
+
|
49
|
+
devpl_config
|
50
|
+
end
|
51
|
+
end
|
52
|
+
end
|
@@ -3,7 +3,11 @@ module Maestrano
|
|
3
3
|
class OpenStruct < ::OpenStruct
|
4
4
|
# Return all object defined attributes
|
5
5
|
def attributes
|
6
|
-
|
6
|
+
if self.respond_to?(:to_h)
|
7
|
+
self.to_h.keys
|
8
|
+
else
|
9
|
+
(self.methods - self.class.new.methods).reject {|method| method =~ /=$/ }
|
10
|
+
end
|
7
11
|
end
|
8
12
|
end
|
9
13
|
end
|
data/lib/maestrano/version.rb
CHANGED
data/maestrano.gemspec
CHANGED
@@ -16,18 +16,19 @@ Gem::Specification.new do |s|
|
|
16
16
|
s.test_files = `git ls-files -- test/*`.split("\n")
|
17
17
|
s.executables = `git ls-files -- bin/*`.split("\n").map{ |f| File.basename(f) }
|
18
18
|
s.require_paths = ['lib']
|
19
|
-
|
20
|
-
s.add_dependency('rest-client', '~> 1.
|
19
|
+
|
20
|
+
s.add_dependency('rest-client', '~> 1.8')
|
21
21
|
s.add_dependency('mime-types', '~> 1.25')
|
22
22
|
s.add_dependency('json', '~> 1.8')
|
23
|
-
s.add_dependency('httparty', '~> 0.
|
24
|
-
|
25
|
-
s.add_development_dependency('test-unit', '~>
|
26
|
-
s.add_development_dependency('mocha', '~>
|
27
|
-
s.add_development_dependency('shoulda', '~>
|
23
|
+
s.add_dependency('httparty', '~> 0.14')
|
24
|
+
|
25
|
+
s.add_development_dependency('test-unit', '~> 3')
|
26
|
+
s.add_development_dependency('mocha', '~> 1.1')
|
27
|
+
s.add_development_dependency('shoulda', '~> 3.5')
|
28
|
+
s.add_development_dependency('activesupport', '~> 4.2')
|
28
29
|
s.add_development_dependency('timecop', '<= 0.6.0')
|
29
30
|
s.add_development_dependency('rake', '~> 10')
|
30
|
-
|
31
|
+
|
31
32
|
s.add_runtime_dependency("uuid", ["~> 2.3"])
|
32
33
|
s.add_runtime_dependency("nokogiri", [">= 1.5.0"])
|
33
34
|
end
|
@@ -5,105 +5,105 @@ class MaestranoTest < Test::Unit::TestCase
|
|
5
5
|
@config = {
|
6
6
|
'environment' => 'production',
|
7
7
|
'app.host' => 'http://mysuperapp.com',
|
8
|
-
|
8
|
+
|
9
9
|
'api.id' => 'app-f54ds4f8',
|
10
10
|
'api.key' => 'someapikey',
|
11
11
|
|
12
12
|
'connec.enabled' => true,
|
13
|
-
|
13
|
+
|
14
14
|
'sso.enabled' => false,
|
15
15
|
'sso.slo_enabled' => false,
|
16
16
|
'sso.init_path' => '/mno/sso/init',
|
17
17
|
'sso.consume_path' => '/mno/sso/consume',
|
18
18
|
'sso.creation_mode' => 'real',
|
19
19
|
'sso.idm' => 'http://idp.mysuperapp.com',
|
20
|
-
|
20
|
+
|
21
21
|
'webhook.account.groups_path' => '/mno/groups/:id',
|
22
22
|
'webhook.account.group_users_path' => '/mno/groups/:group_id/users/:id',
|
23
23
|
'webhook.connec.notifications_path' => 'mno/receive',
|
24
24
|
'webhook.connec.subscriptions' => { organizations: true, people: true }
|
25
25
|
}
|
26
|
-
|
26
|
+
|
27
27
|
Maestrano.configure do |config|
|
28
28
|
config.environment = @config['environment']
|
29
29
|
config.app.host = @config['app.host']
|
30
|
-
|
30
|
+
|
31
31
|
config.api.id = @config['api.id']
|
32
32
|
config.api.key = @config['api.key']
|
33
33
|
|
34
34
|
config.connec.enabled = @config['connec.enabled']
|
35
|
-
|
35
|
+
|
36
36
|
config.sso.enabled = @config['sso.enabled']
|
37
37
|
config.sso.slo_enabled = @config['sso.slo_enabled']
|
38
38
|
config.sso.idm = @config['sso.idm']
|
39
39
|
config.sso.init_path = @config['sso.init_path']
|
40
40
|
config.sso.consume_path = @config['sso.consume_path']
|
41
41
|
config.sso.creation_mode = @config['sso.creation_mode']
|
42
|
-
|
42
|
+
|
43
43
|
config.webhook.account.groups_path = @config['webhook.account.groups_path']
|
44
44
|
config.webhook.account.group_users_path = @config['webhook.account.group_users_path']
|
45
|
-
|
45
|
+
|
46
46
|
config.webhook.connec.notifications_path = @config['webhook.connec.notifications_path']
|
47
47
|
config.webhook.connec.subscriptions = @config['webhook.connec.subscriptions']
|
48
48
|
end
|
49
49
|
end
|
50
|
-
|
50
|
+
|
51
51
|
context "new style configuration" do
|
52
52
|
should "return the specified parameters" do
|
53
53
|
@config.keys.each do |key|
|
54
54
|
assert_equal @config[key], Maestrano.param(key)
|
55
55
|
end
|
56
56
|
end
|
57
|
-
|
57
|
+
|
58
58
|
should "set the sso.creation_mode to 'real' by default" do
|
59
59
|
Maestrano.configs = {'default' => Maestrano::Configuration.new }
|
60
60
|
Maestrano.configure { |config| config.app.host = "https://someapp.com" }
|
61
61
|
assert_equal 'real', Maestrano.param('sso.creation_mode')
|
62
62
|
end
|
63
|
-
|
63
|
+
|
64
64
|
should "build the api_token based on the app_id and api_key" do
|
65
65
|
Maestrano.configure { |config| config.app_id = "bla"; config.api_key = "blo" }
|
66
66
|
assert_equal "bla:blo", Maestrano.param('api.token')
|
67
67
|
end
|
68
|
-
|
68
|
+
|
69
69
|
should "assign the sso.idm to app.host if not provided" do
|
70
70
|
Maestrano.configs = {'default' => Maestrano::Configuration.new }
|
71
71
|
Maestrano.configure { |config| config.app.host = "https://someapp.com" }
|
72
72
|
assert_equal Maestrano.param('app.host'), Maestrano.param('sso.idm')
|
73
73
|
end
|
74
|
-
|
74
|
+
|
75
75
|
should "force assign the api.lang" do
|
76
76
|
Maestrano.configure { |config| config.api.lang = "bla" }
|
77
77
|
assert_equal 'ruby', Maestrano.param('api.lang')
|
78
78
|
end
|
79
|
-
|
79
|
+
|
80
80
|
should "force assign the api.lang_version" do
|
81
81
|
Maestrano.configure { |config| config.api.lang_version = "123456" }
|
82
82
|
assert_equal "#{RUBY_VERSION} p#{RUBY_PATCHLEVEL} (#{RUBY_RELEASE_DATE})", Maestrano.param('api.lang_version')
|
83
83
|
end
|
84
|
-
|
84
|
+
|
85
85
|
should "force assign the api.version" do
|
86
86
|
Maestrano.configure { |config| config.api.version = "1245" }
|
87
87
|
assert_equal Maestrano::VERSION, Maestrano.param('api.version')
|
88
88
|
end
|
89
|
-
|
89
|
+
|
90
90
|
should "force slo_enabled to false if sso is disabled" do
|
91
91
|
Maestrano.configure { |config| config.sso.slo_enabled = true; config.sso.enabled = false }
|
92
92
|
assert_false Maestrano.param('sso.slo_enabled')
|
93
93
|
end
|
94
|
-
|
94
|
+
|
95
95
|
context "with environment params" do
|
96
96
|
should "return the right test parameters" do
|
97
97
|
Maestrano.configure { |config| config.environment = 'test' }
|
98
|
-
|
98
|
+
|
99
99
|
['api.host', 'api.base', 'sso.idp', 'sso.name_id_format', 'sso.x509_certificate', 'connec.host', 'connec.base_path'].each do |parameter|
|
100
100
|
assert_equal Maestrano::Configuration::EVT_CONFIG['test'][parameter], Maestrano.param(parameter)
|
101
101
|
end
|
102
102
|
end
|
103
|
-
|
103
|
+
|
104
104
|
should "return the right production parameters" do
|
105
105
|
Maestrano.configure { |config| config.environment = 'production' }
|
106
|
-
|
106
|
+
|
107
107
|
['api.host', 'api.base', 'sso.idp', 'sso.name_id_format', 'sso.x509_certificate', 'connec.host', 'connec.base_path'].each do |parameter|
|
108
108
|
assert_equal Maestrano::Configuration::EVT_CONFIG['production'][parameter], Maestrano.param(parameter)
|
109
109
|
end
|
@@ -113,24 +113,26 @@ class MaestranoTest < Test::Unit::TestCase
|
|
113
113
|
|
114
114
|
context "new style configuration with presets" do
|
115
115
|
setup do
|
116
|
+
Maestrano.reset!
|
117
|
+
|
116
118
|
@preset = 'mypreset'
|
117
119
|
|
118
120
|
@config = {
|
119
121
|
'environment' => 'production',
|
120
122
|
'app.host' => 'http://mysuperapp.com',
|
121
|
-
|
123
|
+
|
122
124
|
'api.id' => 'app-f54ds4f8',
|
123
125
|
'api.key' => 'someapikey',
|
124
126
|
|
125
127
|
'connec.enabled' => true,
|
126
|
-
|
128
|
+
|
127
129
|
'sso.enabled' => false,
|
128
130
|
'sso.slo_enabled' => false,
|
129
131
|
'sso.init_path' => '/mno/sso/init',
|
130
132
|
'sso.consume_path' => '/mno/sso/consume',
|
131
133
|
'sso.creation_mode' => 'real',
|
132
134
|
'sso.idm' => 'http://idp.mysuperapp.com',
|
133
|
-
|
135
|
+
|
134
136
|
'webhook.account.groups_path' => '/mno/groups/:id',
|
135
137
|
'webhook.account.group_users_path' => '/mno/groups/:group_id/users/:id',
|
136
138
|
'webhook.connec.notifications_path' => 'mno/receive',
|
@@ -140,7 +142,7 @@ class MaestranoTest < Test::Unit::TestCase
|
|
140
142
|
@preset_config = {
|
141
143
|
'environment' => 'production',
|
142
144
|
'app.host' => 'http://myotherapp.com',
|
143
|
-
|
145
|
+
|
144
146
|
'api.id' => 'app-553941',
|
145
147
|
'api.key' => 'otherapikey',
|
146
148
|
}
|
@@ -148,30 +150,30 @@ class MaestranoTest < Test::Unit::TestCase
|
|
148
150
|
Maestrano.configure do |config|
|
149
151
|
config.environment = @config['environment']
|
150
152
|
config.app.host = @config['app.host']
|
151
|
-
|
153
|
+
|
152
154
|
config.api.id = @config['api.id']
|
153
155
|
config.api.key = @config['api.key']
|
154
156
|
|
155
157
|
config.connec.enabled = @config['connec.enabled']
|
156
|
-
|
158
|
+
|
157
159
|
config.sso.enabled = @config['sso.enabled']
|
158
160
|
config.sso.slo_enabled = @config['sso.slo_enabled']
|
159
161
|
config.sso.idm = @config['sso.idm']
|
160
162
|
config.sso.init_path = @config['sso.init_path']
|
161
163
|
config.sso.consume_path = @config['sso.consume_path']
|
162
164
|
config.sso.creation_mode = @config['sso.creation_mode']
|
163
|
-
|
165
|
+
|
164
166
|
config.webhook.account.groups_path = @config['webhook.account.groups_path']
|
165
167
|
config.webhook.account.group_users_path = @config['webhook.account.group_users_path']
|
166
|
-
|
168
|
+
|
167
169
|
config.webhook.connec.notifications_path = @config['webhook.connec.notifications_path']
|
168
170
|
config.webhook.connec.subscriptions = @config['webhook.connec.subscriptions']
|
169
171
|
end
|
170
|
-
|
172
|
+
|
171
173
|
Maestrano[@preset].configure do |config|
|
172
174
|
config.environment = @preset_config['environment']
|
173
175
|
config.app.host = @preset_config['app.host']
|
174
|
-
|
176
|
+
|
175
177
|
config.api.id = @preset_config['api.id']
|
176
178
|
config.api.key = @preset_config['api.key']
|
177
179
|
end
|
@@ -182,39 +184,39 @@ class MaestranoTest < Test::Unit::TestCase
|
|
182
184
|
assert_equal @preset_config[key], Maestrano[@preset].param(key)
|
183
185
|
end
|
184
186
|
end
|
185
|
-
|
187
|
+
|
186
188
|
should "set the sso.creation_mode to 'real' by default" do
|
187
189
|
Maestrano.configs = {@preset => Maestrano::Configuration.new }
|
188
190
|
Maestrano[@preset].configure { |config| config.app.host = "https://someapp.com" }
|
189
191
|
assert_equal 'real', Maestrano[@preset].param('sso.creation_mode')
|
190
192
|
end
|
191
|
-
|
193
|
+
|
192
194
|
should "build the api_token based on the app_id and api_key" do
|
193
195
|
Maestrano[@preset].configure { |config| config.app_id = "bla"; config.api_key = "blo" }
|
194
196
|
assert_equal "bla:blo", Maestrano[@preset].param('api.token')
|
195
197
|
end
|
196
|
-
|
198
|
+
|
197
199
|
should "assign the sso.idm to app.host if not provided" do
|
198
200
|
Maestrano.configs = {@preset => Maestrano::Configuration.new }
|
199
201
|
Maestrano[@preset].configure { |config| config.app.host = "https://someapp.com" }
|
200
202
|
assert_equal Maestrano[@preset].param('app.host'), Maestrano[@preset].param('sso.idm')
|
201
203
|
end
|
202
|
-
|
204
|
+
|
203
205
|
should "force assign the api.lang" do
|
204
206
|
Maestrano[@preset].configure { |config| config.api.lang = "bla" }
|
205
207
|
assert_equal 'ruby', Maestrano[@preset].param('api.lang')
|
206
208
|
end
|
207
|
-
|
209
|
+
|
208
210
|
should "force assign the api.lang_version" do
|
209
211
|
Maestrano[@preset].configure { |config| config.api.lang_version = "123456" }
|
210
212
|
assert_equal "#{RUBY_VERSION} p#{RUBY_PATCHLEVEL} (#{RUBY_RELEASE_DATE})", Maestrano[@preset].param('api.lang_version')
|
211
213
|
end
|
212
|
-
|
214
|
+
|
213
215
|
should "force assign the api.version" do
|
214
216
|
Maestrano[@preset].configure { |config| config.api.version = "1245" }
|
215
217
|
assert_equal Maestrano::VERSION, Maestrano[@preset].param('api.version')
|
216
218
|
end
|
217
|
-
|
219
|
+
|
218
220
|
should "force slo_enabled to false if sso is disabled" do
|
219
221
|
Maestrano[@preset].configure { |config| config.sso.slo_enabled = true; config.sso.enabled = false }
|
220
222
|
assert_false Maestrano[@preset].param('sso.slo_enabled')
|
@@ -225,26 +227,131 @@ class MaestranoTest < Test::Unit::TestCase
|
|
225
227
|
assert_equal 'http://mydataserver.org', Maestrano[@preset].param('connec.host')
|
226
228
|
assert_equal '/data', Maestrano[@preset].param('connec.base_path')
|
227
229
|
end
|
228
|
-
|
230
|
+
|
229
231
|
context "with environment params" do
|
230
232
|
should "return the right test parameters" do
|
231
233
|
Maestrano[@preset].configure { |config| config.environment = 'test' }
|
232
|
-
|
234
|
+
|
233
235
|
['api.host','api.base','sso.idp', 'sso.name_id_format', 'sso.x509_certificate', 'connec.host','connec.base_path'].each do |parameter|
|
234
236
|
assert_equal Maestrano::Configuration::EVT_CONFIG['test'][parameter], Maestrano[@preset].param(parameter)
|
235
237
|
end
|
236
238
|
end
|
237
|
-
|
239
|
+
|
238
240
|
should "return the right production parameters" do
|
239
241
|
Maestrano[@preset].configure { |config| config.environment = 'production' }
|
240
|
-
|
242
|
+
|
241
243
|
['api.host','api.base','sso.idp', 'sso.name_id_format', 'sso.x509_certificate','connec.host','connec.base_path'].each do |parameter|
|
242
244
|
assert_equal Maestrano::Configuration::EVT_CONFIG['production'][parameter], Maestrano[@preset].param(parameter)
|
243
245
|
end
|
244
246
|
end
|
245
247
|
end
|
246
|
-
|
247
|
-
|
248
|
+
|
249
|
+
context 'with dynamic dev platform config' do
|
250
|
+
context 'with no config' do
|
251
|
+
should 'raise error' do
|
252
|
+
assert_raise { Maestrano.auto_configure }
|
253
|
+
end
|
254
|
+
end
|
255
|
+
|
256
|
+
context 'with an invalid config' do
|
257
|
+
should 'raise error' do
|
258
|
+
assert_raise { Maestrano.auto_configure('test/support/yml/wrong_dev_platform.yml') }
|
259
|
+
end
|
260
|
+
end
|
261
|
+
|
262
|
+
context 'with a valid config' do
|
263
|
+
context 'with no response from dev plateform' do
|
264
|
+
should 'raise error' do
|
265
|
+
assert_raise { Maestrano.auto_configure('test/support/yml/dev_platform.yml') }
|
266
|
+
end
|
267
|
+
end
|
268
|
+
|
269
|
+
context 'with bad response from dev plateform' do
|
270
|
+
setup do
|
271
|
+
RestClient::Request.any_instance.stubs(:execute).returns('<html></html>')
|
272
|
+
end
|
273
|
+
|
274
|
+
should 'raise error' do
|
275
|
+
assert_raise { Maestrano.auto_configure('test/support/yml/dev_platform.yml') }
|
276
|
+
end
|
277
|
+
end
|
278
|
+
|
279
|
+
context 'with valid response from dev plateform' do
|
280
|
+
setup do
|
281
|
+
@preset = 'this_awesome_one'
|
282
|
+
@marketplace = {
|
283
|
+
marketplace: @preset,
|
284
|
+
environment: "myotherapp-uat",
|
285
|
+
app: {
|
286
|
+
host: 'http://myotherapp.uat.com'
|
287
|
+
},
|
288
|
+
api: {
|
289
|
+
id: "app-abcd",
|
290
|
+
key: "642be9cd60eb17f50deaf416787274a9e07f4b8b2e99103e578bc61859410c5f",
|
291
|
+
host: "https://api-hub-uat.maestrano.io",
|
292
|
+
base: "/api/v1/"
|
293
|
+
},
|
294
|
+
sso: {
|
295
|
+
idm: "http://rails-demoapp.maestrano.io",
|
296
|
+
init_path: "/maestrano/auth/saml/init/#{@preset}",
|
297
|
+
consume_path: "/maestrano/auth/saml/consume/#{@preset}",
|
298
|
+
idp: "https://api-hub-uat.maestrano.io",
|
299
|
+
x509_fingerprint: "29:C2:88:D9:F5:C5:30:D3:D4:D5:0B:9F:0D:D6:2E:3A:0F:80:7C:50",
|
300
|
+
x509_certificate: "-----BEGIN CERTIFICATE-----\nMIIDeTCCAmGgAwIBAgIBAzANBgkqhkiG9w0BAQsFADBMMQswCQYDVQQGEwJBVTEa\nMBgGA1UECgwRTWFlc3RyYW5vIFB0eSBMdGQxITAfBgNVBAMMGGRldmVsb3BlcnMu\nbWFlc3RyYW5vLmNvbTAeFw0xNjA4MjUwNTQwNTFaFw0zNjA4MjYwNTQwNTFaMEQx\nCzAJBgNVBAYTAkFVMRowGAYDVQQKDBFNYWVzdHJhbm8gUHR5IEx0ZDEZMBcGA1UE\nAwwQdWF0Lm1hZXN0cmFuby5pbzCCASIwDQYJKoZIhvcNAQEBBQADggEPADCCAQoC\nggEBAK4aVXl1EpXOXA11rcay+g/lmkm0r5zSWT5b8TpIqpD/qbvaF/qwp1kKKhBw\nzMz5896GAjmPQCYfGeKy1aSleh17FUPKAtYr/qL5DpVOpDBmA3kI8BXUeVveiY3Y\nhoylqyucE+Ch+iBJ/Rx3hPxHvQlRWl/SugmHX/RbX3UsHBepBc9VA5yfT9CNwwPK\nZ63opQ6fZJlRJ1uPnhkJpA/e/72F3kPZClreVe2TRKuCij+TFb+3gOKB08qJdhjK\nVnOgJcb9XWcdpsV35KvvvwffSHxjqt4SSwVdy5mhvkJcjwVRaE1xHUq7CXRxJ/X2\nowG5SQbUjTj6Hu4q4NdvbKxRYU0CAwEAAaNuMGwwLQYJYIZIAYb4QgENBCAWHk1h\nZXN0cmFubyBJbnRlcm5hbCBDZXJ0aWZpY2F0ZTAdBgNVHQ4EFgQUPk2GG6uGEnDc\nqgqbEtWuak8sjwQwDAYDVR0TAQH/BAIwADAOBgNVHQ8BAf8EBAMCBLAwDQYJKoZI\nhvcNAQELBQADggEBAJMTiBbxwV0irz7R8Zpxo2mCVm0JcUoyL//NsRkgOSbN1q75\nsfBKDLCGuG79/JpBbmKKFVlZplWyLjKPhkE6Mz3/lJ5U0dKQOI7rfqtZYjEyxpr5\nHaju5Uxm7VMyIrVDgJFeFZQu76CCe7sw6qKfZoHMbrcNuQQzBrCc1pOikHqCtRE5\nTeNfkpUiBvXWb8GVYwa9G95BOUa3feK/8gmhcrv4XMtJkJbn3hCobkZcws2kQT6k\nOEmKL7ZFXtZjc/RNYEiUzeBJbLRTg+tJEZcLW3MdyLYlYgZqwaLp/Q4pmqbQqC/n\nX9wrxgOYwrA+JT7Dc0kfhis5sWVBokFnbPTOxQw=\n-----END CERTIFICATE-----\n"
|
301
|
+
},
|
302
|
+
connec: {
|
303
|
+
host: "http://api-connec.uat.maestrano.io"
|
304
|
+
}
|
305
|
+
}
|
306
|
+
@marketplaces = {
|
307
|
+
marketplaces: [@marketplace]
|
308
|
+
}
|
309
|
+
|
310
|
+
RestClient::Request.any_instance.stubs(:execute).returns(@marketplaces.to_json)
|
311
|
+
end
|
312
|
+
|
313
|
+
should 'creates a new preset' do
|
314
|
+
@preset = 'this_awesome_one'
|
315
|
+
assert_nothing_raised { Maestrano.auto_configure('test/support/yml/dev_platform.yml') }
|
316
|
+
|
317
|
+
assert_equal @preset, Maestrano.configs[@preset].param('environment')
|
318
|
+
assert_equal @marketplace[:app][:host], Maestrano.configs[@preset].param('app.host')
|
319
|
+
assert_equal @marketplace[:api][:id], Maestrano.configs[@preset].param('api.id')
|
320
|
+
assert_equal @marketplace[:api][:key], Maestrano.configs[@preset].param('api.key')
|
321
|
+
assert_equal @marketplace[:api][:host], Maestrano.configs[@preset].param('api.host')
|
322
|
+
assert_equal @marketplace[:api][:base], Maestrano.configs[@preset].param('api.base')
|
323
|
+
assert_equal @marketplace[:sso][:idm], Maestrano.configs[@preset].param('sso.idm')
|
324
|
+
assert_equal @marketplace[:sso][:init_path], Maestrano.configs[@preset].param('sso.init_path')
|
325
|
+
assert_equal @marketplace[:sso][:consume_path], Maestrano.configs[@preset].param('sso.consume_path')
|
326
|
+
assert_equal @marketplace[:sso][:idp], Maestrano.configs[@preset].param('sso.idp')
|
327
|
+
assert_equal @marketplace[:sso][:x509_fingerprint], Maestrano.configs[@preset].param('sso.x509_fingerprint')
|
328
|
+
assert_equal @marketplace[:sso][:x509_certificate], Maestrano.configs[@preset].param('sso.x509_certificate')
|
329
|
+
assert_equal @marketplace[:connec][:host], Maestrano.configs[@preset].param('connec.host')
|
330
|
+
end
|
331
|
+
|
332
|
+
should 'overwrites the exisiting preset' do
|
333
|
+
assert_nothing_raised { Maestrano.auto_configure('test/support/yml/dev_platform.yml') }
|
334
|
+
|
335
|
+
assert_equal @preset, Maestrano.configs[@preset].param('environment')
|
336
|
+
assert_equal @marketplace[:app][:host], Maestrano.configs[@preset].param('app.host')
|
337
|
+
assert_equal @marketplace[:api][:id], Maestrano.configs[@preset].param('api.id')
|
338
|
+
assert_equal @marketplace[:api][:key], Maestrano.configs[@preset].param('api.key')
|
339
|
+
assert_equal @marketplace[:api][:host], Maestrano.configs[@preset].param('api.host')
|
340
|
+
assert_equal @marketplace[:api][:base], Maestrano.configs[@preset].param('api.base')
|
341
|
+
assert_equal @marketplace[:sso][:idm], Maestrano.configs[@preset].param('sso.idm')
|
342
|
+
assert_equal @marketplace[:sso][:init_path], Maestrano.configs[@preset].param('sso.init_path')
|
343
|
+
assert_equal @marketplace[:sso][:consume_path], Maestrano.configs[@preset].param('sso.consume_path')
|
344
|
+
assert_equal @marketplace[:sso][:idp], Maestrano.configs[@preset].param('sso.idp')
|
345
|
+
assert_equal @marketplace[:sso][:x509_fingerprint], Maestrano.configs[@preset].param('sso.x509_fingerprint')
|
346
|
+
assert_equal @marketplace[:sso][:x509_certificate], Maestrano.configs[@preset].param('sso.x509_certificate')
|
347
|
+
assert_equal @marketplace[:connec][:host], Maestrano.configs[@preset].param('connec.host')
|
348
|
+
end
|
349
|
+
end
|
350
|
+
|
351
|
+
end
|
352
|
+
end
|
353
|
+
end
|
354
|
+
|
248
355
|
context "old style configuration" do
|
249
356
|
setup do
|
250
357
|
@config = {
|
@@ -256,7 +363,7 @@ class MaestranoTest < Test::Unit::TestCase
|
|
256
363
|
sso_app_consume_path: '/mno/sso/consume',
|
257
364
|
user_creation_mode: 'real',
|
258
365
|
}
|
259
|
-
|
366
|
+
|
260
367
|
Maestrano.configure do |config|
|
261
368
|
config.environment = @config[:environment]
|
262
369
|
config.api_key = @config[:api_key]
|
@@ -267,51 +374,51 @@ class MaestranoTest < Test::Unit::TestCase
|
|
267
374
|
config.user_creation_mode = @config[:user_creation_mode]
|
268
375
|
end
|
269
376
|
end
|
270
|
-
|
377
|
+
|
271
378
|
should "build the api_token based on the app_id and api_key" do
|
272
379
|
Maestrano.configure { |config| config.app_id = "bla"; config.api_key = "blo" }
|
273
380
|
assert_equal "bla:blo", Maestrano.param(:api_token)
|
274
381
|
end
|
275
|
-
|
382
|
+
|
276
383
|
should "assign the sso.idm if explicitly set to nil" do
|
277
384
|
Maestrano.configure { |config| config.sso.idm = nil }
|
278
385
|
assert_equal Maestrano.param('app.host'), Maestrano.param('sso.idm')
|
279
386
|
end
|
280
|
-
|
387
|
+
|
281
388
|
should "force assign the api.lang" do
|
282
389
|
Maestrano.configure { |config| config.api.lang = "bla" }
|
283
390
|
assert_equal 'ruby', Maestrano.param('api.lang')
|
284
391
|
end
|
285
|
-
|
392
|
+
|
286
393
|
should "force assign the api.lang_version" do
|
287
394
|
Maestrano.configure { |config| config.api.lang_version = "123456" }
|
288
395
|
assert_equal "#{RUBY_VERSION} p#{RUBY_PATCHLEVEL} (#{RUBY_RELEASE_DATE})", Maestrano.param('api.lang_version')
|
289
396
|
end
|
290
|
-
|
397
|
+
|
291
398
|
should "force assign the api.version" do
|
292
399
|
Maestrano.configure { |config| config.api.version = "1245" }
|
293
400
|
assert_equal Maestrano::VERSION, Maestrano.param('api.version')
|
294
401
|
end
|
295
|
-
|
402
|
+
|
296
403
|
should "return the specified parameters" do
|
297
404
|
@config.keys.each do |key|
|
298
405
|
assert Maestrano.param(key) == @config[key]
|
299
406
|
end
|
300
407
|
end
|
301
|
-
|
408
|
+
|
302
409
|
context "with environment params" do
|
303
410
|
should "return the right test parameters" do
|
304
411
|
Maestrano.configure { |config| config.environment = 'test' }
|
305
|
-
|
412
|
+
|
306
413
|
['api_host','api_base','sso_name_id_format', 'sso_x509_certificate'].each do |parameter|
|
307
414
|
key = Maestrano::Configuration.new.legacy_param_to_new(parameter)
|
308
415
|
assert_equal Maestrano::Configuration::EVT_CONFIG['test'][key], Maestrano.param(parameter)
|
309
416
|
end
|
310
417
|
end
|
311
|
-
|
418
|
+
|
312
419
|
should "return the right production parameters" do
|
313
420
|
Maestrano.configure { |config| config.environment = 'production' }
|
314
|
-
|
421
|
+
|
315
422
|
['api_host','api_base','sso_name_id_format', 'sso_x509_certificate'].each do |parameter|
|
316
423
|
key = Maestrano::Configuration.new.legacy_param_to_new(parameter)
|
317
424
|
assert_equal Maestrano::Configuration::EVT_CONFIG['production'][key], Maestrano.param(parameter)
|
@@ -319,45 +426,45 @@ class MaestranoTest < Test::Unit::TestCase
|
|
319
426
|
end
|
320
427
|
end
|
321
428
|
end
|
322
|
-
|
429
|
+
|
323
430
|
context "authenticate" do
|
324
431
|
should "return true if app_id and api_key match" do
|
325
432
|
assert Maestrano.authenticate(Maestrano.param(:app_id),Maestrano.param(:api_key))
|
326
433
|
end
|
327
|
-
|
434
|
+
|
328
435
|
should "return false otherwise" do
|
329
436
|
assert !Maestrano.authenticate(Maestrano.param(:app_id) + 'a',Maestrano.param(:api_key))
|
330
437
|
assert !Maestrano.authenticate(Maestrano.param(:app_id),Maestrano.param(:api_key) + 'a')
|
331
438
|
end
|
332
439
|
end
|
333
|
-
|
440
|
+
|
334
441
|
context "mask_user_uid" do
|
335
442
|
should "return the composite uid if creation_mode is virtual" do
|
336
443
|
Maestrano.configure { |c| c.user_creation_mode = 'virtual' }
|
337
444
|
assert_equal 'usr-1.cld-1', Maestrano.mask_user('usr-1','cld-1')
|
338
445
|
end
|
339
|
-
|
446
|
+
|
340
447
|
should "not double up the composite uid" do
|
341
448
|
Maestrano.configure { |c| c.user_creation_mode = 'virtual' }
|
342
449
|
assert_equal 'usr-1.cld-1', Maestrano.mask_user('usr-1.cld-1','cld-1')
|
343
450
|
end
|
344
|
-
|
451
|
+
|
345
452
|
should "return the real uid if creation_mode is real" do
|
346
453
|
Maestrano.configure { |c| c.user_creation_mode = 'real' }
|
347
454
|
assert_equal 'usr-1', Maestrano.mask_user('usr-1','cld-1')
|
348
455
|
end
|
349
456
|
end
|
350
|
-
|
457
|
+
|
351
458
|
context "unmask_user_uid" do
|
352
459
|
should "return the right uid if composite" do
|
353
460
|
assert_equal 'usr-1', Maestrano.unmask_user('usr-1.cld-1')
|
354
461
|
end
|
355
|
-
|
462
|
+
|
356
463
|
should "return the right uid if non composite" do
|
357
464
|
assert_equal 'usr-1', Maestrano.unmask_user('usr-1')
|
358
465
|
end
|
359
466
|
end
|
360
|
-
|
467
|
+
|
361
468
|
context "to_metadata" do
|
362
469
|
should "should return the right hash" do
|
363
470
|
expected = {
|
@@ -373,7 +480,7 @@ class MaestranoTest < Test::Unit::TestCase
|
|
373
480
|
'lang_version' => "#{RUBY_VERSION} p#{RUBY_PATCHLEVEL} (#{RUBY_RELEASE_DATE})",
|
374
481
|
'host' => Maestrano::Configuration::EVT_CONFIG[@config['environment']]['api.host'],
|
375
482
|
'base' => Maestrano::Configuration::EVT_CONFIG[@config['environment']]['api.base'],
|
376
|
-
|
483
|
+
|
377
484
|
},
|
378
485
|
'sso' => {
|
379
486
|
'enabled' => @config['sso.enabled'],
|
@@ -398,9 +505,9 @@ class MaestranoTest < Test::Unit::TestCase
|
|
398
505
|
}
|
399
506
|
}
|
400
507
|
}
|
401
|
-
|
508
|
+
|
402
509
|
assert_equal expected, Maestrano.to_metadata
|
403
510
|
end
|
404
511
|
end
|
405
|
-
|
406
|
-
end
|
512
|
+
|
513
|
+
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: maestrano
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 1.0.0.pre.RC1
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Arnaud Lachaume
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2016-
|
11
|
+
date: 2016-08-31 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: rest-client
|
@@ -16,14 +16,14 @@ dependencies:
|
|
16
16
|
requirements:
|
17
17
|
- - "~>"
|
18
18
|
- !ruby/object:Gem::Version
|
19
|
-
version: '1.
|
19
|
+
version: '1.8'
|
20
20
|
type: :runtime
|
21
21
|
prerelease: false
|
22
22
|
version_requirements: !ruby/object:Gem::Requirement
|
23
23
|
requirements:
|
24
24
|
- - "~>"
|
25
25
|
- !ruby/object:Gem::Version
|
26
|
-
version: '1.
|
26
|
+
version: '1.8'
|
27
27
|
- !ruby/object:Gem::Dependency
|
28
28
|
name: mime-types
|
29
29
|
requirement: !ruby/object:Gem::Requirement
|
@@ -58,56 +58,70 @@ dependencies:
|
|
58
58
|
requirements:
|
59
59
|
- - "~>"
|
60
60
|
- !ruby/object:Gem::Version
|
61
|
-
version: '0.
|
61
|
+
version: '0.14'
|
62
62
|
type: :runtime
|
63
63
|
prerelease: false
|
64
64
|
version_requirements: !ruby/object:Gem::Requirement
|
65
65
|
requirements:
|
66
66
|
- - "~>"
|
67
67
|
- !ruby/object:Gem::Version
|
68
|
-
version: '0.
|
68
|
+
version: '0.14'
|
69
69
|
- !ruby/object:Gem::Dependency
|
70
70
|
name: test-unit
|
71
71
|
requirement: !ruby/object:Gem::Requirement
|
72
72
|
requirements:
|
73
73
|
- - "~>"
|
74
74
|
- !ruby/object:Gem::Version
|
75
|
-
version: '
|
75
|
+
version: '3'
|
76
76
|
type: :development
|
77
77
|
prerelease: false
|
78
78
|
version_requirements: !ruby/object:Gem::Requirement
|
79
79
|
requirements:
|
80
80
|
- - "~>"
|
81
81
|
- !ruby/object:Gem::Version
|
82
|
-
version: '
|
82
|
+
version: '3'
|
83
83
|
- !ruby/object:Gem::Dependency
|
84
84
|
name: mocha
|
85
85
|
requirement: !ruby/object:Gem::Requirement
|
86
86
|
requirements:
|
87
87
|
- - "~>"
|
88
88
|
- !ruby/object:Gem::Version
|
89
|
-
version: '
|
89
|
+
version: '1.1'
|
90
90
|
type: :development
|
91
91
|
prerelease: false
|
92
92
|
version_requirements: !ruby/object:Gem::Requirement
|
93
93
|
requirements:
|
94
94
|
- - "~>"
|
95
95
|
- !ruby/object:Gem::Version
|
96
|
-
version: '
|
96
|
+
version: '1.1'
|
97
97
|
- !ruby/object:Gem::Dependency
|
98
98
|
name: shoulda
|
99
99
|
requirement: !ruby/object:Gem::Requirement
|
100
100
|
requirements:
|
101
101
|
- - "~>"
|
102
102
|
- !ruby/object:Gem::Version
|
103
|
-
version: '
|
103
|
+
version: '3.5'
|
104
104
|
type: :development
|
105
105
|
prerelease: false
|
106
106
|
version_requirements: !ruby/object:Gem::Requirement
|
107
107
|
requirements:
|
108
108
|
- - "~>"
|
109
109
|
- !ruby/object:Gem::Version
|
110
|
-
version: '
|
110
|
+
version: '3.5'
|
111
|
+
- !ruby/object:Gem::Dependency
|
112
|
+
name: activesupport
|
113
|
+
requirement: !ruby/object:Gem::Requirement
|
114
|
+
requirements:
|
115
|
+
- - "~>"
|
116
|
+
- !ruby/object:Gem::Version
|
117
|
+
version: '4.2'
|
118
|
+
type: :development
|
119
|
+
prerelease: false
|
120
|
+
version_requirements: !ruby/object:Gem::Requirement
|
121
|
+
requirements:
|
122
|
+
- - "~>"
|
123
|
+
- !ruby/object:Gem::Version
|
124
|
+
version: '4.2'
|
111
125
|
- !ruby/object:Gem::Dependency
|
112
126
|
name: timecop
|
113
127
|
requirement: !ruby/object:Gem::Requirement
|
@@ -199,6 +213,7 @@ files:
|
|
199
213
|
- lib/maestrano/api/operation/update.rb
|
200
214
|
- lib/maestrano/api/resource.rb
|
201
215
|
- lib/maestrano/api/util.rb
|
216
|
+
- lib/maestrano/auto_configure.rb
|
202
217
|
- lib/maestrano/connec/client.rb
|
203
218
|
- lib/maestrano/open_struct.rb
|
204
219
|
- lib/maestrano/preset.rb
|
@@ -267,6 +282,8 @@ files:
|
|
267
282
|
- test/support/saml/responses/simple_saml_php.xml
|
268
283
|
- test/support/saml/responses/starfield_response.xml.base64
|
269
284
|
- test/support/saml/responses/wrapped_response_2.xml.base64
|
285
|
+
- test/support/yml/dev_platform.yml
|
286
|
+
- test/support/yml/wrong_dev_platform.yml
|
270
287
|
- test/test_helper.rb
|
271
288
|
homepage: https://maestrano.com
|
272
289
|
licenses:
|
@@ -283,12 +300,12 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
283
300
|
version: '0'
|
284
301
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
285
302
|
requirements:
|
286
|
-
- - "
|
303
|
+
- - ">"
|
287
304
|
- !ruby/object:Gem::Version
|
288
|
-
version:
|
305
|
+
version: 1.3.1
|
289
306
|
requirements: []
|
290
307
|
rubyforge_project:
|
291
|
-
rubygems_version: 2.
|
308
|
+
rubygems_version: 2.2.2
|
292
309
|
signing_key:
|
293
310
|
specification_version: 4
|
294
311
|
summary: Ruby bindings for the Maestrano API
|
@@ -337,4 +354,6 @@ test_files:
|
|
337
354
|
- test/support/saml/responses/simple_saml_php.xml
|
338
355
|
- test/support/saml/responses/starfield_response.xml.base64
|
339
356
|
- test/support/saml/responses/wrapped_response_2.xml.base64
|
357
|
+
- test/support/yml/dev_platform.yml
|
358
|
+
- test/support/yml/wrong_dev_platform.yml
|
340
359
|
- test/test_helper.rb
|