3scale_toolbox 0.8.0 → 0.9.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 (56) hide show
  1. checksums.yaml +4 -4
  2. data/README.md +13 -1
  3. data/lib/3scale_toolbox/cli/error_handler.rb +0 -2
  4. data/lib/3scale_toolbox/commands/3scale_command.rb +0 -4
  5. data/lib/3scale_toolbox/commands/copy_command/copy_service.rb +5 -4
  6. data/lib/3scale_toolbox/commands/copy_command.rb +0 -2
  7. data/lib/3scale_toolbox/commands/help_command.rb +0 -3
  8. data/lib/3scale_toolbox/commands/import_command/import_csv.rb +0 -6
  9. data/lib/3scale_toolbox/commands/import_command/openapi/create_activedocs_step.rb +39 -2
  10. data/lib/3scale_toolbox/commands/import_command/openapi/create_method_step.rb +1 -1
  11. data/lib/3scale_toolbox/commands/import_command/openapi/create_service_step.rb +5 -16
  12. data/lib/3scale_toolbox/commands/import_command/openapi/mapping_rule.rb +11 -1
  13. data/lib/3scale_toolbox/commands/import_command/openapi/step.rb +4 -3
  14. data/lib/3scale_toolbox/commands/import_command/openapi/threescale_api_spec.rb +13 -2
  15. data/lib/3scale_toolbox/commands/import_command/openapi/update_policies_step.rb +63 -14
  16. data/lib/3scale_toolbox/commands/import_command/openapi/update_service_proxy_step.rb +6 -3
  17. data/lib/3scale_toolbox/commands/import_command/openapi.rb +11 -5
  18. data/lib/3scale_toolbox/commands/import_command.rb +0 -2
  19. data/lib/3scale_toolbox/commands/plans_command/apply_command.rb +136 -0
  20. data/lib/3scale_toolbox/commands/plans_command/create_command.rb +100 -0
  21. data/lib/3scale_toolbox/commands/plans_command/delete_command.rb +66 -0
  22. data/lib/3scale_toolbox/commands/plans_command/export/read_app_plan_step.rb +16 -0
  23. data/lib/3scale_toolbox/commands/plans_command/export/read_plan_features_step.rb +16 -0
  24. data/lib/3scale_toolbox/commands/plans_command/export/read_plan_limits_step.rb +19 -0
  25. data/lib/3scale_toolbox/commands/plans_command/export/read_plan_methods_step.rb +50 -0
  26. data/lib/3scale_toolbox/commands/plans_command/export/read_plan_metrics_step.rb +49 -0
  27. data/lib/3scale_toolbox/commands/plans_command/export/read_plan_pricing_rules_step.rb +19 -0
  28. data/lib/3scale_toolbox/commands/plans_command/export/step.rb +95 -0
  29. data/lib/3scale_toolbox/commands/plans_command/export/write_artifacts_file_step.rb +84 -0
  30. data/lib/3scale_toolbox/commands/plans_command/export_command.rb +65 -0
  31. data/lib/3scale_toolbox/commands/plans_command/import/create_or_update_app_plan_step.rb +33 -0
  32. data/lib/3scale_toolbox/commands/plans_command/import/import_plan_features_step.rb +45 -0
  33. data/lib/3scale_toolbox/commands/plans_command/import/import_plan_limits_step.rb +41 -0
  34. data/lib/3scale_toolbox/commands/plans_command/import/import_plan_metrics_step.rb +57 -0
  35. data/lib/3scale_toolbox/commands/plans_command/import/import_plan_pricing_rules_step.rb +39 -0
  36. data/lib/3scale_toolbox/commands/plans_command/import/step.rb +129 -0
  37. data/lib/3scale_toolbox/commands/plans_command/import_command.rb +62 -0
  38. data/lib/3scale_toolbox/commands/plans_command/list_command.rb +63 -0
  39. data/lib/3scale_toolbox/commands/plans_command/show_command.rb +81 -0
  40. data/lib/3scale_toolbox/commands/plans_command.rb +34 -0
  41. data/lib/3scale_toolbox/commands/remote_command.rb +0 -3
  42. data/lib/3scale_toolbox/commands/update_command/update_service.rb +5 -4
  43. data/lib/3scale_toolbox/commands/update_command.rb +0 -2
  44. data/lib/3scale_toolbox/commands.rb +3 -1
  45. data/lib/3scale_toolbox/entities/application_plan.rb +150 -0
  46. data/lib/3scale_toolbox/entities/service.rb +25 -12
  47. data/lib/3scale_toolbox/entities.rb +1 -0
  48. data/lib/3scale_toolbox/helper.rb +41 -0
  49. data/lib/3scale_toolbox/resource_reader.rb +42 -0
  50. data/lib/3scale_toolbox/tasks/copy_app_plans_task.rb +1 -1
  51. data/lib/3scale_toolbox/tasks/copy_limits_task.rb +8 -11
  52. data/lib/3scale_toolbox/tasks/copy_pricingrules_task.rb +5 -3
  53. data/lib/3scale_toolbox/version.rb +1 -1
  54. data/lib/3scale_toolbox.rb +10 -0
  55. metadata +28 -5
  56. data/lib/3scale_toolbox/commands/import_command/openapi/resource_reader.rb +0 -51
