3scale_toolbox 0.12.4 → 0.17.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.
Files changed (121) hide show
  1. checksums.yaml +4 -4
  2. data/3scale_toolbox.gemspec +4 -3
  3. data/README.md +31 -10
  4. data/lib/3scale_toolbox.rb +5 -2
  5. data/lib/3scale_toolbox/attribute_filters.rb +2 -0
  6. data/lib/3scale_toolbox/attribute_filters/attribute_filter.rb +9 -0
  7. data/lib/3scale_toolbox/attribute_filters/service_id_from_ref_filter.rb +30 -0
  8. data/lib/3scale_toolbox/cli.rb +4 -0
  9. data/lib/3scale_toolbox/cli/custom_table_printer.rb +32 -0
  10. data/lib/3scale_toolbox/cli/error_handler.rb +17 -14
  11. data/lib/3scale_toolbox/cli/json_printer.rb +13 -0
  12. data/lib/3scale_toolbox/cli/output_flag.rb +20 -0
  13. data/lib/3scale_toolbox/cli/yaml_printer.rb +13 -0
  14. data/lib/3scale_toolbox/commands.rb +5 -1
  15. data/lib/3scale_toolbox/commands/activedocs_command/apply_command.rb +34 -11
  16. data/lib/3scale_toolbox/commands/activedocs_command/create_command.rb +22 -7
  17. data/lib/3scale_toolbox/commands/activedocs_command/list_command.rb +21 -11
  18. data/lib/3scale_toolbox/commands/application_command/apply_command.rb +27 -4
  19. data/lib/3scale_toolbox/commands/application_command/create_command.rb +16 -1
  20. data/lib/3scale_toolbox/commands/application_command/list_command.rb +10 -13
  21. data/lib/3scale_toolbox/commands/application_command/show_command.rb +8 -14
  22. data/lib/3scale_toolbox/commands/backend_command.rb +22 -0
  23. data/lib/3scale_toolbox/commands/backend_command/copy_command.rb +65 -0
  24. data/lib/3scale_toolbox/commands/backend_command/copy_command/copy_mapping_rules_task.rb +52 -0
  25. data/lib/3scale_toolbox/commands/backend_command/copy_command/copy_methods_task.rb +40 -0
  26. data/lib/3scale_toolbox/commands/backend_command/copy_command/copy_metrics_task.rb +30 -0
  27. data/lib/3scale_toolbox/commands/backend_command/copy_command/create_or_update_target_backend_task.rb +45 -0
  28. data/lib/3scale_toolbox/commands/backend_command/copy_command/task.rb +89 -0
  29. data/lib/3scale_toolbox/commands/copy_command.rb +2 -2
  30. data/lib/3scale_toolbox/commands/copy_command/service_command.rb +40 -0
  31. data/lib/3scale_toolbox/commands/import_command/openapi.rb +29 -7
  32. data/lib/3scale_toolbox/commands/import_command/openapi/create_activedocs_step.rb +4 -17
  33. data/lib/3scale_toolbox/commands/import_command/openapi/create_service_step.rb +1 -5
  34. data/lib/3scale_toolbox/commands/import_command/openapi/mapping_rule.rb +3 -2
  35. data/lib/3scale_toolbox/commands/import_command/openapi/step.rb +43 -5
  36. data/lib/3scale_toolbox/commands/import_command/openapi/update_policies_step.rb +9 -10
  37. data/lib/3scale_toolbox/commands/import_command/openapi/update_service_oidc_conf_step.rb +2 -17
  38. data/lib/3scale_toolbox/commands/import_command/openapi/update_service_proxy_step.rb +10 -10
  39. data/lib/3scale_toolbox/commands/methods_command/apply_command.rb +26 -4
  40. data/lib/3scale_toolbox/commands/methods_command/create_command.rb +23 -1
  41. data/lib/3scale_toolbox/commands/methods_command/list_command.rb +11 -9
  42. data/lib/3scale_toolbox/commands/metrics_command/apply_command.rb +26 -4
  43. data/lib/3scale_toolbox/commands/metrics_command/create_command.rb +23 -1
  44. data/lib/3scale_toolbox/commands/metrics_command/list_command.rb +7 -12
  45. data/lib/3scale_toolbox/commands/plans_command/apply_command.rb +36 -7
  46. data/lib/3scale_toolbox/commands/plans_command/create_command.rb +23 -1
  47. data/lib/3scale_toolbox/commands/plans_command/import/import_plan_limits_step.rb +11 -12
  48. data/lib/3scale_toolbox/commands/plans_command/import/import_plan_pricing_rules_step.rb +11 -12
  49. data/lib/3scale_toolbox/commands/plans_command/list_command.rb +8 -13
  50. data/lib/3scale_toolbox/commands/plans_command/show_command.rb +6 -14
  51. data/lib/3scale_toolbox/commands/product_command.rb +22 -0
  52. data/lib/3scale_toolbox/commands/product_command/copy_command.rb +78 -0
  53. data/lib/3scale_toolbox/commands/product_command/copy_command/copy_backends_task.rb +71 -0
  54. data/lib/3scale_toolbox/commands/product_command/copy_command/delete_target_backend_usages_task.rb +48 -0
  55. data/lib/3scale_toolbox/commands/proxy_config_command.rb +3 -0
  56. data/lib/3scale_toolbox/commands/proxy_config_command/export_command.rb +74 -0
  57. data/lib/3scale_toolbox/commands/proxy_config_command/helper.rb +15 -0
  58. data/lib/3scale_toolbox/commands/proxy_config_command/list_command.rb +13 -29
  59. data/lib/3scale_toolbox/commands/proxy_config_command/show_command.rb +20 -23
  60. data/lib/3scale_toolbox/commands/service_command.rb +7 -5
  61. data/lib/3scale_toolbox/commands/service_command/apply_command.rb +69 -58
  62. data/lib/3scale_toolbox/commands/service_command/copy_command.rb +95 -0
  63. data/lib/3scale_toolbox/commands/service_command/copy_command/bump_proxy_version_task.rb +36 -0
  64. data/lib/3scale_toolbox/commands/service_command/copy_command/copy_activedocs_task.rb +46 -0
  65. data/lib/3scale_toolbox/commands/service_command/copy_command/copy_app_plans_task.rb +35 -0
  66. data/lib/3scale_toolbox/commands/service_command/copy_command/copy_limits_task.rb +39 -0
  67. data/lib/3scale_toolbox/commands/service_command/copy_command/copy_mapping_rules_task.rb +35 -0
  68. data/lib/3scale_toolbox/commands/service_command/copy_command/copy_methods_task.rb +40 -0
  69. data/lib/3scale_toolbox/commands/service_command/copy_command/copy_metrics_task.rb +37 -0
  70. data/lib/3scale_toolbox/commands/service_command/copy_command/copy_policies_task.rb +17 -0
  71. data/lib/3scale_toolbox/commands/service_command/copy_command/copy_pricingrules_task.rb +44 -0
  72. data/lib/3scale_toolbox/commands/service_command/copy_command/copy_service_proxy_task.rb +32 -0
  73. data/lib/3scale_toolbox/commands/service_command/copy_command/create_or_update_service_task.rb +48 -0
  74. data/lib/3scale_toolbox/commands/service_command/copy_command/destroy_mapping_rules_task.rb +34 -0
  75. data/lib/3scale_toolbox/commands/service_command/copy_command/task.rb +99 -0
  76. data/lib/3scale_toolbox/commands/service_command/create_command.rb +58 -44
  77. data/lib/3scale_toolbox/commands/service_command/delete_command.rb +31 -33
  78. data/lib/3scale_toolbox/commands/service_command/list_command.rb +24 -34
  79. data/lib/3scale_toolbox/commands/service_command/show_command.rb +39 -44
  80. data/lib/3scale_toolbox/commands/update_command.rb +3 -3
  81. data/lib/3scale_toolbox/commands/update_command/{update_service.rb → service_command.rb} +22 -18
  82. data/lib/3scale_toolbox/commands/update_command/service_command/copy_service_settings_task.rb +35 -0
  83. data/lib/3scale_toolbox/commands/update_command/service_command/delete_activedocs_task.rb +26 -0
  84. data/lib/3scale_toolbox/entities.rb +5 -0
  85. data/lib/3scale_toolbox/entities/application_plan.rb +31 -4
  86. data/lib/3scale_toolbox/entities/backend.rb +152 -0
  87. data/lib/3scale_toolbox/entities/backend_mapping_rule.rb +76 -0
  88. data/lib/3scale_toolbox/entities/backend_method.rb +90 -0
  89. data/lib/3scale_toolbox/entities/backend_metric.rb +88 -0
  90. data/lib/3scale_toolbox/entities/backend_usage.rb +99 -0
  91. data/lib/3scale_toolbox/entities/service.rb +18 -3
  92. data/lib/3scale_toolbox/error.rb +53 -0
  93. data/lib/3scale_toolbox/helper.rb +20 -0
  94. data/lib/3scale_toolbox/openapi.rb +2 -0
  95. data/lib/3scale_toolbox/openapi/oas3.rb +232 -0
  96. data/lib/3scale_toolbox/openapi/swagger.rb +192 -0
  97. data/lib/3scale_toolbox/proxy_logger.rb +1 -1
  98. data/lib/3scale_toolbox/version.rb +1 -1
  99. data/licenses.xml +190 -20
  100. data/resources/oas3_meta_schema.json +1654 -0
  101. metadata +69 -30
  102. data/lib/3scale_toolbox/commands/copy_command/copy_service.rb +0 -142
  103. data/lib/3scale_toolbox/commands/import_command/openapi/threescale_api_spec.rb +0 -80
  104. data/lib/3scale_toolbox/swagger.rb +0 -1
  105. data/lib/3scale_toolbox/swagger/swagger.rb +0 -123
  106. data/lib/3scale_toolbox/tasks.rb +0 -15
  107. data/lib/3scale_toolbox/tasks/bump_proxy_version_task.rb +0 -32
  108. data/lib/3scale_toolbox/tasks/copy_activedocs_task.rb +0 -42
  109. data/lib/3scale_toolbox/tasks/copy_app_plans_task.rb +0 -31
  110. data/lib/3scale_toolbox/tasks/copy_limits_task.rb +0 -36
  111. data/lib/3scale_toolbox/tasks/copy_mapping_rules_task.rb +0 -32
  112. data/lib/3scale_toolbox/tasks/copy_methods_task.rb +0 -36
  113. data/lib/3scale_toolbox/tasks/copy_metrics_task.rb +0 -33
  114. data/lib/3scale_toolbox/tasks/copy_policies_task.rb +0 -13
  115. data/lib/3scale_toolbox/tasks/copy_pricingrules_task.rb +0 -41
  116. data/lib/3scale_toolbox/tasks/copy_service_proxy_task.rb +0 -12
  117. data/lib/3scale_toolbox/tasks/copy_service_settings_task.rb +0 -38
  118. data/lib/3scale_toolbox/tasks/copy_task.rb +0 -66
  119. data/lib/3scale_toolbox/tasks/delete_activedocs_task.rb +0 -22
  120. data/lib/3scale_toolbox/tasks/destroy_mapping_rules_task.rb +0 -22
  121. data/lib/3scale_toolbox/tasks/helper_task.rb +0 -25
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: 3scale_toolbox
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.12.4
4
+ version: 0.17.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Michal Cichra
@@ -9,7 +9,7 @@ authors:
9
9
  autorequire:
