3scale_toolbox 0.10.0 → 0.11.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/README.md +21 -144
- data/lib/3scale_toolbox.rb +0 -1
- data/lib/3scale_toolbox/commands.rb +12 -0
- data/lib/3scale_toolbox/commands/3scale_command.rb +1 -1
- data/lib/3scale_toolbox/commands/account_command.rb +23 -0
- data/lib/3scale_toolbox/commands/account_command/find_command.rb +41 -0
- data/lib/3scale_toolbox/commands/activedocs_command.rb +32 -0
- data/lib/3scale_toolbox/commands/activedocs_command/apply_command.rb +127 -0
- data/lib/3scale_toolbox/commands/activedocs_command/create_command.rb +65 -0
- data/lib/3scale_toolbox/commands/activedocs_command/delete_command.rb +49 -0
- data/lib/3scale_toolbox/commands/activedocs_command/list_command.rb +54 -0
- data/lib/3scale_toolbox/commands/application_command.rb +30 -0
- data/lib/3scale_toolbox/commands/application_command/apply_command.rb +179 -0
- data/lib/3scale_toolbox/commands/application_command/create_command.rb +110 -0
- data/lib/3scale_toolbox/commands/application_command/delete_command.rb +57 -0
- data/lib/3scale_toolbox/commands/application_command/list_command.rb +124 -0
- data/lib/3scale_toolbox/commands/application_command/show_command.rb +72 -0
- data/lib/3scale_toolbox/commands/copy_command/copy_service.rb +97 -28
- data/lib/3scale_toolbox/commands/import_command/import_csv.rb +16 -17
- data/lib/3scale_toolbox/commands/import_command/openapi.rb +14 -10
- data/lib/3scale_toolbox/commands/import_command/openapi/create_service_step.rb +3 -2
- data/lib/3scale_toolbox/commands/import_command/openapi/method.rb +0 -1
- data/lib/3scale_toolbox/commands/import_command/openapi/step.rb +8 -1
- data/lib/3scale_toolbox/commands/import_command/openapi/update_service_proxy_step.rb +17 -7
- data/lib/3scale_toolbox/commands/methods_command.rb +4 -4
- data/lib/3scale_toolbox/commands/methods_command/apply_command.rb +2 -2
- data/lib/3scale_toolbox/commands/methods_command/create_command.rb +1 -1
- data/lib/3scale_toolbox/commands/metrics_command.rb +4 -4
- data/lib/3scale_toolbox/commands/metrics_command/apply_command.rb +2 -2
- data/lib/3scale_toolbox/commands/metrics_command/create_command.rb +1 -1
- data/lib/3scale_toolbox/commands/plans_command/apply_command.rb +7 -7
- data/lib/3scale_toolbox/commands/plans_command/create_command.rb +5 -5
- data/lib/3scale_toolbox/commands/policy_registry_command.rb +22 -0
- data/lib/3scale_toolbox/commands/policy_registry_command/copy_command.rb +85 -0
- data/lib/3scale_toolbox/commands/proxy_config_command.rb +30 -0
- data/lib/3scale_toolbox/commands/proxy_config_command/list_command.rb +78 -0
- data/lib/3scale_toolbox/commands/proxy_config_command/promote_command.rb +68 -0
- data/lib/3scale_toolbox/commands/proxy_config_command/show_command.rb +88 -0
- data/lib/3scale_toolbox/commands/service_command.rb +34 -0
- data/lib/3scale_toolbox/commands/service_command/apply_command.rb +77 -0
- data/lib/3scale_toolbox/commands/service_command/create_command.rb +59 -0
- data/lib/3scale_toolbox/commands/service_command/delete_command.rb +49 -0
- data/lib/3scale_toolbox/commands/service_command/list_command.rb +50 -0
- data/lib/3scale_toolbox/commands/service_command/show_command.rb +63 -0
- data/lib/3scale_toolbox/commands/update_command/update_service.rb +6 -3
- data/lib/3scale_toolbox/entities.rb +4 -0
- data/lib/3scale_toolbox/entities/account.rb +63 -0
- data/lib/3scale_toolbox/entities/activedocs.rb +88 -0
- data/lib/3scale_toolbox/entities/application.rb +124 -0
- data/lib/3scale_toolbox/entities/application_plan.rb +28 -4
- data/lib/3scale_toolbox/entities/base_entity.rb +44 -0
- data/lib/3scale_toolbox/entities/proxy_config.rb +58 -0
- data/lib/3scale_toolbox/entities/service.rb +42 -8
- data/lib/3scale_toolbox/error.rb +8 -0
- data/lib/3scale_toolbox/tasks.rb +2 -1
- data/lib/3scale_toolbox/tasks/bump_proxy_version_task.rb +32 -0
- data/lib/3scale_toolbox/tasks/copy_service_settings_task.rb +38 -0
- data/lib/3scale_toolbox/version.rb +1 -1
- metadata +36 -5
- data/lib/3scale_toolbox/tasks/update_service_settings_task.rb +0 -49
@@ -22,9 +22,9 @@ module ThreeScaleToolbox
|
|
22
22
|
def self.command
|
23
23
|
Cri::Command.define do
|
24
24
|
name 'openapi'
|
25
|
-
usage 'openapi [opts] -d <
|
26
|
-
summary 'Import API defintion in OpenAPI specification'
|
27
|
-
description 'Using an API definition format like OpenAPI, import to your 3scale API'
|
25
|
+
usage 'openapi [opts] -d <destination> <spec> (/path/to/your/spec/file.[json|yaml|yml] OR http[s]://domain/resource/path.[json|yaml|yml])'
|
26
|
+
summary 'Import API defintion in OpenAPI specification from a local file or URL'
|
27
|
+
description 'Using an API definition format like OpenAPI, import to your 3scale API directly from a local OpenAPI spec compliant file or a remote URL'
|
28
28
|
|
29
29
|
option :d, :destination, '3scale target instance. Format: "http[s]://<authentication>@3scale_domain"', argument: :required
|
30
30
|
option :t, 'target_system_name', 'Target system name', argument: :required
|
@@ -34,6 +34,8 @@ module ThreeScaleToolbox
|
|
34
34
|
option nil, 'default-credentials-userkey', 'Default credentials policy userkey', argument: :required
|
35
35
|
option nil, 'override-private-basepath', 'Override the basepath for the public URLs', argument: :required
|
36
36
|
option nil, 'override-public-basepath', 'Override the basepath for the private URLs', argument: :required
|
37
|
+
option nil, 'staging-public-base-url', 'Custom public staging URL', argument: :required
|
38
|
+
option nil, 'production-public-base-url', 'Custom public production URL', argument: :required
|
37
39
|
param :openapi_resource
|
38
40
|
|
39
41
|
runner OpenAPISubcommand
|
@@ -43,20 +45,20 @@ module ThreeScaleToolbox
|
|
43
45
|
def run
|
44
46
|
tasks = []
|
45
47
|
tasks << CreateServiceStep.new(context)
|
48
|
+
# other tasks might read proxy settings (CreateActiveDocsStep does)
|
49
|
+
tasks << UpdateServiceProxyStep.new(context)
|
46
50
|
tasks << CreateMethodsStep.new(context)
|
47
|
-
tasks <<
|
51
|
+
tasks << Tasks::DestroyMappingRulesTask.new(context)
|
48
52
|
tasks << CreateMappingRulesStep.new(context)
|
49
53
|
tasks << CreateActiveDocsStep.new(context)
|
50
54
|
tasks << UpdateServiceOidcConfStep.new(context)
|
51
55
|
tasks << UpdatePoliciesStep.new(context)
|
52
|
-
# Update proxy must be the last step
|
53
|
-
# Proxy update is the mechanism to increase version of the proxy,
|
54
|
-
# Hence propagating (mapping rules, poicies, oidc, auth) update to
|
55
|
-
# latest proxy config, making available to gateway.
|
56
|
-
tasks << UpdateServiceProxyStep.new(context)
|
57
56
|
|
58
57
|
# run tasks
|
59
58
|
tasks.each(&:call)
|
59
|
+
|
60
|
+
# This should be the last step
|
61
|
+
Tasks::BumpProxyVersionTask.new(service: context[:target]).call
|
60
62
|
end
|
61
63
|
|
62
64
|
private
|
@@ -76,7 +78,9 @@ module ThreeScaleToolbox
|
|
76
78
|
oidc_issuer_endpoint: options[:'oidc-issuer-endpoint'],
|
77
79
|
default_credentials_userkey: options[:'default-credentials-userkey'],
|
78
80
|
skip_openapi_validation: options[:'skip-openapi-validation'],
|
79
|
-
override_private_basepath: options[:'override-private-basepath']
|
81
|
+
override_private_basepath: options[:'override-private-basepath'],
|
82
|
+
production_public_base_url: options[:'production-public-base-url'],
|
83
|
+
staging_public_base_url: options[:'staging-public-base-url']
|
80
84
|
}
|
81
85
|
end
|
82
86
|
|
@@ -15,8 +15,7 @@ module ThreeScaleToolbox
|
|
15
15
|
if service.nil?
|
16
16
|
# Create service and update context
|
17
17
|
self.service = Entities::Service.create(remote: threescale_client,
|
18
|
-
|
19
|
-
system_name: service_system_name)
|
18
|
+
service_params: service_settings)
|
20
19
|
puts "Created service id: #{service.id}, name: #{service_name}"
|
21
20
|
else
|
22
21
|
service.update(service_settings)
|
@@ -35,6 +34,8 @@ module ThreeScaleToolbox
|
|
35
34
|
svc['name'] = service_name
|
36
35
|
svc['description'] = service_description
|
37
36
|
svc['backend_version'] = backend_version
|
37
|
+
svc['system_name'] = service_system_name
|
38
|
+
svc['deployment_option'] = 'self_managed' if !production_public_base_url.nil? || !staging_public_base_url.nil?
|
38
39
|
end
|
39
40
|
end
|
40
41
|
|
@@ -43,7 +43,6 @@ module ThreeScaleToolbox
|
|
43
43
|
context[:api_spec_resource]
|
44
44
|
end
|
45
45
|
|
46
|
-
|
47
46
|
def security
|
48
47
|
api_spec.security
|
49
48
|
end
|
@@ -59,6 +58,14 @@ module ThreeScaleToolbox
|
|
59
58
|
def override_private_basepath
|
60
59
|
context[:override_private_basepath]
|
61
60
|
end
|
61
|
+
|
62
|
+
def production_public_base_url
|
63
|
+
context[:production_public_base_url]
|
64
|
+
end
|
65
|
+
|
66
|
+
def staging_public_base_url
|
67
|
+
context[:staging_public_base_url]
|
68
|
+
end
|
62
69
|
end
|
63
70
|
end
|
64
71
|
end
|
@@ -8,17 +8,15 @@ module ThreeScaleToolbox
|
|
8
8
|
##
|
9
9
|
# Updates Proxy config
|
10
10
|
def call
|
11
|
-
|
12
|
-
proxy_settings = {
|
13
|
-
# Adding harmless attribute to avoid empty body
|
14
|
-
# update_proxy cannot be done with empty body
|
15
|
-
# and must be done to increase proxy version
|
16
|
-
service_id: service.id
|
17
|
-
}
|
11
|
+
proxy_settings = {}
|
18
12
|
|
13
|
+
add_endpoint_settings(proxy_settings)
|
14
|
+
add_sandbox_endpoint_settings(proxy_settings)
|
19
15
|
add_api_backend_settings(proxy_settings)
|
20
16
|
add_security_proxy_settings(proxy_settings)
|
21
17
|
|
18
|
+
return unless proxy_settings.size.positive?
|
19
|
+
|
22
20
|
res = service.update_proxy proxy_settings
|
23
21
|
if (errors = res['errors'])
|
24
22
|
raise ThreeScaleToolbox::Error, "Service proxy has not been updated. #{errors}"
|
@@ -29,6 +27,18 @@ module ThreeScaleToolbox
|
|
29
27
|
|
30
28
|
private
|
31
29
|
|
30
|
+
def add_endpoint_settings(settings)
|
31
|
+
return if production_public_base_url.nil?
|
32
|
+
|
33
|
+
settings[:endpoint] = production_public_base_url
|
34
|
+
end
|
35
|
+
|
36
|
+
def add_sandbox_endpoint_settings(settings)
|
37
|
+
return if staging_public_base_url.nil?
|
38
|
+
|
39
|
+
settings[:sandbox_endpoint] = staging_public_base_url
|
40
|
+
end
|
41
|
+
|
32
42
|
def add_api_backend_settings(settings)
|
33
43
|
return if api_spec.host.nil?
|
34
44
|
|
@@ -9,10 +9,10 @@ module ThreeScaleToolbox
|
|
9
9
|
include ThreeScaleToolbox::Command
|
10
10
|
def self.command
|
11
11
|
Cri::Command.define do
|
12
|
-
name '
|
13
|
-
usage '
|
14
|
-
summary '
|
15
|
-
description '
|
12
|
+
name 'method'
|
13
|
+
usage 'method <sub-command> [options]'
|
14
|
+
summary 'method super command'
|
15
|
+
description 'Method commands'
|
16
16
|
|
17
17
|
run do |_opts, _args, cmd|
|
18
18
|
puts cmd.help
|
@@ -9,10 +9,10 @@ module ThreeScaleToolbox
|
|
9
9
|
include ThreeScaleToolbox::Command
|
10
10
|
def self.command
|
11
11
|
Cri::Command.define do
|
12
|
-
name '
|
13
|
-
usage '
|
14
|
-
summary '
|
15
|
-
description '
|
12
|
+
name 'metric'
|
13
|
+
usage 'metric <sub-command> [options]'
|
14
|
+
summary 'metric super command'
|
15
|
+
description 'Metric commands'
|
16
16
|
|
17
17
|
run do |_opts, _args, cmd|
|
18
18
|
puts cmd.help
|
@@ -19,8 +19,8 @@ module ThreeScaleToolbox
|
|
19
19
|
flag :p, :publish, 'Publish application plan'
|
20
20
|
flag nil, :hide, 'Hide application plan'
|
21
21
|
option nil, 'approval-required', 'Applications require approval. true or false', argument: :required, transform: ThreeScaleToolbox::Helper::BooleanTransformer.new
|
22
|
-
option nil, 'cost-per-month', 'Cost per month', argument: :required, transform: method(:
|
23
|
-
option nil, 'setup-fee', 'Setup fee', argument: :required, transform: method(:
|
22
|
+
option nil, 'cost-per-month', 'Cost per month', argument: :required, transform: method(:Float)
|
23
|
+
option nil, 'setup-fee', 'Setup fee', argument: :required, transform: method(:Float)
|
24
24
|
option nil, 'trial-period-days', 'Trial period days', argument: :required, transform: method(:Integer)
|
25
25
|
option nil, 'end-user-required', 'End user required. true or false', argument: :required, transform: ThreeScaleToolbox::Helper::BooleanTransformer.new
|
26
26
|
param :remote
|
@@ -88,23 +88,23 @@ module ThreeScaleToolbox
|
|
88
88
|
end
|
89
89
|
|
90
90
|
def option_default
|
91
|
-
|
91
|
+
options.fetch(:default, false)
|
92
92
|
end
|
93
93
|
|
94
94
|
def option_enabled
|
95
|
-
|
95
|
+
options.fetch(:enabled, false)
|
96
96
|
end
|
97
97
|
|
98
98
|
def option_disabled
|
99
|
-
|
99
|
+
options.fetch(:disabled, false)
|
100
100
|
end
|
101
101
|
|
102
102
|
def option_publish
|
103
|
-
|
103
|
+
options.fetch(:publish, false)
|
104
104
|
end
|
105
105
|
|
106
106
|
def option_hide
|
107
|
-
|
107
|
+
options.fetch(:hide, false)
|
108
108
|
end
|
109
109
|
|
110
110
|
def service
|
@@ -17,8 +17,8 @@ module ThreeScaleToolbox
|
|
17
17
|
flag nil, :disabled, 'Disables all methods and metrics in this application plan'
|
18
18
|
flag :p, :publish, 'Publish application plan'
|
19
19
|
option nil, 'approval-required', 'Applications require approval. true or false', argument: :required, transform: ThreeScaleToolbox::Helper::BooleanTransformer.new
|
20
|
-
option nil, 'cost-per-month', 'Cost per month', argument: :required, transform: method(:
|
21
|
-
option nil, 'setup-fee', 'Setup fee', argument: :required, transform: method(:
|
20
|
+
option nil, 'cost-per-month', 'Cost per month', argument: :required, transform: method(:Float)
|
21
|
+
option nil, 'setup-fee', 'Setup fee', argument: :required, transform: method(:Float)
|
22
22
|
option nil, 'trial-period-days', 'Trial period days', argument: :required, transform: method(:Integer)
|
23
23
|
option nil, 'end-user-required', 'End user required. true or false', argument: :required, transform: ThreeScaleToolbox::Helper::BooleanTransformer.new
|
24
24
|
param :remote
|
@@ -64,15 +64,15 @@ module ThreeScaleToolbox
|
|
64
64
|
end
|
65
65
|
|
66
66
|
def option_default
|
67
|
-
|
67
|
+
options.fetch(:default, false)
|
68
68
|
end
|
69
69
|
|
70
70
|
def option_disabled
|
71
|
-
|
71
|
+
options.fetch(:disabled, false)
|
72
72
|
end
|
73
73
|
|
74
74
|
def option_publish
|
75
|
-
|
75
|
+
options.fetch(:publish, false)
|
76
76
|
end
|
77
77
|
|
78
78
|
def service
|
@@ -0,0 +1,22 @@
|
|
1
|
+
require '3scale_toolbox/commands/policy_registry_command/copy_command'
|
2
|
+
|
3
|
+
module ThreeScaleToolbox
|
4
|
+
module Commands
|
5
|
+
module PolicyRegistryCommand
|
6
|
+
include ThreeScaleToolbox::Command
|
7
|
+
def self.command
|
8
|
+
Cri::Command.define do
|
9
|
+
name 'policy-registry'
|
10
|
+
usage 'policy-registry <sub-command> [options]'
|
11
|
+
summary 'policy-registry super command'
|
12
|
+
description 'Pôlicy Registry commands'
|
13
|
+
|
14
|
+
run do |_opts, _args, cmd|
|
15
|
+
puts cmd.help
|
16
|
+
end
|
17
|
+
end
|
18
|
+
end
|
19
|
+
add_subcommand(Copy::CopySubcommand)
|
20
|
+
end
|
21
|
+
end
|
22
|
+
end
|
@@ -0,0 +1,85 @@
|
|
1
|
+
module ThreeScaleToolbox
|
2
|
+
module Commands
|
3
|
+
module PolicyRegistryCommand
|
4
|
+
module Copy
|
5
|
+
class CopySubcommand < Cri::CommandRunner
|
6
|
+
include ThreeScaleToolbox::Command
|
7
|
+
|
8
|
+
def self.command
|
9
|
+
Cri::Command.define do
|
10
|
+
name 'copy'
|
11
|
+
usage 'copy [opts] <source_remote> <target_remote>'
|
12
|
+
summary 'Copy policy registry'
|
13
|
+
description 'Copy policy registry'
|
14
|
+
|
15
|
+
param :source_remote
|
16
|
+
param :target_remote
|
17
|
+
|
18
|
+
runner CopySubcommand
|
19
|
+
end
|
20
|
+
end
|
21
|
+
|
22
|
+
def run
|
23
|
+
source_policies = source_remote.list_policy_registry
|
24
|
+
if source_policies.respond_to?(:has_key?) && (errors = source_policies['errors'])
|
25
|
+
raise ThreeScaleToolbox::ThreeScaleApiError.new('Could not list source policy registry', errors)
|
26
|
+
end
|
27
|
+
|
28
|
+
target_policies = target_remote.list_policy_registry
|
29
|
+
if target_policies.respond_to?(:has_key?) && (errors = target_policies['errors'])
|
30
|
+
raise ThreeScaleToolbox::ThreeScaleApiError.new('Could not list target policy registry', errors)
|
31
|
+
end
|
32
|
+
|
33
|
+
# Create missing
|
34
|
+
missing = missing_policies(source_policies, target_policies)
|
35
|
+
missing.each do |policy|
|
36
|
+
new_policy_registry = target_remote.create_policy_registry(policy)
|
37
|
+
if (errors = new_policy_registry['errors'])
|
38
|
+
raise ThreeScaleToolbox::ThreeScaleApiError.new('Could not create target policy registry', errors)
|
39
|
+
end
|
40
|
+
end
|
41
|
+
|
42
|
+
# Update those matching
|
43
|
+
matching = matching_policies(source_policies, target_policies)
|
44
|
+
matching.each do |policy|
|
45
|
+
updated_policy = target_remote.update_policy_registry(
|
46
|
+
"#{policy['name']}-#{policy['version']}", policy
|
47
|
+
)
|
48
|
+
if (errors = updated_policy['errors'])
|
49
|
+
raise ThreeScaleToolbox::ThreeScaleApiError.new('Could not update target policy registry', errors)
|
50
|
+
end
|
51
|
+
end
|
52
|
+
|
53
|
+
puts "Created #{missing.size} missing policies on target tenant"
|
54
|
+
puts "Updated #{matching.size} matching policies on target tenant"
|
55
|
+
end
|
56
|
+
|
57
|
+
private
|
58
|
+
|
59
|
+
def missing_policies(source_policies, target_policies)
|
60
|
+
ThreeScaleToolbox::Helper.array_difference(source_policies,
|
61
|
+
target_policies) do |source, target|
|
62
|
+
ThreeScaleToolbox::Helper.compare_hashes(source, target, %w[name version])
|
63
|
+
end
|
64
|
+
end
|
65
|
+
|
66
|
+
def matching_policies(source_policies, target_policies)
|
67
|
+
source_policies.select do |source|
|
68
|
+
target_policies.find do |target|
|
69
|
+
ThreeScaleToolbox::Helper.compare_hashes(source, target, %w[name version])
|
70
|
+
end
|
71
|
+
end
|
72
|
+
end
|
73
|
+
|
74
|
+
def source_remote
|
75
|
+
@source_remote ||= threescale_client(arguments[:source_remote])
|
76
|
+
end
|
77
|
+
|
78
|
+
def target_remote
|
79
|
+
@target_remote ||= threescale_client(arguments[:target_remote])
|
80
|
+
end
|
81
|
+
end
|
82
|
+
end
|
83
|
+
end
|
84
|
+
end
|
85
|
+
end
|
@@ -0,0 +1,30 @@
|
|
1
|
+
require 'cri'
|
2
|
+
require '3scale_toolbox/base_command'
|
3
|
+
require '3scale_toolbox/commands/proxy_config_command/list_command'
|
4
|
+
require '3scale_toolbox/commands/proxy_config_command/show_command'
|
5
|
+
require '3scale_toolbox/commands/proxy_config_command/promote_command'
|
6
|
+
|
7
|
+
module ThreeScaleToolbox
|
8
|
+
module Commands
|
9
|
+
module ProxyConfigCommand
|
10
|
+
include ThreeScaleToolbox::Command
|
11
|
+
|
12
|
+
def self.command
|
13
|
+
Cri::Command.define do
|
14
|
+
name 'proxy-config'
|
15
|
+
usage 'proxy-config <sub-command> [options]'
|
16
|
+
summary 'proxy-config super command'
|
17
|
+
description 'Manage your Proxy Configurations'
|
18
|
+
|
19
|
+
run do |_opts, _args, cmd|
|
20
|
+
puts cmd.help
|
21
|
+
end
|
22
|
+
end
|
23
|
+
end
|
24
|
+
|
25
|
+
add_subcommand(List::ListSubcommand)
|
26
|
+
add_subcommand(Show::ShowSubcommand)
|
27
|
+
add_subcommand(Promote::PromoteSubcommand)
|
28
|
+
end
|
29
|
+
end
|
30
|
+
end
|