etcdist 0.0.6 → 0.0.7

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: 7a580dea440da658265dfe8df8b0ef76279b396a
4
- data.tar.gz: d1849a2743d6ef4619ea50b9c53ee6e5b0b797a9
3
+ metadata.gz: d0526fae37a18d1b0e85b8672c0962adaa15b7f1
4
+ data.tar.gz: a96e751c7045642a80c072e43ae19a0eacd007cf
5
5
  SHA512:
6
- metadata.gz: 9c3ccd1069755f49c8a3bd6939ecaecb86792d45c560366f33df6156a7f615359800e373721942f3019263c345046a5a20b93d5b6bb56b29d6a4ff79954d6160
7
- data.tar.gz: 11c1bd5a0682da315cfa09077cad21c3f1d0eafd81f4b768798c865f44893aecdb6b1df5597ccf76c553ed8bd9231e9806c21dd89bcb19769e994053f1579a6a
6
+ metadata.gz: 4d44b969b49f88baf6207019f851cb912fda3bbd8cf2d6eb06f73356cfeca1cc889a9b3bb5888cc65f865c25a0262b165a97ffffd956272ad095a1f8df06068c
7
+ data.tar.gz: 834e05e047afc19f0ef355edd3cc4b9e283fd070f45248cc8d21f34801fcf1c354d7439101910c477a241c3b61ece6c2445fe51f6186d573bf7d021d7a353dcb
@@ -1,4 +1,5 @@
1
1
  require 'etcdist/log'
2
+ require 'pathname'
2
3
 
3
4
  module Etcdist
4
5
  # Reads data from file system into directories, keys and values.
@@ -23,6 +24,17 @@ module Etcdist
23
24
  end
24
25
  end
25
26
 
27
+ def all_dirs
28
+ @dir = Pathname.new File.expand_path(@dir)
29
+ root = Pathname.new '/'
30
+
31
+ descendant_dirs = Dir[File.join(@dir, '**', '*')].select { |p| File.directory? p }
32
+ relative_descendant_dirs = descendant_dirs.map { |d| Pathname.new(d).relative_path_from @dir }
33
+ dirs = relative_descendant_dirs.map { |d| root.join(d).to_s }
34
+
35
+ dirs.push '/'
36
+ end
37
+
26
38
  private
27
39
 
28
40
  def read_non_blank_lines(f)
@@ -1,3 +1,3 @@
1
1
  module Etcdist
2
- VERSION = '0.0.6'
2
+ VERSION = '0.0.7'
3
3
  end
@@ -20,9 +20,21 @@ module Etcdist
20
20
  count[:put] += put(dir, entries)
21
21
  count[:del] += delete(dir, entries) if @dangerous
22
22
  end
23
+
23
24
  Log.info("#{count[:put]} entries added/modified. #{count[:del]} entries deleted.")
24
25
  end
25
26
 
27
+ # Deletes any directories that are present in etcd but not on the file system
28
+ def delete_absent_directories(all_dirs)
29
+ dirs_to_delete = all_etcd_dirs('/').sort.reverse - all_dirs
30
+ dirs_to_delete.each do |dir|
31
+ Log.debug("deleting directory #{dir}") if @dangerous
32
+ @etcd.delete(dir, recursive: true) if @dangerous && !@dry_run
33
+ end
34
+
35
+ Log.info("#{dirs_to_delete.length} directories deleted.") if @dangerous
36
+ end
37
+
26
38
  private
27
39
 
28
40
  def put(dir, entries)
@@ -43,5 +55,21 @@ module Etcdist
43
55
  def entries_in(dir)
