3scale_toolbox 0.5.1 → 0.6.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 (51) hide show
  1. checksums.yaml +4 -4
  2. data/README.md +143 -23
  3. data/exe/3scale +10 -3
  4. data/lib/3scale_toolbox.rb +18 -0
  5. data/lib/3scale_toolbox/3scale_client_factory.rb +33 -0
  6. data/lib/3scale_toolbox/base_command.rb +52 -14
  7. data/lib/3scale_toolbox/cli.rb +26 -5
  8. data/lib/3scale_toolbox/cli/error_handler.rb +120 -0
  9. data/lib/3scale_toolbox/commands.rb +3 -9
  10. data/lib/3scale_toolbox/commands/3scale_command.rb +8 -6
  11. data/lib/3scale_toolbox/commands/copy_command.rb +4 -4
  12. data/lib/3scale_toolbox/commands/copy_command/copy_service.rb +40 -193
  13. data/lib/3scale_toolbox/commands/help_command.rb +1 -1
  14. data/lib/3scale_toolbox/commands/import_command.rb +6 -4
  15. data/lib/3scale_toolbox/commands/import_command/import_csv.rb +15 -41
  16. data/lib/3scale_toolbox/commands/import_command/openapi.rb +70 -0
  17. data/lib/3scale_toolbox/commands/import_command/openapi/create_mapping_rule_step.rb +18 -0
  18. data/lib/3scale_toolbox/commands/import_command/openapi/create_method_step.rb +39 -0
  19. data/lib/3scale_toolbox/commands/import_command/openapi/create_service_step.rb +69 -0
  20. data/lib/3scale_toolbox/commands/import_command/openapi/mapping_rule.rb +35 -0
  21. data/lib/3scale_toolbox/commands/import_command/openapi/method.rb +25 -0
  22. data/lib/3scale_toolbox/commands/import_command/openapi/operation.rb +22 -0
  23. data/lib/3scale_toolbox/commands/import_command/openapi/resource_reader.rb +49 -0
  24. data/lib/3scale_toolbox/commands/import_command/openapi/step.rb +45 -0
  25. data/lib/3scale_toolbox/commands/import_command/openapi/threescale_api_spec.rb +33 -0
  26. data/lib/3scale_toolbox/commands/remote_command.rb +36 -0
  27. data/lib/3scale_toolbox/commands/remote_command/remote_add.rb +47 -0
  28. data/lib/3scale_toolbox/commands/remote_command/remote_list.rb +29 -0
  29. data/lib/3scale_toolbox/commands/remote_command/remote_remove.rb +26 -0
  30. data/lib/3scale_toolbox/commands/remote_command/remote_rename.rb +42 -0
  31. data/lib/3scale_toolbox/commands/update_command.rb +4 -4
  32. data/lib/3scale_toolbox/commands/update_command/update_service.rb +45 -235
  33. data/lib/3scale_toolbox/configuration.rb +35 -0
  34. data/lib/3scale_toolbox/entities.rb +1 -0
  35. data/lib/3scale_toolbox/entities/service.rb +113 -0
  36. data/lib/3scale_toolbox/error.rb +8 -0
  37. data/lib/3scale_toolbox/helper.rb +37 -0
  38. data/lib/3scale_toolbox/remotes.rb +93 -0
  39. data/lib/3scale_toolbox/tasks.rb +10 -0
  40. data/lib/3scale_toolbox/tasks/copy_app_plans_task.rb +31 -0
  41. data/lib/3scale_toolbox/tasks/copy_limits_task.rb +36 -0
  42. data/lib/3scale_toolbox/tasks/copy_mapping_rules_task.rb +29 -0
  43. data/lib/3scale_toolbox/tasks/copy_methods_task.rb +29 -0
  44. data/lib/3scale_toolbox/tasks/copy_metrics_task.rb +33 -0
  45. data/lib/3scale_toolbox/tasks/copy_service_proxy_task.rb +12 -0
  46. data/lib/3scale_toolbox/tasks/copy_task.rb +26 -0
  47. data/lib/3scale_toolbox/tasks/destroy_mapping_rules_task.rb +22 -0
  48. data/lib/3scale_toolbox/tasks/helper_task.rb +25 -0
  49. data/lib/3scale_toolbox/tasks/update_service_settings_task.rb +32 -0
  50. data/lib/3scale_toolbox/version.rb +1 -1
  51. metadata +87 -11
