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 CHANGED
@@ -1,15 +1,15 @@
1
1
  ---
2
2
  !binary "U0hBMQ==":
3
3
  metadata.gz: !binary |-
4
- NjYxZjc4ZjhhNzViZGZhZTA1YTc1MWZlNTFjMWU4ZDg4YjkyNTU2Nw==
4
+ MmNjZWJjMTUxNzA4ZWViMDk3MzhhMWJiZjg2MWFkMDVkNTk0ZmU4MQ==
5
5
  data.tar.gz: !binary |-
6
- MWI2YjEyOTkwMGRjYTUzNWZiMDdjNzQ5OWExMWUzNzg3YmM3ZDk1Ng==
6
+ MGZmMzMwZjZiNzNiMWJhYTFkMGJlMzBjZTJhNGIzNDI2N2M2NTg1YQ==
7
7
  !binary "U0hBNTEy":
8
8
  metadata.gz: !binary |-
9
- ZmE2OTNkZTY3MzY5ZTg0NGQ0NWY2YjE1ZmNiYmJjOGQ0NTllY2U5MzE0OTMx
10
- ODJiYTZlZmIxOTlkY2MyZmZkMzQyYWRkMjUzZTY5MjM5NzNhOWEyZDg1MDQ3
11
- NzUyN2ZiMDFiMGYxZDIyNzFjOTE4NThjOWFhM2NlNjM1OWNkODc=
9
+ NTJjYzViMTU4NjM5Y2NhNDViYWFlNmYzNDZkYWViNjAyMDFjNzgzOTI2Njhh
10
+ NDA1ZWQxM2ExZWVlMDllZjcyY2YxYzhiODZkOTAwY2M3MDM4NTBkOTYzZGYz
11
+ ZmQ2MTExNGM3YmQ2Y2QzMmYzNjVlNzQ5MjQ5NzA1MTE3OTllMWQ=
12
12
  data.tar.gz: !binary |-
13
- M2M2NTQ3YzFiMmI0Njk5MTY0NjRiNTNlM2Q2YzhmZDI1ZGYwMGY4NGQ1MGVi
14
- MjM4YzYyNDJhODFhYjk3ZTM3NzNmNDE5ZTcyNGYyNDgzZWNjNDc4NWQ0NTI3
15
- MGIxNjA1OWEwNDAxY2NjY2VjZmQ0ZTFiYzI1NzA4NWRiYjhmMjQ=
13
+ N2MxMzJkZmVhNGJjZjljYzYyZmNkMDA2NzU1N2I5YzY2Y2U1NzY3MGM3Nzg3
14
+ OGQ1ODc2MTIyYjc3MjgyMTYxYjkzOWYxYjA2MTljMGNjN2VjZTJkYjEzM2U5
15
+ MGY4MDI4MzA1N2MzZGJjM2RkN2ZhMjEzOWU1YTM5Zjk5OGYyMDg=
@@ -1,5 +1,10 @@
1
1
  # Changes
2
2
 
3
+ ## 0.0.2
4
+ * Fix checkpresent hook
5
+ * Fix item ids
6
+ * Actually rotate keys
7
+
3
8
  ## 0.0.1
4
9
 
5
10
  * Initial release
@@ -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'].gsub(/[^[:alnum:]_\-]+/, '_')
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, annex_key)
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, annex_key)
49
+ item = ChefVault::Item.new(DATA_BAG, item_id)
42
50
  end
43
51
  item['data'] = File.read(annex_file)
44
- item.admins(admins.join(','))
52
+ item.admins(admins)
45
53
  item.save
46
54
  when 'retrieve'
47
- item = ChefVault::Item.load(DATA_BAG, annex_key)
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, annex_key).destroy
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, annex_key)
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
- items = ( @name_args.empty? ?
69
- Chef::DataBag.load(DATA_BAG).keys.reject { |k| k =~ /_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
- p rotate: items
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
@@ -1,3 +1,3 @@
1
1
  module KnifeAnnex
2
- VERSION = "0.0.1"
2
+ VERSION = "0.0.2"
3
3
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: knife-annex
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.1
4
+ version: 0.0.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - Maciej Pasternacki