pisoni 1.27.0 → 1.28.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 0b9921a2c40849229cd27b57db87570d21794d2d65d4673aef8faa157f5f4782
4
- data.tar.gz: 5b6b50ff45e57e8c55ba4b873b0529b7902a2c67c34372475aefe39938e0df74
3
+ metadata.gz: b4bd300163940397f3151f3648985d23dfa38da6a18d1fabb235020f69cd3ef0
4
+ data.tar.gz: de16fdc8e8dc900f80c33bac0e324ac831e1260830d5a456b4bc509bcbc4d54e
5
5
  SHA512:
6
- metadata.gz: f3c2931b7987037a397b43e491db1dcf3985148672270b33b5703b08a4a4f9e01ac15de8a29433f13fdd9d5985d50f87275a7a17542bfddc2d71b2e42f6d528d
7
- data.tar.gz: 2fa14e7b0ff82f7701b279503e2957a6978aca5bdb07b59a2ba75d9a1724926009bf46876202985c4a3414c1694a28929e7f6b79424686171e8d1d9eabedccf9
6
+ metadata.gz: 5f582b3622c904272fccad3c65ca34789fc16f6601825c11b62f63d46aefe2c820ed786038e69def7e278432fc7435ee4bfc80e2e5e04e095a7b6971fd0007da
7
+ data.tar.gz: 2c1994bd77a4baadcc19fb75b87d99b872842cc0bee6e0d6f9a77ab52fd1aa0677ae976aeccc85f5fec463679106a30252c80efe0325a0cc5fd79a8b369c8bdc
data/CHANGELOG.md CHANGED
@@ -2,6 +2,20 @@
2
2
 
3
3
  Notable changes to Pisoni will be tracked in this document.
4
4
 