@@ -0,0 +1,150 @@
1
+ module ThreeScaleToolbox
2
+ module Entities
3
+ class ApplicationPlan
4
+ class << self
5
+ def create(service:, plan_attrs:)
6
+ plan = service.remote.create_application_plan service.id, build_plan_attrs(plan_attrs)
7
+ if (errors = plan['errors'])
8
+ raise ThreeScaleToolbox::Error, "Application plan has not been saved. Errors: #{errors}"
9
+ end
10
+
11
+ new(id: plan.fetch('id'), service: service)
12
+ end
13
+
14
+ # ref can be system_name or service_id
15
+ def find(service:, ref:)
16
+ new(id: ref, service: service).tap(&:show)
17
+ rescue ThreeScale::API::HttpClient::NotFoundError
18
+ find_by_system_name(service: service, system_name: ref)
19
+ end
20
+
21
+ def find_by_system_name(service:, system_name:)
22
+ plan = service.plans.find { |p| p['system_name'] == system_name }
23
+ return if plan.nil?
24
+
25
+ new(id: plan.fetch('id'), service: service)
26
+ end
27
+
28
+ def build_plan_attrs(source_attrs)
29
+ # shallow copy is enough
30
+ source_attrs.clone.tap do |new_plan_attrs|
31
+ # plans are created by default in hidden state
32
+ # If published is required, 'state_event' attr has to be added
33
+ new_plan_attrs['state_event'] = 'publish' if new_plan_attrs['state'] == 'published'
34
+ new_plan_attrs['state_event'] = 'hide' if new_plan_attrs['state'] == 'hidden'
35
+ end
36
+ end
37
+ end
38
+
39
+ attr_reader :id, :service, :remote
40
+
41
+ def initialize(id:, service:)
42
+ @id = id
43
+ @service = service
44
+ @remote = service.remote
45
+ end
46
+
47
+ def show
48
+ remote.show_application_plan service.id, id
49
+ end
50
+
51
+ def update(plan_attrs)
52
+ remote.update_application_plan(service.id, id, self.class.build_plan_attrs(plan_attrs))
53
+ end
54
+
55
+ def make_default
56
+ plan = remote.application_plan_as_default service.id, id
57
+ if (errors = plan['errors'])
58
+ raise ThreeScaleToolbox::Error, "Application plan has not been set to default. Errors: #{errors}"
59
+ end
60
+
61
+ plan
62
+ end
63
+
64
+ def disable
65
+ # Split metrics into three groups:
66
+ # a) metrics having limits set with eternity period and zero value, nothing to do.
67
+ # b) metrics having limits set with eternity period, but not zero value, must be updated
68
+ # c) metrics not having limits set with eternity period, must be created
69
+
70
+ eternity_limits = limits.select { |limit| limit.fetch('period') == 'eternity' }
71
+ eternity_metric_ids = eternity_limits.map { |limit| limit.fetch('metric_id') }
72
+ service_metric_ids = service.metrics.map { |metric| metric.fetch('id') }
73
+ metric_ids_without_eternity = service_metric_ids - eternity_metric_ids
74
+
75
+ # create eternity zero limit for each metric without eternity limit set
76
+ metric_ids_without_eternity.each do |metric_id|
77
+ create_limit(metric_id, zero_eternity_limit_attrs)
78
+ end
79
+
80
+ # update eternity zero limit those metrics already having eternity limit set
81
+ not_zero_eternity_limits = eternity_limits.reject { |limit| limit.fetch('value').zero? }
82
+ not_zero_eternity_limits.each do |limit|
83
+ update_limit(limit.fetch('metric_id'), limit.fetch('id'), zero_eternity_limit_attrs)
84
+ end
85
+ end
86
+
87
+ def enable
88
+ eternity_zero_limits.each do |limit|
89
+ delete_limit(limit.fetch('metric_id'), limit.fetch('id'))
90
+ end
91
+ end
92
+
93
+ def limits
94
+ remote.list_application_plan_limits id
95
+ end
96
+
97
+ def create_limit(metric_id, limit_attrs)
98
+ limit = remote.create_application_plan_limit id, metric_id, limit_attrs
99
+ if (errors = limit['errors'])
100
+ raise ThreeScaleToolbox::Error, "Limit has not been created. Errors: #{errors}"
101
+ end
102
+
103
+ limit
104
+ end
105
+
106
+ def update_limit(metric_id, limit_id, limit_attrs)
107
+ limit = remote.update_application_plan_limit id, metric_id, limit_id, limit_attrs
108
+ if (errors = limit['errors'])
109
+ raise ThreeScaleToolbox::Error, "Limit #{limit_id} has not been updated. Errors: #{errors}"
110
+ end
111
+
112
+ limit
113
+ end
114
+
115
+ def delete_limit(metric_id, limit_id)
116
+ remote.delete_application_plan_limit id, metric_id, limit_id
117
+ end
118
+
119
+ def create_pricing_rule(metric_id, pr_attrs)
120
+ remote.create_pricingrule id, metric_id, pr_attrs
121
+ end
122
+
123
+ def pricing_rules
124
+ remote.list_pricingrules_per_application_plan id
125
+ end
126
+
127
+ def features
128
+ remote.list_features_per_application_plan id
129
+ end
130
+
131
+ def create_feature(feature_id)
132
+ remote.create_application_plan_feature id, feature_id
133
+ end
134
+
135
+ def delete
136
+ remote.delete_application_plan service.id, id
137
+ end
138
+
139
+ private
140
+
141
+ def eternity_zero_limits
142
+ limits.select { |limit| zero_eternity_limit_attrs < limit }
143
+ end
144
+
145
+ def zero_eternity_limit_attrs
146
+ { 'period' => 'eternity', 'value' => 0 }
147
+ end
148
+ end
149
+ end
150
+ end
@@ -21,6 +21,20 @@ module ThreeScaleToolbox
21
21
  new(id: svc_obj.fetch('id'), remote: remote)
