hiera-gpg 0.1.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (2) hide show
  1. data/lib/hiera/backend/gpg_backend.rb +63 -0
  2. metadata +64 -0
@@ -0,0 +1,63 @@
1
+ class Hiera
2
+ module Backend
3
+ class Gpg_backend
4
+ def lookup(key, scope, order_override, resolution_type)
5
+ Hiera.debug("loaded gpg_backend")
6
+ answer = Backend.empty_answer(resolution_type)
7
+
8
+ Backend.datasources(scope, order_override) do |source|
9
+ gpgfile = Backend.datafile(:gpg, scope, source, "gpg") || next
10
+
11
+
12
+ Hiera.debug("Loading file #{gpgfile}")
13
+
14
+ ## Homedir is the location of our GPG private keys
15
+ ## default: ~/.gnupg
16
+ homedir = Config[:gpg][:homedir] || ""
17
+
18
+ plain = decrypt(gpgfile, homedir)
19
+
20
+ if plain.empty?
21
+ Hiera.debug("GPG decrypt returned empty string")
22
+ next
23
+ end
24
+
25
+ data = YAML.load(plain)
26
+
27
+ next if data.empty?
28
+ next unless data.include?(key)
29
+
30
+
31
+ case resolution_type
32
+ when :array
33
+ answer << Backend.parse_answer(data[key], scope)
34
+ else
35
+ answer = Backend.parse_answer(data[key], scope)
36
+ break
37
+ end
38
+ end
39
+ return answer
40
+
41
+ end
42
+
43
+
44
+ def decrypt (file, homedir)
45
+ # This should be tied in with the gpgme API, but for now
46
+ # we just shell this out to the gpg command, a future todo
47
+ # is to replace this.
48
+ #
49
+
50
+ opts = ["--decrypt"]
51
+ if !homedir.empty?
52
+ opts << "--homedir #{homedir}"
53
+ end
54
+
55
+ data = `/usr/bin/env gpg #{opts.join(" ")} < #{file} 2> /dev/null`
56
+ Hiera.debug("Return code of gpg command was #{$?}")
57
+ return data
58
+ end
59
+ end
60
+ end
61
+ end
62
+
63
+
metadata ADDED
@@ -0,0 +1,64 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: hiera-gpg
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.0
5
+ platform: ruby
6
+ authors:
7
+ - Craig Dunn
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+
12
+ date: 2011-10-10 00:00:00 +01:00
13
+ default_executable:
14
+ dependencies:
15
+ - !ruby/object:Gem::Dependency
16
+ name: hiera
17
+ type: :runtime
18
+ version_requirement:
19
+ version_requirements: !ruby/object:Gem::Requirement
20
+ requirements:
21
+ - - ~>
22
+ - !ruby/object:Gem::Version
23
+ version: 0.2.0
24
+ version:
25
+ description: Hiera backend for storing secret data and decrypting with GPG
26
+ email: craig@craigdunn.org
27
+ executables: []
28
+
29
+ extensions: []
30
+
31
+ extra_rdoc_files: []
32
+
33
+ files:
34
+ - lib/hiera
35
+ - lib/hiera/backend
36
+ - lib/hiera/backend/gpg_backend.rb
37
+ has_rdoc: false
38
+ homepage: http://github.com/crayfishx/hiera-gpg
39
+ post_install_message:
40
+ rdoc_options: []
41
+
42
+ require_paths:
43
+ - lib
44
+ required_ruby_version: !ruby/object:Gem::Requirement
45
+ requirements:
46
+ - - ">="
47
+ - !ruby/object:Gem::Version
48
+ version: "0"
49
+ version:
50
+ required_rubygems_version: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - ">="
53
+ - !ruby/object:Gem::Version
54
+ version: "0"
55
+ version:
56
+ requirements: []
57
+
58
+ rubyforge_project:
59
+ rubygems_version: 1.3.1
60
+ signing_key:
61
+ specification_version: 2
62
+ summary: GPG backend for Hiera
63
+ test_files: []
64
+