codily 0.2.0 → 0.3.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: d5ccea29ad8df53e57d7ea9a3f4f7cf39f2c4ba4
4
- data.tar.gz: 6f15de9ea8cf711a27d9025ebbe188b67ee1c8ea
3
+ metadata.gz: 9101d20d4d6d01e3dca68580eb3604844848c74c
4
+ data.tar.gz: f0d018dace390dc03f9d4331ff9966c300378d40
5
5
  SHA512:
6
- metadata.gz: d2e8231b7369ac78b0977a95e0f77617a8cce6b6dd4f2ab075dc7c0c6d2461abe3813a116ba387a49c771c325f394249a803ec68362c8d05789f8f0e08138c63
7
- data.tar.gz: a5195b25eddb9b7cab63133be12bf54edc7d883381b008496bdd9e4161677f12920939188c1db5334b229656c3005141a6a17e22bdc6dadbe1aa6f5e7b47eb0d
6
+ metadata.gz: 7a6c69fea4315b52b6de100fd1990f045197a2737fc5dd282fbf49f70a8ee94bbec784fd732d99884008ec2350b746c5e2684ad77088ba35cfd9be9fcb9e721d
7
+ data.tar.gz: 36734debdd91241dc72e7e5a9dff19ff9d24ec28b478d4cdee6fcfea5b113bec50b8a5b23bf40797dc728834157423018f217142e612fdcad5bdf52fcdbf0ec5
data/README.md CHANGED
@@ -27,7 +27,8 @@ Usage: codily [options]
27
27
  -t, --target REGEXP Filter services by name to apply or export.
28
28
  -n, --dry-run Just displays the oprerations that would be performed, without actually running them.
29
29
  -D, --debug Debug mode
30
- -V, --target-version SVC_VER Choose version to export (format= service_name:version) This option can be used multiple time.
30
+ -A, --activate Activate after apply
31
+ -V, --target-version SVC_VER Choose version to export (format= service_name:version) This option can be used multiple time..
31
32
  ```
32
33
 
33
34
  ```
@@ -39,6 +40,7 @@ codily --export --target my-service --target-version my-service:42
39
40
  codily --export --file ./codily.rb
40
41
 
41
42
  codily --apply --file ./codily.rb
43
+ codily --apply --file ./codily.rb --activate
42
44
  codily --apply --file ./codily.rb --dry-run
43
45
  codily --apply --file ./codily.rb --target my-service
