3scale_toolbox 0.18.0 → 0.19.1

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: d8b53876bf5759606f9517c2c62a32d66587a28ee6425afd1ba011f20222359c
4
- data.tar.gz: 35a2783fdf7d5ee796014cbb7d1e3f85b08987b134b168a84ee40c42308b6150
3
+ metadata.gz: e6612a1233c5601cb6c08ccdfdf3f05c9b12d7b1746b3d0394082eecf91b3059
4
+ data.tar.gz: dc672daa8b8293c16565ade6d6eab1a7abea6c76f16e61d3383d0c592e44478d
5
5
  SHA512:
6
- metadata.gz: 958cb7be80dfc2293e00ad6ca4f9021c12e6e817871f7eb0f25c4ead5aa9a10fca8b42db16b45d01e998cd39980545e30087f5a8064ba57c3e3acb07f07c4934
7
- data.tar.gz: 7c6e163ad4948037a50c88365407e2b91dd4217d0e3effc9c21d79badbbcd93f823e0695997edf791ade3ffe0e7f67e0b4bf61dde91729a1a62fdc4de42ba7c8
6
+ metadata.gz: a2b1652854dedbf1d508a135c2c227fefa8f6872032f02a75e48fcc921780709a595e6dd5ab8d245712b1fe8fac412b38ee12ac1bbfd31c20273d67eaf13c3ce
7
+ data.tar.gz: d5636f0a7ee7223a70e6215bbf41d084df57b0b9b583b98b9f5b111f6835c59ab14a0e6fad6e19c12b2a92d54600dc475913e853fcf4c350f14774e86088aace
@@ -8,8 +8,8 @@ Gem::Specification.new do |spec|
8
8
  spec.name = '3scale_toolbox'
9
9
  spec.version = ThreeScaleToolbox::VERSION
10
10
  spec.licenses = ['MIT']
11
- spec.authors = ['Michal Cichra', 'Eguzki Astiz Lezaun']
12
- spec.email = ['michal@3scale.net', 'eastizle@redhat.com']
11
+ spec.authors = ['Miguel Soriano', 'Eguzki Astiz Lezaun']
12
+ spec.email = ['msoriano@redhat.com', 'eastizle@redhat.com']
13
13
 
14
14
  spec.summary = %q{3scale Toolbox.}
15
15
  spec.description = %q{3scale tools to manage your API from the terminal.}
@@ -34,7 +34,7 @@ Gem::Specification.new do |spec|
34
34
  spec.add_development_dependency 'rake', '~> 13.0'
35
35
  spec.add_development_dependency 'rspec', '~> 3.8'
36
36
  spec.add_development_dependency 'webmock', '~> 3.4'
37
- spec.required_ruby_version = '>= 2.5'
37
+ spec.required_ruby_version = '>= 2.6'
38
38
 
39
39
  spec.add_dependency '3scale-api', '~> 1.4'
40
40
  spec.add_dependency 'cri', '~> 2.15'
data/README.md CHANGED
@@ -39,7 +39,6 @@
39
39
  ## Requirements
40
40
  Supported Ruby interpreters
41
41
 
42
- * MRI 2.5
43
42
  * MRI 2.6
44
43
  * MRI 2.7
45
44
 
