3scale_toolbox 0.1.1 → 0.2.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.
- checksums.yaml +4 -4
- data/README.md +1 -1
- data/exe/3scale-copy +66 -28
- data/lib/3scale_toolbox/version.rb +1 -1
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 2210eb206ba4503c7a5e144ee02a579e128699e3
|
4
|
+
data.tar.gz: 36bb0f56aefa3366fb804c3c93699a778e982543
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 1891b41f0278ca43b71fbaa27b05a993babf785917e0fb4dadc5f188db31d6122897dd855e819af0f2ea4951376ef0048d5dde8d7d16ff76c9e71d774ef81d78
|
7
|
+
data.tar.gz: db6158bc763ac25acc70bc12ecac8667d8af0d7572345b3a66244e330a99d39253d3f6b0bf2ec417edfc2a26b1b0bf91a47e4bc811611b0072ac4c270ca862e7
|
data/README.md
CHANGED
@@ -20,7 +20,7 @@ Install the CLI:
|
|
20
20
|
Will create a new service, copy existing methods, metrics, application plans and their usage limits.
|
21
21
|
|
22
22
|
```shell
|
23
|
-
3scale copy service NUMBER --
|
23
|
+
3scale copy service NUMBER --source=https://provider_key@foo-admin.3scale.net --destination=https://provider_key@foo2-admin.3scale.net
|
24
24
|
```
|
25
25
|
|
26
26
|
## Development
|
data/exe/3scale-copy
CHANGED
@@ -5,63 +5,94 @@ require '3scale_toolbox/cli'
|
|
5
5
|
require 'optparse'
|
6
6
|
|
7
7
|
options = {}
|
8
|
-
|
8
|
+
|
9
|
+
parser = OptionParser.new do |parser|
|
9
10
|
parser.banner = '3scale copy <command> [options]'
|
10
11
|
|
11
|
-
parser.on('-
|
12
|
-
options[:
|
12
|
+
parser.on('-source', '--source SOURCE', "Source") do |domain|
|
13
|
+
options[:source] = domain
|
13
14
|
end
|
14
15
|
|
15
|
-
parser.on('-
|
16
|
-
options[:
|
16
|
+
parser.on('-destination', '--destination DESTINATION', "Destination") do |domain|
|
17
|
+
options[:destination] = domain
|
17
18
|
end
|
18
19
|
|
19
20
|
parser.on('-h', '--help', 'Prints this help') do
|
20
21
|
puts parser
|
22
|
+
puts
|
23
|
+
puts 'Available Commands:', ['service <service_id>', 'help']
|
21
24
|
exit
|
22
25
|
end
|
23
|
-
end
|
26
|
+
end
|
24
27
|
|
25
|
-
|
26
|
-
|
28
|
+
print_help = ->(error = nil) do
|
29
|
+
if error
|
30
|
+
puts "Error: #{error}"
|
31
|
+
puts
|
32
|
+
end
|
33
|
+
parser.parse(['--help'])
|
34
|
+
end
|
27
35
|
|
28
|
-
require '3scale/api'
|
29
36
|
|
30
|
-
|
37
|
+
parser.parse!
|
31
38
|
|
32
39
|
def compare_hashes(first, second, keys)
|
33
40
|
keys.map{ |key| first.fetch(key) } == keys.map{ |key| second.fetch(key) }
|
34
41
|
end
|
35
42
|
|
43
|
+
def fetch_option(options, key)
|
44
|
+
options.fetch(key) { raise OptionParser::MissingArgument, key }
|
45
|
+
end
|
46
|
+
|
47
|
+
def provider_key_from_url(url)
|
48
|
+
url[/\w*@/][0..-2]
|
49
|
+
end
|
50
|
+
|
51
|
+
def endpoint_from_url(url)
|
52
|
+
url.sub /\w*@/, ''
|
53
|
+
end
|
54
|
+
|
36
55
|
case (command = ARGV.shift)
|
37
56
|
when 'service'
|
38
|
-
|
39
|
-
|
40
|
-
|
57
|
+
source = fetch_option options, :source
|
58
|
+
destination = fetch_option options, :destination
|
59
|
+
|
60
|
+
require '3scale/api'
|
41
61
|
|
42
|
-
|
62
|
+
service_id = ARGV.shift or raise OptionParser::MissingArgument, 'service_id'
|
43
63
|
|
44
|
-
|
45
|
-
|
46
|
-
|
64
|
+
source_client = ThreeScale::API.new(
|
65
|
+
endpoint: endpoint_from_url(source),
|
66
|
+
provider_key: provider_key_from_url(source)
|
67
|
+
)
|
68
|
+
client = ThreeScale::API.new(
|
69
|
+
endpoint: endpoint_from_url(destination),
|
70
|
+
provider_key: provider_key_from_url(destination)
|
71
|
+
)
|
72
|
+
|
73
|
+
service = source_client.show_service(service_id)
|
74
|
+
copy = client.create_service(
|
75
|
+
name: service['name'],
|
76
|
+
end_user_registration_required: service['end_user_registration_required']
|
77
|
+
)
|
78
|
+
|
79
|
+
raise "Service has not been saved. Errors: #{copy['errors']}" unless copy['errors'].nil?
|
47
80
|
|
48
|
-
copy ||= client.create_service(name: name,
|
49
|
-
end_user_registration_required: service['end_user_registration_required'])
|
50
81
|
service_copy_id = copy.fetch('id')
|
51
82
|
|
52
83
|
puts "new service id #{service_copy_id}"
|
53
84
|
|
54
|
-
proxy =
|
85
|
+
proxy = source_client.show_proxy(service_id)
|
55
86
|
client.update_proxy(service_copy_id, proxy)
|
56
87
|
puts "updated proxy of #{service_copy_id} to match the original"
|
57
88
|
|
58
|
-
metrics =
|
89
|
+
metrics = source_client.list_metrics(service_id)
|
59
90
|
metrics_copies = client.list_metrics(service_copy_id)
|
60
91
|
|
61
92
|
hits = metrics.find{ |metric| metric['system_name'] == 'hits' } or raise 'missing hits metric'
|
62
93
|
hits_copy = metrics_copies.find{ |metric| metric['system_name'] == 'hits' } or raise 'missing hits metric'
|
63
94
|
|
64
|
-
methods =
|
95
|
+
methods = source_client.list_methods(service_id, hits['id'])
|
65
96
|
methods_copies = client.list_methods(service_copy_id, hits_copy['id'])
|
66
97
|
|
67
98
|
puts "original service hits metric #{hits['id']} has #{methods.size} methods"
|
@@ -79,7 +110,7 @@ case (command = ARGV.shift)
|
|
79
110
|
metrics_copies = client.list_metrics(service_copy_id)
|
80
111
|
|
81
112
|
puts "original service has #{metrics.size} metrics"
|
82
|
-
puts "copied service has #{
|
113
|
+
puts "copied service has #{metrics_copies.size} metrics"
|
83
114
|
|
84
115
|
missing_metrics = metrics.reject { |metric| metrics_copies.find{|copy| compare_hashes(metric, copy, ['system_name']) } }
|
85
116
|
|
@@ -90,7 +121,7 @@ case (command = ARGV.shift)
|
|
90
121
|
|
91
122
|
puts "created #{missing_metrics.size} metrics on the copied service"
|
92
123
|
|
93
|
-
plans =
|
124
|
+
plans = source_client.list_service_application_plans(service_id)
|
94
125
|
plan_copies = client.list_service_application_plans(service_copy_id)
|
95
126
|
|
96
127
|
puts "original service has #{plans.size} application plans "
|
@@ -120,12 +151,17 @@ case (command = ARGV.shift)
|
|
120
151
|
|
121
152
|
metrics_mapping = client.list_metrics(service_copy_id).map do |copy|
|
122
153
|
metric = metrics.find{|metric| metric.fetch('system_name') == copy.fetch('system_name') }
|
154
|
+
metric ||= {}
|
123
155
|
|
124
156
|
[metric['id'], copy['id']]
|
125
157
|
end.to_h
|
126
158
|
|
159
|
+
puts "destroying all mapping rules of the copy which have been created by default"
|
160
|
+
client.list_mapping_rules(service_copy_id).each do |mapping_rule|
|
161
|
+
client.delete_mapping_rule(service_copy_id, mapping_rule['id'])
|
162
|
+
end
|
127
163
|
|
128
|
-
mapping_rules =
|
164
|
+
mapping_rules = source_client.list_mapping_rules(service_id)
|
129
165
|
mapping_rules_copy = client.list_mapping_rules(service_copy_id)
|
130
166
|
|
131
167
|
puts "the original service has #{mapping_rules.size} mapping rules"
|
@@ -155,7 +191,7 @@ case (command = ARGV.shift)
|
|
155
191
|
puts unique_mapping_rules_copy.each{|rule| rule.delete('links') }
|
156
192
|
|
157
193
|
application_plan_mapping.each do |original_id, copy_id|
|
158
|
-
limits =
|
194
|
+
limits = source_client.list_application_plan_limits(original_id)
|
159
195
|
limits_copy = client.list_application_plan_limits(copy_id)
|
160
196
|
|
161
197
|
missing_limits = limits.reject { |limit| limits_copy.find{|limit_copy| limit.fetch('period') == limit_copy.fetch('period') } }
|
@@ -166,8 +202,10 @@ case (command = ARGV.shift)
|
|
166
202
|
end
|
167
203
|
puts "copied application plan #{copy_id} is missing #{missing_limits.size} from the original plan #{original_id}"
|
168
204
|
end
|
205
|
+
when 'help'
|
206
|
+
print_help.call
|
169
207
|
when nil
|
170
|
-
|
208
|
+
print_help.call("missing subcommand")
|
171
209
|
else
|
172
|
-
|
210
|
+
print_help.call("unknown command #{command}")
|
173
211
|
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: 3scale_toolbox
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.2.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Michal Cichra
|
8
8
|
autorequire:
|
9
9
|
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date: 2016-03-
|
11
|
+
date: 2016-03-30 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: bundler
|