22
22
  end
23
23
 
24
+ # ref can be system_name or service_id
25
+ def find(remote:, ref:)
26
+ new(id: ref, remote: remote).tap(&:show_service)
27
+ rescue ThreeScale::API::HttpClient::NotFoundError
28
+ find_by_system_name(remote: remote, system_name: ref)
29
+ end
30
+
31
+ def find_by_system_name(remote:, system_name:)
32
+ service = remote.list_services.find { |svc| svc['system_name'] == system_name }
33
+ return if service.nil?
34
+
35
+ new(id: service.fetch('id'), remote: remote)
36
+ end
37
+
24
38
  private
25
39
 
26
40
  def create_service(remote:, service:)
@@ -94,18 +108,6 @@ module ThreeScaleToolbox
94
108
  remote.list_service_application_plans id
95
109
  end
96
110
 
97
- def create_application_plan(plan)
98
- remote.create_application_plan id, plan
99
- end
100
-
101
- def plan_limits(plan_id)
102
- remote.list_application_plan_limits(plan_id)
103
- end
104
-
105
- def create_application_plan_limit(plan_id, metric_id, limit)
106
- remote.create_application_plan_limit plan_id, metric_id, limit
107
- end
108
-
109
111
  def mapping_rules
110
112
  remote.list_mapping_rules id