10
10
  bindir: exe
11
11
  cert_chain: []
12
- date: 2019-08-07 00:00:00.000000000 Z
12
+ date: 2020-07-20 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: bundler
@@ -45,14 +45,14 @@ dependencies:
45
45
  requirements:
46
46
  - - "~>"
47
47
  - !ruby/object:Gem::Version
48
- version: '10.0'
48
+ version: '13.0'
49
49
  type: :development
50
50
  prerelease: false
51
51
  version_requirements: !ruby/object:Gem::Requirement
52
52
  requirements:
53
53
  - - "~>"
54
54
  - !ruby/object:Gem::Version
55
- version: '10.0'
55
+ version: '13.0'
56
56
  - !ruby/object:Gem::Dependency
57
57
  name: rspec
58
58
  requirement: !ruby/object:Gem::Requirement
@@ -87,14 +87,14 @@ dependencies:
87
87
  requirements:
88
88
  - - "~>"
89
89
  - !ruby/object:Gem::Version
90
- version: 0.6.0
90
+ version: '1.1'
91
91
  type: :runtime
92
92
  prerelease: false
93
93
  version_requirements: !ruby/object:Gem::Requirement
94
94
  requirements:
95
95
  - - "~>"
96
96
  - !ruby/object:Gem::Version
97
- version: 0.6.0
97
+ version: '1.1'
98
98
  - !ruby/object:Gem::Dependency