@@ -219,5 +218,5 @@ Install, uninstall and update plugins using tools like [RubyGems](https://guides
219
218
 
220
219
  ## Contributing
221
220
 
222
- Bug reports and pull requests are welcome on GitHub at https://github.com/3scale/3scale_toolbox.
221
+ If you are interested in contributing to 3scale Toolbox, please refer to instructions available [here](docs/contributing.md)
223
222
 
@@ -0,0 +1,18 @@
1
+ module ThreeScaleToolbox
2
+ module Commands
3
+ module BackendCommand
4
+ module CopyCommand
5
+ class DeleteMappingRulesTask
6
+ include Task
7
+
8
+ # entrypoint
9
+ def run
10
+ return unless delete_mapping_rules
11
+
12
+ target_backend.mapping_rules.each(&:delete)
13
+ end
14
+ end
15
+ end
16
+ end
17
+ end
18
+ end
@@ -53,6 +53,10 @@ module ThreeScaleToolbox
53
53
  context[:report] ||= {}
54
54
  end
55
55
 
56
+ def delete_mapping_rules
57
+ context.fetch(:delete_mapping_rules, false)
58
+ end
59
+
56
60
  private
57
61
 
58
62
  def find_source_backend
@@ -2,6 +2,7 @@ require '3scale_toolbox/commands/backend_command/copy_command/task'
2
2
  require '3scale_toolbox/commands/backend_command/copy_command/create_or_update_target_backend_task'
3
3
  require '3scale_toolbox/commands/backend_command/copy_command/copy_metrics_task'
4
4
  require '3scale_toolbox/commands/backend_command/copy_command/copy_methods_task'
5
+ require '3scale_toolbox/commands/backend_command/copy_command/delete_mapping_rules_task'
5
6
  require '3scale_toolbox/commands/backend_command/copy_command/copy_mapping_rules_task'
6
7
 
7
8
  module ThreeScaleToolbox
@@ -41,6 +42,7 @@ module ThreeScaleToolbox
41
42
  # First metrics as methods need 'hits' metric in target backend
42
43
  tasks << CopyCommand::CopyMetricsTask.new(context)
43
44
  tasks << CopyCommand::CopyMethodsTask.new(context)
45
+ tasks << CopyCommand::DeleteMappingRulesTask.new(context)
44
46
  tasks << CopyCommand::CopyMappingRulesTask.new(context)
45
47
  tasks.each(&:call)
46
48
  end
@@ -56,6 +58,7 @@ module ThreeScaleToolbox
56
58
  source_remote: threescale_client(fetch_required_option(:source)),
57
59
  target_remote: threescale_client(fetch_required_option(:destination)),
58
60
  source_backend_ref: arguments[:source_backend],
61
+ delete_mapping_rules: true,
59
62
  option_target_system_name: options[:'target-system-name']
60
63
  }
61
64
  end
@@ -104,14 +104,14 @@ module ThreeScaleToolbox
104
104
 
105
105
  # create a mapping rule
106
106
  if (metric_id = metric['id'] || method['id'])
107
- mapping_rule = client.create_mapping_rule(service['id'], {
108
- metric_id: metric_id,
109
- pattern: item['endpoint_path'],
110
- http_method: item['endpoint_http_method'],
111
- metric_system_name: item['endpoint_system_name'],
112
- auth_app_key: auth_app_key_according_service(service),
113
- delta: 1
114
- })
107
+ mapping_rule = client.create_mapping_rule(service['id'],{
108
+ metric_id: metric_id,
109
+ pattern: item['endpoint_path'],
110
+ http_method: item['endpoint_http_method'],
111
+ metric_system_name: item['endpoint_system_name'],
112
+ auth_app_key: auth_app_key_according_service(service),
113
+ delta: 1
114
+ })
115
115
 
116
116
  if mapping_rule['errors'].nil?
117
117
  stats[:mapping_rules] += 1
@@ -54,8 +54,9 @@ module ThreeScaleToolbox
54
54
  Helper.hash_deep_dup(resource).tap do |activedocs|
55
55
  # public production base URL
56
56
  # the basePath field is updated to a new value only when overriden by optional param
57
- api_spec.set_server_url(activedocs,
58
- URI.join(service.proxy.fetch('endpoint'), public_base_path))
57
+ unless service.proxy['endpoint'].nil?
58
+ api_spec.set_server_url(activedocs, URI.join(service.proxy.fetch('endpoint'), public_base_path))
59
+ end
59
60
  # security definitions
60
61
  # just valid for oauth2 when oidc_issuer_endpoint is supplied
