hiera-yaml-gather 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.
- data/.gitignore +17 -0
- data/.rvmrc +48 -0
- data/Gemfile +4 -0
- data/LICENSE.txt +22 -0
- data/README.md +38 -0
- data/Rakefile +1 -0
- data/bin/hiera-yaml-gather +96 -0
- data/hiera-yaml-gather.gemspec +24 -0
- data/lib/hiera-yaml-gather.rb +9 -0
- data/lib/hiera-yaml-gather/version.rb +7 -0
- metadata +74 -0
data/.gitignore
ADDED
data/.rvmrc
ADDED
@@ -0,0 +1,48 @@
|
|
1
|
+
#!/usr/bin/env bash
|
2
|
+
|
3
|
+
# This is an RVM Project .rvmrc file, used to automatically load the ruby
|
4
|
+
# development environment upon cd'ing into the directory
|
5
|
+
|
6
|
+
# First we specify our desired <ruby>[@<gemset>], the @gemset name is optional,
|
7
|
+
# Only full ruby name is supported here, for short names use:
|
8
|
+
# echo "rvm use 1.9.3" > .rvmrc
|
9
|
+
environment_id="ruby-1.9.3-p194@hiera-yaml-gather"
|
10
|
+
|
11
|
+
# Uncomment the following lines if you want to verify rvm version per project
|
12
|
+
# rvmrc_rvm_version="1.16.11 (stable)" # 1.10.1 seams as a safe start
|
13
|
+
# eval "$(echo ${rvm_version}.${rvmrc_rvm_version} | awk -F. '{print "[[ "$1*65536+$2*256+$3" -ge "$4*65536+$5*256+$6" ]]"}' )" || {
|
14
|
+
# echo "This .rvmrc file requires at least RVM ${rvmrc_rvm_version}, aborting loading."
|
15
|
+
# return 1
|
16
|
+
# }
|
17
|
+
|
18
|
+
# First we attempt to load the desired environment directly from the environment
|
19
|
+
# file. This is very fast and efficient compared to running through the entire
|
20
|
+
# CLI and selector. If you want feedback on which environment was used then
|
21
|
+
# insert the word 'use' after --create as this triggers verbose mode.
|
22
|
+
if [[ -d "${rvm_path:-$HOME/.rvm}/environments"
|
23
|
+
&& -s "${rvm_path:-$HOME/.rvm}/environments/$environment_id" ]]
|
24
|
+
then
|
25
|
+
\. "${rvm_path:-$HOME/.rvm}/environments/$environment_id"
|
26
|
+
[[ -s "${rvm_path:-$HOME/.rvm}/hooks/after_use" ]] &&
|
27
|
+
\. "${rvm_path:-$HOME/.rvm}/hooks/after_use" || true
|
28
|
+
else
|
29
|
+
# If the environment file has not yet been created, use the RVM CLI to select.
|
30
|
+
rvm --create "$environment_id" || {
|
31
|
+
echo "Failed to create RVM environment '${environment_id}'."
|
32
|
+
return 1
|
33
|
+
}
|
34
|
+
fi
|
35
|
+
|
36
|
+
# If you use bundler, this might be useful to you:
|
37
|
+
# if [[ -s Gemfile ]] && {
|
38
|
+
# ! builtin command -v bundle >/dev/null ||
|
39
|
+
# builtin command -v bundle | GREP_OPTIONS= \grep $rvm_path/bin/bundle >/dev/null
|
40
|
+
# }
|
41
|
+
# then
|
42
|
+
# printf "%b" "The rubygem 'bundler' is not installed. Installing it now.\n"
|
43
|
+
# gem install bundler
|
44
|
+
# fi
|
45
|
+
# if [[ -s Gemfile ]] && builtin command -v bundle >/dev/null
|
46
|
+
# then
|
47
|
+
# bundle install | GREP_OPTIONS= \grep -vE '^Using|Your bundle is complete'
|
48
|
+
# fi
|
data/Gemfile
ADDED
data/LICENSE.txt
ADDED
@@ -0,0 +1,22 @@
|
|
1
|
+
Copyright (c) 2012 Justin Karimi
|
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,38 @@
|
|
1
|
+
# hiera-yaml-gather
|
2
|
+
|
3
|
+
Based on a query passed to the utility, parse and return a Hash of all configuration
|
4
|
+
variables that correspond to the particular query string. The files parsed are based
|
5
|
+
on the Hierarchy specified in the Hiera configuration file.
|
6
|
+
|
7
|
+
## Installation
|
8
|
+
|
9
|
+
Add this line to your application's Gemfile:
|
10
|
+
|
11
|
+
gem 'hiera-yaml-gather'
|
12
|
+
|
13
|
+
And then execute:
|
14
|
+
|
15
|
+
$ bundle
|
16
|
+
|
17
|
+
Or install it yourself as:
|
18
|
+
|
19
|
+
$ gem install hiera-yaml-gather
|
20
|
+
|
21
|
+
## Usage
|
22
|
+
|
23
|
+
Usage mimics the generic hiera usage minus providing a key to search for:
|
24
|
+
|
25
|
+
$ hiera-yaml-gather <scope>
|
26
|
+
|
27
|
+
Where:
|
28
|
+
|
29
|
+
scope is a list of scope=val pairs used to discover configuration variables as
|
30
|
+
defined within the hiera.yaml configuration file
|
31
|
+
|
32
|
+
## Contributing
|
33
|
+
|
34
|
+
1. Fork it
|
35
|
+
2. Create your feature branch (`git checkout -b my-new-feature`)
|
36
|
+
3. Commit your changes (`git commit -am 'Add some feature'`)
|
37
|
+
4. Push to the branch (`git push origin my-new-feature`)
|
38
|
+
5. Create new Pull Request
|
data/Rakefile
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
require "bundler/gem_tasks"
|
@@ -0,0 +1,96 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
|
3
|
+
require 'hiera'
|
4
|
+
require 'hiera/config'
|
5
|
+
require 'optparse'
|
6
|
+
require 'yaml'
|
7
|
+
require 'pp'
|
8
|
+
|
9
|
+
class OptParse
|
10
|
+
def self.parse(args)
|
11
|
+
options = {}
|
12
|
+
options[:hiera_config] = '/etc/hiera.yaml'
|
13
|
+
|
14
|
+
opts = OptionParser.new do |opts|
|
15
|
+
opts.banner = 'Usage: hiera-gather [options]'
|
16
|
+
|
17
|
+
opts.separator 'Optional:'
|
18
|
+
|
19
|
+
# directory containing Hiera configuration files
|
20
|
+
opts.on('-c', '--hiera-config FILE', 'File containing Hiera configuration settings') { |v| options[:hiera_config] = v }
|
21
|
+
|
22
|
+
opts.on_tail('-d', '--debug', 'Debug mode - print output') { |v| options[:debug] = true }
|
23
|
+
|
24
|
+
# list of options
|
25
|
+
opts.on_tail('-h', '--help', 'Show this message') { puts opts; exit }
|
26
|
+
end
|
27
|
+
|
28
|
+
# error handling for required (but missing) options and invalid parsing
|
29
|
+
begin
|
30
|
+
opts.parse! args
|
31
|
+
rescue OptionParser::InvalidOption, OptionParser::MissingArgument
|
32
|
+
puts $!.to_s
|
33
|
+
puts opts
|
34
|
+
exit
|
35
|
+
end
|
36
|
+
|
37
|
+
options
|
38
|
+
end
|
39
|
+
end
|
40
|
+
|
41
|
+
options = OptParse.parse(ARGV)
|
42
|
+
|
43
|
+
# ensure the Hiera configuration file specified is valid
|
44
|
+
unless File.exists? options[:hiera_config]
|
45
|
+
puts "Hiera directory #{options[:hiera_config]} does not exist"
|
46
|
+
puts "Please double-check your configuration"
|
47
|
+
exit 1
|
48
|
+
end
|
49
|
+
|
50
|
+
# initialize the configuration based on the user-defined options
|
51
|
+
@config = Hiera::Config.load(options[:hiera_config])
|
52
|
+
Hiera.logger = 'noop' unless options[:debug]
|
53
|
+
|
54
|
+
Hiera.debug "Config settings: #{@config.inspect}"
|
55
|
+
|
56
|
+
# ensure the Hiera directory specified is valid
|
57
|
+
unless File.directory? @config[:yaml][:datadir]
|
58
|
+
puts "Hiera directory #{@config[:yaml][:datadir]} does not exist"
|
59
|
+
puts "Please double-check your configuration"
|
60
|
+
exit 1
|
61
|
+
end
|
62
|
+
|
63
|
+
# parse scope options
|
64
|
+
options[:scope] = {}
|
65
|
+
unless ARGV.empty?
|
66
|
+
ARGV.each do |arg|
|
67
|
+
if arg =~ /^(.+?)=(.+?)$/
|
68
|
+
options[:scope][$1] = $2
|
69
|
+
else
|
70
|
+
STDERR.puts "Don't know how to parse scope argument: #{arg}"
|
71
|
+
exit 1
|
72
|
+
end
|
73
|
+
end
|
74
|
+
end
|
75
|
+
Hiera.debug "Scope: #{options[:scope]}"
|
76
|
+
|
77
|
+
# obtain yaml files given scope
|
78
|
+
yaml_files = []
|
79
|
+
Hiera::Backend.datasources(options[:scope]) do |datasource|
|
80
|
+
file = File.join [@config[:yaml][:datadir], "#{datasource}.yaml"]
|
81
|
+
|
82
|
+
Hiera.debug "Checking for file: #{file.inspect}"
|
83
|
+
yaml_files << file if File.exists? file
|
84
|
+
end
|
85
|
+
|
86
|
+
# parse variables in YAML files
|
87
|
+
vars = {}
|
88
|
+
yaml_files.each do |yaml_file|
|
89
|
+
Hiera.debug "Parsing YAML config file: #{yaml_file}"
|
90
|
+
|
91
|
+
YAML.load_file(yaml_file).each do |key, val|
|
92
|
+
vars[key] = val unless vars[key]
|
93
|
+
end
|
94
|
+
end
|
95
|
+
|
96
|
+
pp Hash[vars.sort]
|
@@ -0,0 +1,24 @@
|
|
1
|
+
# -*- encoding: utf-8 -*-
|
2
|
+
lib = File.expand_path('../lib', __FILE__)
|
3
|
+
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
4
|
+
require 'hiera-yaml-gather/version'
|
5
|
+
|
6
|
+
Gem::Specification.new do |gem|
|
7
|
+
gem.name = "hiera-yaml-gather"
|
8
|
+
gem.version = Hiera::Yaml::Gather::VERSION
|
9
|
+
gem.authors = ["Justin Karimi"]
|
10
|
+
gem.email = ["jekhokie@me.com"]
|
11
|
+
gem.description = %q{Gathers and normalizes all configuration parameters for a Hiera configuration}
|
12
|
+
gem.summary = %q{Parse the Hiera configuration directory structure based on the Hierarchy specified in
|
13
|
+
the Hiera configuration file. Returns a Hash object containing all corresponding
|
14
|
+
configuration variables defined for a particular node within Hiera. Overrides are honored
|
15
|
+
based on the Hierarchical structure of the YAML files.}
|
16
|
+
gem.homepage = 'https://github.com/jekhokie/hiera-yaml-gather'
|
17
|
+
|
18
|
+
gem.files = `git ls-files`.split($/)
|
19
|
+
gem.executables = gem.files.grep(%r{^bin/}).map{ |f| File.basename(f) }
|
20
|
+
gem.test_files = gem.files.grep(%r{^(test|spec|features)/})
|
21
|
+
gem.require_paths = ["lib"]
|
22
|
+
|
23
|
+
gem.add_runtime_dependency 'hiera'
|
24
|
+
end
|
metadata
ADDED
@@ -0,0 +1,74 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: hiera-yaml-gather
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
prerelease:
|
5
|
+
version: 0.0.1
|
6
|
+
platform: ruby
|
7
|
+
authors:
|
8
|
+
- Justin Karimi
|
9
|
+
autorequire:
|
10
|
+
bindir: bin
|
11
|
+
cert_chain: []
|
12
|
+
|
13
|
+
date: 2012-12-20 00:00:00 Z
|
14
|
+
dependencies:
|
15
|
+
- !ruby/object:Gem::Dependency
|
16
|
+
name: hiera
|
17
|
+
prerelease: false
|
18
|
+
requirement: &id001 !ruby/object:Gem::Requirement
|
19
|
+
none: false
|
20
|
+
requirements:
|
21
|
+
- - ">="
|
22
|
+
- !ruby/object:Gem::Version
|
23
|
+
version: "0"
|
24
|
+
type: :runtime
|
25
|
+
version_requirements: *id001
|
26
|
+
description: Gathers and normalizes all configuration parameters for a Hiera configuration
|
27
|
+
email:
|
28
|
+
- jekhokie@me.com
|
29
|
+
executables:
|
30
|
+
- hiera-yaml-gather
|
31
|
+
extensions: []
|
32
|
+
|
33
|
+
extra_rdoc_files: []
|
34
|
+
|
35
|
+
files:
|
36
|
+
- .gitignore
|
37
|
+
- .rvmrc
|
38
|
+
- Gemfile
|
39
|
+
- LICENSE.txt
|
40
|
+
- README.md
|
41
|
+
- Rakefile
|
42
|
+
- bin/hiera-yaml-gather
|
43
|
+
- hiera-yaml-gather.gemspec
|
44
|
+
- lib/hiera-yaml-gather.rb
|
45
|
+
- lib/hiera-yaml-gather/version.rb
|
46
|
+
homepage: https://github.com/jekhokie/hiera-yaml-gather
|
47
|
+
licenses: []
|
48
|
+
|
49
|
+
post_install_message:
|
50
|
+
rdoc_options: []
|
51
|
+
|
52
|
+
require_paths:
|
53
|
+
- lib
|
54
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
55
|
+
none: false
|
56
|
+
requirements:
|
57
|
+
- - ">="
|
58
|
+
- !ruby/object:Gem::Version
|
59
|
+
version: "0"
|
60
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
61
|
+
none: false
|
62
|
+
requirements:
|
63
|
+
- - ">="
|
64
|
+
- !ruby/object:Gem::Version
|
65
|
+
version: "0"
|
66
|
+
requirements: []
|
67
|
+
|
68
|
+
rubyforge_project:
|
69
|
+
rubygems_version: 1.8.24
|
70
|
+
signing_key:
|
71
|
+
specification_version: 3
|
72
|
+
summary: Parse the Hiera configuration directory structure based on the Hierarchy specified in the Hiera configuration file. Returns a Hash object containing all corresponding configuration variables defined for a particular node within Hiera. Overrides are honored based on the Hierarchical structure of the YAML files.
|
73
|
+
test_files: []
|
74
|
+
|