99
99
  name: cri
100
100
  requirement: !ruby/object:Gem::Requirement
@@ -123,6 +123,20 @@ dependencies:
123
123
  - - "~>"
124
124
  - !ruby/object:Gem::Version
125
125
  version: '2.8'
126
+ - !ruby/object:Gem::Dependency
127
+ name: oas_parser
128
+ requirement: !ruby/object:Gem::Requirement
129
+ requirements:
130
+ - - "~>"
131
+ - !ruby/object:Gem::Version
132
+ version: '0.20'
133
+ type: :runtime
134
+ prerelease: false
135
+ version_requirements: !ruby/object:Gem::Requirement
136
+ requirements:
137
+ - - "~>"
138
+ - !ruby/object:Gem::Version
139
+ version: '0.20'
126
140
  description: 3scale tools to manage your API from the terminal.
127
141
  email:
128
142
  - michal@3scale.net
@@ -139,9 +153,16 @@ files:
139
153
  - exe/3scale
140
154
  - lib/3scale_toolbox.rb
141
155
  - lib/3scale_toolbox/3scale_client_factory.rb
156
+ - lib/3scale_toolbox/attribute_filters.rb
157
+ - lib/3scale_toolbox/attribute_filters/attribute_filter.rb
158
+ - lib/3scale_toolbox/attribute_filters/service_id_from_ref_filter.rb
142
159
  - lib/3scale_toolbox/base_command.rb
