hiera-mock 0.1.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: 343d08822320eb6e5b55527bab8834fa9a18abdd
4
+ data.tar.gz: abee4c54cec007c8e2372ca14a40e7004cee8be8
5
+ SHA512:
6
+ metadata.gz: 8fc88b73b9078aed14cf89da6ce781fe70efaa7b88c75b4c37e0aa7d1d198c024eca6b373b81647c5b9ac4db21923127b9cd36697800b60ed07469883443dd8f
7
+ data.tar.gz: 54fec93b17203512120c2b4ce8c60a52b677a9335edb8a8f92adf962ab5ab835fbc640f14adf27808d41d4b477e7f46a14c9edc437f4012d2843278a2febff85
@@ -0,0 +1,61 @@
1
+ class Hiera
2
+ module Backend
3
+ class Mock_backend
4
+ attr_reader :data
5
+
6
+ def initialize(cache = nil)
7
+ require 'yaml'
8
+
9
+ datafile = Config[:mock][:datafile]
10
+
11
+ @data = File.exists?(datafile) ? YAML.load(File.read(datafile)) : {}
12
+
13
+ Hiera.debug("hiera mock initialized")
14
+ end
15
+
16
+ def lookup(key, scope, order_override, resolution_type)
17
+ Hiera.debug("Looking up #{key} in yaml file")
18
+ return @data[key] if @data.include?(key)
19
+
20
+ Hiera.debug("Couldn't find '#{key}' -- making up random data...")
21
+
22
+ case resolution_type
23
+ when :array
24
+ return random_array
25
+ when :hash
26
+ return random_hash
27
+ else
28
+ return random_string
29
+ end
30
+ end
31
+
32
+ def random_array
33
+ result = []
34
+ size = rand(3..8)
35
+
36
+ size.times do
37
+ result << random_string
38
+ end
39
+
40
+ return result
41
+ end
42
+
43
+ def random_hash
44
+ result = {}
45
+ size = rand(3..8)
46
+
47
+ size.times do
48
+ result[random_string] = random_string
49
+ end
50
+
51
+ return result
52
+ end
53
+
54
+ def random_string
55
+ chars = ['a'..'z', 'A'..'Z', '0'..'9'].flat_map(&:to_a)
56
+ size = rand(6..16)
57
+ return chars.sample(size).join
58
+ end
59
+ end
60
+ end
61
+ end
metadata ADDED
@@ -0,0 +1,49 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: hiera-mock
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.0
5
+ platform: ruby
6
+ authors:
7
+ - Jo Vandeginste
8
+ - Tom Leuse
9
+ autorequire:
10
+ bindir: bin
11
+ cert_chain: []
12
+ date: 2016-06-24 00:00:00.000000000 Z
13
+ dependencies: []
14
+ description: |
15
+ Hiera backend to return data from a single yaml file or random data (meant for testing purposes)
16
+ email:
17
+ - jo.vandeginste@kuleuven.be
18
+ - tom.leuse@kuleuven.be
19
+ executables: []
20
+ extensions: []
21
+ extra_rdoc_files: []
22
+ files:
23
+ - lib/hiera/backend/mock_backend.rb
24
+ homepage: https://github.com/jovandeginste/hiera-mock
25
+ licenses:
26
+ - Apache-2.0
27
+ metadata: {}
28
+ post_install_message:
29
+ rdoc_options: []
30
+ require_paths:
31
+ - lib
32
+ required_ruby_version: !ruby/object:Gem::Requirement
33
+ requirements:
34
+ - - ">="
35
+ - !ruby/object:Gem::Version
36
+ version: '0'
37
+ required_rubygems_version: !ruby/object:Gem::Requirement
38
+ requirements:
39
+ - - ">="
40
+ - !ruby/object:Gem::Version
41
+ version: '0'
42
+ requirements: []
43
+ rubyforge_project:
44
+ rubygems_version: 2.4.5
45
+ signing_key:
46
+ specification_version: 4
47
+ summary: Hiera backend to return data from a single yaml file or random data (meant
48
+ for testing purposes)
49
+ test_files: []