3scale_toolbox 0.16.0 → 0.18.3

Sign up to get free protection for your applications and to get access to all the features.
Files changed (103) hide show
  1. checksums.yaml +4 -4
  2. data/3scale_toolbox.gemspec +2 -2
  3. data/README.md +11 -8
  4. data/lib/3scale_toolbox.rb +3 -0
  5. data/lib/3scale_toolbox/3scale_client_factory.rb +3 -4
  6. data/lib/3scale_toolbox/cli/error_handler.rb +17 -14
  7. data/lib/3scale_toolbox/commands.rb +2 -0
  8. data/lib/3scale_toolbox/commands/backend_command/copy_command/copy_mapping_rules_task.rb +11 -27
  9. data/lib/3scale_toolbox/commands/backend_command/copy_command/copy_methods_task.rb +5 -10
  10. data/lib/3scale_toolbox/commands/backend_command/copy_command/copy_metrics_task.rb +4 -4
  11. data/lib/3scale_toolbox/commands/backend_command/copy_command/create_or_update_target_backend_task.rb +3 -2
  12. data/lib/3scale_toolbox/commands/backend_command/copy_command/task.rb +10 -32
  13. data/lib/3scale_toolbox/commands/import_command/issuer_type_transformer.rb +16 -0
  14. data/lib/3scale_toolbox/commands/import_command/openapi.rb +3 -0
  15. data/lib/3scale_toolbox/commands/import_command/openapi/create_activedocs_step.rb +3 -2
  16. data/lib/3scale_toolbox/commands/import_command/openapi/create_mapping_rule_step.rb +2 -1
  17. data/lib/3scale_toolbox/commands/import_command/openapi/create_method_step.rb +5 -14
  18. data/lib/3scale_toolbox/commands/import_command/openapi/step.rb +4 -0
  19. data/lib/3scale_toolbox/commands/import_command/openapi/update_service_proxy_step.rb +1 -0
  20. data/lib/3scale_toolbox/commands/methods_command/apply_command.rb +2 -4
  21. data/lib/3scale_toolbox/commands/methods_command/create_command.rb +0 -2
  22. data/lib/3scale_toolbox/commands/methods_command/delete_command.rb +1 -1
  23. data/lib/3scale_toolbox/commands/methods_command/list_command.rb +1 -9
  24. data/lib/3scale_toolbox/commands/metrics_command/list_command.rb +1 -1
  25. data/lib/3scale_toolbox/commands/plans_command/export/read_plan_limits_step.rb +1 -1
  26. data/lib/3scale_toolbox/commands/plans_command/export/read_plan_methods_step.rb +2 -2
  27. data/lib/3scale_toolbox/commands/plans_command/export/read_plan_metrics_step.rb +2 -2
  28. data/lib/3scale_toolbox/commands/plans_command/export/read_plan_pricing_rules_step.rb +1 -2
  29. data/lib/3scale_toolbox/commands/plans_command/export/step.rb +8 -20
  30. data/lib/3scale_toolbox/commands/plans_command/import/import_plan_limits_step.rb +12 -14
  31. data/lib/3scale_toolbox/commands/plans_command/import/import_plan_metrics_step.rb +6 -13
  32. data/lib/3scale_toolbox/commands/plans_command/import/import_plan_pricing_rules_step.rb +12 -20
  33. data/lib/3scale_toolbox/commands/plans_command/import/step.rb +2 -22
  34. data/lib/3scale_toolbox/commands/plans_command/list_command.rb +1 -1
  35. data/lib/3scale_toolbox/commands/plans_command/show_command.rb +1 -1
  36. data/lib/3scale_toolbox/commands/policies_command.rb +24 -0
  37. data/lib/3scale_toolbox/commands/policies_command/export_command.rb +98 -0
  38. data/lib/3scale_toolbox/commands/policies_command/import_command.rb +61 -0
  39. data/lib/3scale_toolbox/commands/product_command.rb +4 -0
  40. data/lib/3scale_toolbox/commands/product_command/copy_command.rb +7 -3
  41. data/lib/3scale_toolbox/commands/product_command/copy_command/copy_backends_task.rb +22 -5
  42. data/lib/3scale_toolbox/commands/product_command/export_command.rb +81 -0
  43. data/lib/3scale_toolbox/commands/product_command/import_command.rb +125 -0
  44. data/lib/3scale_toolbox/commands/proxy_config_command.rb +5 -0
  45. data/lib/3scale_toolbox/commands/proxy_config_command/deploy_command.rb +54 -0
  46. data/lib/3scale_toolbox/commands/proxy_config_command/export_command.rb +74 -0
  47. data/lib/3scale_toolbox/commands/proxy_config_command/helper.rb +15 -0
  48. data/lib/3scale_toolbox/commands/service_command/copy_command/copy_activedocs_task.rb +15 -12
  49. data/lib/3scale_toolbox/commands/service_command/copy_command/copy_app_plans_task.rb +15 -15
  50. data/lib/3scale_toolbox/commands/service_command/copy_command/copy_limits_task.rb +12 -13
  51. data/lib/3scale_toolbox/commands/service_command/copy_command/copy_mapping_rules_task.rb +11 -11
  52. data/lib/3scale_toolbox/commands/service_command/copy_command/copy_methods_task.rb +9 -12
  53. data/lib/3scale_toolbox/commands/service_command/copy_command/copy_metrics_task.rb +8 -8
  54. data/lib/3scale_toolbox/commands/service_command/copy_command/copy_policies_task.rb +1 -1
  55. data/lib/3scale_toolbox/commands/service_command/copy_command/copy_pricingrules_task.rb +15 -18
  56. data/lib/3scale_toolbox/commands/service_command/copy_command/copy_service_proxy_task.rb +17 -2
  57. data/lib/3scale_toolbox/commands/service_command/copy_command/create_or_update_service_task.rb +2 -1
  58. data/lib/3scale_toolbox/commands/service_command/copy_command/destroy_mapping_rules_task.rb +9 -5
  59. data/lib/3scale_toolbox/commands/service_command/copy_command/task.rb +20 -34
  60. data/lib/3scale_toolbox/commands/update_command.rb +1 -1
  61. data/lib/3scale_toolbox/commands/update_command/service_command.rb +3 -2
  62. data/lib/3scale_toolbox/commands/update_command/service_command/delete_activedocs_task.rb +1 -3
  63. data/lib/3scale_toolbox/crds.rb +16 -0
  64. data/lib/3scale_toolbox/crds/application_plan_dump.rb +19 -0
  65. data/lib/3scale_toolbox/crds/backend_dump.rb +39 -0
  66. data/lib/3scale_toolbox/crds/backend_mapping_rule_dump.rb +26 -0
  67. data/lib/3scale_toolbox/crds/backend_method_dump.rb +12 -0
  68. data/lib/3scale_toolbox/crds/backend_metric_dump.rb +13 -0
  69. data/lib/3scale_toolbox/crds/backend_parser.rb +55 -0
  70. data/lib/3scale_toolbox/crds/backend_usage_dump.rb +11 -0
  71. data/lib/3scale_toolbox/crds/limit_dump.rb +37 -0
  72. data/lib/3scale_toolbox/crds/mapping_rule_dump.rb +26 -0
  73. data/lib/3scale_toolbox/crds/method_dump.rb +12 -0
  74. data/lib/3scale_toolbox/crds/metric_dump.rb +13 -0
  75. data/lib/3scale_toolbox/crds/pricing_rule_dump.rb +38 -0
  76. data/lib/3scale_toolbox/crds/product_deployment_parser.rb +329 -0
  77. data/lib/3scale_toolbox/crds/product_dump.rb +157 -0
  78. data/lib/3scale_toolbox/crds/product_parser.rb +114 -0
  79. data/lib/3scale_toolbox/crds/remote.rb +682 -0
  80. data/lib/3scale_toolbox/entities.rb +3 -0
  81. data/lib/3scale_toolbox/entities/activedocs.rb +12 -0
  82. data/lib/3scale_toolbox/entities/application_plan.rb +74 -39
  83. data/lib/3scale_toolbox/entities/backend.rb +65 -30
  84. data/lib/3scale_toolbox/entities/backend_mapping_rule.rb +29 -3
  85. data/lib/3scale_toolbox/entities/backend_method.rb +25 -16
  86. data/lib/3scale_toolbox/entities/backend_metric.rb +12 -2
  87. data/lib/3scale_toolbox/entities/backend_usage.rb +7 -1
  88. data/lib/3scale_toolbox/entities/limit.rb +71 -0
  89. data/lib/3scale_toolbox/entities/mapping_rule.rb +90 -0
  90. data/lib/3scale_toolbox/entities/method.rb +33 -19
  91. data/lib/3scale_toolbox/entities/metric.rb +29 -18
  92. data/lib/3scale_toolbox/entities/pricing_rule.rb +63 -0
  93. data/lib/3scale_toolbox/entities/proxy_config.rb +0 -1
  94. data/lib/3scale_toolbox/entities/service.rb +149 -46
  95. data/lib/3scale_toolbox/error.rb +50 -0
  96. data/lib/3scale_toolbox/helper.rb +13 -16
  97. data/lib/3scale_toolbox/openapi/oas3.rb +1 -1
  98. data/lib/3scale_toolbox/proxy_logger.rb +4 -0
  99. data/lib/3scale_toolbox/remote_cache.rb +157 -0
  100. data/lib/3scale_toolbox/remotes.rb +2 -2
  101. data/lib/3scale_toolbox/version.rb +1 -1
  102. data/licenses.xml +113 -45
  103. metadata +37 -8
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 77ce2f220c416d634541773317d35da8018a75d7e3d91c009338b7a971614eee
4
- data.tar.gz: 4d5ee60b4cc55c0ba002fc007ba578801012c9c5580b4fe540f03c3c9dbb2d26
3
+ metadata.gz: 0a3084c0b2b684a252c7e07c4c9a87e3087ada1ad6a677766aa508ac98e1f313
4
+ data.tar.gz: 158b1b008a67836c2b27ccd8cbcd49f59995e4ac776eae93c59bf44b002cbf3a
5
5
  SHA512:
6
- metadata.gz: 947d84f88a8b8e673ea313ba79a3e72eda4b03b85af30f12003b8c6b867f98addf8bc0eebea2e4a3c3bdbc64f80f241346c0e70bdb2ec9e5e9b3a698ab539438
7
- data.tar.gz: 106e99be0a64a27284d6b7a64b796ac0ef6b14e30011b3d42366d1e6494e9f623fdb6221924204830e4e9dbb59a6086b0aac8601a4e7b5a968a59f9bfaefed61
6
+ metadata.gz: '02789c23291a2191617a56c3456297539b09e0922bbf62b57b613065b04d8951800d91f49989d510258c0c3b1baa308d1219f4c29373879c8a65f9a93bd4653a'
7
+ data.tar.gz: abaca7089c51b5de57c118f5154a74466dd6671a96d7ec043b47ba0d4772761a2d9896b1195e762115ff121296c16cc2f195a5d39e9c20191393f45e6ee756bc
@@ -31,12 +31,12 @@ Gem::Specification.new do |spec|
31
31
 
32
32
  spec.add_development_dependency 'bundler'
33
33
  spec.add_development_dependency 'dotenv'
34
- spec.add_development_dependency 'rake', '~> 10.0'
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
37
  spec.required_ruby_version = '>= 2.5'