61
62
  if !api_spec.security.nil? && api_spec.security[:type] == 'oauth2' && !oidc_issuer_endpoint.nil?
@@ -12,7 +12,7 @@ module ThreeScaleToolbox
12
12
  end
13
13
 
14
14
  existing_operations.each do |op|
15
- method_attrs = methods_index.fetch(op.method['system_name'])
15
+ method_attrs = methods_index.fetch(op.method['system_name']).attrs
16
16
  method = Entities::Method.new(id: method_attrs.fetch('id'), service: service)
17
17
  method.update(op.method)
18
18
  op.set(:metric_id, method.id)
@@ -23,7 +23,7 @@ module ThreeScaleToolbox
23
23
 
24
24
  def methods_index
25
25
  @methods_index ||= service.methods.each_with_object({}) do |method, acc|
26
- acc[method['system_name']] = method
26
+ acc[method.system_name] = method
27
27
  end
28
28
  end
29
29
 
@@ -108,6 +108,8 @@ module ThreeScaleToolbox
108
108
  end
109
109
 
110
110
  def openapi_parser
111
+ raise ThreeScaleToolbox::Error, 'only JSON/YAML format is supported' unless openapi_resource.is_a?(Hash)
112
+
111
113
  if openapi_resource.key?('openapi')
112
114
  ThreeScaleToolbox::OpenAPI::OAS3.build(openapi_path, openapi_resource, validate: validate)
113
115
  else
@@ -27,6 +27,7 @@ module ThreeScaleToolbox
27
27
  # First metrics as methods need 'hits' metric in target backend
28
28
  tasks << Commands::BackendCommand::CopyCommand::CopyMetricsTask.new(backend_context)
29
29
  tasks << Commands::BackendCommand::CopyCommand::CopyMethodsTask.new(backend_context)
30
+ tasks << Commands::BackendCommand::CopyCommand::DeleteMappingRulesTask.new(backend_context)
30
31
  tasks << Commands::BackendCommand::CopyCommand::CopyMappingRulesTask.new(backend_context)
31
32
  tasks.each(&:call)
32
33
 
@@ -72,12 +73,17 @@ module ThreeScaleToolbox
72
73
  context.fetch(:logger)
73
74
  end
74
75
 
76
+ def delete_mapping_rules
77
+ context.fetch(:delete_mapping_rules, false)
78
+ end
79
+
75
80
  def create_backend_context(source_backend)
76
81
  {
77
82
  source_remote: source_remote,
78
83
  target_remote: target_remote,
79
84
  source_backend: source_backend,
80
85
  source_backend_ref: source_backend.id,
86
+ delete_mapping_rules: delete_mapping_rules,
81
87
  logger: logger
82
88
  }
83
89
  end
@@ -73,6 +73,7 @@ module ThreeScaleToolbox
73
73
  source_remote: threescale_client(fetch_required_option(:source)),
74
74
  target_remote: threescale_client(fetch_required_option(:destination)),
75
75
  source_service_ref: arguments[:source_product],
76
+ delete_mapping_rules: true,
76
77
  option_target_system_name: options[:'target-system-name']
77
78
  }
78
79
  end
@@ -28,7 +28,8 @@ module ThreeScaleToolbox
28
28
  target_remote: remote,
29
29
  source_remote: crd_remote,
30
30
  source_service_ref: product.system_name,
31
- logger: Logger.new('/dev/null')
31
+ delete_mapping_rules: true,
32
+ logger: Logger.new(File::NULL)
32
33
  }
33
34
 
34
35
  Commands::ProductCommand::CopySubcommand.workflow(context)
@@ -16,10 +16,8 @@ module ThreeScaleToolbox
16
16
  private
17
17
 
18
18
  def create_method(method)
19
- Entities::Method.create(
20
- service: target,
21
- attrs: ThreeScaleToolbox::Helper.filter_params(%w[friendly_name system_name], method.attrs)
22
- )
19
+ new_method = method.attrs.reject { |key, _| %w[id links].include? key }
20
+ Entities::Method.create(service: target, attrs: new_method)
23
21
  rescue ThreeScaleToolbox::ThreeScaleApiError => e
