3scale_toolbox 0.1.0 → 0.1.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/exe/3scale-copy +43 -6
- data/lib/3scale_toolbox/version.rb +1 -1
- metadata +4 -4
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 01faabdd78fbba6945dd5c5648ecf70a7ee5307e
|
4
|
+
data.tar.gz: 09110b6291e2698d984816afa1ae195e1607c39d
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: ba7960b6f7f2259297a95867fcd6fad4fc1916c9248a69571713399789cb6f9d5f4f64f33db14136f583507ff59dcf5649eb1aa5d820acca1d21689783b315d2
|
7
|
+
data.tar.gz: 334aa15532171cbdecf9c744d4446de407da481459271f26412ab4f1f16e4349b38dc99cfb65bce863b6f993654147d7a4affb333ece3531ccbf9794d20ab3df
|
data/exe/3scale-copy
CHANGED
@@ -29,6 +29,10 @@ require '3scale/api'
|
|
29
29
|
|
30
30
|
client = ThreeScale::API.new(endpoint: endpoint, provider_key: provider_key)
|
31
31
|
|
32
|
+
def compare_hashes(first, second, keys)
|
33
|
+
keys.map{ |key| first.fetch(key) } == keys.map{ |key| second.fetch(key) }
|
34
|
+
end
|
35
|
+
|
32
36
|
case (command = ARGV.shift)
|
33
37
|
when 'service'
|
34
38
|
service_id = ARGV.shift or raise OptionParser::MissingArgument, 'service_id'
|
@@ -47,6 +51,10 @@ case (command = ARGV.shift)
|
|
47
51
|
|
48
52
|
puts "new service id #{service_copy_id}"
|
49
53
|
|
54
|
+
proxy = client.show_proxy(service_id)
|
55
|
+
client.update_proxy(service_copy_id, proxy)
|
56
|
+
puts "updated proxy of #{service_copy_id} to match the original"
|
57
|
+
|
50
58
|
metrics = client.list_metrics(service_id)
|
51
59
|
metrics_copies = client.list_metrics(service_copy_id)
|
52
60
|
|
@@ -59,7 +67,7 @@ case (command = ARGV.shift)
|
|
59
67
|
puts "original service hits metric #{hits['id']} has #{methods.size} methods"
|
60
68
|
puts "copied service hits metric #{hits_copy['id']} has #{methods_copies.size} methods"
|
61
69
|
|
62
|
-
missing_methods = methods.reject { |method| methods_copies.find{|copy| method
|
70
|
+
missing_methods = methods.reject { |method| methods_copies.find{|copy| compare_hashes(method, copy, ['system_name']) } }
|
63
71
|
|
64
72
|
puts "creating #{missing_methods.size} missing methods on copied service"
|
65
73
|
|
@@ -73,7 +81,7 @@ case (command = ARGV.shift)
|
|
73
81
|
puts "original service has #{metrics.size} metrics"
|
74
82
|
puts "copied service has #{metrics.size} metrics"
|
75
83
|
|
76
|
-
missing_metrics = metrics.reject { |metric| metrics_copies.find{|copy| metric
|
84
|
+
missing_metrics = metrics.reject { |metric| metrics_copies.find{|copy| compare_hashes(metric, copy, ['system_name']) } }
|
77
85
|
|
78
86
|
missing_metrics.map do |metric|
|
79
87
|
metric.delete('links')
|
@@ -116,6 +124,36 @@ case (command = ARGV.shift)
|
|
116
124
|
[metric['id'], copy['id']]
|
117
125
|
end.to_h
|
118
126
|
|
127
|
+
|
128
|
+
mapping_rules = client.list_mapping_rules(service_id)
|
129
|
+
mapping_rules_copy = client.list_mapping_rules(service_copy_id)
|
130
|
+
|
131
|
+
puts "the original service has #{mapping_rules.size} mapping rules"
|
132
|
+
puts "the copy has #{mapping_rules_copy.size} mapping rules"
|
133
|
+
|
134
|
+
unique_mapping_rules_copy = mapping_rules_copy.dup
|
135
|
+
|
136
|
+
missing_mapping_rules = mapping_rules.reject do |mapping_rule|
|
137
|
+
matching_metric = unique_mapping_rules_copy.find do |copy|
|
138
|
+
compare_hashes(mapping_rule, copy, %w(pattern http_method delta)) &&
|
139
|
+
metrics_mapping.fetch(mapping_rule.fetch('metric_id')) == copy.fetch('metric_id')
|
140
|
+
end
|
141
|
+
|
142
|
+
unique_mapping_rules_copy.delete(matching_metric)
|
143
|
+
end
|
144
|
+
|
145
|
+
puts "missing #{missing_mapping_rules.size} mapping rules"
|
146
|
+
|
147
|
+
missing_mapping_rules.each do |mapping_rule|
|
148
|
+
mapping_rule.delete('links')
|
149
|
+
mapping_rule['metric_id'] = metrics_mapping.fetch(mapping_rule.delete('metric_id'))
|
150
|
+
client.create_mapping_rule(service_copy_id, mapping_rule)
|
151
|
+
end
|
152
|
+
puts "created #{missing_mapping_rules.size} mapping rules"
|
153
|
+
|
154
|
+
puts "extra #{unique_mapping_rules_copy.size} mapping rules"
|
155
|
+
puts unique_mapping_rules_copy.each{|rule| rule.delete('links') }
|
156
|
+
|
119
157
|
application_plan_mapping.each do |original_id, copy_id|
|
120
158
|
limits = client.list_application_plan_limits(original_id)
|
121
159
|
limits_copy = client.list_application_plan_limits(copy_id)
|
@@ -128,9 +166,8 @@ case (command = ARGV.shift)
|
|
128
166
|
end
|
129
167
|
puts "copied application plan #{copy_id} is missing #{missing_limits.size} from the original plan #{original_id}"
|
130
168
|
end
|
131
|
-
|
132
|
-
|
133
|
-
|
169
|
+
when nil
|
170
|
+
puts "missing subcommand"
|
134
171
|
else
|
135
|
-
|
172
|
+
puts "unknown command #{command}"
|
136
173
|
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.1.
|
4
|
+
version: 0.1.1
|
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-16 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: bundler
|
@@ -44,14 +44,14 @@ dependencies:
|
|
44
44
|
requirements:
|
45
45
|
- - "~>"
|
46
46
|
- !ruby/object:Gem::Version
|
47
|
-
version: 0.1.
|
47
|
+
version: 0.1.2
|
48
48
|
type: :runtime
|
49
49
|
prerelease: false
|
50
50
|
version_requirements: !ruby/object:Gem::Requirement
|
51
51
|
requirements:
|
52
52
|
- - "~>"
|
53
53
|
- !ruby/object:Gem::Version
|
54
|
-
version: 0.1.
|
54
|
+
version: 0.1.2
|
55
55
|
description: 3scale CLI tools to manage your API from the terminal.
|
56
56
|
email:
|
57
57
|
- michal@3scale.net
|