@@ -0,0 +1,12 @@
1
+ module ThreeScaleToolbox
2
+ module Tasks
3
+ class CopyServiceProxyTask
4
+ include CopyTask
5
+
6
+ def call
7
+ target.update_proxy source.show_proxy
8
+ puts "updated proxy of #{target.id} to match the original"
9
+ end
10
+ end
11
+ end
12
+ end
@@ -0,0 +1,26 @@
1
+ module ThreeScaleToolbox
2
+ module Tasks
3
+ module CopyTask
4
+ def self.included(base)
5
+ base.extend(ClassMethods)
6
+ end
7
+
8
+ module ClassMethods
9
+ end
10
+
11
+ attr_reader :context
12
+
13
+ def initialize(context)
14
+ @context = context
15
+ end
16
+
17
+ def source
18
+ context[:source]
19
+ end
20
+
21
+ def target
22
+ context[:target]
23
+ end
24
+ end
25
+ end
26
+ end
@@ -0,0 +1,22 @@
1
+ module ThreeScaleToolbox
2
+ module Tasks
3
+ class DestroyMappingRulesTask
4
+ attr_reader :context
5
+
6
+ def initialize(context)
7
+ @context = context
8
+ end
9
+
10
+ def call
11
+ puts 'destroying all mapping rules'
12
+ target.mapping_rules.each do |mapping_rule|
13
+ target.delete_mapping_rule mapping_rule['id']
14
+ end
15
+ end
16
+
17
+ def target
18
+ context[:target]
19
+ end
20
+ end
21
+ end
22
+ end
@@ -0,0 +1,25 @@
1
+ module ThreeScaleToolbox
2
+ module Tasks
3
+ module Helper
4
+ def metrics_mapping(source_metrics, target_metrics)
5
+ target_metrics.map do |target|
6
+ source = source_metrics.find do |m|
7
+ ThreeScaleToolbox::Helper.compare_hashes(m, target, ['system_name'])
8
+ end || {}
9
+
10
+ [source['id'], target['id']]
11
+ end.to_h
12
+ end
13
+
14
+ def application_plan_mapping(source_app_plans, target_app_plans)
15
+ mapping = target_app_plans.map do |target|
16
+ source = source_app_plans.find do |app_plan|
17
+ ThreeScaleToolbox::Helper.compare_hashes(app_plan, target, ['system_name'])
18
+ end || {}
19
+ [source['id'], target]
20
+ end
21
+ mapping.reject { |key, _| key.nil? }
22
+ end
23
+ end
24
+ end
25
+ end
@@ -0,0 +1,32 @@
1
+ module ThreeScaleToolbox
2
+ module Tasks
3
+ class UpdateServiceSettingsTask
4
+ attr_reader :source, :target, :target_system_name
5
+
6
+ def initialize(source:, target:, target_name:)
7
+ @source = source
8
+ @target = target
9
+ @target_system_name = target_name
10
+ end
11
+
12
+ def call
13
+ source_obj = source.show_service
14
+ response = target.update_service(target_service_params(source_obj))
15
+ raise Error, "Service has not been saved. Errors: #{response['errors']}" unless response['errors'].nil?
16
+
17
+ puts "updated service settings for service id #{source.id}..."
18
+ end
19
+
20
+ private
21
+
22
+ # system name only included when specified from options
23
+ def target_service_params(source)
24
+ target_svc_obj = ThreeScaleToolbox::Helper.filter_params(Entities::Service::VALID_PARAMS, source)
25
+ target_svc_obj.delete('system_name')
26
+ target_svc_obj.tap do |hash|
27
+ hash['system_name'] = target_system_name unless target_system_name.nil?
28
+ end
29
+ end
30
+ end
31
+ end
32
+ end
@@ -1,3 +1,3 @@
1
1
  module ThreeScaleToolbox