111
113
  end
@@ -149,6 +151,17 @@ module ThreeScaleToolbox
149
151
  def update_oidc(oidc_settings)
150
152
  remote.update_oidc(id, oidc_settings)
151
153
  end
154
+
155
+ def features
156
+ remote.list_service_features id
157
+ end
158
+
159
+ def create_feature(attrs)
160
+ # Workaround until issue is fixed: https://github.com/3scale/porta/issues/774
161
+ attrs['scope'] = 'ApplicationPlan' if attrs['scope'] == 'application_plan'
162
+ attrs['scope'] = 'ServicePlan' if attrs['scope'] == 'service_plan'
163
+ remote.create_service_feature id, attrs
164
+ end
152
165
  end
153
166
  end
154
167
  end
@@ -1 +1,2 @@
1
1
  require '3scale_toolbox/entities/service'
2
+ require '3scale_toolbox/entities/application_plan'
@@ -33,11 +33,52 @@ module ThreeScaleToolbox
33
33
  uri_obj
34
34
  end
35
35
 
36
+ def hash_deep_dup(hash)
37
+ JSON.parse(JSON.generate(hash))
38
+ end
39
+
36
40
  def service_invalid_deployment_option?(error)
37
41
  Array(Hash(error)['deployment_option']).any? do |msg|
38
42
  msg.match(/is not included in the list/)
39
43
  end
40
44
  end
45
+
46
+ def system_name_already_taken_error?(error)
47
+ Array(Hash(error)['system_name']).any? { |msg| msg.match(/has already been taken/) }
48
+ end
49
+
50
+ def period_already_taken_error?(error)
51
+ Array(Hash(error)['period']).any? { |msg| msg.match(/has already been taken/) }
52
+ end
53
+ end
54
+
55
+ class BooleanTransformer
56
+ def call(param_str)
57
+ raise ArgumentError unless param_str.is_a?(String)
58
+
59
+ return true if true?(param_str)
60
+ return false if false?(param_str)
61
+
62
+ raise ArgumentError
63
+ end
64
+
65
+ def true?(param_str)
66
+ case param_str
67
+ when 'true', '1'
68
+ true
69
+ else
70
+ false
71
+ end
72
+ end
73
+
74
+ def false?(param_str)
75
+ case param_str
76
+ when 'false', '0'
77
+ true
78
+ else
79
+ false
80
+ end
81
+ end
41
82
  end
42
83
  end
43
84
  end
