knife-annex 0.0.1 → 0.0.2
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +8 -8
- data/CHANGELOG.md +5 -0
- data/lib/chef/knife/annex.rb +24 -12
- data/lib/knife-annex/version.rb +1 -1
- metadata +1 -1
checksums.yaml
CHANGED
@@ -1,15 +1,15 @@
|
|
1
1
|
---
|
2
2
|
!binary "U0hBMQ==":
|
3
3
|
metadata.gz: !binary |-
|
4
|
-
|
4
|
+
MmNjZWJjMTUxNzA4ZWViMDk3MzhhMWJiZjg2MWFkMDVkNTk0ZmU4MQ==
|
5
5
|
data.tar.gz: !binary |-
|
6
|
-
|
6
|
+
MGZmMzMwZjZiNzNiMWJhYTFkMGJlMzBjZTJhNGIzNDI2N2M2NTg1YQ==
|
7
7
|
!binary "U0hBNTEy":
|
8
8
|
metadata.gz: !binary |-
|
9
|
-
|
10
|
-
|
11
|
-
|
9
|
+
NTJjYzViMTU4NjM5Y2NhNDViYWFlNmYzNDZkYWViNjAyMDFjNzgzOTI2Njhh
|
10
|
+
NDA1ZWQxM2ExZWVlMDllZjcyY2YxYzhiODZkOTAwY2M3MDM4NTBkOTYzZGYz
|
11
|
+
ZmQ2MTExNGM3YmQ2Y2QzMmYzNjVlNzQ5MjQ5NzA1MTE3OTllMWQ=
|
12
12
|
data.tar.gz: !binary |-
|
13
|
-
|
14
|
-
|
15
|
-
|
13
|
+
N2MxMzJkZmVhNGJjZjljYzYyZmNkMDA2NzU1N2I5YzY2Y2U1NzY3MGM3Nzg3
|
14
|
+
OGQ1ODc2MTIyYjc3MjgyMTYxYjkzOWYxYjA2MTljMGNjN2VjZTJkYjEzM2U5
|
15
|
+
MGY4MDI4MzA1N2MzZGJjM2RkN2ZhMjEzOWU1YTM5Zjk5OGYyMDg=
|
data/CHANGELOG.md
CHANGED
data/lib/chef/knife/annex.rb
CHANGED
@@ -20,31 +20,39 @@ class Chef
|
|
20
20
|
def admins
|
21
21
|
@admins ||= Chef::User.list.
|
22
22
|
keys.
|
23
|
-
select { |u| !IGNORE_USERS.include?(u) && Chef::User.load(u).admin }
|
23
|
+
select { |u| !IGNORE_USERS.include?(u) && Chef::User.load(u).admin }.
|
24
|
+
join(',')
|
24
25
|
end
|
25
26
|
|
26
27
|
def annex_key
|
27
|
-
ENV['ANNEX_KEY']
|
28
|
+
ENV['ANNEX_KEY']
|
28
29
|
end
|
29
30
|
|
30
31
|
def annex_file
|
31
32
|
ENV['ANNEX_FILE']
|
32
33
|
end
|
33
34
|
|
35
|
+
def item_id
|
36
|
+
# We substitute characters invalid for data bag item id with
|
37
|
+
# underscore, and add "__i" to allow any file extension
|
38
|
+
# including ".keys" without confusing list for rekey.
|
39
|
+
@item_id ||= annex_key.gsub(/[^[:alnum:]_\-]+/, '_') << "__i"
|
40
|
+
end
|
41
|
+
|
34
42
|
def run
|
35
43
|
case ENV['ANNEX_ACTION']
|
36
44
|
when 'store'
|
37
45
|
begin
|
38
|
-
item = ChefVault::Item.load(DATA_BAG,
|
46
|
+
item = ChefVault::Item.load(DATA_BAG, item_id)
|
39
47
|
rescue ChefVault::Exceptions::KeysNotFound,
|
40
48
|
ChefVault::Exceptions::ItemNotFound
|
41
|
-
item = ChefVault::Item.new(DATA_BAG,
|
49
|
+
item = ChefVault::Item.new(DATA_BAG, item_id)
|
42
50
|
end
|
43
51
|
item['data'] = File.read(annex_file)
|
44
|
-
item.admins(admins
|
52
|
+
item.admins(admins)
|
45
53
|
item.save
|
46
54
|
when 'retrieve'
|
47
|
-
item = ChefVault::Item.load(DATA_BAG,
|
55
|
+
item = ChefVault::Item.load(DATA_BAG, item_id)
|
48
56
|
if annex_file
|
49
57
|
File.write(annex_file, item['data'])
|
50
58
|
else
|
@@ -52,24 +60,28 @@ class Chef
|
|
52
60
|
end
|
53
61
|
when 'remove'
|
54
62
|
delete_object(ChefVault::Item, "#{vault}/#{item}", "chef_vault_item") do
|
55
|
-
ChefVault::Item.load(DATA_BAG,
|
63
|
+
ChefVault::Item.load(DATA_BAG, item_id).destroy
|
56
64
|
end
|
57
65
|
when 'checkpresent'
|
58
66
|
begin
|
59
|
-
ChefVault::Item.load(DATA_BAG,
|
67
|
+
ChefVault::Item.load(DATA_BAG, item_id)
|
60
68
|
rescue ChefVault::Exceptions::KeysNotFound,
|
61
69
|
ChefVault::Exceptions::ItemNotFound
|
62
70
|
# not found, we do nothing
|
63
71
|
else
|
64
|
-
# found
|
72
|
+
# found, print original key
|
65
73
|
puts annex_key
|
66
74
|
end
|
67
75
|
else
|
68
|
-
|
69
|
-
Chef::DataBag.load(DATA_BAG).keys.
|
76
|
+
item_ids = ( @name_args.empty? ?
|
77
|
+
Chef::DataBag.load(DATA_BAG).keys.grep(/__i$/) :
|
70
78
|
@name_args )
|
71
79
|
if config[:rotate_keys]
|
72
|
-
|
80
|
+
item_ids.each do |item_id|
|
81
|
+
item = ChefVault::Item.load(DATA_BAG, item_id)
|
82
|
+
item.admins(admins)
|
83
|
+
item.rotate_keys!
|
84
|
+
end
|
73
85
|
else
|
74
86
|
puts "Use this command as git-annex hook"
|
75
87
|
end
|
data/lib/knife-annex/version.rb
CHANGED