2
- VERSION = '0.5.1'
2
+ VERSION = '0.6.0'
3
3
  end
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.5.1
4
+ version: 0.6.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: 2018-11-12 00:00:00.000000000 Z
12
+ date: 2019-02-05 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: bundler
@@ -25,6 +25,20 @@ dependencies:
25
25
  - - ">="
26
26
  - !ruby/object:Gem::Version
27
27
  version: '0'
28
+ - !ruby/object:Gem::Dependency
29
+ name: dotenv
30
+ requirement: !ruby/object:Gem::Requirement
31
+ requirements:
32
+ - - ">="
33
+ - !ruby/object:Gem::Version
34
+ version: '0'
35
+ type: :development
36
+ prerelease: false
37
+ version_requirements: !ruby/object:Gem::Requirement
38
+ requirements:
39
+ - - ">="
40
+ - !ruby/object:Gem::Version
41
+ version: '0'
28
42
  - !ruby/object:Gem::Dependency
29
43
  name: rake
30
44
  requirement: !ruby/object:Gem::Requirement
@@ -45,43 +59,71 @@ dependencies:
45
59
  requirements:
46
60
  - - "~>"
47
61
  - !ruby/object:Gem::Version
48
- version: '3.7'
62
+ version: '3.8'
49
63
  type: :development
50
64
  prerelease: false
51
65
  version_requirements: !ruby/object:Gem::Requirement
52
66
  requirements:
53
67
  - - "~>"
54
68
  - !ruby/object:Gem::Version
55
- version: '3.7'
69
+ version: '3.8'
70
+ - !ruby/object:Gem::Dependency
71
+ name: webmock
72
+ requirement: !ruby/object:Gem::Requirement
73
+ requirements:
74
+ - - "~>"
75
+ - !ruby/object:Gem::Version
76
+ version: '3.4'
77
+ type: :development
78
+ prerelease: false
79
+ version_requirements: !ruby/object:Gem::Requirement
80
+ requirements:
81
+ - - "~>"
82
+ - !ruby/object:Gem::Version
83
+ version: '3.4'
56
84
  - !ruby/object:Gem::Dependency
57
85
  name: 3scale-api
58
86
  requirement: !ruby/object:Gem::Requirement
59
87
  requirements:
60
88
  - - "~>"
61
89
  - !ruby/object:Gem::Version
62
- version: '0.1'
90
+ version: 0.1.7
63
91
  type: :runtime
64
92
  prerelease: false
65
93
  version_requirements: !ruby/object:Gem::Requirement
66
94
  requirements:
67
95
  - - "~>"
68
96
  - !ruby/object:Gem::Version
69
- version: '0.1'
97
+ version: 0.1.7
70
98
  - !ruby/object:Gem::Dependency
71
99
  name: cri
72
100
  requirement: !ruby/object:Gem::Requirement
73
101
  requirements:
74
102
  - - "~>"
75
103
  - !ruby/object:Gem::Version
76
- version: '2.10'
104
+ version: '2.15'
105
+ type: :runtime
106
+ prerelease: false
107
+ version_requirements: !ruby/object:Gem::Requirement
108
+ requirements:
109
+ - - "~>"
110
+ - !ruby/object:Gem::Version
111
+ version: '2.15'
112
+ - !ruby/object:Gem::Dependency
113
+ name: swagger-core
114
+ requirement: !ruby/object:Gem::Requirement
115
+ requirements:
116
+ - - "~>"
117
+ - !ruby/object:Gem::Version
118
+ version: '0.3'
77
119
  type: :runtime
78
120
  prerelease: false
79
121
  version_requirements: !ruby/object:Gem::Requirement
80
122
  requirements:
81
123
  - - "~>"
82
124
  - !ruby/object:Gem::Version
83
- version: '2.10'
84
- description: 3scale CLI tools to manage your API from the terminal.
125
+ version: '0.3'
126
+ description: 3scale tools to manage your API from the terminal.
85
127
  email:
86
128
  - michal@3scale.net
87
129
  - eastizle@redhat.com
@@ -93,8 +135,10 @@ files:
93
135
  - README.md
94
136
  - exe/3scale
95
137
  - lib/3scale_toolbox.rb
138
+ - lib/3scale_toolbox/3scale_client_factory.rb
96
139
  - lib/3scale_toolbox/base_command.rb