24
22
  raise e unless ThreeScaleToolbox::Helper.system_name_already_taken_error?(e.apierrors)
25
23
 
@@ -5,6 +5,7 @@ module ThreeScaleToolbox
5
5
  end
6
6
 
7
7
  def method_missing(name, *args)
8
+ # Correct delegation https://eregon.me/blog/2021/02/13/correct-delegation-in-ruby-2-27-3.html
8
9
  start_time = ::Process.clock_gettime(::Process::CLOCK_MONOTONIC)
9
10
  result = @subject.public_send(name, *args)
10
11
  ensure
@@ -12,6 +13,7 @@ module ThreeScaleToolbox
12
13
  ::Kernel.warn "-- call #{name} args |#{args.inspect[0..2000]}| response |#{result.inspect[0..2000]}| - (#{end_time}s)"
13
14
  result
14
15
  end
16
+ ruby2_keywords :method_missing if respond_to?(:ruby2_keywords, true)
15
17
 
16
18
  def public_send(name, *args)
17
19
  method_missing(name, *args)
@@ -141,7 +141,13 @@ module ThreeScaleToolbox
141
141
  ###
142
142
 
143
143
  def method_missing(name, *args)
144
- subject.public_send(name, *args)
144
+ # Correct delegation https://eregon.me/blog/2021/02/13/correct-delegation-in-ruby-2-27-3.html
145
+ @subject.public_send(name, *args)
146
+ end
147
+ ruby2_keywords :method_missing if respond_to?(:ruby2_keywords, true)
148
+
149
+ def public_send(name, *args)
150
+ method_missing(name, *args)
145
151
  end
146
152
 
147
153
  def respond_to_missing?(method_name, include_private = false)
@@ -1,3 +1,3 @@
1
1
  module ThreeScaleToolbox
2
- VERSION = '0.18.0'
2
+ VERSION = '0.19.1'
3
3
  end
data/licenses.xml CHANGED
@@ -13,7 +13,7 @@
13
13
  </dependency>
14
14
  <dependency>
15
15
  <packageName>3scale_toolbox</packageName>
16
- <version>0.18.0</version>
16
+ <version>0.19.1</version>
17
17
  <licenses>
18
18
  <license>
19
19
  <name>MIT</name>
@@ -23,7 +23,7 @@
23
23
  </dependency>
24
24
  <dependency>
25
25
  <packageName>activesupport</packageName>
26
- <version>6.1.3</version>
26
+ <version>6.1.4.1</version>
27
27
  <licenses>
28
28
  <license>
29
29
  <name>MIT</name>
@@ -33,7 +33,7 @@
33
33
  </dependency>
34
34
  <dependency>
35
35
  <packageName>addressable</packageName>
36
- <version>2.7.0</version>
36
+ <version>2.8.0</version>
37
37
  <licenses>
38
38
  <license>
39
39
  <name>Apache 2.0</name>
@@ -53,7 +53,17 @@
53
53
  </dependency>
54
54
  <dependency>
55
55
  <packageName>bundler</packageName>
56
- <version>2.1.4</version>
56
+ <version>2.2.21</version>
57
+ <licenses>
58
+ <license>
59
+ <name>MIT</name>
60
+ <url>http://opensource.org/licenses/mit-license</url>
61
+ </license>
62
+ </licenses>
63
+ </dependency>
64
+ <dependency>
65
+ <packageName>codecov</packageName>
66
+ <version>0.5.2</version>
57
67
  <licenses>
58
68
  <license>
59
69
  <name>MIT</name>
@@ -73,7 +83,7 @@
73
83
  </dependency>
74
84
  <dependency>
75
85
  <packageName>concurrent-ruby</packageName>