143
160
  - lib/3scale_toolbox/cli.rb
161
+ - lib/3scale_toolbox/cli/custom_table_printer.rb
144
162
  - lib/3scale_toolbox/cli/error_handler.rb
163
+ - lib/3scale_toolbox/cli/json_printer.rb
164
+ - lib/3scale_toolbox/cli/output_flag.rb
165
+ - lib/3scale_toolbox/cli/yaml_printer.rb
145
166
  - lib/3scale_toolbox/commands.rb
146
167
  - lib/3scale_toolbox/commands/3scale_command.rb
147
168
  - lib/3scale_toolbox/commands/account_command.rb
@@ -157,8 +178,15 @@ files:
157
178
  - lib/3scale_toolbox/commands/application_command/delete_command.rb
158
179
  - lib/3scale_toolbox/commands/application_command/list_command.rb
159
180
  - lib/3scale_toolbox/commands/application_command/show_command.rb
181
+ - lib/3scale_toolbox/commands/backend_command.rb
182
+ - lib/3scale_toolbox/commands/backend_command/copy_command.rb
183
+ - lib/3scale_toolbox/commands/backend_command/copy_command/copy_mapping_rules_task.rb
184
+ - lib/3scale_toolbox/commands/backend_command/copy_command/copy_methods_task.rb
185
+ - lib/3scale_toolbox/commands/backend_command/copy_command/copy_metrics_task.rb
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/task.rb
160
188
  - lib/3scale_toolbox/commands/copy_command.rb
161
- - lib/3scale_toolbox/commands/copy_command/copy_service.rb
189
+ - lib/3scale_toolbox/commands/copy_command/service_command.rb
162
190
  - lib/3scale_toolbox/commands/help_command.rb
163
191
  - lib/3scale_toolbox/commands/import_command.rb
164
192
  - lib/3scale_toolbox/commands/import_command/import_csv.rb
@@ -171,7 +199,6 @@ files:
171
199
  - lib/3scale_toolbox/commands/import_command/openapi/method.rb
172
200
  - lib/3scale_toolbox/commands/import_command/openapi/operation.rb
173
201
  - lib/3scale_toolbox/commands/import_command/openapi/step.rb
174
- - lib/3scale_toolbox/commands/import_command/openapi/threescale_api_spec.rb
175
202
  - lib/3scale_toolbox/commands/import_command/openapi/update_policies_step.rb
176
203
  - lib/3scale_toolbox/commands/import_command/openapi/update_service_oidc_conf_step.rb
177
204
  - lib/3scale_toolbox/commands/import_command/openapi/update_service_proxy_step.rb
@@ -209,7 +236,13 @@ files:
209
236
  - lib/3scale_toolbox/commands/plans_command/show_command.rb
210
237
  - lib/3scale_toolbox/commands/policy_registry_command.rb
211
238
  - lib/3scale_toolbox/commands/policy_registry_command/copy_command.rb