38
38
 
39
- spec.add_dependency '3scale-api', '~> 1.0'
39
+ spec.add_dependency '3scale-api', '~> 1.4'
40
40
  spec.add_dependency 'cri', '~> 2.15'
41
41
  spec.add_dependency 'json-schema', '~> 2.8'
42
42
  spec.add_dependency 'oas_parser', '~> 0.20'
data/README.md CHANGED
@@ -1,9 +1,7 @@
1
1
  # 3scale toolbox
2
2
  [![CircleCI](https://circleci.com/gh/3scale/3scale_toolbox.svg?style=svg)](https://circleci.com/gh/3scale/3scale_toolbox)
3
-
4
- This software is licensed under the [Apache 2.0 license](https://www.apache.org/licenses/LICENSE-2.0).
5
-
6
- See the LICENSE and NOTICE files that should have been provided along with this software for details.
3
+ [![License](https://img.shields.io/badge/license-Apache--2.0-blue.svg)](http://www.apache.org/licenses/LICENSE-2.0)
4
+ [![GitHub release](https://img.shields.io/github/v/release/3scale/3scale_toolbox.svg)](https://github.com/3scale/3scale_toolbox/releases/latest)
7
5
 
8
6
  ## Description
9
7
  3scale toolbox is a set of tools to help you manage your 3scale product. Using the [3scale API Ruby Client](https://github.com/3scale/3scale-api-ruby).
@@ -15,6 +13,7 @@ See the LICENSE and NOTICE files that should have been provided along with this
15
13
  * [Copy service](docs/copy-service.md)
16
14
  * [Copy backend](docs/copy-backend.md)
17
15
  * [Copy product](docs/copy-product.md)
16
+ * [Export/Import product](docs/export-import-product.md)
18
17
  * [Import from CSV](docs/import-csv.md)
19
18
  * [Import from OpenAPI definition](docs/openapi.md)
20
19
  * [Export/Import Application Plan](docs/export-import-app-plan.md)
@@ -23,15 +22,17 @@ See the LICENSE and NOTICE files that should have been provided along with this
23
22
  * Create, Apply, List, Delete [Method](docs/method.md)
24
23
  * Create, Apply, List, Show, Delete [Service](docs/service.md)
25
24
  * Create, Apply, List, Delete [ActiveDocs](docs/activedocs.md)
26
- * List, Show, Promote [Proxy Configuration](docs/proxy-config.md)
25
+ * List, Show, Promote, Export, Deploy [Proxy Configuration](docs/proxy-config.md)
27
26
  * [Copy Policy Registry](docs/copy-policy-registry.md)
28
27
  * Create, Apply, List, Show, Delete, Suspend, Resume [Applications](docs/applications.md)
28
+ * [Export/Import Product Policy Chain](docs/export-import-policy-chain.md)
29
29
  * [Remotes](docs/remotes.md)
30
30
  * [Development](#development)
31
31
  * [Testing](#testing)
32
32
  * [Develop your own core command](#develop-core-command)
33
33
  * [Licenses](#licenses)
34
34
  * [Plugins](#plugins)
35
+ * [Error Reporting](docs/errors.md)
35
36
  * [Troubleshooting](#troubleshooting)
36
37
  * [Contributing](#contributing)
37
38
 
@@ -40,6 +41,7 @@ Supported Ruby interpreters
40
41
 
41
42
  * MRI 2.5
42
43
  * MRI 2.6
44
+ * MRI 2.7
43
45
 
44
46
  ## Installation
45
47
  Install the toolbox:
@@ -82,10 +84,11 @@ COMMANDS
82
84
  method method super command
83
85
  metric metric super command
84
86
  policy-registry policy-registry super command
87
+ product product super command
85
88
  proxy-config proxy-config super command
86
89
  remote remotes super command
87
90
  service services super command
88
- update [DEPRECTATED] update super command
91
+ update [DEPRECATED] update super command
89
92
 
90
93
  OPTIONS
91
94
  -c --config-file=<value> 3scale toolbox configuration file (default:
@@ -120,7 +123,7 @@ rake spec:integration
120
123
 
121
124
  Integration tests can be run locally or against a real 3scale account.
122
125
  When details of the account are set via environment variables,
123
- integration tests are run agains given account.
126
+ integration tests are run against the given account.
124
127
  Otherwise, tests are run locally with mocked 3scale clients.
125
128
 
126
129
  The easiest way to set everything up is it to have a `.env` file in the root of the project with the following environment variables (set your own values):
@@ -163,7 +166,7 @@ end
163
166
  A few things worth highlighting:
164
167
  - Your module must include the *ThreeScaleToolbox::Command* module. It allows your command to be added to the toobox command tree.
165
168
  - You must implement the `command` module function and return an instance of `Cri::Command` from [cri](https://github.com/ddfreyne/cri)
166
- - `threescale_client` helper method returns *3scale API* client instance. All the process remote parsing, fetching from remote list and client instantiation is done out of the box.
169
+ - `threescale_client` helper method returns *3scale API* client instance. All the process remote parsing, fetching from the remote list and client instantiation is done out of the box.
167
170
 
168
171
  Then register the core command in `lib/3scale_toolbox/commands.rb`
169
172
  ```
@@ -10,15 +10,18 @@ require 'oas_parser'
10
10
  require '3scale/api'
11
11
  require 'json-schema'
12
12
  require 'erb'
13
+ require 'logger'
13
14
 
14
15
  require '3scale_toolbox/version'
15
16
  require '3scale_toolbox/helper'
16
17
  require '3scale_toolbox/error'
18
+ require '3scale_toolbox/remote_cache'
17
19
  require '3scale_toolbox/proxy_logger'
18
20
  require '3scale_toolbox/resource_reader'
19
21
  require '3scale_toolbox/configuration'
20
22
  require '3scale_toolbox/remotes'
21
23
  require '3scale_toolbox/3scale_client_factory'
24
+ require '3scale_toolbox/crds'
22
25
  require '3scale_toolbox/entities'
23
26
  require '3scale_toolbox/attribute_filters'
24
27
  require '3scale_toolbox/base_command'
@@ -22,10 +22,9 @@ module ThreeScaleToolbox
22
22
  remote = remotes.fetch(remote_str)
23
23
  end
24
24
 
25
- client = remote_client(remote.merge(verify_ssl: verify_ssl))
26
- return ProxyLogger.new(client) if verbose
27
-
28
- client
25
+ client = remote_client(**remote.merge(verify_ssl: verify_ssl))
26
+ client = ProxyLogger.new(client) if verbose
27
+ RemoteCache.new(client)
29
28
  end
30
29
 
31
30
  private
@@ -20,10 +20,9 @@ module ThreeScaleToolbox
20
20
 
21
21
  def handle_error(error)
22
22
  if expected_error?(error)
23
- warn
24
- warn "\e[1m\e[31mError: #{error.message}\e[0m"
23
+ warn error_serialize(error)
25
24
  else
26
- print_error(error)
25
+ print_unexpected_error(error)
27
26
  end
28
27
  end
29
28
 
@@ -36,21 +35,12 @@ module ThreeScaleToolbox
36
35
  end
37
36
  end
38
37
 
39
- def print_error(error)
40
- write_error(error, $stderr)
41
-
38
+ def print_unexpected_error(error)
42
39
  File.open('crash.log', 'w') do |io|
43
40
  write_verbose_error(error, io)
44
41
  end
45
42
 
46
- write_section_header($stderr, 'Detailed information')
47
- warn
48
- warn 'A detailed crash log has been written to ./crash.log.'
49
- end
50
-
51
- def write_error(error, stream)
52
- write_error_message(error, stream)
53
- write_stack_trace(error, stream)
43
+ warn error_serialize(UnexpectedError.new(error))
54
44
  end
55
45
 
56
46
  def write_error_message(error, stream)
@@ -113,6 +103,19 @@ module ThreeScaleToolbox
113
103
  stream.puts "===== #{title.upcase}:"
114
104
  stream.puts
115
105
  end
106
+
107
+ def error_serialize(error)
108
+ JSON.pretty_generate format_error(error)
109
+ end
110
+
111
+ def format_error(error)
112
+ {
113
+ code: error.code,
114
+ message: error.message,
115
+ class: error.kind,
116
+ stacktrace: error.stacktrace
117
+ }.compact
118
+ end
116
119
  end
117
120
  end
118
121
  end
@@ -15,6 +15,7 @@ require '3scale_toolbox/commands/policy_registry_command'
15
15
  require '3scale_toolbox/commands/application_command'
16
16
  require '3scale_toolbox/commands/backend_command'
17
17
  require '3scale_toolbox/commands/product_command'
18
+ require '3scale_toolbox/commands/policies_command'
18
19
 
19
20
  module ThreeScaleToolbox
20
21
  module Commands
@@ -35,6 +36,7 @@ module ThreeScaleToolbox
35
36
  ThreeScaleToolbox::Commands::ApplicationCommand,
36
37
  ThreeScaleToolbox::Commands::BackendCommand,
37
38
  ThreeScaleToolbox::Commands::ProductCommand,
39
+ ThreeScaleToolbox::Commands::PoliciesCommand,
38
40
  ].freeze
39
41
  end
40
42
  end
@@ -7,42 +7,26 @@ module ThreeScaleToolbox
7
7
 
8
8
  # entrypoint
9
9
  def run
10
- missing_rules = missing_mapping_rules(source_backend.mapping_rules,
11
- target_backend.mapping_rules, metrics_map)
12
10
  missing_rules.each do |mapping_rule|
13
- mapping_rule.metric_id = metrics_map.fetch(mapping_rule.metric_id)
14
- Entities::BackendMappingRule.create(backend: target_backend,
15
- attrs: mapping_rule.attrs)
11
+ mr_attrs = mapping_rule.attrs.merge('metric_id' => metrics_map.fetch(mapping_rule.metric_id))
12
+ Entities::BackendMappingRule.create(backend: target_backend, attrs: mr_attrs)
16
13
  end
17
- puts "created #{missing_rules.size} mapping rules"
14
+ logger.info "created #{missing_rules.size} mapping rules"
15
+ report['missing_mapping_rules_created'] = missing_rules.size
18
16
  end
19
17
 
20
18
  private
21
19
 
22
20
  def metrics_map
23
- @metrics_map ||= build_metrics_mapping
21
+ @metrics_map ||= source_backend.metrics_mapping(target_backend)
24
22
  end
25
23
 
26
- def build_metrics_mapping
27
- target_mm = target_metrics + target_methods
28
- source_mm = source_metrics + source_methods
29
- target_mm.map do |target|
30
- source = source_mm.find do |m|
31
- m.system_name == target.system_name
32
- end
33
- next if source.nil?
34
-
35
- [source.id, target.id]
36
- end.compact.to_h
37
- end
38
-
39
- def missing_mapping_rules(source_rules, target_rules, metrics_map)
40
- ThreeScaleToolbox::Helper.array_difference(source_rules, target_rules) do |source, target|
41
- # map metric_id to the target backend domain
42
- source_attrs = source.attrs.merge('metric_id' => metrics_map.fetch(source.metric_id))
43
- ThreeScaleToolbox::Helper.compare_hashes(source_attrs,
44
- target.attrs,
45
- %w[pattern http_method delta metric_id])
24
+ def missing_rules
25
+ @missing_rules ||= ThreeScaleToolbox::Helper.array_difference(source_backend.mapping_rules, target_backend.mapping_rules) do |source_rule, target_rule|
26
+ source_rule.pattern == target_rule.pattern &&
27
+ source_rule.http_method == target_rule.http_method &&
28
+ source_rule.delta == target_rule.delta &&
29
+ metrics_map.fetch(source_rule.metric_id) == target_rule.metric_id
46
30
  end
47
31
  end
48
32
  end
@@ -8,28 +8,23 @@ module ThreeScaleToolbox
8
8
  # entrypoint
9
9
  def run
10
10
  missing_methods.each(&method(:create_method))
11
- puts "created #{missing_methods.size} missing methods"
12
- invalidate_target_methods if missing_methods.size.positive?
11
+ logger.info "created #{missing_methods.size} missing methods"
12
+ report['missing_methods_created'] = missing_methods.size
13
13
  end
14
14
 
15
15
  private
16
16
 
17
17
  def create_method(method)
18
- # return silently if target metric hits does not exist
19
- return if target_hits.nil?
20
-
21
- Entities::BackendMethod.create(backend: target_backend,
22
- parent_id: target_hits.id,
23
- attrs: method.attrs)
18
+ Entities::BackendMethod.create(backend: target_backend, attrs: method.attrs)
24
19
  rescue ThreeScaleToolbox::ThreeScaleApiError => e
25
20
  raise e unless ThreeScaleToolbox::Helper.system_name_already_taken_error?(e.apierrors)
26
21
 
27
- warn "[WARN] backend method #{method.attrs.fetch('system_name')} not created. " \
22
+ warn "[WARN] backend method #{method.system_name} not created. " \
28
23
  'Backend metric with the same system_name exists.'
29
24
  end
30
25
 
31
26
  def missing_methods
32
- @missing_methods ||= ThreeScaleToolbox::Helper.array_difference(source_methods, target_methods) do |source, target|
27
+ @missing_methods ||= ThreeScaleToolbox::Helper.array_difference(source_backend.methods, target_backend.methods) do |source, target|
33
28
  source.system_name == target.system_name
34
29
  end
35
30
  end
@@ -8,8 +8,8 @@ module ThreeScaleToolbox
8
8
  # entrypoint
9
9
  def run
10
10
  missing_metrics.each(&method(:create_metric))
11
- puts "created #{missing_metrics.size} missing metrics"
12
- invalidate_target_metrics if missing_metrics.size.positive?
11
+ logger.info "created #{missing_metrics.size} missing metrics"
12
+ report['missing_metrics_created'] = missing_metrics.size
13
13
  end
14
14
 
15
15
  private
@@ -19,8 +19,8 @@ module ThreeScaleToolbox
19
19
  end
20
20
 
21
21
  def missing_metrics
22
- @missing_metrics ||= ThreeScaleToolbox::Helper.array_difference(source_metrics, target_metrics) do |source, target|
23
- source.system_name == target.system_name
22
+ @missing_metrics ||= ThreeScaleToolbox::Helper.array_difference(source_backend.metrics, target_backend.metrics) do |s_m, t_m|
23
+ s_m.system_name == t_m.system_name
24
24
  end
25
25
  end
26
26
  end
@@ -23,8 +23,9 @@ module ThreeScaleToolbox
23
23
  # assign target backend for other tasks to have it available
24
24
  self.target_backend = backend
25
25
 
26
- puts "source backend ID: #{source_backend.id} system_name: #{source_backend.attrs['system_name']}"
27
- puts "target backend ID: #{target_backend.id} system_name: #{target_backend.attrs['system_name']}"
26
+ logger.info "source backend ID: #{source_backend.id} system_name: #{source_backend.system_name}"
27
+ logger.info "target backend ID: #{target_backend.id} system_name: #{target_backend.system_name}"
28
+ report['backend_id'] = target_backend.id
28
29
  end
29
30
 
30
31
  def create_attrs
@@ -26,38 +26,6 @@ module ThreeScaleToolbox
26
26
  context[:source_backend] ||= find_source_backend
27
27
  end
28
28
 
29
- def source_methods
30
- context[:source_methods] ||= source_backend.methods(source_hits)
31
- end
32
-
33
- def source_hits
34
- context[:source_hits] ||= source_backend.hits
35
- end
36
-
37
- def source_metrics
38
- context[:source_metrics] ||= source_backend.metrics
39
- end
40
-
41
- def target_metrics
42
- context[:target_metrics] ||= target_backend.metrics
43
- end
44
-
45
- def target_hits
46
- context[:target_hits] ||= target_backend.hits
47
- end
48
-
49
- def target_methods
50
- context[:target_methods] ||= target_backend.methods(target_hits)
51
- end
52
-
53
- def invalidate_target_methods
54
- context[:target_methods] = nil
55
- end
56
-
57
- def invalidate_target_metrics
58
- context[:target_metrics] = nil
59
- end
60
-
61
29
  def source_remote
62
30
  context[:source_remote]
63
31
  end
@@ -75,6 +43,16 @@ module ThreeScaleToolbox
75
43
  context[:option_target_system_name]
76
44
  end
77
45
 
46
+ def logger
47
+ context[:logger] ||= Logger.new($stdout).tap do |logger|
48
+ logger.formatter = proc { |severity, datetime, progname, msg| "#{msg}\n" }
49
+ end
50
+ end
51
+
52
+ def report
53
+ context[:report] ||= {}
54
+ end
55
+
78
56
  private
79
57
 
80
58
  def find_source_backend
@@ -0,0 +1,16 @@
1
+ module ThreeScaleToolbox
2
+ module Commands
3
+ module ImportCommand
4
+ module OpenAPI
5
+ # Helper class to validate values for the oidc-issuer-type argument of the import openapi command
6
+ class IssuerTypeTransformer
7
+ def call(issuer_type)
8
+ raise unless %w[rest keycloak].include?(issuer_type)
9
+
10
+ issuer_type
11
+ end
12
+ end
13
+ end
14
+ end
15
+ end
16
+ end
@@ -9,6 +9,7 @@ require '3scale_toolbox/commands/import_command/openapi/create_activedocs_step'
9
9
  require '3scale_toolbox/commands/import_command/openapi/update_service_proxy_step'
10
10
  require '3scale_toolbox/commands/import_command/openapi/update_service_oidc_conf_step'
11
11
  require '3scale_toolbox/commands/import_command/openapi/update_policies_step'
12
+ require '3scale_toolbox/commands/import_command/issuer_type_transformer'
12
13
 
13
14
  module ThreeScaleToolbox
14
15
  module Commands
@@ -30,6 +31,7 @@ module ThreeScaleToolbox
30
31
  flag nil, 'activedocs-hidden', 'Create ActiveDocs in hidden state'
31
32
  flag nil, 'skip-openapi-validation', 'Skip OpenAPI schema validation'
32
33
  flag nil, 'prefix-matching', 'Use prefix matching instead of strict matching on mapping rules derived from openapi operations'
34
+ option nil, 'oidc-issuer-type', 'OIDC Issuer Type (rest, keycloak)', argument: :required, transform: IssuerTypeTransformer.new
33
35
  option nil, 'oidc-issuer-endpoint', 'OIDC Issuer Endpoint', argument: :required
34
36
  option nil, 'default-credentials-userkey', 'Default credentials policy userkey', argument: :required
35
37
  option nil, 'override-private-basepath', 'Override the basepath for the private URLs', argument: :required
@@ -77,6 +79,7 @@ module ThreeScaleToolbox
77
79
  threescale_client: threescale_client(fetch_required_option(:destination)),
78
80
  target_system_name: options[:target_system_name],
79
81
  activedocs_published: !options[:'activedocs-hidden'],
82
+ oidc_issuer_type: options[:'oidc-issuer-type'],
80
83
  oidc_issuer_endpoint: options[:'oidc-issuer-endpoint'],
81
84
  default_credentials_userkey: options[:'default-credentials-userkey'],
82
85
  skip_openapi_validation: options[:'skip-openapi-validation'],
@@ -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?