76
- <version>1.1.8</version>
86
+ <version>1.1.9</version>
77
87
  <licenses>
78
88
  <license>
79
89
  <name>MIT</name>
@@ -128,6 +138,16 @@
128
138
  <url></url>
129
139
  </license>
130
140
  </licenses>
141
+ </dependency>
142
+ <dependency>
143
+ <packageName>docile</packageName>
144
+ <version>1.4.0</version>
145
+ <licenses>
146
+ <license>
147
+ <name>MIT</name>
148
+ <url>http://opensource.org/licenses/mit-license</url>
149
+ </license>
150
+ </licenses>
131
151
  </dependency>
132
152
  <dependency>
133
153
  <packageName>dotenv</packageName>
@@ -171,7 +191,7 @@
171
191
  </dependency>
172
192
  <dependency>
173
193
  <packageName>i18n</packageName>
174
- <version>1.8.9</version>
194
+ <version>1.8.10</version>
175
195
  <licenses>
176
196
  <license>
177
197
  <name>MIT</name>
@@ -208,20 +228,10 @@
208
228
  <url>http://opensource.org/licenses/mit-license</url>
209
229
  </license>
210
230
  </licenses>
211
- </dependency>
212
- <dependency>
213
- <packageName>mini_portile2</packageName>
214
- <version>2.5.0</version>
215
- <licenses>
216
- <license>
217
- <name>MIT</name>
218
- <url>http://opensource.org/licenses/mit-license</url>
219
- </license>
220
- </licenses>
221
231
  </dependency>
222
232
  <dependency>
223
233
  <packageName>minitest</packageName>
224
- <version>5.14.3</version>
234
+ <version>5.14.4</version>
225
235
  <licenses>
226
236
  <license>
227
237
  <name>MIT</name>
@@ -251,7 +261,7 @@
251
261
  </dependency>
252
262
  <dependency>
253
263
  <packageName>nokogiri</packageName>
254
- <version>1.11.1</version>
264
+ <version>1.12.4</version>
255
265
  <licenses>
256
266
  <license>
257
267
  <name>MIT</name>
@@ -261,7 +271,7 @@
261
271
  </dependency>
262
272
  <dependency>
263
273
  <packageName>oas_parser</packageName>
264
- <version>0.25.1</version>
274
+ <version>0.25.4</version>
265
275
  <licenses>
266
276
  <license>
267
277
  <name>MIT</name>
@@ -281,7 +291,7 @@
281
291
  </dependency>
282
292
  <dependency>
283
293
  <packageName>pry</packageName>
284
- <version>0.13.1</version>
294
+ <version>0.14.1</version>
285
295
  <licenses>
286
296
  <license>
287
297
  <name>MIT</name>
@@ -325,7 +335,7 @@
325
335
  </dependency>
326
336
  <dependency>
327
337
  <packageName>rexml</packageName>
328
- <version>3.2.4</version>
338
+ <version>3.2.5</version>
329
339
  <licenses>
330
340
  <license>
331
341
  <name>Simplified BSD</name>
@@ -365,7 +375,7 @@
365
375
  </dependency>
366
376
  <dependency>
367
377
  <packageName>rspec-mocks</packageName>
368
- <version>3.10.1</version>
378
+ <version>3.10.2</version>
369
379
  <licenses>
370
380
  <license>
371
381
  <name>MIT</name>
@@ -375,7 +385,7 @@
375
385
  </dependency>
376
386
  <dependency>
377
387
  <packageName>rspec-support</packageName>
378
- <version>3.10.1</version>
388
+ <version>3.10.2</version>
379
389
  <licenses>
380
390
  <license>
381
391
  <name>MIT</name>
@@ -385,7 +395,7 @@
385
395
  </dependency>
386
396
  <dependency>
387
397
  <packageName>ruby2_keywords</packageName>
388
- <version>0.0.4</version>
398
+ <version>0.0.5</version>
389
399
  <licenses>
390
400
  <license>