5
+ ## 1.28.0 - 2019-12-20
6
+
7
+ ### Changed
8
+
9
+ - `Service.delete_stats` has been adapted to the changes in Apisonator. Now it
10
+ only needs to receive the service ID as a param and deletes all the stats for
11
+ that service. The second param of the function, "delete_job" is ignored now.
12
+ [#24](https://github.com/3scale/pisoni/pull/24)
13
+
14
+ ### Removed
15
+
16
+ - Support for end-users, a feature that's no longer supported in recent
17
+ Apisonator. [#25](https://github.com/3scale/pisoni/pull/25)
18
+
5
19
  ## 1.27.0 - 2019-06-28
6
20
 
7
21
  ### Added
data/lib/3scale/core.rb CHANGED
@@ -18,7 +18,6 @@ require '3scale/core/application'
18
18
  require '3scale/core/metric'
19
19
  require '3scale/core/service'
20
20
  require '3scale/core/usage_limit'
21
- require '3scale/core/user'
22
21
  require '3scale/core/event'
23
22
  require '3scale/core/alert_limit'
24
23
  require '3scale/core/errors'
@@ -37,12 +37,6 @@ module ThreeScale
37
37
  end
38
38
  end
39
39
 
40
- class ServiceRequiresDefaultUserPlan < Error
41
- def initialize
42
- super %(Services without the need for registered users require a default user plan)
43
- end
44
- end
45
-
46
40
  class ServiceIsDefaultService < Error
47
41
  def initialize(id = nil)
48
42
  super %(Service id="#{id}" is the default service, must be removed forcefully or make it not default before removal)
@@ -55,30 +49,6 @@ module ThreeScale
55
49
  end
56
50
  end
57
51
 
58
- class UserRequiresUsername < Error
59
- def initialize
60
- super %(User requires username)
61
- end
62
- end
63
-
64
- class UserRequiresServiceId < Error
65
- def initialize
66
- super %(User requires a service id)
67
- end
68
- end
69
-
70
- class UserRequiresValidServiceId < Error
71
- def initialize(id)
72
- super %(Service id #{id} is invalid, user requires a valid id)
73
- end
74
- end
75
-
76
- class UserRequiresDefinedPlan < Error
77
- def initialize(plan_id, plan_name)
78
- super %(User requires a defined plan, plan id: #{plan_id} plan name: #{plan_name})
79
- end
80
- end
81
-
82
52
  class InvalidProviderKeys < Error
83
53
  def initialize
84
54
  super %(Provider keys are not valid, must be not nil and different)
@@ -20,12 +20,7 @@ module ThreeScale
20
20
 
21
21
  def save!(attributes)
22
22
  id = attributes.fetch(:id)
23
- api_update(attributes, uri: service_uri(id)) do |result|
24
- if result[:response].status == 400
25
- raise ServiceRequiresDefaultUserPlan
26
- end
27
- true
28
- end
23
+ api_update(attributes, uri: service_uri(id))
29
24
  end
30
25
 
31
26
  def change_provider_key!(old_key, new_key)
@@ -46,8 +41,11 @@ module ThreeScale
46
41
  save! id: service_id, default_service: true
47
42
  end
48
43
 
49
- def delete_stats(service_id, delete_job)
50
- api_delete(delete_job, uri: "#{service_uri(service_id)}/stats", prefix: '')
44
+ # Deletes all the stats for the given service.
45
+ # Note: delete_job is no longer needed. It's kept to avoid breaking
46
+ # compatibility.
47
+ def delete_stats(service_id, _delete_job)
48
+ api_delete({}, uri: "#{service_uri(service_id)}/stats", prefix: '')
51
49
  end
52
50
 
53
51
  private
@@ -1,5 +1,5 @@
1
1
  module ThreeScale
2
2
  module Core
3
- VERSION = '1.27.0'
3
+ VERSION = '1.28.0'
4
4
  end
5
5
  end
data/spec/service_spec.rb CHANGED
@@ -97,14 +97,6 @@ module ThreeScale
97
97
  service.provider_key.must_equal default_provider_key
98
98
  end
99
99
 
100
- it 'raises an exception when missing a default user plan' do
101
- @service_params.merge! user_registration_required: false
102
-
103
- lambda do
104
- Service.save!(@service_params)
105
- end.must_raise ServiceRequiresDefaultUserPlan
106
- end
107
-
108
100
  it 'save active service' do
109
101
  service = Service.new(@service_params)
110
102
  service.wont_be_nil
@@ -240,8 +232,14 @@ module ThreeScale
240
232
  }
241
233
  end
242
234
 
243
- describe 'with valid job' do
235
+ describe 'with a service ID' do
244
236
  it 'does not raise error' do
237
+ Service.delete_stats(default_service_id, nil).must_equal true
238
+ end
239
+ end
240
+
241
+ describe 'with a deprecated delete_job param' do
242
+ it 'ignores it without raising error' do
245
243
  Service.delete_stats(default_service_id, delete_job).must_equal true
246
244
  end
247
245
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: pisoni
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.27.0
4
+ version: 1.28.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Alejandro Martinez Ruiz
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2019-06-28 00:00:00.000000000 Z
11
+ date: 2019-12-20 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: faraday
@@ -115,7 +115,6 @@ files:
115
115
  - lib/3scale/core/service_token.rb
116
116
  - lib/3scale/core/transaction.rb
117
117
  - lib/3scale/core/usage_limit.rb
118
- - lib/3scale/core/user.rb
119
118
  - lib/3scale/core/utilization.rb
120
119
  - lib/3scale/core/version.rb
121
120
  - lib/3scale_core.rb
@@ -136,7 +135,6 @@ files:
136
135
  - spec/spec_helper.rb
137
136
  - spec/transaction_spec.rb
138
137
  - spec/usagelimit_spec.rb
139
- - spec/user_spec.rb
140
138
  - spec/utilization_spec.rb
141
139
  homepage: https://github.com/3scale/pisoni
142
140
  licenses:
@@ -178,5 +176,4 @@ test_files:
178
176
  - spec/spec_helper.rb
179
177
  - spec/transaction_spec.rb
180
178
  - spec/usagelimit_spec.rb
181
- - spec/user_spec.rb
182
179
  - spec/utilization_spec.rb
@@ -1,58 +0,0 @@
1
- module ThreeScale
2
- module Core
3
- class User < APIClient::Resource
4
- attributes :service_id, :username, :state, :plan_id, :plan_name
5
-
6
- default_uri '/internal/services/'
7
-
8
- def self.base_uri(service_id, username)
9
- "#{default_uri}#{service_id}/users/#{username}"
10
- end
11
- private_class_method :base_uri
12
-
13
- def self.users_base_uri(service_id)
14
- "#{default_uri}#{service_id}/users"
15
- end
16
- private_class_method :users_base_uri
17
-
18
- def self.check_params(service_id, username)
19
- raise UserRequiresUsername if username.nil? || username == ''.freeze
20
- raise UserRequiresServiceId if service_id.nil? || service_id == ''.freeze
21
- end
22
- private_class_method :check_params
23
-
24
- def self.load(service_id, username)
25
- check_params service_id, username
26
- api_read({}, uri: base_uri(service_id, username))
27
- end
28
-
29
- def self.save!(attributes)
30
- service_id, username = attributes[:service_id], attributes[:username]
31
- check_params service_id, username
32
- api_update(attributes,
33
- uri: base_uri(service_id, username)) do |result|
34
- if result[:response].status == 400
35
- if result[:response_json][:error] =~ /requires a valid service/
36
- raise UserRequiresValidServiceId.new(service_id)
37
- elsif result[:response_json][:error] =~ /requires a defined plan/
38
- raise UserRequiresDefinedPlan.new(attributes[:plan_id],
39
- attributes[:plan_name])
40
- end
41
- end
42
- true
43
- end
44
- end
45
-
46
- def self.delete!(service_id, username)
47
- check_params service_id, username
48
- api_delete({}, uri: base_uri(service_id, username))
49
- end
50
-
51
- def self.delete_all_for_service(service_id)
52
- raise UserRequiresServiceId if service_id.nil? || service_id == ''.freeze
53
-
54
- api_delete({}, uri: users_base_uri(service_id))
55
- end
56
- end
57
- end
58
- end
data/spec/user_spec.rb DELETED
@@ -1,192 +0,0 @@
1
- require_relative './spec_helper'
2
-
3
- module ThreeScale
4
- module Core
5
- describe User do
6
- def nothing_raised
7
- yield
8
- true
9
- rescue => e
10
- e
11
- end
12
-
13
- let(:service_id) { 2001 }
14
- let(:nonexistent_service_id) { service_id.succ }
15
- let(:provider_key) { 'provider_for_user_spec' }
16
- let(:username) { 'pancho' }
17
- let(:nonexistent_username) { 'rodolfo' }
18
- let(:state) { :active }
19
- let(:plan_id) { 6789 }
20
- let(:plan_name) { 'plan_for_panchos' }
21
-
22
- before do
23
- Service.save! provider_key: provider_key,
24
- id: service_id, default_service: true
25
-
26
- Service.delete_by_id! nonexistent_service_id rescue nil
27
- User.delete! service_id, nonexistent_username
28
- @user = User.save! service_id: service_id, username: username, state: state,
29
- plan_id: plan_id, plan_name: plan_name
30
- end
31
-
32
- describe '.load' do
33
- it 'returns a User object' do
34
- User.load(service_id, username).class.must_equal User
35
- end
36
-
37
- it 'parses data from received JSON' do
38
- user = User.load(service_id, username)
39
-
40
- user.wont_be_nil
41
- user.service_id.must_equal service_id.to_s
42
- user.state.must_equal state.to_s
43
- user.plan_id.must_equal plan_id.to_s
44
- user.plan_name.must_equal plan_name
45
- end
46
-
47
- it 'raises when the service id is missing or empty' do
48
- ['', nil].each do |service_id|
49
- lambda do
50
- User.load service_id, username
51
- end.must_raise UserRequiresServiceId
52
- end
53
- end
54
-
55
- it 'raises when the user name is missing or empty' do
56
- ['', nil].each do |user_name|
57
- lambda do
58
- User.load service_id, user_name
59
- end.must_raise UserRequiresUsername
60
- end
61
- end
62
-
63
- it 'returns nil when a non-existent service id is used' do
64
- User.load(nonexistent_service_id, username).must_be_nil
65
- end
66
-
67
- it 'returns nil when a non-existent user name is used' do
68
- User.load(service_id, nonexistent_username).must_be_nil
69
- end
70
- end
71
-
72
- describe '.save!' do
73
- before do
74
- User.delete! service_id, nonexistent_username
75
- end
76
-
77
- it 'returns a User object' do
78
- @user.wont_be_nil
79
- @user.class.must_equal User
80
- end
81
-
82
- it 'returns an object with the saved attributes' do
83
- @user.wont_be_nil
84
- @user.service_id.must_equal service_id.to_s
85
- @user.username.must_equal username
86
- @user.state.must_equal state.to_s
87
- @user.plan_id.must_equal plan_id
88
- @user.plan_name.must_equal plan_name
89
- end
90
-
91
- it 'raises when the service id is missing or empty' do
92
- ['', nil].each do |service_id|
93
- lambda do
94
- User.save! service_id: service_id, username: username, plan_id: plan_id,
95
- plan_name: plan_name
96
- end.must_raise UserRequiresServiceId
97
- end
98
- end
99
-
100
- it 'raises when the user name is missing or empty' do
101
- ['', nil].each do |user_name|
102
- lambda do
103
- User.save! service_id: service_id, username: user_name, plan_id: plan_id,
104
- plan_name: plan_name
105
- end.must_raise UserRequiresUsername
106
- end
107
- end
108
-
109
- it 'raises when a non-existent service id is used' do
110
- lambda do
111
- User.save! service_id: nonexistent_service_id, username: username,
112
- plan_id: plan_id, plan_name: plan_name
113
- end.must_raise UserRequiresValidServiceId
114
- end
115
-
116
- it 'raises when plan_id is nil' do
117
- lambda do
118
- User.save! service_id: service_id, username: username,
119
- plan_id: nil, plan_name: plan_name
120
- end.must_raise UserRequiresDefinedPlan
121
- end
122
-
123
- it 'raises when plan_name is nil' do
124
- lambda do
125
- User.save! service_id: service_id, username: username,
126
- plan_id: plan_id, plan_name: nil
127
- end.must_raise UserRequiresDefinedPlan
128
- end
129
-
130
- it 'returns a new user when a non-existent user name is used' do
131
- nothing_raised do
132
- User.save! service_id: service_id, username: nonexistent_username,
133
- plan_id: plan_id, plan_name: plan_name
134
- end.must_equal true
135
-
136
- user = User.load service_id, nonexistent_username
137
-
138
- user.wont_be_nil
139
- user.service_id.must_equal service_id.to_s
140
- user.username.must_equal nonexistent_username
141
- user.state.must_equal state.to_s
142
- user.plan_id.must_equal plan_id.to_s
143
- user.plan_name.must_equal plan_name
144
- end
145
- end
146
-
147
- describe '.delete!' do
148
- before do
149
- User.save! service_id: service_id, username: username, state: state,
150
- plan_id: plan_id, plan_name: plan_name
151
- end
152
-
153
- it 'deletes the user' do
154
- nothing_raised do
155
- User.delete! service_id, username
156
- end.must_equal true
157
-
158
- User.save! service_id: service_id, username: username, state: state,
159
- plan_id: plan_id, plan_name: plan_name
160
- end
161
- end
162
-
163
- describe '.delete_all_for_service' do
164
- let(:service_id) { '2001_delete_all_for_service' }
165
- let(:provider_key) { 'provider_for_delete_all_for_service' }
166
- let(:state) { :active }
167
-
168
- before do
169
- Service.save! provider_key: provider_key, id: service_id, default_service: true
170
- end
171
-
172
- it 'deletes all users' do
173
- user01 = User.save!(service_id: service_id, username: 'username01', state: :active,
174
- plan_id: 'plan_id_01', plan_name: 'plan_01')
175
- user02 = User.save!(service_id: service_id, username: 'username02', state: :active,
176
- plan_id: 'plan_id_02', plan_name: 'plan_02')
177
- User.delete_all_for_service(service_id).must_equal true
178
- User.load(service_id, user01.username).must_be_nil
179
- User.load(service_id, user02.username).must_be_nil
180
- end
181
-
182
- it 'raises error on empty service' do
183
- proc { User.delete_all_for_service('') }.must_raise UserRequiresServiceId
184
- end
185
-
186
- it 'raises error on nil service' do
187
- proc { User.delete_all_for_service(nil) }.must_raise UserRequiresServiceId
188
- end
189
- end
190
- end
191
- end
192
- end