hiera-fs 0.0.1 → 1.0

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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
- SHA1:
3
- metadata.gz: 6d846eab0030cfdd9864f3b9e7f188389fe6bbe9
4
- data.tar.gz: 560777fe3604096865d9933d8d19bb187f3d0227
5
2
  SHA512:
6
- metadata.gz: bfbff9c16d2771f614abcae9b1ba8085502fe68124620fb57934a3a785a01befc41b611084bd66c22058526aaa4717028c5e573f05cda519a8597d484d6a5e35
7
- data.tar.gz: d235a3108d137f8a22248bf10672bb1d8835600adb832182d0099fb0e9abda4af95a8d0ed9951b962b5739623d638f8cb1b5ab79d1ea683fc923e737bee4ee83
3
+ metadata.gz: bb1f92c9f8d7660f1d3692ad8d25d9da85d2ddaa08b22ceba25fef8d9eceff9e2d0c5f115f71e3cea7a4afcf88a4a495dbef7ab20756d85b3441b215d152b4cc
4
+ data.tar.gz: e73faecdd85a9c561a70dfe12c6a2b7fe3e01086fffd2d3449ef5cc3c5cbccbe9a530852b4eecf63df9f166c5d5fb405684dbaf6aa5855ccc49ab1ccbe987bf7
5
+ SHA1:
6
+ metadata.gz: 328266ae920023536a9e509d471423f047d7ad00
7
+ data.tar.gz: 58813d71c058b55eb14d21a1eb8d32a02db6fe0e
@@ -3,21 +3,22 @@ class Hiera
3
3
  class Fs_backend
4
4
 
5
5
  def initialize
6
- Hiera.debug("[HieraFs]::Hiera fs backend starting")
6
+ Hiera.debug("[HieraFs]::Hiera-fs backend starting")
7
7
  end
8
8
 
9
9
  def lookup(key, scope, order_override, resolution_type)
10
10
  answer = nil
11
11
 
12
+ Hiera.debug("HieraFs::lookup - Looking up '#{key}' in fs backend")
13
+
12
14
  calling_class = scope.resource.name.to_s.downcase
13
15
  calling_module = calling_class.split("::").first
14
16
 
15
- Hiera.debug("[HieraFs]::calling_class: #{calling_class}")
16
- Hiera.debug("[HieraFs]::calling_module: #{calling_module}")
17
- Hiera.debug("[HieraFs]::Looking up #{key} in fs backend")
17
+ Hiera.debug("HieraFs::lookup - Calling class: #{calling_class}")
18
+ Hiera.debug("HieraFs::lookup - Calling module: #{calling_module}")
18
19
 
19
20
  Backend.datasources(scope, order_override) do |source|
20
- Hiera.debug("[HieraFs]::Looking for data source '#{source}'")
21
+ Hiera.debug("HieraFs::lookup - Looking for data source '#{source}'")
21
22
 
22
23
  datadir = Backend.datafile(:fs, scope, source, "d") or next
23
24
 
@@ -24,12 +24,7 @@ module HieraFs
24
24
  module_path = arr.slice(0, arr.index('manifests')).join(File::SEPARATOR)
25
25
  module_source_path = File.join(module_path, default_dir)
26
26
 
27
- default_source = File.join(module_source_path, key)
28
- if File.exists?(default_source)
29
- return default_source
30
- else
31
- return nil
32
- end
27
+ return File.join(module_source_path, key)
33
28
 
34
29
  end
35
30
 
@@ -45,8 +40,6 @@ module HieraFs
45
40
 
46
41
  files_in_dir = Dir.entries(dir).select { |f| File.file?(File.join(dir, f)) }
47
42
 
48
- Puppet.debug("Files in #{dir}: #{files_in_dir}")
49
-
50
43
  files_hash = Hash[ files_in_dir.map{ |f| [f, File.join(dir, f)] } ]
51
44
  all_files_in_hierarchy = files_hash.merge(all_files_in_hierarchy)
52
45
 