44
46
  ```
data/lib/codily/cli.rb CHANGED
@@ -44,7 +44,7 @@ module Codily
44
44
 
45
45
  require_fastly_auth!
46
46
 
47
- engine = Engine.new(fastly, present, desired, service_filter: options[:target])
47
+ engine = Engine.new(fastly, present, desired, service_filter: options[:target], activate: options[:activate])
48
48
 
49
49
  act = engine.run(dry_run: options[:dry_run])
50
50
 
@@ -108,9 +108,9 @@ module Codily
108
108
  options[:debug] = true
109
109
  end
110
110
 
111
- #opt.on('-A', '--activate', "Activate after apply") do
112
- # options[:activate] = true
113
- #end
111
+ opt.on('-A', '--activate', "Activate after apply") do
112
+ options[:activate] = true
113
+ end
114
114
 
115
115
  #opt.on('-d', '--diff', "Call diff API after apply") do
116
116
  # options[:diff] = true
data/lib/codily/engine.rb CHANGED
@@ -17,15 +17,16 @@ require 'codily/elements/settings'
17
17
 
18
18
  module Codily
19
19
  class Engine
20
- def initialize(fastly, present, desired, service_filter: nil)
20
+ def initialize(fastly, present, desired, service_filter: nil, activate: false)
21
21
  @fastly = fastly
22
22
  @present = present
23
23
  @desired = desired
24
24
 
25
25
  @service_filter = service_filter
26
+ @activate = activate
26
27
  end
27
28
 
28
- attr_reader :fastly, :present, :desired, :service_filter
29
+ attr_reader :fastly, :present, :desired, :service_filter, :activate
29
30
 
30
31
  ORDER = [
31
32
  Elements::Service,
@@ -49,14 +50,12 @@ module Codily
49
50
  puts
50
51
  end
51
52
 
52
- act_any = false
53
- act = false
54
-
55
- present.service_versions.each do |id, version|
53
+ affected_services.each do |key|
54
+ version = present.service_version_get(key)
56
55
  if !version[:dev]
57
56
  puts "CLONE VERSION: #{version[:name]}.#{version[:active]}"
58
57
  if !dry_run
59
- version[:dev] = fastly.get_version(id, version[:active]).clone.number
58
+ version[:dev] = fastly.get_version(version[:id], version[:active]).clone.number
60
59
  end
61
60
  end
62
61
  end
@@ -64,7 +63,6 @@ module Codily
64
63
  puts
65
64
 
66
65
  creations.each do |new_element|
67
- act_any = act = true
68
66
  puts "CREATE: #{new_element.inspect}"
69
67
 
70
68
  hash = new_element.as_hash
@@ -84,11 +82,7 @@ module Codily
84
82
  end
85
83
  end
86
84
 
87
- puts if act
88
- act = false
89
-
90
85
  updates.each do |present_elem, desired_elem|
91
- act_any = act = true
92
86
  puts "UPDATE: - #{present_elem.inspect}"
93
87
  puts " + #{desired_elem.inspect}"
94
88
 
@@ -104,11 +98,7 @@ module Codily
104
98
  end
105
99
  end
106
100
 
107
- puts if act
108
- act = false
109
-
110
101
  removals.each do |removed_element|
111
- act_any = act = true
112
102
  puts "DELETE: #{removed_element.inspect}"
113
103
 
114
104
  unless dry_run
@@ -116,37 +106,65 @@ module Codily
116
106
  end
117
107
  end
118
108
 
109
+ act_any = !affected_services.empty?
110
+
119
111
  unless act_any
120
112
  puts "No difference."
121
113
  end
114
+
115
+ puts
116
+
117
+ if activate
118
+ affected_services.each do |id|
119
+ version = present.service_version_get(id)
120
+ puts "ACTIVATE VERSION: #{version[:name]}.#{version[:dev]}"
121
+ if !dry_run
122
+ fastly.get_version(version[:id], version[:dev]).activate!
123
+ end
124
+ end
125
+ end
126
+
122
127
  act_any
123
128
  end
124
129
 
125
130
  def creations
126
- new_keys = desired_element_keys - present_element_keys
127
- sort_elements(new_keys.map{ |_| desired.elements[_[0]][_[1]] })
131
+ @creations ||= begin
132
+ new_keys = desired_element_keys - present_element_keys
133
+ sort_elements(new_keys.map{ |_| desired.elements[_[0]][_[1]] })
134
+ end
128
135
  end
129
136
 
130
137
  def updates
131
- common = present_element_keys & desired_element_keys
138
+ @updates ||= begin
139
+ common = present_element_keys & desired_element_keys
132
140
 
133
- present_existing = common.map{ |_| present.elements[_[0]][_[1]] }
134
- desired_existing = common.map{ |_| desired.elements[_[0]][_[1]] }
141
+ present_existing = common.map{ |_| present.elements[_[0]][_[1]] }
142
+ desired_existing = common.map{ |_| desired.elements[_[0]][_[1]] }
135
143
 
136
- raise '!?' if present_existing.size != desired_existing.size
144
+ raise '!?' if present_existing.size != desired_existing.size
137
145
 
138
- present_existing.zip(desired_existing).map do |present_elem, desired_elem|
139
- if present_elem.as_hash != desired_elem.as_hash
140
- [present_elem, desired_elem]
141
- else
142
- nil
143
- end
144
- end.compact.sort_by { |_| ORDER.index(_[0].class) }
146
+ present_existing.zip(desired_existing).map do |present_elem, desired_elem|
147
+ if present_elem.as_hash != desired_elem.as_hash
148
+ [present_elem, desired_elem]
149
+ else
150
+ nil
151
+ end
152
+ end.compact.sort_by { |_| ORDER.index(_[0].class) }
153
+ end
145
154
  end
146
155
 
147
156
  def removals
148
- removed_keys = present_element_keys - desired_element_keys
149
- sort_elements(removed_keys.map{ |_| present.elements[_[0]][_[1]] })
157
+ @removals ||= begin
158
+ removed_keys = present_element_keys - desired_element_keys
159
+ sort_elements(removed_keys.map{ |_| present.elements[_[0]][_[1]] })
160
+ end
161
+ end
162
+
163
+ def affected_services
164
+ [*creations, *removals, *updates.map(&:first)].
165
+ select { |_| _.parent_class == Elements::Service }.
166
+ map(&:parent_key).
167
+ uniq
150
168
  end
151
169
 
152
170
  private
@@ -1,3 +1,3 @@
1
1
  module Codily
2
- VERSION = "0.2.0"
2
+ VERSION = "0.3.0"
3
3
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: codily
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.2.0
4
+ version: 0.3.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Sorah Fukumori
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2016-09-21 00:00:00.000000000 Z
11
+ date: 2016-10-20 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: fastly
@@ -131,7 +131,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
131
131
  version: '0'
132
132
  requirements: []
133
133
  rubyforge_project:
134
- rubygems_version: 2.6.6
134
+ rubygems_version: 2.6.7
135
135
  signing_key:
136
136
  specification_version: 4
137
137
  summary: Codificate Fastly configuration