@@ -0,0 +1,42 @@
1
+ module ThreeScaleToolbox
2
+ module ResourceReader
3
+ ##
4
+ # Load resource from different types of sources.
5
+ # Supported types are: file, URL, stdin
6
+ # Loaded content is returned
7
+ def load_resource(resource)
8
+ # Json format is parsed as well
9
+ YAML.safe_load(read_content(resource))
10
+ rescue Psych::SyntaxError => e
11
+ raise ThreeScaleToolbox::Error, "JSON/YAML validation failed: #{e.message}"
12
+ end
13
+
14
+ ##
15
+ # Reads resources from different types of sources.
16
+ # Supported types are: file, URL, stdin
17
+ # Resource raw content is returned
18
+ def read_content(resource)
19
+ case resource
20
+ when '-'
21
+ method(:read_stdin)
22
+ when /\A#{URI::DEFAULT_PARSER.make_regexp}\z/
23
+ method(:read_url)
24
+ else
25
+ method(:read_file)
26
+ end.call(resource)
27
+ end
28
+
29
+ # Detect format from file extension
30
+ def read_file(resource)
31
+ File.read(resource)
32
+ end
33
+
34
+ def read_stdin(_resource)
35
+ STDIN.read
36
+ end
37
+
38
+ def read_url(resource)
39
+ Net::HTTP.get(URI.parse(resource))
40
+ end
41
+ end
42
+ end
@@ -13,7 +13,7 @@ module ThreeScaleToolbox
13
13
  if plan.delete('custom') # TODO: what to do with custom plans?
14
14
  puts "skipping custom plan #{plan}"
15
15
  else
16
- target.create_application_plan(plan)
16
+ ThreeScaleToolbox::Entities::ApplicationPlan.create(service: target, plan_attrs: plan)
17
17
  end
18
18
  end
19
19
  puts "target service missing #{missing_plans.size} application plans"
@@ -8,27 +8,24 @@ module ThreeScaleToolbox
8
8
  metrics_map = metrics_mapping(source.metrics, target.metrics)
9
9
  plan_mapping = application_plan_mapping(source.plans, target.plans)
10
10
  plan_mapping.each do |plan_id, target_plan|
11
- limits = source.plan_limits(plan_id)
12
- limits_target = target.plan_limits(target_plan['id'])
13
- missing_limits = missing_limits(limits, limits_target)
11
+ source_plan = ThreeScaleToolbox::Entities::ApplicationPlan.new(id: plan_id, service: source)
12
+ target_plan = ThreeScaleToolbox::Entities::ApplicationPlan.new(id: target_plan['id'], service: target)
13
+ missing_limits = missing_limits(source_plan.limits, target_plan.limits, metrics_map)
14
14
  missing_limits.each do |limit|
15
15
  limit.delete('links')
16
- target.create_application_plan_limit(
17
- target_plan['id'],
18
- metrics_map.fetch(limit.fetch('metric_id')),
19
- limit
20
- )
16
+ target_plan.create_limit(metrics_map.fetch(limit.fetch('metric_id')), limit)
21
17
  end
22
18
  puts "Missing #{missing_limits.size} plan limits from target application plan " \
23
- "#{target_plan['id']}. Source plan #{plan_id}"
19
+ "#{target_plan.id}. Source plan #{plan_id}"
24
20
  end
25
21
  end
26
22
 
27
23
  private
28
24
 
29
- def missing_limits(source_limits, target_limits)
25
+ def missing_limits(source_limits, target_limits, metrics_map)
30
26
  ThreeScaleToolbox::Helper.array_difference(source_limits, target_limits) do |limit, target|
31
- ThreeScaleToolbox::Helper.compare_hashes(limit, target, ['period'])
27
+ ThreeScaleToolbox::Helper.compare_hashes(limit, target, ['period']) &&
28
+ metrics_map.fetch(limit.fetch('metric_id')) == target.fetch('metric_id')
32
29
  end
33
30
  end
34
31
  end
@@ -10,7 +10,8 @@ module ThreeScaleToolbox
10
10
  plan_mapping.each do |plan_id, target_plan|
11
11
  pricing_rules_source = source.remote.list_pricingrules_per_application_plan(plan_id)
12
12
  pricing_rules_target = target.remote.list_pricingrules_per_application_plan(target_plan['id'])
13
- missing_pricing_rules = missing_pricing_rules(pricing_rules_source, pricing_rules_target)
13
+ missing_pricing_rules = missing_pricing_rules(pricing_rules_source, pricing_rules_target,
14
+ metrics_map)
14
15
  missing_pricing_rules.each do |pricing_rule|
15
16
  pricing_rule.delete('links')
