ach_flattenmeta 0.4.0 → 0.5.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 3c1d2b9ae767b34edcf82fb77f7ccc53f72c9e041f0e7460ad3e0cd02a2a863f
4
- data.tar.gz: 9ef45eafa4ee8ab4f3ca92398429a0c2e2b23f3906ae35c16d48165158fcf1bd
3
+ metadata.gz: 1bcdbc5f2be0ec39033d928401cbb57e8f07e88e4a4f5808222b6b366f9bad8e
4
+ data.tar.gz: 4f7dce1ed8b363d236e9bb420cb0b85b3441f0e9c449adf14de6640ea95a53fb
5
5
  SHA512:
6
- metadata.gz: ed62f52a3fe3c3e384265703a4f3a0ee93ad406d8726572bc273445aaff357e99689272975eb3420afa7dce7298d1d4dfade1110cdf4a8d0e38562ed764e3235
7
- data.tar.gz: 99eacc1d08760d7d2cb3855869f86bf470cb8f4e066b988492ecd0b742578502bcf554d9c7ffbd08ffd947233b22e890c7d69791286842616366d7ca29a26827
6
+ metadata.gz: 04bc9856287cb72df3e70434500f26280671e39aba576defb7a5b89a1a219a5ff4d2d23e80b17b537a37f00f809233b400c585ee57f5dcd8de211a8604c8508e
7
+ data.tar.gz: fb9e81ada15fb9de6b8c5e99f5eb42e8fbf16f3d5194b62b472bcd33bed1b991d7ff15eec950f13e9de85708847b05bc746c0a789f6b20bae7916d36057ffba7
data/README.md CHANGED
@@ -1 +1,58 @@
1
- # ach_flattenmeta
1
+ ach_flattenmeta gem
2
+ ===================
3
+
4
+ This gem provides a class to read a config hash with metadata and return only the relevant config items for your platform and environment
5
+ based on the data in your metadata.
6
+
7
+ It is to be used in chef resources, to make the attribute system more usabled and to write "data driven" resources.
8
+
9
+
10
+ - FlattenMeta class
11
+
12
+ Generic class to read a config hash metadata and return only the relevant config items for your platform and environment based on a metadata hash
13
+
14
+ Example:
15
+ ```
16
+ # Firewall rich rules
17
+ default['fw_richrules']['ach_base'] = {
18
+ 'metadata': {
19
+ 'platforms' => ['rhel7'],
20
+ 'environments' => ['all'],
21
+ 'priority' => ['99'],
22
+ 'active' => true
23
+ },
24
+ 'rule family="ipv4" source address="192.168.1.101/32" service name="https" accept limit value="1/m"': true
25
+ }
26
+ ```
27
+
28
+ the keyword `all` can be used in the `platforms` and `environments` array to specify any platform/environment
29
+
30
+ A priority system is used to override values of existing config items, the lowest priority number equals the highest priority.
31
+ ach_base config items should default to prio value 99, application cookbooks should defaut to prio 50
32
+
33
+ If you want to totally disable a config key,value pair you have to define a new config hash with its `active` property in the meta hash set to false
34
+
35
+ Example:# ach_flattenmeta
36
+ Example:
37
+ ```
38
+ default['ach_sysctl']['ach_base'] = {
39
+ 'metadata' => {
40
+ 'platform' => ['default'],
41
+ 'environments' => ['default'],
42
+ 'priority' => 99,
43
+ 'active'=> true
44
+ },
45
+ 'sunrpc.transports' => 'udp 32768',
46
+ 'vm.nr_hugepages' => 0
47
+ }
48
+
49
+ default['ach_sysctl']['ach_base_override'] = {
50
+ 'metadata' => {
51
+ 'platform' => ['default'],
52
+ 'environments' => ['default'],
53
+ 'priority' => 99,
54
+ 'active'=> false
55
+ },
56
+ 'vm.nr_hugepages' => 0
57
+ }
58
+ ```
@@ -1,6 +1,6 @@
1
1
  Gem::Specification.new do |s|
2
2
  s.name = 'ach_flattenmeta'
3
- s.version = '0.4.0'
3
+ s.version = '0.5.0'
4
4
  s.date = '2018-07-26'
5
5
  s.summary = "flattenmeta helper gem"
6
6
  s.description = "A flattenmeta helper gem"
@@ -20,22 +20,27 @@ module AchFlattenMeta
20
20
  private
21
21
  def filter()
22
22
  @confhash.each do | location, data|
23
- if (data['metadata']['environments'] & [@node_environment, 'all']).any? &&
24
- (data['metadata']['platforms'] & [@os_version, 'all']).any?
23
+ # Do some basic sanity checks on the config hash passed
24
+ raise ArgumentError, 'environments is not an Array' unless data['metadata']['environments'].kind_of?(Array)
25
+ raise ArgumentError, 'platforms is not an Array' unless data['metadata']['platforms'].kind_of?(Array)
26
+ raise ArgumentError, 'priority is not an Integer' unless data['metadata']['priority'].is_a? Integer
27
+ raise ArgumentError, 'active is not a Boolean' unless data['metadata']['active'].is_a? TrueClass or data['metadata']['active'].is_a? FalseClass
28
+ if(data['metadata']['environments'] & [@node_environment, 'all']).any? &&
29
+ (data['metadata']['platforms'] & [@os_version, 'all']).any?
25
30
 
26
- prio = data['metadata']['priority']
27
- active = data['metadata']['active']
31
+ prio = data['metadata']['priority']
32
+ active = data['metadata']['active']
28
33
 
29
- data.each do | k, v |
30
- next if k == 'metadata'
31
- if @flatconf.key?(k)
32
- @flatconf[k] = { 'value' => v, 'priority' => prio, 'active' => active } if @flatconf[k]['priority'] > prio
33
- else
34
- @flatconf[k] = { 'value' => v, 'priority' => prio, 'active' => active }
35
- end # if
36
- end #each
37
- end # if
38
- end # each
39
- end # def
40
- end # class
41
- end
34
+ data.each do | k, v |
35
+ next if k == 'metadata'
36
+ if @flatconf.key?(k)
37
+ @flatconf[k] = { 'value' => v, 'priority' => prio, 'active' => active } if @flatconf[k]['priority'] > prio
38
+ else
39
+ @flatconf[k] = { 'value' => v, 'priority' => prio, 'active' => active }
40
+ end # if 'metadata'
41
+ end #data.each
42
+ end # if any?
43
+ end # @confhas.each
44
+ end # def filter
45
+ end # class FlattenMeta
46
+ end # module AchFlattenMeta
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: ach_flattenmeta
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.4.0
4
+ version: 0.5.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Rogier Jobse