nurego 1.1.18 → 1.1.19
Sign up to get free protection for your applications and to get access to all the features.
- data/Gemfile.lock +1 -1
- data/VERSION +1 -1
- data/lib/nurego.rb +2 -0
- data/lib/nurego/cf/broker_utility.rb +97 -0
- data/lib/nurego/customer.rb +2 -2
- data/lib/nurego/entitlement.rb +1 -1
- data/lib/nurego/organization.rb +5 -0
- data/lib/nurego/service.rb +0 -50
- data/lib/nurego/subscription.rb +50 -0
- data/lib/nurego/util.rb +1 -0
- metadata +4 -3
data/Gemfile.lock
CHANGED
data/VERSION
CHANGED
@@ -1 +1 @@
|
|
1
|
-
1.1.
|
1
|
+
1.1.19
|
data/lib/nurego.rb
CHANGED
@@ -0,0 +1,97 @@
|
|
1
|
+
module Nurego
|
2
|
+
module Cf
|
3
|
+
class BrokerUtility
|
4
|
+
PROVIDER = 'cloud-foundry'
|
5
|
+
@external_ids = true
|
6
|
+
|
7
|
+
class << self
|
8
|
+
attr_accessor :external_ids
|
9
|
+
end
|
10
|
+
|
11
|
+
def self.provision(params)
|
12
|
+
return nil if nurego_notified(params)
|
13
|
+
raise InvalidRequestError.new('Invalid parameter instance_id', 'instance_id') unless params['instance_id']
|
14
|
+
create_params = { provider: PROVIDER,
|
15
|
+
external_subscription_id: params['instance_id'],
|
16
|
+
plan_id: params['plan_id'],
|
17
|
+
skip_service_webhook: true
|
18
|
+
}
|
19
|
+
Subscription.create(params['organization_guid'], create_params)
|
20
|
+
end
|
21
|
+
|
22
|
+
def self.update(params)
|
23
|
+
return nil if nurego_notified(params)
|
24
|
+
raise InvalidRequestError.new('Invalid parameter instance_id', 'instance_id') unless params['instance_id']
|
25
|
+
sub = Subscription.retrieve(params['instance_id'])
|
26
|
+
sub.plan_id = params['plan_id']
|
27
|
+
sub.provider = PROVIDER
|
28
|
+
sub.skip_service_webhook = true
|
29
|
+
sub.save
|
30
|
+
end
|
31
|
+
|
32
|
+
def self.deprovision(params)
|
33
|
+
return nil if nurego_notified(params)
|
34
|
+
raise InvalidRequestError.new('Invalid parameter instance_id', 'instance_id') unless params['instance_id']
|
35
|
+
sub = Subscription.retrieve(params['instance_id'])
|
36
|
+
sub.delete({ provider: PROVIDER, skip_service_webhook: true })
|
37
|
+
end
|
38
|
+
|
39
|
+
def self.nurego_notified(params)
|
40
|
+
params['nurego_notified'] == true
|
41
|
+
end
|
42
|
+
|
43
|
+
def self.get_service_catalog(service_id)
|
44
|
+
service = Service.retrieve(service_id)
|
45
|
+
service_to_cloud_foundry_catalog(service)
|
46
|
+
end
|
47
|
+
|
48
|
+
private
|
49
|
+
|
50
|
+
def self.service_to_cloud_foundry_catalog(service)
|
51
|
+
cf_catalog = {
|
52
|
+
offer_id: service.offerings.first['id'],
|
53
|
+
offer_name: service.offerings.first['name'],
|
54
|
+
offer_description: service.offerings.first['description'],
|
55
|
+
services: []
|
56
|
+
}
|
57
|
+
cf_service = {
|
58
|
+
# required
|
59
|
+
id: service['id'],
|
60
|
+
name: service['name'],
|
61
|
+
description: service['description'],
|
62
|
+
bindable: true,
|
63
|
+
plans: []
|
64
|
+
|
65
|
+
## possible
|
66
|
+
# tags: [],
|
67
|
+
# metadata: Object,
|
68
|
+
# requires: [],
|
69
|
+
# plan_updateable: true,
|
70
|
+
# dashboard_client: Object {id,secret,redirect_uri}
|
71
|
+
|
72
|
+
}
|
73
|
+
service.offerings.first['plans']['data'].each do | nurego_plan |
|
74
|
+
cf_plan = {
|
75
|
+
# required
|
76
|
+
id: nurego_plan['id'],
|
77
|
+
name: nurego_plan['name'],
|
78
|
+
description: nurego_plan['description'] || " ",
|
79
|
+
|
80
|
+
## possible
|
81
|
+
# metadata: Object,
|
82
|
+
# free: true,
|
83
|
+
}
|
84
|
+
|
85
|
+
recurring = nurego_plan['features']['data'].find { | feature | feature['element_type'] == 'recurring' }
|
86
|
+
cf_plan[:free] = !(recurring && recurring['price'] > 0)
|
87
|
+
|
88
|
+
cf_service[:plans] << cf_plan # Add plans to the service
|
89
|
+
end
|
90
|
+
cf_catalog[:services] << cf_service # Add service to offer
|
91
|
+
|
92
|
+
cf_catalog.to_json
|
93
|
+
end
|
94
|
+
|
95
|
+
end
|
96
|
+
end
|
97
|
+
end
|
data/lib/nurego/customer.rb
CHANGED
@@ -15,8 +15,8 @@ module Nurego
|
|
15
15
|
'/v1/customers/me'
|
16
16
|
end
|
17
17
|
|
18
|
-
def self.update_plan(plan_id)
|
19
|
-
response, api_key = Nurego.request(:
|
18
|
+
def self.update_plan(plan_id, sub_id)
|
19
|
+
response, api_key = Nurego.request(:post, "/v1/customers/subscriptions/#{CGI.escape(sub_id)}", nil, { :plan_id => plan_id })
|
20
20
|
Util.convert_to_nurego_object(response, api_key)
|
21
21
|
end
|
22
22
|
|
data/lib/nurego/entitlement.rb
CHANGED
@@ -8,7 +8,7 @@ module Nurego
|
|
8
8
|
feature_id: feature_id,
|
9
9
|
amount: amount,
|
10
10
|
}
|
11
|
-
response, api_key = Nurego.request(:
|
11
|
+
response, api_key = Nurego.request(:post, "/v1/organizations/#{id}/entitlements/usage", nil, payload)
|
12
12
|
end
|
13
13
|
|
14
14
|
def self.all(organization_id, filters={}, api_key=nil)
|
data/lib/nurego/organization.rb
CHANGED
@@ -28,6 +28,11 @@ module Nurego
|
|
28
28
|
Util.convert_to_nurego_object(response, api_key)
|
29
29
|
end
|
30
30
|
|
31
|
+
def feature_data(params = {}, api_key = nil)
|
32
|
+
response, api_key = Nurego.request(:get, url + "/feature_data", api_key, params)
|
33
|
+
Util.convert_to_nurego_object(response, api_key)
|
34
|
+
end
|
35
|
+
|
31
36
|
def cancel(params = {}, api_key = nil)
|
32
37
|
response, api_key = Nurego.request(:post, url + '/cancel', api_key, params)
|
33
38
|
Util.convert_to_nurego_object(response, api_key)
|
data/lib/nurego/service.rb
CHANGED
@@ -2,55 +2,5 @@ module Nurego
|
|
2
2
|
|
3
3
|
class Service < APIResource
|
4
4
|
|
5
|
-
def to_cloud_foundry_catalog
|
6
|
-
service_to_cloud_foundry_catalog.to_json
|
7
|
-
end
|
8
|
-
|
9
|
-
private
|
10
|
-
|
11
|
-
def service_to_cloud_foundry_catalog
|
12
|
-
cf_catalog = {
|
13
|
-
offer_id: self.offerings.first['id'],
|
14
|
-
offer_name: self.offerings.first['name'],
|
15
|
-
offer_description: self.offerings.first['description'],
|
16
|
-
services: []
|
17
|
-
}
|
18
|
-
cf_service = {
|
19
|
-
# required
|
20
|
-
id: self['id'],
|
21
|
-
name: self['name'],
|
22
|
-
description: self['description'],
|
23
|
-
bindable: true,
|
24
|
-
plans: []
|
25
|
-
|
26
|
-
## possible
|
27
|
-
# tags: [],
|
28
|
-
# metadata: Object,
|
29
|
-
# requires: [],
|
30
|
-
# plan_updateable: true,
|
31
|
-
# dashboard_client: Object {id,secret,redirect_uri}
|
32
|
-
|
33
|
-
}
|
34
|
-
self.offerings.first['plans']['data'].each do | nurego_plan |
|
35
|
-
cf_plan = {
|
36
|
-
# required
|
37
|
-
id: nurego_plan['id'],
|
38
|
-
name: nurego_plan['name'],
|
39
|
-
description: nurego_plan['description'],
|
40
|
-
|
41
|
-
## possible
|
42
|
-
# metadata: Object,
|
43
|
-
# free: true,
|
44
|
-
}
|
45
|
-
|
46
|
-
recurring = nurego_plan['features']['data'].find { | feature | feature['element_type'] == 'recurring' }
|
47
|
-
cf_plan[:free] = !(recurring && recurring['price'] > 0)
|
48
|
-
|
49
|
-
cf_service[:plans] << cf_plan # Add plans to the service
|
50
|
-
end
|
51
|
-
cf_catalog[:services] << cf_service # Add service to offer
|
52
|
-
|
53
|
-
cf_catalog
|
54
|
-
end
|
55
5
|
end
|
56
6
|
end
|
@@ -0,0 +1,50 @@
|
|
1
|
+
module Nurego
|
2
|
+
class Subscription < APIResource
|
3
|
+
# include Nurego::APIOperations::Create
|
4
|
+
include Nurego::APIOperations::Update
|
5
|
+
# include Nurego::APIOperations::Delete
|
6
|
+
|
7
|
+
# Create override
|
8
|
+
def self.create(org_id, params={}, api_key=nil)
|
9
|
+
response, api_key = Nurego.request(:post, self.url(org_id), api_key, params)
|
10
|
+
Util.convert_to_nurego_object(response, api_key)
|
11
|
+
end
|
12
|
+
|
13
|
+
# Update override
|
14
|
+
def save
|
15
|
+
values = serialize_params(self)
|
16
|
+
|
17
|
+
if values.length > 0
|
18
|
+
values.delete(:id)
|
19
|
+
|
20
|
+
response, api_key = Nurego.request(:post, url(self.organization_id), @api_key, values)
|
21
|
+
refresh_from(response, api_key)
|
22
|
+
end
|
23
|
+
self
|
24
|
+
end
|
25
|
+
|
26
|
+
# Delete override
|
27
|
+
def delete(params={})
|
28
|
+
# use params to pass extra parameters to Nurego backend
|
29
|
+
response, api_key = Nurego.request(:delete, url(self.organization_id), @api_key, params)
|
30
|
+
refresh_from(response, api_key)
|
31
|
+
self
|
32
|
+
end
|
33
|
+
|
34
|
+
# override class url
|
35
|
+
def self.url(org_id = nil)
|
36
|
+
return super() unless org_id
|
37
|
+
"/v1/organizations/#{CGI.escape(org_id)}/#{CGI.escape(class_name.downcase)}s"
|
38
|
+
end
|
39
|
+
|
40
|
+
# override instance url
|
41
|
+
def url(org_id = nil)
|
42
|
+
return super() unless org_id
|
43
|
+
unless id = self['id']
|
44
|
+
raise InvalidRequestError.new("Could not determine which URL to request: #{self.class} instance has no ID: #{self.inspect}", 'id')
|
45
|
+
end
|
46
|
+
"#{self.class.url(org_id)}/#{CGI.escape(id)}"
|
47
|
+
end
|
48
|
+
|
49
|
+
end
|
50
|
+
end
|
data/lib/nurego/util.rb
CHANGED
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: nurego
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 1.1.
|
4
|
+
version: 1.1.19
|
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: 2015-
|
12
|
+
date: 2015-06-22 00:00:00.000000000 Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: rest-client
|
@@ -224,6 +224,7 @@ files:
|
|
224
224
|
- lib/nurego/discount.rb
|
225
225
|
- lib/nurego/util.rb
|
226
226
|
- lib/nurego/registration.rb
|
227
|
+
- lib/nurego/cf/broker_utility.rb
|
227
228
|
- lib/nurego/version.rb
|
228
229
|
- lib/nurego/bill.rb
|
229
230
|
- lib/nurego/json.rb
|
@@ -231,6 +232,7 @@ files:
|
|
231
232
|
- lib/nurego/list_object.rb
|
232
233
|
- lib/nurego/payment_method.rb
|
233
234
|
- lib/nurego/offering.rb
|
235
|
+
- lib/nurego/subscription.rb
|
234
236
|
- lib/nurego/plan.rb
|
235
237
|
- lib/nurego/feature.rb
|
236
238
|
- lib/nurego/auth.rb
|
@@ -297,4 +299,3 @@ test_files:
|
|
297
299
|
- spec/unit/nurego/list_object_spec.rb
|
298
300
|
- spec/unit/nurego/util_spec.rb
|
299
301
|
- spec/unit/test_helper.rb
|
300
|
-
has_rdoc:
|