239
+ - lib/3scale_toolbox/commands/product_command.rb
240
+ - lib/3scale_toolbox/commands/product_command/copy_command.rb
241
+ - lib/3scale_toolbox/commands/product_command/copy_command/copy_backends_task.rb
242
+ - lib/3scale_toolbox/commands/product_command/copy_command/delete_target_backend_usages_task.rb
212
243
  - lib/3scale_toolbox/commands/proxy_config_command.rb
244
+ - lib/3scale_toolbox/commands/proxy_config_command/export_command.rb
245
+ - lib/3scale_toolbox/commands/proxy_config_command/helper.rb
213
246
  - lib/3scale_toolbox/commands/proxy_config_command/list_command.rb
214
247
  - lib/3scale_toolbox/commands/proxy_config_command/promote_command.rb
215
248
  - lib/3scale_toolbox/commands/proxy_config_command/show_command.rb
@@ -220,18 +253,39 @@ files:
220
253
  - lib/3scale_toolbox/commands/remote_command/remote_rename.rb
221
254
  - lib/3scale_toolbox/commands/service_command.rb
222
255
  - lib/3scale_toolbox/commands/service_command/apply_command.rb
256
+ - lib/3scale_toolbox/commands/service_command/copy_command.rb
257
+ - lib/3scale_toolbox/commands/service_command/copy_command/bump_proxy_version_task.rb
258
+ - lib/3scale_toolbox/commands/service_command/copy_command/copy_activedocs_task.rb
259
+ - lib/3scale_toolbox/commands/service_command/copy_command/copy_app_plans_task.rb
260
+ - lib/3scale_toolbox/commands/service_command/copy_command/copy_limits_task.rb
261
+ - lib/3scale_toolbox/commands/service_command/copy_command/copy_mapping_rules_task.rb
262
+ - lib/3scale_toolbox/commands/service_command/copy_command/copy_methods_task.rb
263
+ - lib/3scale_toolbox/commands/service_command/copy_command/copy_metrics_task.rb
264
+ - lib/3scale_toolbox/commands/service_command/copy_command/copy_policies_task.rb
265
+ - lib/3scale_toolbox/commands/service_command/copy_command/copy_pricingrules_task.rb
266
+ - lib/3scale_toolbox/commands/service_command/copy_command/copy_service_proxy_task.rb
267
+ - lib/3scale_toolbox/commands/service_command/copy_command/create_or_update_service_task.rb
268
+ - lib/3scale_toolbox/commands/service_command/copy_command/destroy_mapping_rules_task.rb
269
+ - lib/3scale_toolbox/commands/service_command/copy_command/task.rb
223
270
  - lib/3scale_toolbox/commands/service_command/create_command.rb
224
271
  - lib/3scale_toolbox/commands/service_command/delete_command.rb
225
272
  - lib/3scale_toolbox/commands/service_command/list_command.rb
226
273
  - lib/3scale_toolbox/commands/service_command/show_command.rb
227
274
  - lib/3scale_toolbox/commands/update_command.rb
228
- - lib/3scale_toolbox/commands/update_command/update_service.rb
275
+ - lib/3scale_toolbox/commands/update_command/service_command.rb
276
+ - lib/3scale_toolbox/commands/update_command/service_command/copy_service_settings_task.rb
277
+ - lib/3scale_toolbox/commands/update_command/service_command/delete_activedocs_task.rb
229
278
  - lib/3scale_toolbox/configuration.rb
230
279
  - lib/3scale_toolbox/entities.rb
231
280
  - lib/3scale_toolbox/entities/account.rb
232
281
  - lib/3scale_toolbox/entities/activedocs.rb
233
282
  - lib/3scale_toolbox/entities/application.rb
234
283
  - lib/3scale_toolbox/entities/application_plan.rb
284
+ - lib/3scale_toolbox/entities/backend.rb
285
+ - lib/3scale_toolbox/entities/backend_mapping_rule.rb
286
+ - lib/3scale_toolbox/entities/backend_method.rb
287
+ - lib/3scale_toolbox/entities/backend_metric.rb
288
+ - lib/3scale_toolbox/entities/backend_usage.rb
235
289
  - lib/3scale_toolbox/entities/base_entity.rb
236
290
  - lib/3scale_toolbox/entities/method.rb
237
291
  - lib/3scale_toolbox/entities/metric.rb
@@ -239,29 +293,15 @@ files:
239
293
  - lib/3scale_toolbox/entities/service.rb
240
294
  - lib/3scale_toolbox/error.rb