@@ -1,3 +1,3 @@
1
1
  module HieraFs
2
- VERSION = '0.0.1'
2
+ VERSION = '1.0'
3
3
  end
@@ -6,18 +6,13 @@ module Puppet::Parser::Functions
6
6
  require 'hierafs/utils'
7
7
  require 'hiera_puppet'
8
8
 
9
- Puppet.debug "In hiera_template function"
10
-
11
9
  key = args[0]
12
10
  override = args[1]
13
11
 
14
- Puppet.debug "key: #{key} override: #{override}"
15
-
16
12
  default_template_file = HieraFs::Utils::get_default_source(self, key, :template)
17
- Puppet.debug("Default template: #{default_template_file}")
13
+ Puppet.debug("HieraFs::hiera_template - Default template: #{default_template_file}")
18
14
 
19
15
  answer = HieraPuppet.lookup(key, default_template_file, self, override, :priority)
20
- debug "Answer: #{answer}"
21
16
  raise(Puppet::ParseError, "Could not find data item #{key} in any Hiera data file and no default supplied") if answer.nil?
22
17
  raise(Puppet::ParseError, "Template file: #{answer} does not exists") unless File.exists?(answer)
23
18
  raise(Puppet::ParseError, "Template file: #{answer} is not a file") unless File.file?(answer)
metadata CHANGED
@@ -1,18 +1,21 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: hiera-fs
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.1
4
+ version: "1.0"
5
5
  platform: ruby
6
6
  authors:
7
7
  - Alan Castro
8
+ - Paulo Henrique
8
9
  autorequire:
9
10
  bindir: bin
10
11
  cert_chain: []
11
12
 
12
- date: 2014-04-11 00:00:00 Z
13
+ date: 2014-04-12 00:00:00 Z
13
14
  dependencies: []
14
15
 
15
- description: " File system hiera backend.\n"
16
+ description: |
17
+ A data backend for Hiera that can return content of files, parsed templates and directorie's files.
18
+
16
19
  email: alanclic@gmail.com
17
20
  executables: []
18
21
 
@@ -21,12 +24,6 @@ extensions: []
21
24
  extra_rdoc_files: []
22
25
 
23
26
  files:
24
- - .gitignore
25
- - Gemfile
26
- - LICENSE.txt
27
- - README.md
28
- - Rakefile
29
- - hiera-fs.gemspec
30
27
  - lib/hiera/backend/fs_backend.rb
31
28
  - lib/hierafs/utils.rb
32
29
  - lib/hierafs/version.rb
