3scale_toolbox 0.15.0 → 0.18.2

Sign up to get free protection for your applications and to get access to all the features.
Files changed (151) hide show
  1. checksums.yaml +4 -4
  2. data/3scale_toolbox.gemspec +2 -2
  3. data/README.md +15 -9
  4. data/lib/3scale_toolbox.rb +3 -1
  5. data/lib/3scale_toolbox/3scale_client_factory.rb +3 -4
  6. data/lib/3scale_toolbox/cli.rb +4 -0
  7. data/lib/3scale_toolbox/cli/custom_table_printer.rb +32 -0
  8. data/lib/3scale_toolbox/cli/error_handler.rb +17 -14
  9. data/lib/3scale_toolbox/cli/json_printer.rb +13 -0
  10. data/lib/3scale_toolbox/cli/output_flag.rb +20 -0
  11. data/lib/3scale_toolbox/cli/yaml_printer.rb +13 -0
  12. data/lib/3scale_toolbox/commands.rb +7 -1
  13. data/lib/3scale_toolbox/commands/activedocs_command/apply_command.rb +33 -10
  14. data/lib/3scale_toolbox/commands/activedocs_command/create_command.rb +22 -7
  15. data/lib/3scale_toolbox/commands/activedocs_command/list_command.rb +10 -17
  16. data/lib/3scale_toolbox/commands/application_command/apply_command.rb +27 -4
  17. data/lib/3scale_toolbox/commands/application_command/create_command.rb +16 -1
  18. data/lib/3scale_toolbox/commands/application_command/list_command.rb +10 -13
  19. data/lib/3scale_toolbox/commands/application_command/show_command.rb +8 -14
  20. data/lib/3scale_toolbox/commands/backend_command.rb +22 -0
  21. data/lib/3scale_toolbox/commands/backend_command/copy_command.rb +65 -0
  22. data/lib/3scale_toolbox/commands/backend_command/copy_command/copy_mapping_rules_task.rb +36 -0
  23. data/lib/3scale_toolbox/commands/backend_command/copy_command/copy_methods_task.rb +35 -0
  24. data/lib/3scale_toolbox/commands/backend_command/copy_command/copy_metrics_task.rb +30 -0
  25. data/lib/3scale_toolbox/commands/backend_command/copy_command/create_or_update_target_backend_task.rb +46 -0
  26. data/lib/3scale_toolbox/commands/backend_command/copy_command/task.rb +67 -0
  27. data/lib/3scale_toolbox/commands/copy_command.rb +2 -2
  28. data/lib/3scale_toolbox/commands/copy_command/service_command.rb +40 -0
  29. data/lib/3scale_toolbox/commands/import_command/issuer_type_transformer.rb +16 -0
  30. data/lib/3scale_toolbox/commands/import_command/openapi.rb +6 -2
  31. data/lib/3scale_toolbox/commands/import_command/openapi/create_mapping_rule_step.rb +2 -1
  32. data/lib/3scale_toolbox/commands/import_command/openapi/create_method_step.rb +5 -14
  33. data/lib/3scale_toolbox/commands/import_command/openapi/step.rb +4 -0
  34. data/lib/3scale_toolbox/commands/import_command/openapi/update_service_proxy_step.rb +1 -0
  35. data/lib/3scale_toolbox/commands/methods_command/apply_command.rb +28 -8
  36. data/lib/3scale_toolbox/commands/methods_command/create_command.rb +23 -3
  37. data/lib/3scale_toolbox/commands/methods_command/delete_command.rb +1 -1
  38. data/lib/3scale_toolbox/commands/methods_command/list_command.rb +7 -13
  39. data/lib/3scale_toolbox/commands/metrics_command/apply_command.rb +26 -4
  40. data/lib/3scale_toolbox/commands/metrics_command/create_command.rb +23 -1
  41. data/lib/3scale_toolbox/commands/metrics_command/list_command.rb +7 -12
  42. data/lib/3scale_toolbox/commands/plans_command/apply_command.rb +36 -7
  43. data/lib/3scale_toolbox/commands/plans_command/create_command.rb +23 -1
  44. data/lib/3scale_toolbox/commands/plans_command/export/read_plan_limits_step.rb +1 -1
  45. data/lib/3scale_toolbox/commands/plans_command/export/read_plan_methods_step.rb +2 -2
  46. data/lib/3scale_toolbox/commands/plans_command/export/read_plan_metrics_step.rb +2 -2
  47. data/lib/3scale_toolbox/commands/plans_command/export/read_plan_pricing_rules_step.rb +1 -2
  48. data/lib/3scale_toolbox/commands/plans_command/export/step.rb +8 -20
  49. data/lib/3scale_toolbox/commands/plans_command/import/import_plan_limits_step.rb +12 -14
  50. data/lib/3scale_toolbox/commands/plans_command/import/import_plan_metrics_step.rb +6 -13
  51. data/lib/3scale_toolbox/commands/plans_command/import/import_plan_pricing_rules_step.rb +12 -20
  52. data/lib/3scale_toolbox/commands/plans_command/import/step.rb +2 -22
  53. data/lib/3scale_toolbox/commands/plans_command/list_command.rb +8 -13
  54. data/lib/3scale_toolbox/commands/plans_command/show_command.rb +7 -15
  55. data/lib/3scale_toolbox/commands/policies_command.rb +24 -0
  56. data/lib/3scale_toolbox/commands/policies_command/export_command.rb +98 -0
  57. data/lib/3scale_toolbox/commands/policies_command/import_command.rb +61 -0
  58. data/lib/3scale_toolbox/commands/product_command.rb +26 -0
  59. data/lib/3scale_toolbox/commands/product_command/copy_command.rb +82 -0
  60. data/lib/3scale_toolbox/commands/product_command/copy_command/copy_backends_task.rb +88 -0
  61. data/lib/3scale_toolbox/commands/product_command/copy_command/delete_target_backend_usages_task.rb +48 -0
  62. data/lib/3scale_toolbox/commands/product_command/export_command.rb +81 -0
  63. data/lib/3scale_toolbox/commands/product_command/import_command.rb +125 -0
  64. data/lib/3scale_toolbox/commands/proxy_config_command.rb +5 -0
  65. data/lib/3scale_toolbox/commands/proxy_config_command/deploy_command.rb +54 -0
  66. data/lib/3scale_toolbox/commands/proxy_config_command/export_command.rb +74 -0
  67. data/lib/3scale_toolbox/commands/proxy_config_command/helper.rb +15 -0
  68. data/lib/3scale_toolbox/commands/proxy_config_command/list_command.rb +13 -29
  69. data/lib/3scale_toolbox/commands/proxy_config_command/show_command.rb +20 -23
  70. data/lib/3scale_toolbox/commands/service_command.rb +7 -5
  71. data/lib/3scale_toolbox/commands/service_command/apply_command.rb +69 -58
  72. data/lib/3scale_toolbox/commands/service_command/copy_command.rb +95 -0
  73. data/lib/3scale_toolbox/commands/service_command/copy_command/bump_proxy_version_task.rb +36 -0
  74. data/lib/3scale_toolbox/commands/service_command/copy_command/copy_activedocs_task.rb +49 -0
  75. data/lib/3scale_toolbox/commands/service_command/copy_command/copy_app_plans_task.rb +35 -0
  76. data/lib/3scale_toolbox/commands/service_command/copy_command/copy_limits_task.rb +38 -0
  77. data/lib/3scale_toolbox/commands/service_command/copy_command/copy_mapping_rules_task.rb +35 -0
  78. data/lib/3scale_toolbox/commands/service_command/copy_command/copy_methods_task.rb +37 -0
  79. data/lib/3scale_toolbox/commands/service_command/copy_command/copy_metrics_task.rb +37 -0
  80. data/lib/3scale_toolbox/commands/service_command/copy_command/copy_policies_task.rb +17 -0
  81. data/lib/3scale_toolbox/commands/service_command/copy_command/copy_pricingrules_task.rb +41 -0
  82. data/lib/3scale_toolbox/commands/service_command/copy_command/copy_service_proxy_task.rb +32 -0
  83. data/lib/3scale_toolbox/commands/service_command/copy_command/create_or_update_service_task.rb +49 -0
  84. data/lib/3scale_toolbox/commands/service_command/copy_command/destroy_mapping_rules_task.rb +38 -0
  85. data/lib/3scale_toolbox/commands/service_command/copy_command/task.rb +85 -0
  86. data/lib/3scale_toolbox/commands/service_command/create_command.rb +58 -44
  87. data/lib/3scale_toolbox/commands/service_command/delete_command.rb +31 -33
  88. data/lib/3scale_toolbox/commands/service_command/list_command.rb +24 -34
  89. data/lib/3scale_toolbox/commands/service_command/show_command.rb +39 -44
  90. data/lib/3scale_toolbox/commands/update_command.rb +3 -3
  91. data/lib/3scale_toolbox/commands/update_command/{update_service.rb → service_command.rb} +22 -18
  92. data/lib/3scale_toolbox/commands/update_command/service_command/copy_service_settings_task.rb +35 -0
  93. data/lib/3scale_toolbox/commands/update_command/service_command/delete_activedocs_task.rb +24 -0
  94. data/lib/3scale_toolbox/crds.rb +16 -0
  95. data/lib/3scale_toolbox/crds/application_plan_dump.rb +19 -0
  96. data/lib/3scale_toolbox/crds/backend_dump.rb +39 -0
  97. data/lib/3scale_toolbox/crds/backend_mapping_rule_dump.rb +26 -0
  98. data/lib/3scale_toolbox/crds/backend_method_dump.rb +12 -0
  99. data/lib/3scale_toolbox/crds/backend_metric_dump.rb +13 -0
  100. data/lib/3scale_toolbox/crds/backend_parser.rb +55 -0
  101. data/lib/3scale_toolbox/crds/backend_usage_dump.rb +11 -0
  102. data/lib/3scale_toolbox/crds/limit_dump.rb +37 -0
  103. data/lib/3scale_toolbox/crds/mapping_rule_dump.rb +26 -0
  104. data/lib/3scale_toolbox/crds/method_dump.rb +12 -0
  105. data/lib/3scale_toolbox/crds/metric_dump.rb +13 -0
  106. data/lib/3scale_toolbox/crds/pricing_rule_dump.rb +38 -0
  107. data/lib/3scale_toolbox/crds/product_deployment_parser.rb +329 -0
  108. data/lib/3scale_toolbox/crds/product_dump.rb +157 -0
  109. data/lib/3scale_toolbox/crds/product_parser.rb +114 -0
  110. data/lib/3scale_toolbox/crds/remote.rb +682 -0
  111. data/lib/3scale_toolbox/entities.rb +8 -0
  112. data/lib/3scale_toolbox/entities/activedocs.rb +12 -0
  113. data/lib/3scale_toolbox/entities/application_plan.rb +74 -39
  114. data/lib/3scale_toolbox/entities/backend.rb +187 -0
  115. data/lib/3scale_toolbox/entities/backend_mapping_rule.rb +102 -0
  116. data/lib/3scale_toolbox/entities/backend_method.rb +99 -0
  117. data/lib/3scale_toolbox/entities/backend_metric.rb +98 -0
  118. data/lib/3scale_toolbox/entities/backend_usage.rb +105 -0
  119. data/lib/3scale_toolbox/entities/limit.rb +71 -0
  120. data/lib/3scale_toolbox/entities/mapping_rule.rb +90 -0
  121. data/lib/3scale_toolbox/entities/method.rb +33 -19
  122. data/lib/3scale_toolbox/entities/metric.rb +29 -18
  123. data/lib/3scale_toolbox/entities/pricing_rule.rb +63 -0
  124. data/lib/3scale_toolbox/entities/proxy_config.rb +0 -1
  125. data/lib/3scale_toolbox/entities/service.rb +166 -48
  126. data/lib/3scale_toolbox/error.rb +53 -0
  127. data/lib/3scale_toolbox/helper.rb +17 -0
  128. data/lib/3scale_toolbox/openapi/oas3.rb +1 -1
  129. data/lib/3scale_toolbox/proxy_logger.rb +5 -1
  130. data/lib/3scale_toolbox/remote_cache.rb +157 -0
  131. data/lib/3scale_toolbox/remotes.rb +2 -2
  132. data/lib/3scale_toolbox/version.rb +1 -1
  133. data/licenses.xml +113 -45
  134. metadata +75 -26
  135. data/lib/3scale_toolbox/commands/copy_command/copy_service.rb +0 -144
  136. data/lib/3scale_toolbox/tasks.rb +0 -15
  137. data/lib/3scale_toolbox/tasks/bump_proxy_version_task.rb +0 -32
  138. data/lib/3scale_toolbox/tasks/copy_activedocs_task.rb +0 -42
  139. data/lib/3scale_toolbox/tasks/copy_app_plans_task.rb +0 -31
  140. data/lib/3scale_toolbox/tasks/copy_limits_task.rb +0 -36
  141. data/lib/3scale_toolbox/tasks/copy_mapping_rules_task.rb +0 -32
  142. data/lib/3scale_toolbox/tasks/copy_methods_task.rb +0 -36
  143. data/lib/3scale_toolbox/tasks/copy_metrics_task.rb +0 -33
  144. data/lib/3scale_toolbox/tasks/copy_policies_task.rb +0 -13
  145. data/lib/3scale_toolbox/tasks/copy_pricingrules_task.rb +0 -41
  146. data/lib/3scale_toolbox/tasks/copy_service_proxy_task.rb +0 -13
  147. data/lib/3scale_toolbox/tasks/copy_service_settings_task.rb +0 -38
  148. data/lib/3scale_toolbox/tasks/copy_task.rb +0 -66
  149. data/lib/3scale_toolbox/tasks/delete_activedocs_task.rb +0 -22
  150. data/lib/3scale_toolbox/tasks/destroy_mapping_rules_task.rb +0 -22
  151. data/lib/3scale_toolbox/tasks/helper_task.rb +0 -25
