hiera-regex 0.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 ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: 61c26987dfaa056721bfae4e3165462615537da6
4
+ data.tar.gz: f177917513cab76e8f5cf4ad92ebf8059b00c039
5
+ SHA512:
6
+ metadata.gz: 4793110d130fc07d5d2ebd0afab6146cb3b7748d3a8093f27b3bb4f4ca3de6d2c1f2b30bc2f02dc87691a6a38f3af799ae86dc15145bdb98f31624a6594371a8
7
+ data.tar.gz: a696ac951712c304a2b6d0ec5d39e47edbb3b74dfda41a3cd539993557a5ad526952906a238134d2761db09897cd4809ba6f97b8655e2449d76d662176674d55
data/LICENSE ADDED
@@ -0,0 +1,13 @@
1
+ Copyright 2014 John Julien <john@julienfamily.com>
2
+
3
+ Licensed under the Apache License, Version 2.0 (the "License");
4
+ you may not use this file except in compliance with the License.
5
+ You may obtain a copy of the License at
6
+
7
+ http://www.apache.org/licenses/LICENSE-2.0
8
+
9
+ Unless required by applicable law or agreed to in writing, software
10
+ distributed under the License is distributed on an "AS IS" BASIS,
11
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12
+ See the License for the specific language governing permissions and
13
+ limitations under the License.
@@ -0,0 +1,68 @@
1
+ class Hiera
2
+ module Backend
3
+ class Regex_backend
4
+
5
+ # TODO: Support JSON or YAML format and initialize accordingly
6
+ def initialize
7
+ require 'yaml'
8
+ end
9
+
10
+ # TODO: Support multiple resolution_types, currently only supports :priority
11
+ def lookup(key, scope, order_override, resolution_type)
12
+ answer = nil
13
+ datasourcefiles(scope) do |source|
14
+ scope_key = File.basename(source, ".regex")
15
+ scope_key = "::#{scope_key}" if ! scope[scope_key]
16
+ if ! scope[scope_key]
17
+ Hiera.debug("Could not find key #{scope_key} within scope, skipping check for source #{source}")
18
+ next
19
+ end
20
+ Hiera.debug("Checking #{source} for #{scope_key} regex matching #{scope[scope_key]}")
21
+ # TODO: Add support for more than just YAML format
22
+ data = YAML.load_file(source)
23
+ next if ! data
24
+ next if data.empty?
25
+
26
+ lineno = 0
27
+ data.each do |item|
28
+ lineno = lineno + 1
29
+ item.each_key do |regex_key|
30
+ if scope[scope_key] =~ /#{regex_key}/ and item[regex_key][key]
31
+ Hiera.debug("#{scope_key} with value of '#{scope[scope_key]}' matched regex /#{regex_key}/ at #{source}:#{lineno}")
32
+ answer = item[regex_key][key]
33
+ break
34
+ end
35
+ end
36
+ break if answer
37
+ end
38
+ end
39
+ return answer
40
+ end
41
+
42
+ def datasources(scope)
43
+ datadir = Backend.datadir(:regex, scope)
44
+ Config[:hierarchy].flatten.map do |source|
45
+ # We only support data sources that end in a key. Keys found
46
+ # in the middle of a datasource's name are impossible to support since
47
+ # standard file names do not do well containing regular experssion patterns
48
+ if source =~ /\}$/
49
+ # We need to strip out the ending key's %{::} characters so that they do not
50
+ # get interpolated when we call parse_string
51
+ yield(Backend.parse_string(source.gsub(/%\{:*([^\{]*)\}$/, '\1'), scope))
52
+ end
53
+ end
54
+ end
55
+
56
+ def datasourcefiles(scope)
57
+ datadir = Backend.datadir(:regex, scope)
58
+ datasources(scope) do |source|
59
+ file = Backend.datafile(:regex, scope, source, :regex)
60
+ if file
61
+ yield(file)
62
+ end
63
+ end
64
+ end
65
+
66
+ end
67
+ end
68
+ end
metadata ADDED
@@ -0,0 +1,45 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: hiera-regex
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.0
5
+ platform: ruby
6
+ authors:
7
+ - John Julien
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2014-07-09 00:00:00.000000000 Z
12
+ dependencies: []
13
+ description: Hiera backend for looking up keys using the power of regular expressions
14
+ email:
15
+ executables: []
16
+ extensions: []
17
+ extra_rdoc_files: []
18
+ files:
19
+ - LICENSE
20
+ - lib/hiera/backend/regex_backend.rb
21
+ homepage: http://github.com/jjulien/hiera-regex
22
+ licenses:
23
+ - Apache 2.0
24
+ metadata: {}
25
+ post_install_message:
26
+ rdoc_options: []
27
+ require_paths:
28
+ - lib
29
+ required_ruby_version: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - ">="
32
+ - !ruby/object:Gem::Version
33
+ version: '0'
34
+ required_rubygems_version: !ruby/object:Gem::Requirement
35
+ requirements:
36
+ - - ">="
37
+ - !ruby/object:Gem::Version
38
+ version: '0'
39
+ requirements: []
40
+ rubyforge_project:
41
+ rubygems_version: 2.2.1
42
+ signing_key:
43
+ specification_version: 4
44
+ summary: Hiera regex backend
45
+ test_files: []