enc 0.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.
@@ -0,0 +1,15 @@
1
+ ---
2
+ !binary "U0hBMQ==":
3
+ metadata.gz: !binary |-
4
+ N2RkMDFhMTE5YjNiMjljYWZmYjc3MTMxYTgzODg1MDU1MWY3NTMzZQ==
5
+ data.tar.gz: !binary |-
6
+ OWJjMTcyZWE3MDdjMTlhYjUxM2QxODI1YzBkY2RhOWE0YTU0ZjBlOQ==
7
+ SHA512:
8
+ metadata.gz: !binary |-
9
+ MjY0NmE1YzJiMTQwMGFkMGIxNGE1MjkzZjdlN2UzYTM5OTA5MmE4MjJmZDY1
10
+ ZjM0MjA4MTFiOThjZjJlZTRmYTBiMjg0OTM5ZjNjZTU1NGU2ZDIwOGQxNmU3
11
+ N2FjOTdjNTE4OGMxOGUyZGU5NjAzYzhmNTgwODQyNmE0NDFkMmE=
12
+ data.tar.gz: !binary |-
13
+ MmM5MTY3ZWEwZmViZDQ5MzgzMTYxNjRhNGY3ZjJlNzY1NGUyM2NhYWY2Yjlk
14
+ MGMyYTM0OWM5ODM2N2RhMmExYTQ1MWIwMjhhYjY2NDE1Y2YyZjM3MGNiODZh
15
+ MTY5ZGRjMTY2MmVlZWQzNGI1M2Y0NjEzM2Y0M2Q2ZGI5YTJkMTk=
data/Gemfile ADDED
@@ -0,0 +1,5 @@
1
+ source 'https://rubygems.org'
2
+ ruby '1.9.3'
3
+
4
+ # Specify your gem's dependencies in enc.gemspec
5
+ gemspec
@@ -0,0 +1,47 @@
1
+ PATH
2
+ remote: .
3
+ specs:
4
+ enc (0.0.1)
5
+
6
+ GEM
7
+ remote: https://rubygems.org/
8
+ specs:
9
+ addressable (2.3.6)
10
+ crack (0.4.2)
11
+ safe_yaml (~> 1.0.0)
12
+ diff-lcs (1.2.5)
13
+ docile (1.1.5)
14
+ multi_json (1.10.1)
15
+ rake (10.4.2)
16
+ rspec (3.1.0)
17
+ rspec-core (~> 3.1.0)
18
+ rspec-expectations (~> 3.1.0)
19
+ rspec-mocks (~> 3.1.0)
20
+ rspec-core (3.1.7)
21
+ rspec-support (~> 3.1.0)
22
+ rspec-expectations (3.1.2)
23
+ diff-lcs (>= 1.2.0, < 2.0)
24
+ rspec-support (~> 3.1.0)
25
+ rspec-mocks (3.1.3)
26
+ rspec-support (~> 3.1.0)
27
+ rspec-support (3.1.2)
28
+ safe_yaml (1.0.4)
29
+ simplecov (0.9.1)
30
+ docile (~> 1.1.0)
31
+ multi_json (~> 1.0)
32
+ simplecov-html (~> 0.8.0)
33
+ simplecov-html (0.8.0)
34
+ webmock (1.18.0)
35
+ addressable (>= 2.3.6)
36
+ crack (>= 0.3.2)
37
+
38
+ PLATFORMS
39
+ ruby
40
+
41
+ DEPENDENCIES
42
+ bundler (~> 1.7)
43
+ enc!
44
+ rake (~> 10.0)
45
+ rspec (~> 3.0)
46
+ simplecov
47
+ webmock
@@ -0,0 +1,22 @@
1
+ Copyright (c) 2014 TODO: Write your name
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.
@@ -0,0 +1,54 @@
1
+ # Enc
2
+
3
+ Enc is a role-based customizable puppet external node classifier.
4
+
5
+ ## Installation
6
+
7
+ Install the gem on your puppetmaster server:
8
+ ```bash
9
+ gem install enc
10
+ ```
11
+
12
+ Configure etc/puppet/puppet.conf
13
+ ```conf
14
+ [master]
15
+ external_nodes = /usr/bin/atlas-node-classify
16
+ ```
17
+
18
+ ## Configuration
19
+
20
+ ### Overview
21
+
22
+ Enc itself does not know anything about how you handle your mapping from "hostnames" to "roles".
23
+ This functionality is provided by you, either using one of Enc's builtin provider types, or by writing your own.
24
+
25
+ Enc looks for manifest files in the following locations:
26
+ * /etc/enc/manifests/[role].yaml
27
+ * /etc/enc/manifests/[hostname].yaml
28
+
29
+ These manifests are merged to produce the final, actual manifest for a node. If multiple roles are provided
30
+ for a host, the manifests will be merged in the order that the roles are provided. In this way, you can
31
+ easily override defaults provided by a role in order to test specific behaviour on a single server before rolling
32
+ it out to all servers.
33
+
34
+ If no roles are provided for a host, then only the hostname.yaml will be used.
35
+
36
+ ### Host to Role mapping
37
+
38
+ To specify the mapping, you must write a ruby shim. Create the file /etc/enc/user.rb. As an example (and a
39
+ fairly useful case), Enc provides an out-of-the-box url role provider. You can use it by writing user.rb like so:
40
+
41
+ ```
42
+ require 'enc/url_provider'
43
+ Enc.role_provider = Enc.url_provider('http://myserver.com/roles')
44
+ ```
45
+
46
+ The server is expected to return a JSON array of roles at ```http://myserver.com/roles/[hostname]```
47
+
48
+ ## Contributing
49
+
50
+ 1. Fork it ( https://github.com/[my-github-username]/enc/fork )
51
+ 2. Create your feature branch (`git checkout -b my-new-feature`)
52
+ 3. Commit your changes (`git commit -am 'Add some feature'`)
53
+ 4. Push to the branch (`git push origin my-new-feature`)
54
+ 5. Create a new Pull Request
@@ -0,0 +1,6 @@
1
+ require 'bundler/gem_tasks'
2
+ require 'rspec/core/rake_task'
3
+
4
+ RSpec::Core::RakeTask.new('spec')
5
+
6
+ task :default => :spec
data/bin/enc ADDED
@@ -0,0 +1,10 @@
1
+ #!/usr/bin/env ruby
2
+ $: << File.join(File.dirname(__FILE__), '..', 'lib')
3
+ require 'enc'
4
+ require 'enc/url_provider'
5
+
6
+ # Load user scripts
7
+ load "/etc/enc/user.rb" if File.exists? "/etc/enc/user.rb"
8
+
9
+ # Generate manifest
10
+ puts Enc.manifest.to_yaml
@@ -0,0 +1,25 @@
1
+ # coding: utf-8
2
+ lib = File.expand_path('../lib', __FILE__)
3
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
+ require 'enc/version'
5
+
6
+ Gem::Specification.new do |spec|
7
+ spec.name = "enc"
8
+ spec.version = Enc::VERSION
9
+ spec.authors = ["Michael Shea."]
10
+ spec.email = ["mike.shea@gmail.com"]
11
+ spec.summary = %q{Database-backed puppet ENC}
12
+ spec.homepage = ""
13
+ spec.license = "MIT"
14
+
15
+ spec.files = `git ls-files -z`.split("\x0")
16
+ spec.executables = spec.files.grep(%r{^bin/}) { |f| File.basename(f) }
17
+ spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
18
+ spec.require_paths = ["lib"]
19
+
20
+ spec.add_development_dependency 'bundler', '~> 1.7'
21
+ spec.add_development_dependency 'rspec', '~> 3.0'
22
+ spec.add_development_dependency 'simplecov'
23
+ spec.add_development_dependency 'rake', '~> 10.0'
24
+ spec.add_development_dependency 'webmock'
25
+ end
@@ -0,0 +1,5 @@
1
+ require 'enc/version'
2
+ require 'enc/manifest'
3
+
4
+ module Enc
5
+ end
@@ -0,0 +1,49 @@
1
+ require 'yaml'
2
+
3
+ # http://stackoverflow.com/questions/9381553/ruby-merge-nested-hash
4
+ class ::Hash
5
+ def deep_merge(second)
6
+ merger = proc { |key, v1, v2| Hash === v1 && Hash === v2 ? v1.merge(v2, &merger) : v2 }
7
+ self.merge(second, &merger)
8
+ end
9
+ end
10
+
11
+ module Enc
12
+ class << self
13
+ attr_accessor :role_provider
14
+ attr_accessor :template_dir
15
+
16
+ template_dir = '/etc/enc/manifests'
17
+
18
+ # Generate a manifest for the given host
19
+ def manifest(hostname)
20
+ roles = role_provider ? role_provider.call(hostname) : []
21
+ Manifest.new(hostname, roles).hash
22
+ end
23
+ end
24
+
25
+ class Manifest
26
+ attr_reader :hostname, :roles
27
+
28
+ def initialize(hostname, roles)
29
+ @hostname, @roles = hostname, roles
30
+ end
31
+
32
+ def hash
33
+ manifests.inject({}){ |result, m| result.deep_merge(m) }
34
+ end
35
+
36
+ def manifests
37
+ files.map{ |f| YAML.load(File.read(f)) }
38
+ end
39
+
40
+ def files
41
+ roles.push(hostname).map{ |r| file(r) }.select{ |f| File.exists?(f) }
42
+ end
43
+
44
+ def file(role)
45
+ "#{Enc.template_dir}/#{role}.yml"
46
+ end
47
+ end
48
+
49
+ end
@@ -0,0 +1,13 @@
1
+ require 'enc'
2
+ require 'json'
3
+ require 'open-uri'
4
+
5
+ # Returns roles by parsing JSON returned by hitting a url.
6
+ module Enc
7
+ def self.url_provider(base)
8
+ Proc.new do |hostname|
9
+ JSON.parse open("#{base}/#{hostname}"){ |io| io.read }
10
+ end
11
+ end
12
+ end
13
+
@@ -0,0 +1,3 @@
1
+ module Enc
2
+ VERSION = "0.0.1"
3
+ end
@@ -0,0 +1,35 @@
1
+ require 'enc'
2
+ require 'enc/url_provider'
3
+ require 'webmock/rspec'
4
+
5
+ module Enc
6
+ Enc.template_dir = File.join(File.dirname(__FILE__))
7
+
8
+ describe self do
9
+ it 'should generate a manifest with roles from a url' do
10
+ Enc.role_provider = Enc.url_provider 'http://somewhere.com/roles'
11
+ stub_request(:get, "http://somewhere.com/roles/host").to_return(:body => %w'role'.to_json)
12
+ expect(Enc.manifest('host')).to eq( {
13
+ 'parameters' => { 'P1' => 'value1', 'P2' => 'value2' },
14
+ 'classes' => { 'C1' => {}, 'C2' => { 'key1' => 'value1' }, 'C3' => {} }
15
+ })
16
+ end
17
+
18
+ it 'should generate a manifest with roles' do
19
+ Enc.role_provider = Proc.new{ |h| %w'role' }
20
+ expect(Enc.manifest('host')).to eq( {
21
+ 'parameters' => { 'P1' => 'value1', 'P2' => 'value2' },
22
+ 'classes' => { 'C1' => {}, 'C2' => { 'key1' => 'value1' }, 'C3' => {} }
23
+ })
24
+ end
25
+
26
+ it 'should generate a manifest without roles' do
27
+ Enc.role_provider = nil
28
+ expect(Enc.manifest('host')).to eq( {
29
+ 'parameters' => { 'P2' => 'value2' },
30
+ 'classes' => { 'C2' => { 'key1' => 'value1' }, 'C3' => {} }
31
+ })
32
+ end
33
+
34
+ end
35
+ end
@@ -0,0 +1,7 @@
1
+ ---
2
+ parameters:
3
+ P2: value2
4
+ classes:
5
+ C2:
6
+ key1: value1
7
+ C3: {}
@@ -0,0 +1,6 @@
1
+ ---
2
+ parameters:
3
+ P1: value1
4
+ classes:
5
+ C1: {}
6
+ C2: {}
metadata ADDED
@@ -0,0 +1,132 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: enc
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.1
5
+ platform: ruby
6
+ authors:
7
+ - Michael Shea.
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2014-12-22 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: bundler
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - ~>
18
+ - !ruby/object:Gem::Version
19
+ version: '1.7'
20
+ type: :development
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - ~>
25
+ - !ruby/object:Gem::Version
26
+ version: '1.7'
27
+ - !ruby/object:Gem::Dependency
28
+ name: rspec
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - ~>
32
+ - !ruby/object:Gem::Version
33
+ version: '3.0'
34
+ type: :development
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - ~>
39
+ - !ruby/object:Gem::Version
40
+ version: '3.0'
41
+ - !ruby/object:Gem::Dependency
42
+ name: simplecov
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - ! '>='
46
+ - !ruby/object:Gem::Version
47
+ version: '0'
48
+ type: :development
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - ! '>='
53
+ - !ruby/object:Gem::Version
54
+ version: '0'
55
+ - !ruby/object:Gem::Dependency
56
+ name: rake
57
+ requirement: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - ~>
60
+ - !ruby/object:Gem::Version
61
+ version: '10.0'
62
+ type: :development
63
+ prerelease: false
64
+ version_requirements: !ruby/object:Gem::Requirement
65
+ requirements:
66
+ - - ~>
67
+ - !ruby/object:Gem::Version
68
+ version: '10.0'
69
+ - !ruby/object:Gem::Dependency
70
+ name: webmock
71
+ requirement: !ruby/object:Gem::Requirement
72
+ requirements:
73
+ - - ! '>='
74
+ - !ruby/object:Gem::Version
75
+ version: '0'
76
+ type: :development
77
+ prerelease: false
78
+ version_requirements: !ruby/object:Gem::Requirement
79
+ requirements:
80
+ - - ! '>='
81
+ - !ruby/object:Gem::Version
82
+ version: '0'
83
+ description:
84
+ email:
85
+ - mike.shea@gmail.com
86
+ executables:
87
+ - enc
88
+ extensions: []
89
+ extra_rdoc_files: []
90
+ files:
91
+ - Gemfile
92
+ - Gemfile.lock
93
+ - LICENSE.txt
94
+ - README.md
95
+ - Rakefile
96
+ - bin/enc
97
+ - enc.gemspec
98
+ - lib/enc.rb
99
+ - lib/enc/manifest.rb
100
+ - lib/enc/url_provider.rb
101
+ - lib/enc/version.rb
102
+ - spec/enc_spec.rb
103
+ - spec/host.yml
104
+ - spec/role.yml
105
+ homepage: ''
106
+ licenses:
107
+ - MIT
108
+ metadata: {}
109
+ post_install_message:
110
+ rdoc_options: []
111
+ require_paths:
112
+ - lib
113
+ required_ruby_version: !ruby/object:Gem::Requirement
114
+ requirements:
115
+ - - ! '>='
116
+ - !ruby/object:Gem::Version
117
+ version: '0'
118
+ required_rubygems_version: !ruby/object:Gem::Requirement
119
+ requirements:
120
+ - - ! '>='
121
+ - !ruby/object:Gem::Version
122
+ version: '0'
123
+ requirements: []
124
+ rubyforge_project:
125
+ rubygems_version: 2.2.2
126
+ signing_key:
127
+ specification_version: 4
128
+ summary: Database-backed puppet ENC
129
+ test_files:
130
+ - spec/enc_spec.rb
131
+ - spec/host.yml
132
+ - spec/role.yml