hiera-crypt 0.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: f4f9ddadfa2194dd22b7bb21f285ad2aaa1c8f53
4
+ data.tar.gz: 5c8f3883285be5be667491484cd41a02d8137d08
5
+ SHA512:
6
+ metadata.gz: da6f2ad40a25a9b6098eeed5a4cfbe8393b7ad7ed9d3d882ccf72454d993b9eb6e60a917aae1ee146f19aa0ccc00262e095be71afb6084f29aee9905601ba3b0
7
+ data.tar.gz: 95becd1d2756194762e70c1e7f8924a1d808402e419138d9d874eb37a011f11f11b6f46e81bf7ef651e0bf9bdd08710814235cd855707ecf48a7d6c82ff859d0
data/.gitignore ADDED
@@ -0,0 +1,17 @@
1
+ *.gem
2
+ *.rbc
3
+ .bundle
4
+ .config
5
+ .yardoc
6
+ Gemfile.lock
7
+ InstalledFiles
8
+ _yardoc
9
+ coverage
10
+ doc/
11
+ lib/bundler/man
12
+ pkg
13
+ rdoc
14
+ spec/reports
15
+ test/tmp
16
+ test/version_tmp
17
+ tmp
data/Gemfile ADDED
@@ -0,0 +1,4 @@
1
+ source 'https://rubygems.org'
2
+
3
+ # Specify your gem's dependencies in hiera-crypt.gemspec
4
+ gemspec
data/LICENSE.txt ADDED
@@ -0,0 +1,22 @@
1
+ Copyright (c) 2013 Carl Jackson
2
+
3
+ MIT License
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining
6
+ a copy of this software and associated documentation files (the
7
+ "Software"), to deal in the Software without restriction, including
8
+ without limitation the rights to use, copy, modify, merge, publish,
9
+ distribute, sublicense, and/or sell copies of the Software, and to
10
+ permit persons to whom the Software is furnished to do so, subject to
11
+ the following conditions:
12
+
13
+ The above copyright notice and this permission notice shall be
14
+ included in all copies or substantial portions of the Software.
15
+
16
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
17
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
18
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
19
+ NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
20
+ LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
21
+ OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
22
+ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
data/README.md ADDED
@@ -0,0 +1,4 @@
1
+ # hiera-crypt
2
+
3
+ A data backend for Hiera that returns the decrypted contents of files. Works a
4
+ lot like hiera-file. Useful for secrets.
data/Rakefile ADDED
@@ -0,0 +1 @@
1
+ require "bundler/gem_tasks"
data/bin/hiera-crypt ADDED
@@ -0,0 +1,3 @@
1
+ #!/bin/bash
2
+
3
+ exec gpg --symmetric --cipher-algo AES256 "$@"
@@ -0,0 +1,26 @@
1
+ # coding: utf-8
2
+ lib = File.expand_path('../lib', __FILE__)
3
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
+
5
+ Gem::Specification.new do |spec|
6
+ spec.name = "hiera-crypt"
7
+ spec.version = "0.1"
8
+ spec.authors = ["Carl Jackson"]
9
+ spec.email = ["carl@avtok.com"]
10
+ spec.description = "Encrypted file backend for Hiera"
11
+ spec.summary = "A data backend for Hiera that returns the decrypted " +
12
+ "contents of files. Useful for secrets."
13
+ spec.homepage = "https://github.com/zenazn/hiera-crypt"
14
+ spec.license = "MIT"
15
+
16
+ spec.files = `git ls-files`.split($/)
17
+ spec.executables = spec.files.grep(%r{^bin/}) { |f| File.basename(f) }
18
+ spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
19
+ spec.require_paths = ["lib"]
20
+
21
+ spec.add_dependency "hiera", "~> 1.2.1"
22
+ spec.add_dependency "gpgme", "~> 2.0.2"
23
+
24
+ spec.add_development_dependency "bundler", "~> 1.3"
25
+ spec.add_development_dependency "rake"
26
+ end
@@ -0,0 +1,78 @@
1
+ require 'hiera/config'
2
+
3
+ class Hiera
4
+ module Backend
5
+ class Crypt_backend
6
+ DEBUG_PREFIX = '[crypt backend]'
7
+
8
+ def initialize()
9
+ unless Hiera::Config.include?(:crypt)
10
+ raise "Expected :crypt section in hiera.yaml"
11
+ end
12
+ conf = Hiera::Config[:crypt]
13
+ unless conf.include?(:password) || conf.include?(:password_file)
14
+ end
15
+ password = if conf.include?(:password)
16
+ conf[:password]
17
+ elsif conf.include?(:password_file)
18
+ debug("Reading password from #{conf[:password_file]}")
19
+ password_file = File.expand_path(conf[:password_file])
20
+ File.open(password_file, 'r').read.chomp
21
+ else
22
+ raise "Expected either a :password or :password_file"
23
+ end
24
+
25
+ @cache = {}
26
+
27
+ require 'gpgme'
28
+ @crypto = GPGME::Crypto.new(:password => password)
29
+ debug("Loaded!")
30
+ end
31
+
32
+ def lookup(key, scope, order_override, resolution_type)
33
+ unless [:array, :priority].include?(resolution_type)
34
+ raise "Unsupported resolution type #{resolution_type.inspect}"
35
+ end
36
+
37
+ debug("Looking up #{key}")
38
+
39
+ answers = nil
40
+ Backend.datasources(scope, order_override) do |source|
41
+ debug("Looking for data source #{source}")
42
+
43
+ file = File.join(Backend.datadir(:crypt, scope), source, "#{key}.gpg")
44
+ debug("Examining file #{file}")
45
+ next unless File.exist?(file)
46
+
47
+ plaintext = decrypt(file)
48
+
49
+ return plaintext if resolution_type == :priority
50
+
51
+ answers ||= []
52
+ answers << plaintext
53
+ end
54
+ answers
55
+ end
56
+
57
+ private
58
+ def decrypt(file)
59
+ stat = File.stat(f = File.new(file))
60
+ info = {:inode => stat.ino, :mtime => stat.mtime, :size => stat.size}
61
+ @cache.delete(file) if @cache[file] && @cache[file][:info] != info
62
+
63
+ debug("Using cached value for #{file}") if @cache.include?(file)
64
+
65
+ @cache[file] ||= {
66
+ :contents => @crypto.decrypt(f).to_s,
67
+ :info => info
68
+ }
69
+
70
+ @cache[file][:contents]
71
+ end
72
+
73
+ def debug(msg)
74
+ Hiera.debug("#{DEBUG_PREFIX} #{msg}")
75
+ end
76
+ end
77
+ end
78
+ end
@@ -0,0 +1,12 @@
1
+ Collaboratively administrate empowered markets via plug-and-play networks.
2
+ Dynamically procrastinate B2C users after installed base benefits. Dramatically
3
+ visualize customer directed convergence without revolutionary ROI.
4
+
5
+ Efficiently unleash cross-media information without cross-media value. Quickly
6
+ maximize timely deliverables for real-time schemas. Dramatically maintain
7
+ clicks-and-mortar solutions without functional solutions.
8
+
9
+ Completely synergize resource sucking relationships via premier niche markets.
10
+ Professionally cultivate one-to-one customer service with robust ideas.
11
+ Dynamically innovate resource-leveling customer service for state of the art
12
+ customer service.
@@ -0,0 +1,17 @@
1
+ Blue bottle butcher hoodie fingerstache quinoa. Banh mi biodiesel plaid,
2
+ try-hard Bushwick keffiyeh before they sold out. Blog selvage Pinterest
3
+ flexitarian, bespoke skateboard irony. Blog wayfarers asymmetrical, meggings
4
+ mumblecore mixtape leggings. Tattooed Portland ethnic cray umami trust fund.
5
+ Gastropub pork belly ethnic, blue bottle Godard craft beer wolf sartorial
6
+ single-origin coffee actually. 8-bit Brooklyn Odd Future roof party thundercats
7
+ messenger bag.
8
+
9
+ Freegan cardigan selfies thundercats, Pinterest hoodie you probably haven't
10
+ heard of them swag pickled try-hard kale chips raw denim post-ironic Godard.
11
+ Dreamcatcher Echo Park viral, sustainable VHS mumblecore twee DIY ugh gastropub
12
+ leggings. Pinterest Vice keytar, authentic polaroid Godard +1 hella cray pop-up
13
+ pug fap artisan Cosby sweater cred. Terry Richardson cred banh mi YOLO next
14
+ level. Neutra DIY hella bicycle rights, art party organic post-ironic put a bird
15
+ on it bitters sartorial Etsy flannel. Brunch church-key occupy, High Life
16
+ Brooklyn kogi shabby chic four loko fanny pack. Messenger bag deep v trust fund
17
+ irony freegan street art.
Binary file
Binary file
Binary file
data/test/everything ADDED
@@ -0,0 +1,34 @@
1
+ #!/usr/bin/env ruby
2
+ ROOT = File.expand_path(File.join(File.dirname(__FILE__), '..'))
3
+ $:.unshift(File.join(ROOT, 'lib'))
4
+
5
+ # This totally counts as a test. Promise!
6
+
7
+ $reference ||= File.open("#{ROOT}/test/data/data.txt").read
8
+ $reference2 ||= File.open("#{ROOT}/test/data/data2.txt").read
9
+
10
+ def okay?(key, hiera)
11
+ if hiera.lookup(key, 'not found', {'root' => ROOT}) == $reference
12
+ puts "Everything is ponies!"
13
+ else
14
+ puts "Everything is broken :("
15
+ exit 1
16
+ end
17
+ end
18
+ def a_okay?(key, hiera)
19
+ out = hiera.lookup(key, 'not found', {'root' => ROOT}, nil, :array)
20
+ if out == [$reference, $reference2]
21
+ puts "Everything is ponies!"
22
+ else
23
+ puts "Everything is broken :("
24
+ exit 1
25
+ end
26
+ end
27
+
28
+ require 'hiera'
29
+ okay? 'data.txt', Hiera.new(:config => "#{ROOT}/test/hiera-inline.yaml")
30
+ okay? 'backup.txt', Hiera.new(:config => "#{ROOT}/test/hiera-inline.yaml")
31
+ okay? 'data.txt', Hiera.new(:config => "#{ROOT}/test/hiera-file.yaml")
32
+ okay? 'backup.txt', Hiera.new(:config => "#{ROOT}/test/hiera-file.yaml")
33
+
34
+ a_okay? 'data.txt', Hiera.new(:config => "#{ROOT}/test/hiera-inline.yaml")
@@ -0,0 +1,11 @@
1
+ ---
2
+ :backends:
3
+ - crypt
4
+
5
+ :hierarchy:
6
+ - one
7
+ - two
8
+
9
+ :crypt:
10
+ :datadir: "%{root}/test/data"
11
+ :password_file: "%{root}/test/password"
@@ -0,0 +1,11 @@
1
+ ---
2
+ :backends:
3
+ - crypt
4
+
5
+ :hierarchy:
6
+ - one
7
+ - two
8
+
9
+ :crypt:
10
+ :datadir: "%{root}/test/data"
11
+ :password: synergy
data/test/password ADDED
@@ -0,0 +1 @@
1
+ synergy
metadata ADDED
@@ -0,0 +1,128 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: hiera-crypt
3
+ version: !ruby/object:Gem::Version
4
+ version: '0.1'
5
+ platform: ruby
6
+ authors:
7
+ - Carl Jackson
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2013-07-14 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: hiera
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - ~>
18
+ - !ruby/object:Gem::Version
19
+ version: 1.2.1
20
+ type: :runtime
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - ~>
25
+ - !ruby/object:Gem::Version
26
+ version: 1.2.1
27
+ - !ruby/object:Gem::Dependency
28
+ name: gpgme
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - ~>
32
+ - !ruby/object:Gem::Version
33
+ version: 2.0.2
34
+ type: :runtime
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - ~>
39
+ - !ruby/object:Gem::Version
40
+ version: 2.0.2
41
+ - !ruby/object:Gem::Dependency
42
+ name: bundler
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - ~>
46
+ - !ruby/object:Gem::Version
47
+ version: '1.3'
48
+ type: :development
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - ~>
53
+ - !ruby/object:Gem::Version
54
+ version: '1.3'
55
+ - !ruby/object:Gem::Dependency
56
+ name: rake
57
+ requirement: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - '>='
60
+ - !ruby/object:Gem::Version
61
+ version: '0'
62
+ type: :development
63
+ prerelease: false
64
+ version_requirements: !ruby/object:Gem::Requirement
65
+ requirements:
66
+ - - '>='
67
+ - !ruby/object:Gem::Version
68
+ version: '0'
69
+ description: Encrypted file backend for Hiera
70
+ email:
71
+ - carl@avtok.com
72
+ executables:
73
+ - hiera-crypt
74
+ extensions: []
75
+ extra_rdoc_files: []
76
+ files:
77
+ - .gitignore
78
+ - Gemfile
79
+ - LICENSE.txt
80
+ - README.md
81
+ - Rakefile
82
+ - bin/hiera-crypt
83
+ - hiera-crypt.gemspec
84
+ - lib/hiera/backend/crypt_backend.rb
85
+ - test/data/data.txt
86
+ - test/data/data2.txt
87
+ - test/data/one/data.txt.gpg
88
+ - test/data/two/backup.txt.gpg
89
+ - test/data/two/data.txt.gpg
90
+ - test/everything
91
+ - test/hiera-file.yaml
92
+ - test/hiera-inline.yaml
93
+ - test/password
94
+ homepage: https://github.com/zenazn/hiera-crypt
95
+ licenses:
96
+ - MIT
97
+ metadata: {}
98
+ post_install_message:
99
+ rdoc_options: []
100
+ require_paths:
101
+ - lib
102
+ required_ruby_version: !ruby/object:Gem::Requirement
103
+ requirements:
104
+ - - '>='
105
+ - !ruby/object:Gem::Version
106
+ version: '0'
107
+ required_rubygems_version: !ruby/object:Gem::Requirement
108
+ requirements:
109
+ - - '>='
110
+ - !ruby/object:Gem::Version
111
+ version: '0'
112
+ requirements: []
113
+ rubyforge_project:
114
+ rubygems_version: 2.0.0
115
+ signing_key:
116
+ specification_version: 4
117
+ summary: A data backend for Hiera that returns the decrypted contents of files. Useful
118
+ for secrets.
119
+ test_files:
120
+ - test/data/data.txt
121
+ - test/data/data2.txt
122
+ - test/data/one/data.txt.gpg
123
+ - test/data/two/backup.txt.gpg
124
+ - test/data/two/data.txt.gpg
125
+ - test/everything
126
+ - test/hiera-file.yaml
127
+ - test/hiera-inline.yaml
128
+ - test/password