241
295
  - lib/3scale_toolbox/helper.rb
296
+ - lib/3scale_toolbox/openapi.rb
297
+ - lib/3scale_toolbox/openapi/oas3.rb
298
+ - lib/3scale_toolbox/openapi/swagger.rb
242
299
  - lib/3scale_toolbox/proxy_logger.rb
243
300
  - lib/3scale_toolbox/remotes.rb
244
301
  - lib/3scale_toolbox/resource_reader.rb
245
- - lib/3scale_toolbox/swagger.rb
246
- - lib/3scale_toolbox/swagger/swagger.rb
247
- - lib/3scale_toolbox/tasks.rb
248
- - lib/3scale_toolbox/tasks/bump_proxy_version_task.rb
249
- - lib/3scale_toolbox/tasks/copy_activedocs_task.rb
250
- - lib/3scale_toolbox/tasks/copy_app_plans_task.rb
251
- - lib/3scale_toolbox/tasks/copy_limits_task.rb
252
- - lib/3scale_toolbox/tasks/copy_mapping_rules_task.rb
253
- - lib/3scale_toolbox/tasks/copy_methods_task.rb
254
- - lib/3scale_toolbox/tasks/copy_metrics_task.rb
255
- - lib/3scale_toolbox/tasks/copy_policies_task.rb
256
- - lib/3scale_toolbox/tasks/copy_pricingrules_task.rb
257
- - lib/3scale_toolbox/tasks/copy_service_proxy_task.rb
258
- - lib/3scale_toolbox/tasks/copy_service_settings_task.rb
259
- - lib/3scale_toolbox/tasks/copy_task.rb
260
- - lib/3scale_toolbox/tasks/delete_activedocs_task.rb
261
- - lib/3scale_toolbox/tasks/destroy_mapping_rules_task.rb
262
- - lib/3scale_toolbox/tasks/helper_task.rb
263
302
  - lib/3scale_toolbox/version.rb
264
303
  - licenses.xml
304
+ - resources/oas3_meta_schema.json
265
305
  - resources/swagger_meta_schema.json
266
306
  homepage: https://github.com/3scale/3scale_toolbox
267
307
  licenses:
@@ -275,15 +315,14 @@ required_ruby_version: !ruby/object:Gem::Requirement
275
315
  requirements:
276
316
  - - ">="
277
317
  - !ruby/object:Gem::Version
278
- version: '2.4'
318
+ version: '2.5'
279
319
  required_rubygems_version: !ruby/object:Gem::Requirement
280
320
  requirements:
281
321
  - - ">="
282
322
  - !ruby/object:Gem::Version
283
323
  version: '0'
284
324
  requirements: []
285
- rubyforge_project:
286
- rubygems_version: 2.7.6
325
+ rubygems_version: 3.1.2
287
326
  signing_key:
288
327
  specification_version: 4
289
328
  summary: 3scale Toolbox.
