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 +4 -4
- data/lib/etcdist/reader.rb +12 -0
- data/lib/etcdist/version.rb +1 -1
- data/lib/etcdist/writer.rb +28 -0
- data/lib/etcdist.rb +1 -0
- data/spec/etcdist/reader_spec.rb +0 -1
- data/spec/etcdist/writer_spec.rb +0 -8
- data/spec/etcdist_spec.rb +0 -4
- 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: d0526fae37a18d1b0e85b8672c0962adaa15b7f1
|
4
|
+
data.tar.gz: a96e751c7045642a80c072e43ae19a0eacd007cf
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 4d44b969b49f88baf6207019f851cb912fda3bbd8cf2d6eb06f73356cfeca1cc889a9b3bb5888cc65f865c25a0262b165a97ffffd956272ad095a1f8df06068c
|
7
|
+
data.tar.gz: 834e05e047afc19f0ef355edd3cc4b9e283fd070f45248cc8d21f34801fcf1c354d7439101910c477a241c3b61ece6c2445fe51f6186d573bf7d021d7a353dcb
|
data/lib/etcdist/reader.rb
CHANGED
@@ -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)
|
data/lib/etcdist/version.rb
CHANGED
data/lib/etcdist/writer.rb
CHANGED
@@ -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
data/spec/etcdist/reader_spec.rb
CHANGED
data/spec/etcdist/writer_spec.rb
CHANGED
@@ -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.
|
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:
|
11
|
+
date: 2015-01-06 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: etcd
|