391
401
  <name>ruby</name>
@@ -406,6 +416,36 @@
406
416
  <url>http://opensource.org/licenses/bsd-license</url>
407
417
  </license>
408
418
  </licenses>
419
+ </dependency>
420
+ <dependency>
421
+ <packageName>simplecov</packageName>
422
+ <version>0.21.2</version>
423
+ <licenses>
424
+ <license>
425
+ <name>MIT</name>
426
+ <url>http://opensource.org/licenses/mit-license</url>
427
+ </license>
428
+ </licenses>
429
+ </dependency>
430
+ <dependency>
431
+ <packageName>simplecov-html</packageName>
432
+ <version>0.12.3</version>
433
+ <licenses>
434
+ <license>
435
+ <name>MIT</name>
436
+ <url>http://opensource.org/licenses/mit-license</url>
437
+ </license>
438
+ </licenses>
439
+ </dependency>
440
+ <dependency>
441
+ <packageName>simplecov_json_formatter</packageName>
442
+ <version>0.1.3</version>
443
+ <licenses>
444
+ <license>
445
+ <name>MIT</name>
446
+ <url>http://opensource.org/licenses/mit-license</url>
447
+ </license>
448
+ </licenses>
409
449
  </dependency>
410
450
  <dependency>
411
451
  <packageName>thor</packageName>
@@ -439,7 +479,7 @@
439
479
  </dependency>
440
480
  <dependency>
441
481
  <packageName>webmock</packageName>
442
- <version>3.11.1</version>
482
+ <version>3.13.0</version>
443
483
  <licenses>
444
484
  <license>
445
485
  <name>MIT</name>
metadata CHANGED
@@ -1,15 +1,15 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: 3scale_toolbox
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.18.0
4
+ version: 0.19.1
5
5
  platform: ruby
6
6
  authors:
7
- - Michal Cichra
7
+ - Miguel Soriano
8
8
  - Eguzki Astiz Lezaun
9
9
  autorequire:
10
10
  bindir: exe
11
11
  cert_chain: []
12
- date: 2021-02-22 00:00:00.000000000 Z
12
+ date: 2021-09-08 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: bundler
@@ -139,7 +139,7 @@ dependencies:
139
139
  version: '0.20'
140
140
  description: 3scale tools to manage your API from the terminal.
141
141
  email:
142
- - michal@3scale.net
142
+ - msoriano@redhat.com
143
143
  - eastizle@redhat.com
144
144
  executables:
145
145
  - 3scale
@@ -184,6 +184,7 @@ files:
184
184
  - lib/3scale_toolbox/commands/backend_command/copy_command/copy_methods_task.rb
185
185
  - lib/3scale_toolbox/commands/backend_command/copy_command/copy_metrics_task.rb
186
186
  - lib/3scale_toolbox/commands/backend_command/copy_command/create_or_update_target_backend_task.rb
187
+ - lib/3scale_toolbox/commands/backend_command/copy_command/delete_mapping_rules_task.rb
187
188
  - lib/3scale_toolbox/commands/backend_command/copy_command/task.rb
188
189
  - lib/3scale_toolbox/commands/copy_command.rb
189
190
  - lib/3scale_toolbox/commands/copy_command/service_command.rb
@@ -343,14 +344,14 @@ required_ruby_version: !ruby/object:Gem::Requirement
343
344
  requirements:
344
345
  - - ">="
345
346
  - !ruby/object:Gem::Version
346
- version: '2.5'
347
+ version: '2.6'
347
348
  required_rubygems_version: !ruby/object:Gem::Requirement
348
349
  requirements:
349
350
  - - ">="
350
351
  - !ruby/object:Gem::Version
351
352
  version: '0'
352
353
  requirements: []
353
- rubygems_version: 3.1.2
354
+ rubygems_version: 3.0.3
354
355
  signing_key:
355
356
  specification_version: 4
356
357
  summary: 3scale Toolbox.