44
56
  @etcd.exists?(dir) ? Hash[@etcd.get(dir).children.map { |n| [n.key.sub(/.*\//, ''), n.value] }] : {}
45
57
  end
58
+
59
+ def all_etcd_dirs(dir)
60
+ root_node = @etcd.get(dir, recursive: true).node
61
+
62
+ nodes_to_process_stack = [root_node]
63
+ result = []
64
+
65
+ until nodes_to_process_stack.empty?
66
+ node = nodes_to_process_stack.pop
67
+ result.push(node.key)
68
+ child_dir_nodes = node.children.select(dir)
69
+ child_dir_nodes.each { |child_dir_node| nodes_to_process_stack.push(child_dir_node) }
70
+ end
71
+
72
+ result
73
+ end
46
74
  end
47
75
  end
data/lib/etcdist.rb CHANGED
@@ -20,6 +20,7 @@ module Etcdist
20
20
 
21
21
  Log.info("using etcd host at: #{etcd.host}:#{etcd.port}")
22
22
  writer.write(reader.read)
23
+ writer.delete_absent_directories(reader.all_dirs)
23
24
  Log.info('finished successfully.')
24
25
  end
25
26
  end
@@ -1,7 +1,6 @@
1
1
  require 'spec_helper'
2
2
 
3
3
  describe Etcdist::Reader do
4
-
5
4
  let(:reader) do
6
5
  dir = File.join(File.dirname(__FILE__), '../data')
7
6
  Etcdist::Reader.new(dir)
@@ -1,7 +1,6 @@
1
1
  require 'spec_helper'
2
2
 
3
3
  describe Etcdist::Writer do
4
-
5
4
  let(:etcd) do
6
5
  double('etcd').as_null_object
7
6
  end
@@ -11,7 +10,6 @@ describe Etcdist::Writer do
11
10
  end
12
11
 
13
12
  describe 'PUTs' do
14
-
15
13
  it 'should put entries in etcd' do
16
14
  pretend_etcd_contains(nothing)
17
15
  expect(etcd).to receive(:set).with('/foo/bar/fish', value: 'plankton')
@@ -45,7 +43,6 @@ describe Etcdist::Writer do
45
43
  end
46
44
 
47
45
  describe 'DELETEs' do
48
-
49
46
  it 'should not delete extra entries by default' do
50
47
  pretend_etcd_contains('/foo' => { 'fish' => 'plankton' })
51
48
  expect(etcd).not_to receive(:delete)
@@ -53,7 +50,6 @@ describe Etcdist::Writer do
53
50
  end
54
51
 
55
52
  context 'dangerous mode' do
56
-
57
53
  let(:writer) do
58
54
  Etcdist::Writer.new(etcd, dangerous: true)
59
55
  end
@@ -63,7 +59,6 @@ describe Etcdist::Writer do
63
59
  expect(etcd).to receive(:delete).with('/foo/fish')
64
60
  writer.write('/foo' => { 'cows' => 'grass' })
65
61
  end
66
-
67
62
  end
68
63
 
69
64
  context 'dry run mode' do
@@ -76,9 +71,6 @@ describe Etcdist::Writer do
76
71
  expect(etcd).not_to receive(:delete)
77
72
  writer.write('/foo' => { 'cows' => 'grass' })
78
73
  end
79
-
80
74
  end
81
-
82
75
  end
83
-
84
76
  end
data/spec/etcdist_spec.rb CHANGED
@@ -1,9 +1,7 @@
1
1
  require 'spec_helper'
2
2
 
3
3
  describe Etcdist do
4
-
5
4
  skip 'acceptance test - expects etcd running on localhost:4001' do
6
-
7
5
  let(:etcd_opts) do
8
6
  { host: 'localhost', port: 4001 }
9
7
  end
@@ -20,7 +18,5 @@ describe Etcdist do
20
18
  Etcdist.execute(dir, etcd_opts)
21
19
  expect(etcd.get('/etcdist/foo/fish').value).to eq('plankton')
22
20
  end
23
-
24
21
  end
25
-
26
22
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: etcdist
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.6
4
+ version: 0.0.7
5
5
  platform: ruby
6
6
  authors:
7
7
  - Springer, Part of Springer Science+Business Media
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2014-11-13 00:00:00.000000000 Z
11
+ date: 2015-01-06 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: etcd