@@ -1,142 +0,0 @@
1
- module ThreeScaleToolbox
2
- module Commands
3
- module CopyCommand
4
- class CopyServiceSubcommand < Cri::CommandRunner
5
- include ThreeScaleToolbox::Command
6
-
7
- def self.command
8
- Cri::Command.define do
9
- name 'service'
10
- usage 'service [opts] -s <src> -d <dst> <source-service>'
11
- summary 'copy service'
12
- description <<-HEREDOC
13
- This command makes a copy of the referenced service.
14
- Target service will be searched by source service system name. System name can be overriden with `--target_system_name` option.
15
- If a service with the selected `system_name` is not found, it will be created.
16
- \n Components of the service being copied:
17
- \nservice settings
18
- \nproxy settings
19
- \npricing rules
20
- \nactivedocs
21
- \nmetrics
22
- \nmethods
23
- \napplication plans
24
- \nmapping rules
25
- HEREDOC
26
-
27
- option :s, :source, '3scale source instance. Url or remote name', argument: :required
28
- option :d, :destination, '3scale target instance. Url or remote name', argument: :required
29
- option :t, 'target_system_name', 'Target system name. Default to source system name', argument: :required
30
- flag :f, :force, 'Overwrites the mapping rules by deleting all rules from target service first'
31
- flag :r, 'rules-only', 'Only mapping rules are copied'
32
- param :source_service
33
-
34
- runner CopyServiceSubcommand
35
- end
36
- end
37
-
38
- def run
39
- target_service = Entities::Service.find(remote: target_remote,
40
- ref: target_service_ref)
41
- if target_service.nil?
42
- target_service = Entities::Service.create(remote: target_remote,
43
- service_params: create_service_attrs)
44
- end
45
-
46
- if target_service == source_service
47
- raise ThreeScaleToolbox::Error, 'Source and destination services are the same: ' \
48
- "ID: #{source_service.id} system_name: #{source_service.attrs['system_name']}"
49
- end
50
-
51
- puts "new service id #{target_service.id}"
52
-
53
- context = create_context(source_service, target_service)
54
-
55
- tasks = []
56
- unless option_rules_only
57
- tasks << Tasks::CopyServiceSettingsTask.new(context)
58
- tasks << Tasks::CopyServiceProxyTask.new(context)
59
- tasks << Tasks::CopyMethodsTask.new(context)
60
- tasks << Tasks::CopyMetricsTask.new(context)
61
- tasks << Tasks::CopyApplicationPlansTask.new(context)
62
- tasks << Tasks::CopyLimitsTask.new(context)
63
- tasks << Tasks::CopyPoliciesTask.new(context)
64
- tasks << Tasks::CopyPricingRulesTask.new(context)
65
- tasks << Tasks::CopyActiveDocsTask.new(context)
66
- end
67
- tasks << Tasks::DestroyMappingRulesTask.new(context) if option_force
68
- tasks << Tasks::CopyMappingRulesTask.new(context)
69
- tasks.each(&:call)
70
-
71
- # This should be the last step
72
- Tasks::BumpProxyVersionTask.new(service: target_service).call
73
- end
74
-
75
- private
76
-
77
- def create_context(source, target)
78
- {
79
- source: source,
80
- target: target
81
- }
82
- end
83
-
84
- def option_rules_only
85
- options[:'rules-only']
86
- end
87
-
88
- def option_force
89
- options[:force]
90
- end
91
-
92
- def option_target_system_name
93
- options[:target_system_name]
94
- end
95
-
96
- def create_service_attrs
97
- # minimum required attrs.
98
- # Service settings will be updated in later task
99
- # These attrs are only when service is created
100
- {
101
- 'name' => source_service.attrs.fetch('name'),
102
- 'system_name' => target_service_ref
103
- }.compact
104
- end
105
-
106
- def source_service
107
- @source_service ||= find_source_service
108
- end
109
-
110
- def find_source_service
111
- Entities::Service.find(remote: source_remote, ref: source_service_ref).tap do |svc|
112
- raise ThreeScaleToolbox::Error, "Service #{source_service_ref} does not exist" if svc.nil?
113
- end
114
- end
115
-
116
- def source_remote
117
- @source_remote ||= threescale_client(source)
118
- end
119
-
120
- def target_remote
121
- @target_remote ||= threescale_client(target)
122
- end
123
-
124
- def source_service_ref
125
- arguments[:source_service]
126
- end
127
-
128
- def target_service_ref
129
- option_target_system_name || source_service.attrs.fetch('system_name')
130
- end
131
-
132
- def source
133
- fetch_required_option(:source)
134
- end
135
-
136
- def target
137
- fetch_required_option(:destination)
138
- end
139
- end
140
- end
141
- end
142
- end
@@ -1,80 +0,0 @@
1
- module ThreeScaleToolbox
2
- module Commands
3
- module ImportCommand
4
- module OpenAPI
5
- class ThreeScaleApiSpec
6
- attr_reader :openapi
7
-
8
- def initialize(openapi, base_path = nil)
9
- @openapi = openapi
10
- @base_path = base_path
11
- end
12
-
13
- def title
14
- openapi.info.title
15
- end
16
-
17
- def description
18
- openapi.info.description
19
- end
20
-
21
- def host
22
- openapi.host
23
- end
24
-
25
- def schemes
26
- Array(openapi.schemes)
27
- end
28
-
29
- def backend_version
30
- # default authentication mode if no security requirement
31
- return '1' if security.nil?
32
-
33
- case security.type
34
- when 'oauth2'
35
- 'oidc'
36
- when 'apiKey'
37
- '1'
38
- else
39
- raise ThreeScaleToolbox::Error, "Unexpected security scheme type #{security.type}"
40
- end
41
- end
42
-
43
- def security
44
- @security ||= parse_security
45
- end
46
-
47
- def operations
48
- openapi.operations.map do |op|
49
- Operation.new(
50
- base_path: base_path,
51
- public_base_path: public_base_path,
52
- path: op.path,
53
- verb: op.verb,
54
- operationId: op.operation_id,
55
- description: op.description,
56
- )
57
- end
58
- end
59
-
60
- def public_base_path
61
- @base_path || base_path
62
- end
63
-
64
- def base_path
65
- openapi.base_path || '/'
66
- end
67
-
68
- private
69
-
70
- def parse_security
71
- raise ThreeScaleToolbox::Error, 'Invalid OAS: multiple security requirements' \
72
- if openapi.global_security_requirements.size > 1
73
-
74
- openapi.global_security_requirements.first
75
- end
76
- end
77
- end
78
- end
79
- end
80
- end
@@ -1 +0,0 @@
1
- require '3scale_toolbox/swagger/swagger'
@@ -1,123 +0,0 @@
1
- require 'json-schema'
2
-
3
- module ThreeScaleToolbox
4
- module Swagger
5
- META_SCHEMA_PATH = File.expand_path('../../../resources/swagger_meta_schema.json', __dir__)
6
-
7
- def self.build(raw_specification, validate: true)
8
- if validate
9
- meta_schema = JSON.parse(File.read(META_SCHEMA_PATH))
10
- JSON::Validator.validate!(meta_schema, raw_specification)
11
- end
12
-
13
- Specification.new(raw_specification)
14
- end
15
-
16
- class Info
17
- attr_reader :title, :description
18
-
19
- def initialize(title:, description:)
20
- @title = title
21
- @description = description
22
- end
23
- end
24
-
25
- class Operation
26
- attr_reader :verb, :operation_id, :path, :description
27
-
28
- def initialize(verb:, operation_id:, path:, description:)
29
- @verb = verb
30
- @operation_id = operation_id
31
- @path = path
32
- @description = description
33
- end
34
- end
35
-
36
- class SecurityRequirement
37
- attr_reader :id, :type, :name, :in_f, :flow, :scopes
38
-
39
- def initialize(id:, type:, name: nil, in_f: nil, flow: nil, scopes: [])
40
- @id = id
41
- @type = type
42
- @name = name
43
- @in_f = in_f
44
- @flow = flow
45
- @scopes = scopes
46
- end
47
- end
48
-
49
- class Specification
50
- attr_reader :raw
51
-
52
- def initialize(raw_resource)
53
- @raw = raw_resource
54
- end
55
-
56
- def base_path
57
- raw['basePath']
58
- end
59
-
60
- def host
61
- raw['host']
62
- end
63
-
64
- def schemes
65
- raw['schemes']
66
- end
67
-
68
- def info
69
- @info ||= parse_info(raw['info'])
70
- end
71
-
72
- def operations
73
- @operations ||= parse_operations
74
- end
75
-
76
- def global_security_requirements
77
- @global_security_requirements ||= parse_global_security_reqs
78
- end
79
-
80
- private
81
-
82
- def parse_operations
83
- raw['paths'].flat_map do |path, path_obj|
84
- path_obj.flat_map do |method, operation|
85
- next unless %w[get head post put patch delete trace options].include? method
86
-
87
- Operation.new(verb: method, path: path, description: operation['description'],
88
- operation_id: operation['operationId'])
89
- end.compact
90
- end
91
- end
92
-
93
- def parse_info(info)
94
- Info.new(title: info['title'], description: info['description'])
95
- end
96
-
97
- def parse_global_security_reqs
98
- security_requirements.flat_map do |sec_req|
99
- sec_req.map do |sec_item_name, sec_item|
100
- sec_def = fetch_security_definition(sec_item_name)
101
- SecurityRequirement.new(id: sec_item_name, type: sec_def['type'],
102
- name: sec_def['name'], in_f: sec_def['in'],
103
- flow: sec_def['flow'], scopes: sec_item)
104
- end
105
- end
106
- end
107
-
108
- def fetch_security_definition(name)
109
- security_definitions.fetch(name) do |el|
110
- raise ThreeScaleToolbox::Error, "Swagger parsing error: #{el} not found in security definitions"
111
- end
112
- end
113
-
114
- def security_requirements
115
- raw['security'] || []
116
- end
117
-
118
- def security_definitions
119
- raw['securityDefinitions'] || {}
120
- end
121
- end
122
- end
123
- end