97
140
  - lib/3scale_toolbox/cli.rb
141
+ - lib/3scale_toolbox/cli/error_handler.rb
98
142
  - lib/3scale_toolbox/commands.rb
99
143
  - lib/3scale_toolbox/commands/3scale_command.rb
100
144
  - lib/3scale_toolbox/commands/copy_command.rb
@@ -102,8 +146,40 @@ files:
102
146
  - lib/3scale_toolbox/commands/help_command.rb
103
147
  - lib/3scale_toolbox/commands/import_command.rb
104
148
  - lib/3scale_toolbox/commands/import_command/import_csv.rb
149
+ - lib/3scale_toolbox/commands/import_command/openapi.rb
150
+ - lib/3scale_toolbox/commands/import_command/openapi/create_mapping_rule_step.rb
151
+ - lib/3scale_toolbox/commands/import_command/openapi/create_method_step.rb
152
+ - lib/3scale_toolbox/commands/import_command/openapi/create_service_step.rb
153
+ - lib/3scale_toolbox/commands/import_command/openapi/mapping_rule.rb
154
+ - lib/3scale_toolbox/commands/import_command/openapi/method.rb
155
+ - lib/3scale_toolbox/commands/import_command/openapi/operation.rb
156
+ - lib/3scale_toolbox/commands/import_command/openapi/resource_reader.rb
157
+ - lib/3scale_toolbox/commands/import_command/openapi/step.rb
158
+ - lib/3scale_toolbox/commands/import_command/openapi/threescale_api_spec.rb
159
+ - lib/3scale_toolbox/commands/remote_command.rb
160
+ - lib/3scale_toolbox/commands/remote_command/remote_add.rb
161
+ - lib/3scale_toolbox/commands/remote_command/remote_list.rb
162
+ - lib/3scale_toolbox/commands/remote_command/remote_remove.rb
163
+ - lib/3scale_toolbox/commands/remote_command/remote_rename.rb
105
164
  - lib/3scale_toolbox/commands/update_command.rb
106
165
  - lib/3scale_toolbox/commands/update_command/update_service.rb
166
+ - lib/3scale_toolbox/configuration.rb
167
+ - lib/3scale_toolbox/entities.rb
168
+ - lib/3scale_toolbox/entities/service.rb
169
+ - lib/3scale_toolbox/error.rb
170
+ - lib/3scale_toolbox/helper.rb
171
+ - lib/3scale_toolbox/remotes.rb
172
+ - lib/3scale_toolbox/tasks.rb
173
+ - lib/3scale_toolbox/tasks/copy_app_plans_task.rb
174
+ - lib/3scale_toolbox/tasks/copy_limits_task.rb
175
+ - lib/3scale_toolbox/tasks/copy_mapping_rules_task.rb
176
+ - lib/3scale_toolbox/tasks/copy_methods_task.rb
177
+ - lib/3scale_toolbox/tasks/copy_metrics_task.rb
178
+ - lib/3scale_toolbox/tasks/copy_service_proxy_task.rb
179
+ - lib/3scale_toolbox/tasks/copy_task.rb
180
+ - lib/3scale_toolbox/tasks/destroy_mapping_rules_task.rb
181
+ - lib/3scale_toolbox/tasks/helper_task.rb
182
+ - lib/3scale_toolbox/tasks/update_service_settings_task.rb
107
183
  - lib/3scale_toolbox/version.rb
108
184
  homepage: https://github.com/3scale/3scale_toolbox
109
185
  licenses:
@@ -117,7 +193,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
117
193
  requirements:
118
194
  - - ">="
119
195
  - !ruby/object:Gem::Version
120
- version: '2.1'
196
+ version: '2.3'
121
197
  required_rubygems_version: !ruby/object:Gem::Requirement
122
198
  requirements:
123
199
  - - ">="
@@ -128,5 +204,5 @@ rubyforge_project:
128
204
  rubygems_version: 2.7.6
129
205
  signing_key:
130
206
  specification_version: 4
131
- summary: 3scale CLI Toolbox.
207
+ summary: 3scale Toolbox.
132
208
  test_files: []