@@ -0,0 +1,12 @@
1
+ module ThreeScaleToolbox
2
+ module CRD
3
+ module MethodSerializer
4
+ def to_cr
5
+ {
6
+ 'friendlyName' => friendly_name,
7
+ 'description' => description,
8
+ }
9
+ end
10
+ end
11
+ end
12
+ end
@@ -0,0 +1,13 @@
1
+ module ThreeScaleToolbox
2
+ module CRD
3
+ module MetricSerializer
4
+ def to_cr
5
+ {
6
+ 'friendlyName' => friendly_name,
7
+ 'unit' => unit,
8
+ 'description' => description,
9
+ }
10
+ end
11
+ end
12
+ end
13
+ end
@@ -0,0 +1,38 @@
1
+ module ThreeScaleToolbox
2
+ module CRD
3
+ module PricingRuleSerializer
4
+ def to_cr
5
+ {
6
+ 'from' => min,
7
+ 'to' => max,
8
+ 'pricePerUnit' => cost_per_unit,
9
+ 'metricMethodRef' => metric_system_name,
10
+ }
11
+ end
12
+
13
+ def metric_system_name
14
+ # Find in service methods
15
+ # Find in service metrics
16
+ # Find in backend methods
17
+ # Find in backend metrics
18
+ if (method = plan.service.methods.find { |m| m.id == metric_id })
19
+ { 'systemName' => method.system_name }
20
+ elsif (metric = plan.service.metrics.find { |m| m.id == metric_id })
21
+ { 'systemName' => metric.system_name }
22
+ elsif (backend = backend_from_metric)
23
+ if (backend_metric = backend.metrics.find { |m| m.id == metric_id })
24
+ { 'systemName' => backend_metric.system_name, 'backend' => backend.system_name }
25
+ elsif (backend_method = backend.methods.find { |m| m.id == metric_id })
26
+ { 'systemName' => backend_method.system_name, 'backend' => backend.system_name }
27
+ else
28
+ raise ThreeScaleToolbox::Error, "Unexpected error. PricingRule #{id} " \
29
+ "referencing to metric id #{metric_id} which has not been found"
30
+ end
31
+ else
32
+ raise ThreeScaleToolbox::Error, "Unexpected error. PricingRule #{id} " \
33
+ "referencing to metric id #{metric_id} which has not been found"
34
+ end
35
+ end
36
+ end
37
+ end
38
+ end
@@ -0,0 +1,329 @@
1
+ module ThreeScaleToolbox
2
+ module CRD
3
+ # ProductDeploymentCRDParser parses CRD Format
4
+ # https://github.com/3scale/3scale-operator/blob/3scale-2.10.0-CR2/doc/product-reference.md#productdeploymentspec
5
+ class ProductDeploymentParser
6
+ class ApicastHostedParser
7
+ attr_reader :authentication_parser
8
+
9
+ def initialize(cr)
10
+ @authentication_parser = AuthenticationParser.new(cr.fetch('authentication', {}))
11
+ end
12
+
13
+ def deployment_option
14
+ 'hosted'
15
+ end
16
+
17
+ def method_missing(name, *args)
18
+ authentication_parser.public_send(name, *args)
19
+ end
20
+
21
+ def respond_to_missing?(method_name, include_private = false)
22
+ super
23
+ end
24
+ end
25
+
26
+ class ApicastSelfManagedParser
27
+ attr_reader :authentication_parser, :cr
28
+
29
+ def initialize(cr)
30
+ @cr = cr
31
+ @authentication_parser = AuthenticationParser.new(cr.fetch('authentication', {}))
32
+ end
33
+
34
+ def deployment_option
35
+ 'self_managed'
36
+ end
37
+
38
+ def endpoint
39
+ cr['productionPublicBaseURL']
40
+ end
41
+
42
+ def sandbox_endpoint
43
+ cr['stagingPublicBaseURL']
44
+ end
45
+
46
+ def method_missing(name, *args)
47
+ authentication_parser.public_send(name, *args)
48
+ end
49
+
50
+ def respond_to_missing?(method_name, include_private = false)
51
+ super
52
+ end
53
+ end
54
+
55
+ class AuthenticationParser
56
+ attr_reader :parser
57
+
58
+ def initialize(cr)
59
+ @parser = if cr.has_key? 'userkey'
60
+ UserKeyParser.new(cr.fetch('userkey'))
61
+ elsif cr.has_key? 'appKeyAppID'
62
+ AppKeyParser.new(cr.fetch('appKeyAppID'))
63
+ elsif cr.has_key? 'oidc'
64
+ OidcParser.new(cr.fetch('oidc'))
65
+ else
66
+ raise ThreeScaleToolbox::Error, "Unknown authentication option: #{cr.keys}"
67
+ end
68
+ end
69
+
70
+
71
+ def method_missing(name, *args)
72
+ parser.public_send(name, *args)
73
+ end
74
+
75
+ def respond_to_missing?(method_name, include_private = false)
76
+ super
77
+ end
78
+ end
79
+
80
+ class AppKeyParser
81
+
82
+ attr_reader :cr, :security_parser, :gaterway_response_parser
83
+
84
+ def initialize(cr)
85
+ @cr = cr
86
+ @security_parser = SecurityParser.new(cr.fetch('security', {}))
87
+ @gaterway_response_parser = GatewayResponseParser.new(cr.fetch('gatewayResponse', {}))
88
+ end
89
+
90
+ def auth_app_id
91
+ cr['appID']
92
+ end
93
+
94
+ def auth_app_key
95
+ cr['appKey']
96
+ end
97
+
98
+ def credentials_location
99
+ cr['credentials']
100
+ end
101
+
102
+ def backend_version
103
+ '2'
104
+ end
105
+
106
+ def method_missing(name, *args)
107
+ res = security_parser.public_send(name, *args)
108
+ return res unless res.nil?
109
+
110
+ gaterway_response_parser.public_send(name, *args)
111
+ end
112
+
113
+ def respond_to_missing?(method_name, include_private = false)
114
+ super
115
+ end
116
+ end
117
+
118
+ class UserKeyParser
119
+ attr_reader :cr, :security_parser, :gaterway_response_parser
120
+
121
+ def initialize(cr)
122
+ @cr = cr
123
+ @security_parser = SecurityParser.new(cr.fetch('security', {}))
124
+ @gaterway_response_parser = GatewayResponseParser.new(cr.fetch('gatewayResponse', {}))
125
+ end
126
+
127
+ def backend_version
128
+ '1'
129
+ end
130
+
131
+ def auth_user_key
132
+ cr['authUserKey']
133
+ end
134
+
135
+ def credentials_location
136
+ cr['credentials']
137
+ end
138
+
139
+ def method_missing(name, *args)
140
+ res = security_parser.public_send(name, *args)
141
+ return res unless res.nil?
142
+
143
+ gaterway_response_parser.public_send(name, *args)
144
+ end
145
+
146
+ def respond_to_missing?(method_name, include_private = false)
147
+ super
148
+ end
149
+ end
150
+
151
+ class OidcParser
152
+ attr_reader :cr, :security_parser, :gaterway_response_parser, :authentication_flow_parser
153
+
154
+ def initialize(cr)
155
+ @cr = cr
156
+ @security_parser = SecurityParser.new(cr.fetch('security', {}))
157
+ @gaterway_response_parser = GatewayResponseParser.new(cr.fetch('gatewayResponse', {}))
158
+ @authentication_flow_parser = AuthenticationFlowParser.new(cr.fetch('authenticationFlow', {}))
159
+ end
160
+
161
+ def backend_version
162
+ 'oidc'
163
+ end
164
+
165
+ def credentials_location
166
+ cr['credentials']
167
+ end
168
+
169
+ def oidc_issuer_endpoint
170
+ cr['issuerEndpoint']
171
+ end
172
+
173
+ def oidc_issuer_type
174
+ cr['issuerType']
175
+ end
176
+
177
+ def jwt_claim_with_client_id
178
+ cr['jwtClaimWithClientID']
179
+ end
180
+
181
+ def jwt_claim_with_client_id_type
182
+ cr['jwtClaimWithClientIDType']
183
+ end
184
+
185
+ def method_missing(name, *args)
186
+ res = authentication_flow_parser.public_send(name, *args)
187
+ return res unless res.nil?
188
+
189
+ res = security_parser.public_send(name, *args)
190
+ return res unless res.nil?
191
+
192
+ gaterway_response_parser.public_send(name, *args)
193
+ end
194
+
195
+ def respond_to_missing?(method_name, include_private = false)
196
+ super
197
+ end
198
+ end
199
+
200
+ class SecurityParser
201
+ attr_reader :cr
202
+
203
+ def initialize(cr)
204
+ @cr = cr
205
+ end
206
+
207
+ def secret_token
208
+ cr['secretToken']
209
+ end
210
+
211
+ def hostname_rewrite
212
+ cr['hostHeader']
213
+ end
214
+
215
+ def method_missing(name, *args)
216
+ nil
217
+ end
218
+ end
219
+
220
+ class GatewayResponseParser
221
+ attr_reader :cr
222
+
223
+ def initialize(cr)
224
+ @cr = cr
225
+ end
226
+
227
+ def error_auth_failed
228
+ cr['errorAuthFailed']
229
+ end
230
+
231
+ def error_auth_missing
232
+ cr['errorAuthMissing']
233
+ end
234
+
235
+ def error_status_auth_failed
236
+ cr['errorStatusAuthFailed']
237
+ end
238
+
239
+ def error_headers_auth_failed
240
+ cr['errorHeadersAuthFailed']
241
+ end
242
+
243
+ def error_status_auth_missing
244
+ cr['errorStatusAuthMissing']
245
+ end
246
+
247
+ def error_headers_auth_missing
248
+ cr['errorHeadersAuthMissing']
249
+ end
250
+
251
+ def error_no_match
252
+ cr['errorNoMatch']
253
+ end
254
+
255
+ def error_status_no_match
256
+ cr['errorStatusNoMatch']
257
+ end
258
+
259
+ def error_headers_no_match
260
+ cr['errorHeadersNoMatch']
261
+ end
262
+
263
+ def error_limits_exceeded
264
+ cr['errorLimitsExceeded']
265
+ end
266
+
267
+ def error_status_limits_exceeded
268
+ cr['errorStatusLimitsExceeded']
269
+ end
270
+
271
+ def error_headers_limits_exceeded
272
+ cr['errorHeadersLimitsExceeded']
273
+ end
274
+
275
+ def method_missing(name, *args)
276
+ nil
277
+ end
278
+ end
279
+
280
+ class AuthenticationFlowParser
281
+ attr_reader :cr
282
+
283
+ def initialize(cr)
284
+ @cr = cr
285
+ end
286
+
287
+ def standard_flow_enabled
288
+ cr.fetch('standardFlowEnabled', false)
289
+ end
290
+
291
+ def implicit_flow_enabled
292
+ cr.fetch('implicitFlowEnabled', false)
293
+ end
294
+
295
+ def service_accounts_enabled
296
+ cr.fetch('serviceAccountsEnabled', false)
297
+ end
298
+
299
+ def direct_access_grants_enabled
300
+ cr.fetch('directAccessGrantsEnabled', false)
301
+ end
302
+
303
+ def method_missing(name, *args)
304
+ nil
305
+ end
306
+ end
307
+
308
+ attr_reader :deployment_parser
309
+
310
+ def initialize(cr)
311
+ @deployment_parser = if cr.has_key? 'apicastSelfManaged'
312
+ ApicastSelfManagedParser.new(cr.fetch('apicastSelfManaged'))
313
+ elsif cr.has_key? 'apicastHosted'
314
+ ApicastHostedParser.new(cr.fetch('apicastHosted'))
315
+ else
316
+ raise ThreeScaleToolbox::Error, "Unknown deployment option: #{cr.keys}"
317
+ end
318
+ end
319
+
320
+ def method_missing(name, *args)
321
+ deployment_parser.public_send(name, *args)
322
+ end
323
+
324
+ def respond_to_missing?(method_name, include_private = false)
325
+ super
326
+ end
327
+ end
328
+ end
329
+ end
@@ -0,0 +1,157 @@
1
+ module ThreeScaleToolbox
2
+ module CRD
3
+ module ProductSerializer
4
+ def to_cr
5
+ {
6
+ 'apiVersion' => 'capabilities.3scale.net/v1beta1',
7
+ 'kind' => 'Product',
8
+ 'metadata' => {
9
+ 'annotations' => {
10
+ '3scale_toolbox_created_at' => Time.now.utc.iso8601,
11
+ '3scale_toolbox_version' => ThreeScaleToolbox::VERSION
12
+ },
13
+ 'name' => cr_name
14
+ },
15
+ 'spec' => {
16
+ 'name' => name,
17
+ 'systemName' => system_name,
18
+ 'description' => description,
19
+ 'mappingRules' => mapping_rules.map(&:to_cr),
20
+ 'metrics' => metrics.each_with_object({}) do |metric, hash|
21
+ hash[metric.system_name] = metric.to_cr
22
+ end,
23
+ 'methods' => methods.each_with_object({}) do |method, hash|
24
+ hash[method.system_name] = method.to_cr
25
+ end,
26
+ 'policies' => policies,
27
+ 'applicationPlans' => plans.each_with_object({}) do |app_plan, hash|
28
+ hash[app_plan.system_name] = app_plan.to_cr
29
+ end,
30
+ 'backendUsages' => backend_usage_list.each_with_object({}) do |backend_usage, hash|
31
+ hash[backend_usage.backend.system_name] = backend_usage.to_cr
32
+ end,
33
+ 'deployment' => deployment_to_cr
34
+ }
35
+ }
36
+ end
37
+
38
+ def cr_name
39
+ # Should be DNS1123 subdomain name
40
+ # TODO run validation for DNS1123
41
+ # https://kubernetes.io/docs/concepts/overview/working-with-objects/names/
42
+ "#{system_name.gsub(/[^[a-zA-Z0-9\-\.]]/, '.')}.#{Helper.random_lowercase_name}"
43
+ end
44
+
45
+ def deployment_to_cr
46
+ case deployment_option
47
+ when 'hosted'
48
+ hosted_deployment_to_cr
49
+ when 'self_managed'
50
+ self_managed_deployment_to_cr
51
+ else
52
+ raise ThreeScaleToolbox::Error, "Unknown deployment option: #{deployment_option}"
53
+ end
54
+ end
55
+
56
+ def hosted_deployment_to_cr
57
+ {
58
+ 'apicastHosted' => { 'authentication' => authentication_to_cr }
59
+ }
60
+ end
61
+
62
+ def self_managed_deployment_to_cr
63
+ {
64
+ 'apicastSelfManaged' => {
65
+ 'authentication' => authentication_to_cr,
66
+ 'stagingPublicBaseURL' => cached_proxy['sandbox_endpoint'],
67
+ 'productionPublicBaseURL' => cached_proxy['endpoint']
68
+ }
69
+ }
70
+ end
71
+
72
+ def authentication_to_cr
73
+ case backend_version
74
+ when '1'
75
+ userkey_authentication_to_cr
76
+ when '2'
77
+ appkey_authentication_to_cr
78
+ when 'oidc'
79
+ oidc_authentication_to_cr
80
+ else
81
+ raise ThreeScaleToolbox::Error, "Unknown backend_version: #{backend_version}"
82
+ end
83
+ end
84
+
85
+ def userkey_authentication_to_cr
86
+ {
87
+ 'userkey' => {
88
+ 'authUserKey' => cached_proxy['auth_user_key'],
89
+ 'credentials' => cached_proxy['credentials_location'],
90
+ 'security' => security_to_cr,
91
+ 'gatewayResponse' => gateway_response_to_cr
92
+ }
93
+ }
94
+ end
95
+
96
+ def appkey_authentication_to_cr
97
+ {
98
+ 'appKeyAppID' => {
99
+ 'appID' => cached_proxy['auth_app_id'],
100
+ 'appKey' => cached_proxy['auth_app_key'],
101
+ 'credentials' => cached_proxy['credentials_location'],
102
+ 'security' => security_to_cr,
103
+ 'gatewayResponse' => gateway_response_to_cr
104
+ }
105
+ }
106
+ end
107
+
108
+ def oidc_authentication_to_cr
109
+ {
110
+ 'oidc' => {
111
+ 'issuerType' => cached_proxy['oidc_issuer_type'],
112
+ 'issuerEndpoint' => cached_proxy['oidc_issuer_endpoint'],
113
+ 'jwtClaimWithClientID' => cached_proxy['jwt_claim_with_client_id'],
114
+ 'jwtClaimWithClientIDType' => cached_proxy['jwt_claim_with_client_id_type'],
115
+ 'authenticationFlow' => oidc_flow_to_cr,
116
+ 'credentials' => cached_proxy['credentials_location'],
117
+ 'security' => security_to_cr,
118
+ 'gatewayResponse' => gateway_response_to_cr
119
+ }
120
+ }
121
+ end
122
+
123
+ def oidc_flow_to_cr
124
+ {
125
+ 'standardFlowEnabled' => cached_oidc['standard_flow_enabled'],
126
+ 'implicitFlowEnabled' => cached_oidc['implicit_flow_enabled'],
127
+ 'serviceAccountsEnabled' => cached_oidc['service_accounts_enabled'],
128
+ 'directAccessGrantsEnabled' => cached_oidc['direct_access_grants_enabled']
129
+ }
130
+ end
131
+
132
+ def security_to_cr
133
+ {
134
+ 'hostHeader' => cached_proxy['hostname_rewrite'],
135
+ 'secretToken' => cached_proxy['secret_token']
136
+ }
137
+ end
138
+
139
+ def gateway_response_to_cr
140
+ {
141
+ 'errorStatusAuthFailed' => cached_proxy['error_status_auth_failed'],
142
+ 'errorHeadersAuthFailed' => cached_proxy['error_headers_auth_failed'],
143
+ 'errorAuthFailed' => cached_proxy['error_auth_failed'],
144
+ 'errorStatusAuthMissing' => cached_proxy['error_status_auth_missing'],
145
+ 'errorHeadersAuthMissing' => cached_proxy['error_headers_auth_missing'],
146
+ 'errorAuthMissing' => cached_proxy['error_auth_missing'],
147
+ 'errorStatusNoMatch' => cached_proxy['error_status_no_match'],
148
+ 'errorHeadersNoMatch' => cached_proxy['error_headers_no_match'],
149
+ 'errorNoMatch' => cached_proxy['error_no_match'],
150
+ 'errorStatusLimitsExceeded' => cached_proxy['error_status_limits_exceeded'],
151
+ 'errorHeadersLimitsExceeded' => cached_proxy['error_headers_limits_exceeded'],
152
+ 'errorLimitsExceeded' => cached_proxy['error_limits_exceeded']
153
+ }
154
+ end
155
+ end
156
+ end
157
+ end