16
17
  target.remote.create_pricingrule(
@@ -26,9 +27,10 @@ module ThreeScaleToolbox
26
27
 
27
28
  private
28
29
 
29
- def missing_pricing_rules(source_pricing_rules, target_pricing_rules)
30
+ def missing_pricing_rules(source_pricing_rules, target_pricing_rules, metrics_map)
30
31
  ThreeScaleToolbox::Helper.array_difference(source_pricing_rules, target_pricing_rules) do |src, target|
31
- ThreeScaleToolbox::Helper.compare_hashes(src, target, ['system_name'])
32
+ ThreeScaleToolbox::Helper.compare_hashes(src, target, %w[cost_per_unit min max]) &&
33
+ metrics_map.fetch(src.fetch('metric_id')) == target.fetch('metric_id')
32
34
  end
33
35
  end
34
36
  end
@@ -1,3 +1,3 @@
1
1
  module ThreeScaleToolbox
2
- VERSION = '0.8.0'
2
+ VERSION = '0.9.0'
3
3
  end
@@ -1,7 +1,17 @@
1
+ require 'json'
2
+ require 'cri'
3
+ require 'yaml'
4
+ require 'uri'
5
+ require 'time'
6
+ require 'csv'
7
+ require 'net/http'
8
+ require '3scale/api'
9
+
1
10
  require '3scale_toolbox/version'
2
11
  require '3scale_toolbox/helper'
3
12
  require '3scale_toolbox/error'
4
13
  require '3scale_toolbox/proxy_logger'
14
+ require '3scale_toolbox/resource_reader'
5
15
  require '3scale_toolbox/swagger'
6
16
  require '3scale_toolbox/configuration'
7
17
  require '3scale_toolbox/remotes'
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.8.0
4
+ version: 0.9.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-04-12 00:00:00.000000000 Z
12
+ date: 2019-05-07 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: bundler
@@ -87,14 +87,14 @@ dependencies:
87
87
  requirements:
88
88
  - - "~>"
89
89
  - !ruby/object:Gem::Version
90
- version: 0.1.9
90
+ version: 0.3.0
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.1.9
97
+ version: 0.3.0
98
98
  - !ruby/object:Gem::Dependency
99
99
  name: cri
100
100
  requirement: !ruby/object:Gem::Requirement
@@ -154,12 +154,33 @@ files:
154
154
  - lib/3scale_toolbox/commands/import_command/openapi/mapping_rule.rb
155
155
  - lib/3scale_toolbox/commands/import_command/openapi/method.rb
156
156
  - lib/3scale_toolbox/commands/import_command/openapi/operation.rb
157
- - lib/3scale_toolbox/commands/import_command/openapi/resource_reader.rb
158
157
  - lib/3scale_toolbox/commands/import_command/openapi/step.rb
159
158
  - lib/3scale_toolbox/commands/import_command/openapi/threescale_api_spec.rb
160
159
  - lib/3scale_toolbox/commands/import_command/openapi/update_policies_step.rb
161
160
  - lib/3scale_toolbox/commands/import_command/openapi/update_service_oidc_conf_step.rb
162
161
  - lib/3scale_toolbox/commands/import_command/openapi/update_service_proxy_step.rb
162
+ - lib/3scale_toolbox/commands/plans_command.rb
163
+ - lib/3scale_toolbox/commands/plans_command/apply_command.rb
164
+ - lib/3scale_toolbox/commands/plans_command/create_command.rb
165
+ - lib/3scale_toolbox/commands/plans_command/delete_command.rb
166
+ - lib/3scale_toolbox/commands/plans_command/export/read_app_plan_step.rb
167
+ - lib/3scale_toolbox/commands/plans_command/export/read_plan_features_step.rb
168
+ - lib/3scale_toolbox/commands/plans_command/export/read_plan_limits_step.rb
169
+ - lib/3scale_toolbox/commands/plans_command/export/read_plan_methods_step.rb
170
+ - lib/3scale_toolbox/commands/plans_command/export/read_plan_metrics_step.rb
171
+ - lib/3scale_toolbox/commands/plans_command/export/read_plan_pricing_rules_step.rb
172
+ - lib/3scale_toolbox/commands/plans_command/export/step.rb
173
+ - lib/3scale_toolbox/commands/plans_command/export/write_artifacts_file_step.rb
174
+ - lib/3scale_toolbox/commands/plans_command/export_command.rb
175
+ - lib/3scale_toolbox/commands/plans_command/import/create_or_update_app_plan_step.rb
176
+ - lib/3scale_toolbox/commands/plans_command/import/import_plan_features_step.rb
177
+ - lib/3scale_toolbox/commands/plans_command/import/import_plan_limits_step.rb
178
+ - lib/3scale_toolbox/commands/plans_command/import/import_plan_metrics_step.rb
179
+ - lib/3scale_toolbox/commands/plans_command/import/import_plan_pricing_rules_step.rb
180
+ - lib/3scale_toolbox/commands/plans_command/import/step.rb
181
+ - lib/3scale_toolbox/commands/plans_command/import_command.rb
182
+ - lib/3scale_toolbox/commands/plans_command/list_command.rb
183
+ - lib/3scale_toolbox/commands/plans_command/show_command.rb
163
184
  - lib/3scale_toolbox/commands/remote_command.rb
164
185
  - lib/3scale_toolbox/commands/remote_command/remote_add.rb
165
186
  - lib/3scale_toolbox/commands/remote_command/remote_list.rb
@@ -169,11 +190,13 @@ files:
169
190
  - lib/3scale_toolbox/commands/update_command/update_service.rb
170
191
  - lib/3scale_toolbox/configuration.rb
171
192
  - lib/3scale_toolbox/entities.rb
193
+ - lib/3scale_toolbox/entities/application_plan.rb
172
194
  - lib/3scale_toolbox/entities/service.rb
173
195
  - lib/3scale_toolbox/error.rb
174
196
  - lib/3scale_toolbox/helper.rb
175
197
  - lib/3scale_toolbox/proxy_logger.rb
176
198
  - lib/3scale_toolbox/remotes.rb
199
+ - lib/3scale_toolbox/resource_reader.rb
177
200
  - lib/3scale_toolbox/swagger.rb
178
201
  - lib/3scale_toolbox/swagger/swagger.rb
179
202
  - lib/3scale_toolbox/tasks.rb
@@ -1,51 +0,0 @@
1
- require 'uri'
2
- require 'net/http'
3
-
4
- module ThreeScaleToolbox
5
- module Commands
6
- module ImportCommand
7
- module OpenAPI
8
- module ResourceReader
9
- ##
10
- # Load resource from different types of sources.
11
- # Supported types are: file, URL, stdin
12
- # Loaded content is returned
13
- def load_resource(resource)
14
- # Json format is parsed as well
15
- YAML.safe_load(read_content(resource))
16
- rescue Psych::SyntaxError => e
17
- raise ThreeScaleToolbox::Error, "JSON/YAML validation failed: #{e.message}"
18
- end
19
-
20
- ##
21
- # Reads resources from different types of sources.
22
- # Supported types are: file, URL, stdin
23
- # Resource raw content is returned
24
- def read_content(resource)
25
- case resource
26
- when '-'
27
- method(:read_stdin)
28
- when /\A#{URI::DEFAULT_PARSER.make_regexp}\z/
29
- method(:read_url)
30
- else
31
- method(:read_file)
32
- end.call(resource)
33
- end
34
-
35
- # Detect format from file extension
36
- def read_file(resource)
37
- File.read(resource)
38
- end
39
-
40
- def read_stdin(_resource)
41
- STDIN.read
42
- end
43
-
44
- def read_url(resource)
45
- Net::HTTP.get(URI.parse(resource))
46
- end
47
- end
48
- end
49
- end
50
- end
51
- end