data/.gitignore DELETED
@@ -1,2 +0,0 @@
1
- pkg/
2
- *.gem$
data/Gemfile DELETED
@@ -1,4 +0,0 @@
1
- source 'https://rubygems.org'
2
-
3
- # Specify your gem's dependencies in teste.gemspec
4
- gemspec
@@ -1,22 +0,0 @@
1
- Copyright (c) 2014 Alan Castro
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 DELETED
@@ -1,114 +0,0 @@
1
- ## hiera-fs: a file-system hiera backend
2
-
3
- ### Instalation
4
-
5
- sudo gem install hiera-fs
6
-
7
- ### Description
8
-
9
- Hiera-fs allows you create a more extensible module, by letting the user create
10
- specific files/templates somewhere in his hiera hierarchy.
11
-
12
- ### Functions
13
-
14
- - `hiera_file(<key>, [<override>])`
15
-
16
- Returns a file's content from hiera hierarchy.
17
- The default files is `{modulename}/files/key`.
18
-
19
- - `hiera_template(<key>, [<override>])`
20
-
21
- Returns a templates's content from hiera hierarchy.
22
- The default template is `{modulename}/templates/key`.
23
-
24
- - `hiera_dir(<key>, [<override>])`
25
-
26
- Returns a hash of all files names and paths that exists in `key` directory in our hiera hierarchy.
27
- If directory does not exists, the function returns an empty hash `{}`.
28
-
29
- ### How does it work?
30
-
31
- #### hiera\_template and hiera\_file
32
-
33
- For better understading, let's look at an example.
34
-
35
- Imagine we have the following dns module:
36
-
37
- ├── dns
38
- │   ├── files
39
- │   │   └── resolv.conf
40
- │   ├── manifests
41
- │   │   └── init.pp
42
- │   └── templates
43
- │   └── resolv.conf.erb
44
-
45
- In our `manifests/init.pp` we have the following code:
46
-
47
- class dns {
48
- file { '/etc/resolv.conf.template':
49
- ensure => file,
50
- content => hiera_template('resolv.conf.erb'),
51
- }
52
- file { '/etc/resolv.conf.file':
53
- ensure => file,
54
- content => hiera_file('resolv.conf'),
55
- }
56
- }
57
-
58
- Our `templates/resolv.conf.erb` has the following code:
59
-
60
- resolv.conf template
61
- My operatingsystem <%= @operatingsystem %>
62
-
63
- Our `files/resolv.conf.erb` has the following code:
64
-
65
- my resolv.conf file
66
- <%= @operatingsystem %> will not work :/
67
-
68
- If you don't create any hiera configuration, your dns module will use the files
69
- defined in templates (for hiera\_template) and in files (for hiera\_file).
70
-
71
- Let's say that you have the following `hiera.yaml`
72
-
73
- ---
74
- :backends:
75
- - fs
76
- :fs:
77
- :datadir: /etc/puppet/hiera
78
- :hierarchy:
79
- - common/%{calling_module}
80
- - common
81
-
82
- The `hiera_template` call will look for your template in the following directories and order:
83
-
84
- - /etc/puppet/hiera/common.d/resolv.conf.erb
85
- - /etc/puppet/hiera/common/dns.d/resolv.conf.erb
86
-
87
- The default template used is `dns/templates/resolv.conf.erb`.
88
-
89
- The `hiera_file` call will look for your file in the following directories and order:
90
-
91
- - /etc/puppet/hiera/common.d/resolv.conf
92
- - /etc/puppet/hiera/common/dns.d/resolv.conf
93
-
94
- The default file used is `dns/files/resolv.conf`.
95
-
96
- #### hiera\_dir
97
-
98
- The function `hiera_dir(key)` is quite simple, it looks somewhere in your hiera hierarchy for
99
- a directory named `key` and returns a hash containing with all filenames and filepaths.
100
-
101
- {
102
- 'filename1' => 'filepath1',
103
- 'filename2' => 'filepath2',
104
- 'filename3' => 'filepath3',
105
- 'filename4' => 'filepath4'
106
- }
107
-
108
- If the directory does not exists, the function simple returns `{}`.
109
-
110
- If we use the hiera.yaml defined before and called `hiera_dir('repos')` in our
111
- dns module init.pp manifest, hiera would look `repos` directory in the following paths:
112
-
113
- - /etc/puppet/hiera/common.d/repos
114
- - /etc/puppet/hiera/common/dns.d/repos
data/Rakefile DELETED
@@ -1 +0,0 @@
1
- require "bundler/gem_tasks"
@@ -1,24 +0,0 @@
1
- # coding: utf-8
2
- lib = File.expand_path('../lib', __FILE__)
3
- $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
- require 'hierafs/version'
5
-
6
- Gem::Specification.new do |s|
7
- s.name = "hiera-fs"
8
- s.version = HieraFs::VERSION
9
- s.platform = Gem::Platform::RUBY
10
-
11
- s.authors = "Alan Castro"
12
- s.email = "alanclic@gmail.com"
13
- s.homepage = "http://github.com/alancastro/hiera-fs"
14
- s.summary = "File system hiera backend"
15
- s.description = <<-DESCRIPTION
16
- File system hiera backend.
17
- DESCRIPTION
18
-
19
- s.license = 'MIT'
20
-
21
- s.files = %x[git ls-files].split($/)
22
- s.require_paths = ['lib']
23
-
24
- end