fqdn_facts 0.2.0 → 0.3.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.rubocop.yml +218 -0
- data/fqdn_facts.gemspec +20 -7
- data/lib/fqdn_facts.rb +0 -1
- data/lib/fqdn_facts/core_ext.rb +17 -21
- data/lib/fqdn_facts/handler.rb +43 -36
- data/lib/fqdn_facts/version.rb +6 -2
- data/spec/fqdn_facts_spec.rb +60 -17
- metadata +103 -18
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 59d547e6241c5963958b2de19fd71bfe41556a91
|
4
|
+
data.tar.gz: 113337231cca3023d9f1a4078c9395e2a0a3269e
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 8ab809b6c1096f6da64166e840b32ec79141d158cb309adb40c6ed4f097858e3789dcf49e1f3d3aa8e4ff98a1b826a29b62224dad8993b234ed5ab730aca452b
|
7
|
+
data.tar.gz: 748ba5ab9d238fba1b8e46d4b9fb787711cb563784dc72969d25ae86b97fa54da80e7cfacb48c938dd8ace0726f6d403fb0682c2fb930eb120736a1deaabc9f3
|
data/.rubocop.yml
ADDED
@@ -0,0 +1,218 @@
|
|
1
|
+
AllCops:
|
2
|
+
Include:
|
3
|
+
- Rakefile
|
4
|
+
Exclude:
|
5
|
+
- test.rb
|
6
|
+
- bin/**
|
7
|
+
|
8
|
+
Style/Tab:
|
9
|
+
Enabled: false
|
10
|
+
|
11
|
+
Style/IndentationWidth:
|
12
|
+
Enabled: false
|
13
|
+
|
14
|
+
SpecialGlobalVars:
|
15
|
+
Enabled: false
|
16
|
+
|
17
|
+
BlockComments:
|
18
|
+
Enabled: false
|
19
|
+
|
20
|
+
Encoding:
|
21
|
+
Enabled: false
|
22
|
+
|
23
|
+
RegexpLiteral:
|
24
|
+
Enabled: false
|
25
|
+
|
26
|
+
# dots at the end of lines are okay
|
27
|
+
DotPosition:
|
28
|
+
Enabled: false
|
29
|
+
|
30
|
+
CollectionMethods:
|
31
|
+
PreferredMethods:
|
32
|
+
map: 'collect'
|
33
|
+
map!: 'collect!'
|
34
|
+
reduce: 'inject'
|
35
|
+
detect: 'find'
|
36
|
+
find_all: 'select'
|
37
|
+
|
38
|
+
CaseIndentation:
|
39
|
+
IndentWhenRelativeTo: end
|
40
|
+
IndentOneStep: true
|
41
|
+
|
42
|
+
LineLength:
|
43
|
+
Enabled: false
|
44
|
+
|
45
|
+
# Personally, I prefer to outdent public/protected/private, as it makes
|
46
|
+
# it easier to see the different sections of code.
|
47
|
+
AccessModifierIndentation:
|
48
|
+
EnforcedStyle: outdent
|
49
|
+
|
50
|
+
EmptyLinesAroundAccessModifier:
|
51
|
+
Enabled: true
|
52
|
+
|
53
|
+
EndAlignment:
|
54
|
+
AlignWith: variable
|
55
|
+
|
56
|
+
SpaceInsideBrackets:
|
57
|
+
Enabled: false
|
58
|
+
|
59
|
+
Style/ClassAndModuleChildren:
|
60
|
+
Enabled: false
|
61
|
+
|
62
|
+
Style/CommandLiteral:
|
63
|
+
Enabled: false
|
64
|
+
|
65
|
+
# Relaxed.Ruby.Style
|
66
|
+
|
67
|
+
Style/Alias:
|
68
|
+
Enabled: false
|
69
|
+
StyleGuide: http://relaxed.ruby.style/#stylealias
|
70
|
+
|
71
|
+
Style/BeginBlock:
|
72
|
+
Enabled: false
|
73
|
+
StyleGuide: http://relaxed.ruby.style/#stylebeginblock
|
74
|
+
|
75
|
+
Style/BlockDelimiters:
|
76
|
+
Enabled: false
|
77
|
+
StyleGuide: http://relaxed.ruby.style/#styleblockdelimiters
|
78
|
+
|
79
|
+
Style/Documentation:
|
80
|
+
Enabled: false
|
81
|
+
StyleGuide: http://relaxed.ruby.style/#styledocumentation
|
82
|
+
|
83
|
+
Style/DotPosition:
|
84
|
+
Enabled: false
|
85
|
+
StyleGuide: http://relaxed.ruby.style/#styledotposition
|
86
|
+
|
87
|
+
Style/DoubleNegation:
|
88
|
+
Enabled: false
|
89
|
+
StyleGuide: http://relaxed.ruby.style/#styledoublenegation
|
90
|
+
|
91
|
+
Style/EndBlock:
|
92
|
+
Enabled: false
|
93
|
+
StyleGuide: http://relaxed.ruby.style/#styleendblock
|
94
|
+
|
95
|
+
Style/FormatString:
|
96
|
+
Enabled: false
|
97
|
+
StyleGuide: http://relaxed.ruby.style/#styleformatstring
|
98
|
+
|
99
|
+
Style/IfUnlessModifier:
|
100
|
+
Enabled: false
|
101
|
+
StyleGuide: http://relaxed.ruby.style/#styleifunlessmodifier
|
102
|
+
|
103
|
+
Style/Lambda:
|
104
|
+
Enabled: false
|
105
|
+
StyleGuide: http://relaxed.ruby.style/#stylelambda
|
106
|
+
|
107
|
+
Style/ModuleFunction:
|
108
|
+
Enabled: false
|
109
|
+
StyleGuide: http://relaxed.ruby.style/#stylemodulefunction
|
110
|
+
|
111
|
+
Style/MultilineBlockChain:
|
112
|
+
Enabled: false
|
113
|
+
StyleGuide: http://relaxed.ruby.style/#stylemultilineblockchain
|
114
|
+
|
115
|
+
Style/NegatedIf:
|
116
|
+
Enabled: false
|
117
|
+
StyleGuide: http://relaxed.ruby.style/#stylenegatedif
|
118
|
+
|
119
|
+
Style/NegatedWhile:
|
120
|
+
Enabled: false
|
121
|
+
StyleGuide: http://relaxed.ruby.style/#stylenegatedwhile
|
122
|
+
|
123
|
+
Style/ParallelAssignment:
|
124
|
+
Enabled: false
|
125
|
+
StyleGuide: http://relaxed.ruby.style/#styleparallelassignment
|
126
|
+
|
127
|
+
Style/PercentLiteralDelimiters:
|
128
|
+
Enabled: false
|
129
|
+
StyleGuide: http://relaxed.ruby.style/#stylepercentliteraldelimiters
|
130
|
+
|
131
|
+
Style/PerlBackrefs:
|
132
|
+
Enabled: false
|
133
|
+
StyleGuide: http://relaxed.ruby.style/#styleperlbackrefs
|
134
|
+
|
135
|
+
Style/Semicolon:
|
136
|
+
Enabled: false
|
137
|
+
StyleGuide: http://relaxed.ruby.style/#stylesemicolon
|
138
|
+
|
139
|
+
Style/SignalException:
|
140
|
+
Enabled: false
|
141
|
+
StyleGuide: http://relaxed.ruby.style/#stylesignalexception
|
142
|
+
|
143
|
+
Style/SingleLineBlockParams:
|
144
|
+
Enabled: false
|
145
|
+
StyleGuide: http://relaxed.ruby.style/#stylesinglelineblockparams
|
146
|
+
|
147
|
+
Style/SingleLineMethods:
|
148
|
+
Enabled: false
|
149
|
+
StyleGuide: http://relaxed.ruby.style/#stylesinglelinemethods
|
150
|
+
|
151
|
+
Style/SpaceBeforeBlockBraces:
|
152
|
+
Enabled: false
|
153
|
+
StyleGuide: http://relaxed.ruby.style/#stylespacebeforeblockbraces
|
154
|
+
|
155
|
+
Style/SpaceInsideParens:
|
156
|
+
Enabled: false
|
157
|
+
StyleGuide: http://relaxed.ruby.style/#stylespaceinsideparens
|
158
|
+
|
159
|
+
Style/SpecialGlobalVars:
|
160
|
+
Enabled: false
|
161
|
+
StyleGuide: http://relaxed.ruby.style/#stylespecialglobalvars
|
162
|
+
|
163
|
+
Style/StringLiterals:
|
164
|
+
Enabled: false
|
165
|
+
StyleGuide: http://relaxed.ruby.style/#stylestringliterals
|
166
|
+
|
167
|
+
Style/TrailingComma:
|
168
|
+
Enabled: false
|
169
|
+
StyleGuide: http://relaxed.ruby.style/#styletrailingcomma
|
170
|
+
|
171
|
+
Style/TrailingCommaInLiteral:
|
172
|
+
Enabled: false
|
173
|
+
StyleGuide: http://relaxed.ruby.style/#styletrailingcomma
|
174
|
+
|
175
|
+
Style/TrailingCommaInArguments:
|
176
|
+
Enabled: false
|
177
|
+
StyleGuide: http://relaxed.ruby.style/#styletrailingcomma
|
178
|
+
|
179
|
+
Style/WhileUntilModifier:
|
180
|
+
Enabled: false
|
181
|
+
StyleGuide: http://relaxed.ruby.style/#stylewhileuntilmodifier
|
182
|
+
|
183
|
+
Lint/AmbiguousRegexpLiteral:
|
184
|
+
Enabled: false
|
185
|
+
StyleGuide: http://relaxed.ruby.style/#lintambiguousregexpliteral
|
186
|
+
|
187
|
+
Lint/AssignmentInCondition:
|
188
|
+
Enabled: false
|
189
|
+
StyleGuide: http://relaxed.ruby.style/#lintassignmentincondition
|
190
|
+
|
191
|
+
Metrics/AbcSize:
|
192
|
+
Enabled: false
|
193
|
+
|
194
|
+
Metrics/BlockNesting:
|
195
|
+
Enabled: false
|
196
|
+
|
197
|
+
Metrics/ClassLength:
|
198
|
+
Enabled: false
|
199
|
+
|
200
|
+
Metrics/ModuleLength:
|
201
|
+
Enabled: false
|
202
|
+
|
203
|
+
Metrics/CyclomaticComplexity:
|
204
|
+
Enabled: false
|
205
|
+
|
206
|
+
Metrics/LineLength:
|
207
|
+
Enabled: false
|
208
|
+
|
209
|
+
Metrics/MethodLength:
|
210
|
+
Enabled: false
|
211
|
+
|
212
|
+
Metrics/ParameterLists:
|
213
|
+
Enabled: false
|
214
|
+
|
215
|
+
Metrics/PerceivedComplexity:
|
216
|
+
Enabled: false
|
217
|
+
|
218
|
+
|
data/fqdn_facts.gemspec
CHANGED
@@ -1,6 +1,6 @@
|
|
1
1
|
# coding: utf-8
|
2
|
-
|
3
|
-
|
2
|
+
$LOAD_PATH.unshift File.expand_path('../lib', __FILE__)
|
3
|
+
|
4
4
|
require 'fqdn_facts/version'
|
5
5
|
|
6
6
|
Gem::Specification.new do |spec|
|
@@ -8,8 +8,11 @@ Gem::Specification.new do |spec|
|
|
8
8
|
spec.version = FqdnFacts::VERSION
|
9
9
|
spec.authors = ["Carl P. Corliss"]
|
10
10
|
spec.email = ["rabbitt@gmail.com"]
|
11
|
-
spec.summary =
|
12
|
-
spec.description =
|
11
|
+
spec.summary = 'Provides a DSL for generating FQDN specific facts that can be used with Facter'
|
12
|
+
spec.description = <<-'EOF'
|
13
|
+
FqdnFacts allows you to create fact handlers for different FQDN formats. This is primarily intended for
|
14
|
+
use with Puppet/Facter to facilitate dynamic fact generation based on FQDNs.
|
15
|
+
EOF
|
13
16
|
spec.homepage = "https://github.com/rabbitt/fqdn_facts/"
|
14
17
|
spec.license = "GPLv2"
|
15
18
|
|
@@ -18,7 +21,17 @@ Gem::Specification.new do |spec|
|
|
18
21
|
spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
|
19
22
|
spec.require_paths = ["lib"]
|
20
23
|
|
21
|
-
spec.add_development_dependency "
|
22
|
-
spec.add_development_dependency "
|
23
|
-
spec.add_development_dependency "rspec"
|
24
|
+
spec.add_development_dependency "rake", '~> 10.5.0'
|
25
|
+
spec.add_development_dependency "rack", '~> 1.6.4'
|
26
|
+
spec.add_development_dependency "rspec", '~> 3.4.0'
|
27
|
+
spec.add_development_dependency "rspec-its", '~> 1.2.0'
|
28
|
+
spec.add_development_dependency "rspec-collection_matchers", '~> 1.1.2'
|
29
|
+
spec.add_development_dependency "guard-rspec", '~> 4.6.4'
|
30
|
+
|
31
|
+
# optional dependencies
|
32
|
+
unless RUBY_ENGINE == 'jruby'
|
33
|
+
spec.add_development_dependency "pry", '~> 0.10.3'
|
34
|
+
spec.add_development_dependency "pry-nav", '~> 0.2.4'
|
35
|
+
spec.add_development_dependency 'rabbitt-githooks', '~> 1.6.1'
|
36
|
+
end
|
24
37
|
end
|
data/lib/fqdn_facts.rb
CHANGED
data/lib/fqdn_facts/core_ext.rb
CHANGED
@@ -23,7 +23,7 @@ class Object
|
|
23
23
|
#
|
24
24
|
# @return [false]
|
25
25
|
def empty?
|
26
|
-
|
26
|
+
false
|
27
27
|
end
|
28
28
|
|
29
29
|
# returns true if the object "contains" data
|
@@ -41,11 +41,9 @@ class Object
|
|
41
41
|
#
|
42
42
|
# @return the result of the method call, if the method exists, or nil if it doesn't
|
43
43
|
def try(method, *args, &block)
|
44
|
-
|
45
|
-
|
46
|
-
|
47
|
-
nil
|
48
|
-
end
|
44
|
+
public_send(method, *args, &block)
|
45
|
+
rescue NoMethodError
|
46
|
+
nil
|
49
47
|
end
|
50
48
|
end
|
51
49
|
|
@@ -67,34 +65,32 @@ class String
|
|
67
65
|
# converts a camelized string to underscored
|
68
66
|
# @return String
|
69
67
|
def underscore
|
70
|
-
|
68
|
+
split(/([A-Z][a-z0-9]+)/).reject(&:empty?).collect(&:downcase).join('_')
|
71
69
|
end
|
72
70
|
|
73
71
|
# converts an underscored string to a camelized one
|
74
72
|
# @return String
|
75
73
|
def camelize
|
76
|
-
|
74
|
+
split('_').collect(&:capitalize).join
|
77
75
|
end
|
78
76
|
|
79
77
|
# Attempts to transform string into a class constant
|
80
|
-
def constantize(base=Object)
|
81
|
-
|
82
|
-
|
83
|
-
|
78
|
+
def constantize(base = Object)
|
79
|
+
split('/')
|
80
|
+
.collect(&:camelize)
|
81
|
+
.inject(base) { |obj, klass| obj.const_get(klass) }
|
84
82
|
end
|
85
83
|
end
|
86
84
|
|
87
85
|
class Proc
|
88
86
|
# @see http://stackoverflow.com/a/10059209/988225
|
89
87
|
def call_with_vars(vars, *args)
|
90
|
-
|
91
|
-
|
92
|
-
|
93
|
-
|
94
|
-
|
95
|
-
|
96
|
-
warn "Couldn't find value for key '#{name}' at #{file}:#{line}"
|
97
|
-
end
|
88
|
+
Struct.new(*vars.keys).new(*vars.values).instance_exec(*args, &self)
|
89
|
+
rescue NameError
|
90
|
+
# don't error out - just warn
|
91
|
+
file, line = $!.backtrace.first.split(':')
|
92
|
+
name = $!.message.split(/[`']/)[1]
|
93
|
+
warn "Couldn't find value for key '#{name}' at #{file}:#{line}"
|
98
94
|
end
|
99
95
|
end
|
100
96
|
|
@@ -110,4 +106,4 @@ class Symbol
|
|
110
106
|
def split(*args)
|
111
107
|
to_s.split(*args)
|
112
108
|
end
|
113
|
-
end
|
109
|
+
end
|
data/lib/fqdn_facts/handler.rb
CHANGED
@@ -54,12 +54,14 @@ module FqdnFacts
|
|
54
54
|
# @option data [Array] :order sets the initial order of components
|
55
55
|
# @option data [Hash] :facts sets the initial set of facts
|
56
56
|
def initialize(data = {})
|
57
|
-
|
58
|
-
@
|
59
|
-
@
|
60
|
-
@
|
61
|
-
@
|
57
|
+
# rubocop:disable Style/SpaceAroundOperators
|
58
|
+
@priority = data.delete(:priority) || 1
|
59
|
+
@conversions = data.delete(:conversions) || {}
|
60
|
+
@components = data.delete(:components) || DEFAULT_COMPONENTS.dup
|
61
|
+
@order = data.delete(:order) || DEFAULT_COMPONENTS.keys
|
62
|
+
@facts = data.delete(:facts) || {}
|
62
63
|
@fqdn = ''
|
64
|
+
# rubocop:enable Style/SpaceAroundOperators
|
63
65
|
|
64
66
|
add_fact(:fqdn) { fqdn }
|
65
67
|
add_fact(:handler_class, self.class.to_s)
|
@@ -108,8 +110,8 @@ module FqdnFacts
|
|
108
110
|
#
|
109
111
|
# @param component <Symbol> the name of the component to set validation for
|
110
112
|
# @param validate [Hash{Symbol=>Symbol,Hash,Array,Scalar}] validation to perform for component
|
111
|
-
def component(component, validate
|
112
|
-
|
113
|
+
def component(component, validate = :any)
|
114
|
+
value = case validate
|
113
115
|
when :any then %r:(.+):
|
114
116
|
when Hash then
|
115
117
|
if @components[component.to_sym].is_a?(Hash)
|
@@ -136,12 +138,12 @@ module FqdnFacts
|
|
136
138
|
|
137
139
|
if @components[component.to_sym]
|
138
140
|
# if their not the same class, then remove any conversions
|
139
|
-
unless @components[component.to_sym].is_a?(
|
141
|
+
unless @components[component.to_sym].is_a?(value.class)
|
140
142
|
@conversions.delete(component.to_sym)
|
141
143
|
end
|
142
144
|
end
|
143
145
|
|
144
|
-
@components[component.to_sym]
|
146
|
+
@components[component.to_sym] = value
|
145
147
|
end
|
146
148
|
|
147
149
|
# Defines a conversion rule for a given component.
|
@@ -151,16 +153,16 @@ module FqdnFacts
|
|
151
153
|
# @param conversion [Hash,Proc] optional conversion hash, proc/lambda
|
152
154
|
# @param block [Proc] optional block
|
153
155
|
# @raise [ArgumentError] if conversion isn't Hash, Proc or Block
|
154
|
-
def convert(component, conversion=nil, &block)
|
156
|
+
def convert(component, conversion = nil, &block)
|
155
157
|
unless [Proc, Hash].any? { |klass| conversion.is_a?(klass) } || block_given?
|
156
158
|
raise ArgumentError, 'expected Hash, Proc or Block'
|
157
159
|
end
|
158
160
|
|
159
161
|
component = component.to_sym
|
160
|
-
conversion
|
162
|
+
conversion ||= block
|
161
163
|
|
162
164
|
conversion = if conversion.is_a? Hash
|
163
|
-
(@conversions[component]||={}).merge(conversion)
|
165
|
+
(@conversions[component] ||= {}).merge(conversion)
|
164
166
|
else
|
165
167
|
conversion
|
166
168
|
end
|
@@ -180,7 +182,7 @@ module FqdnFacts
|
|
180
182
|
#
|
181
183
|
# @param name <String> Symbol name of the fact to add
|
182
184
|
# @param value <Scalar,Array,Hash,Proc> value of the fact
|
183
|
-
def add_fact(name, value=nil, &block)
|
185
|
+
def add_fact(name, value = nil, &block)
|
184
186
|
value = block if block_given?
|
185
187
|
facts[name.to_sym] = value
|
186
188
|
end
|
@@ -201,17 +203,16 @@ module FqdnFacts
|
|
201
203
|
# @option options [Array<Symbol>] :only a list of specific facts to retrieve
|
202
204
|
#
|
203
205
|
# @return [Hash{Symbol=><Scalar,Hash,Array>}]
|
204
|
-
def retrieve(options={})
|
206
|
+
def retrieve(options = {})
|
205
207
|
prefix = options.delete(:prefix)
|
206
208
|
only = (o = options.delete(:only)).empty? ? nil : o.collect(&:to_sym)
|
207
209
|
|
208
210
|
assemble.dup.tap do |facts|
|
209
211
|
facts.replace(
|
210
|
-
Hash[facts.
|
211
|
-
next
|
212
|
+
Hash[facts.each_with_object({}) do |(fact, value), hash|
|
213
|
+
next unless only.empty? || only.include?(fact)
|
212
214
|
key = prefix.empty? ? fact : "#{prefix}_#{fact}"
|
213
215
|
hash[key] = value
|
214
|
-
hash
|
215
216
|
end.sort]
|
216
217
|
)
|
217
218
|
end
|
@@ -265,7 +266,7 @@ module FqdnFacts
|
|
265
266
|
debug " #{validation.class} -> #{value.inspect} == #{validation.inspect} == #{r.inspect}"
|
266
267
|
}
|
267
268
|
end
|
268
|
-
end.tap { |r| debug " ---> validation #{r ? 'successful' : 'failed'} for #{self.class}"}
|
269
|
+
end.tap { |r| debug " ---> validation #{r ? 'successful' : 'failed'} for #{self.class}" }
|
269
270
|
end
|
270
271
|
|
271
272
|
# Compares the priority of this handler to another handler
|
@@ -273,34 +274,33 @@ module FqdnFacts
|
|
273
274
|
# @param other <Handler> the handler to compare against
|
274
275
|
# @return [-1, 0, 1] if other is <=, =, or >= self
|
275
276
|
def <=>(other)
|
276
|
-
|
277
|
+
priority <=> other.priority
|
277
278
|
end
|
278
279
|
|
279
280
|
# Exports the internal state as a hash
|
280
281
|
# @api private
|
281
282
|
def export
|
282
|
-
instance_variables.
|
283
|
+
instance_variables.each_with_object({}) do |name, exports|
|
283
284
|
varname = name.to_s.tr('@', '').to_sym
|
284
285
|
exports[varname] = begin
|
285
286
|
Marshal.load(Marshal.dump(instance_variable_get(name)))
|
286
287
|
rescue TypeError
|
287
288
|
instance_variable_get(name).dup
|
288
289
|
end
|
289
|
-
exports
|
290
290
|
end
|
291
291
|
end
|
292
292
|
|
293
|
-
|
293
|
+
private
|
294
294
|
|
295
295
|
# Assemble facts from gathered data
|
296
296
|
# @return [self]
|
297
297
|
# @api private
|
298
298
|
def assemble
|
299
|
-
{
|
299
|
+
{}.tap do |data|
|
300
300
|
data.merge!(facts.merge(Hash[fqdn_components]))
|
301
301
|
|
302
302
|
# expand subtypes
|
303
|
-
@components.each do |name, value|
|
303
|
+
@components.select { |k, _| @order.include? k }.each do |name, value|
|
304
304
|
# components are converted explicitly during expansino, and solely
|
305
305
|
# based on their value
|
306
306
|
conversion = @conversions[name]
|
@@ -316,17 +316,26 @@ module FqdnFacts
|
|
316
316
|
end
|
317
317
|
end
|
318
318
|
|
319
|
+
finished = false
|
320
|
+
|
319
321
|
# handle any remaining runtime generated facts
|
320
|
-
|
321
|
-
|
322
|
-
|
323
|
-
|
324
|
-
|
322
|
+
until finished
|
323
|
+
finished = true
|
324
|
+
data.each do |fact, value|
|
325
|
+
case value
|
326
|
+
when Proc then
|
327
|
+
finished = false
|
328
|
+
value = convert_value(data, value)
|
329
|
+
when Symbol then
|
330
|
+
value
|
331
|
+
else
|
332
|
+
next
|
333
|
+
end
|
334
|
+
data[fact] = value.is_a?(Symbol) ? value.to_s : value
|
325
335
|
end
|
326
|
-
data[fact] = value.is_a?(Symbol) ? value.to_s : value
|
327
336
|
end
|
328
337
|
|
329
|
-
data.reject! { |
|
338
|
+
data.reject! { |_, value| value.empty? }
|
330
339
|
end
|
331
340
|
end
|
332
341
|
|
@@ -334,12 +343,12 @@ module FqdnFacts
|
|
334
343
|
case converter
|
335
344
|
when Proc then
|
336
345
|
bind_data = value.is_a?(Hash) ? value.dup : { value: value }
|
337
|
-
bind_data.merge!(
|
346
|
+
bind_data.merge!(
|
338
347
|
fqdn: fqdn,
|
339
348
|
components: Hash[fqdn_components],
|
340
349
|
priority: priority,
|
341
350
|
handler_class: self.class.name
|
342
|
-
|
351
|
+
)
|
343
352
|
|
344
353
|
value = if converter.arity == 1
|
345
354
|
converter.call_with_vars(bind_data, value)
|
@@ -369,9 +378,7 @@ module FqdnFacts
|
|
369
378
|
|
370
379
|
# @api private
|
371
380
|
def debug(message)
|
372
|
-
if ENV.keys.collect(&:downcase).include? 'debug'
|
373
|
-
STDERR.puts message
|
374
|
-
end
|
381
|
+
STDERR.puts message if ENV.keys.collect(&:downcase).include? 'debug'
|
375
382
|
end
|
376
383
|
end
|
377
384
|
end
|
data/lib/fqdn_facts/version.rb
CHANGED
data/spec/fqdn_facts_spec.rb
CHANGED
@@ -7,17 +7,22 @@ describe FqdnFacts do
|
|
7
7
|
|
8
8
|
components :host, :sub, :tld
|
9
9
|
|
10
|
-
component :host,
|
10
|
+
component :host, type: %r'^([^\d]+)', id: %r'(\d+)', subtype: %r'([ms]?)'
|
11
11
|
component :tld, 'example.com'
|
12
12
|
|
13
|
-
convert :host,
|
14
|
-
|
15
|
-
|
16
|
-
}
|
13
|
+
convert :host,
|
14
|
+
subtype: ->(v) { v == 'm' ? 'master' : 'slave' },
|
15
|
+
id: ->(v) { v.to_i }
|
17
16
|
|
17
|
+
add_fact :hname, ->(f) { f[:hostname] }
|
18
18
|
add_fact :hostname, ->(f) { f[:host] }
|
19
19
|
add_fact :domain, ->(f) { [f[:sub], f[:tld]].join('.') }
|
20
20
|
end
|
21
|
+
|
22
|
+
FqdnFacts.register(:foo, copy: :baseline) do
|
23
|
+
priority 15
|
24
|
+
components :sub, :tld
|
25
|
+
end
|
21
26
|
end
|
22
27
|
|
23
28
|
it 'has a version number' do
|
@@ -28,7 +33,44 @@ describe FqdnFacts do
|
|
28
33
|
expect(FqdnFacts.registry).to include(:baseline)
|
29
34
|
end
|
30
35
|
|
31
|
-
context 'with fqdn "
|
36
|
+
context 'with fqdn set to "bar.example.com"' do
|
37
|
+
before do
|
38
|
+
@fqdn = 'bar.example.com'
|
39
|
+
@handler = FqdnFacts.handler(@fqdn)
|
40
|
+
end
|
41
|
+
|
42
|
+
it 'returns a valid hash' do
|
43
|
+
expect(@handler.retrieve_facts).to be_a Hash
|
44
|
+
end
|
45
|
+
|
46
|
+
describe 'has fact' do
|
47
|
+
let(:facts) { @handler.retrieve_facts }
|
48
|
+
{
|
49
|
+
sub: 'bar',
|
50
|
+
domain: 'bar.example.com',
|
51
|
+
fqdn: 'bar.example.com',
|
52
|
+
handler_name: 'foo'
|
53
|
+
}.each do |key, value|
|
54
|
+
it "#{key.inspect} equal to #{value.inspect}" do
|
55
|
+
expect(facts).to include(key)
|
56
|
+
expect(facts[key]).to eq(value)
|
57
|
+
end
|
58
|
+
end
|
59
|
+
end
|
60
|
+
|
61
|
+
describe "doesn't have fact" do
|
62
|
+
let(:facts) { @handler.retrieve_facts }
|
63
|
+
[
|
64
|
+
:hname, :host, :host_type, :host_id, :host_subtype, :hostname
|
65
|
+
].each do |key, value|
|
66
|
+
it "#{key.inspect}" do
|
67
|
+
expect(facts).not_to include(key)
|
68
|
+
end
|
69
|
+
end
|
70
|
+
end
|
71
|
+
end
|
72
|
+
|
73
|
+
context 'with fqdn set to "foo01m.bar.example.com"' do
|
32
74
|
before do
|
33
75
|
@fqdn = 'foo01m.bar.example.com'
|
34
76
|
@handler = FqdnFacts.handler(@fqdn)
|
@@ -38,20 +80,21 @@ describe FqdnFacts do
|
|
38
80
|
expect(@handler.retrieve_facts).to be_a Hash
|
39
81
|
end
|
40
82
|
|
41
|
-
describe '
|
83
|
+
describe 'has fact' do
|
42
84
|
let(:facts) { @handler.retrieve_facts }
|
43
85
|
{
|
44
|
-
:
|
45
|
-
:
|
46
|
-
:
|
47
|
-
:
|
48
|
-
:
|
49
|
-
:
|
50
|
-
:
|
51
|
-
:
|
52
|
-
:
|
86
|
+
hname: 'foo01m',
|
87
|
+
host: 'foo01m',
|
88
|
+
host_type: 'foo',
|
89
|
+
host_id: 1,
|
90
|
+
host_subtype: 'master',
|
91
|
+
hostname: 'foo01m',
|
92
|
+
sub: 'bar',
|
93
|
+
domain: 'bar.example.com',
|
94
|
+
fqdn: 'foo01m.bar.example.com',
|
95
|
+
handler_name: 'baseline'
|
53
96
|
}.each do |key, value|
|
54
|
-
it "
|
97
|
+
it "#{key.inspect} equal to #{value.inspect}" do
|
55
98
|
expect(facts).to include(key)
|
56
99
|
expect(facts[key]).to eq(value)
|
57
100
|
end
|
metadata
CHANGED
@@ -1,60 +1,144 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: fqdn_facts
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.3.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Carl P. Corliss
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date:
|
11
|
+
date: 2016-04-13 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
|
-
name:
|
14
|
+
name: rake
|
15
15
|
requirement: !ruby/object:Gem::Requirement
|
16
16
|
requirements:
|
17
17
|
- - "~>"
|
18
18
|
- !ruby/object:Gem::Version
|
19
|
-
version:
|
19
|
+
version: 10.5.0
|
20
20
|
type: :development
|
21
21
|
prerelease: false
|
22
22
|
version_requirements: !ruby/object:Gem::Requirement
|
23
23
|
requirements:
|
24
24
|
- - "~>"
|
25
25
|
- !ruby/object:Gem::Version
|
26
|
-
version:
|
26
|
+
version: 10.5.0
|
27
27
|
- !ruby/object:Gem::Dependency
|
28
|
-
name:
|
28
|
+
name: rack
|
29
29
|
requirement: !ruby/object:Gem::Requirement
|
30
30
|
requirements:
|
31
|
-
- - "
|
31
|
+
- - "~>"
|
32
32
|
- !ruby/object:Gem::Version
|
33
|
-
version:
|
33
|
+
version: 1.6.4
|
34
34
|
type: :development
|
35
35
|
prerelease: false
|
36
36
|
version_requirements: !ruby/object:Gem::Requirement
|
37
37
|
requirements:
|
38
|
-
- - "
|
38
|
+
- - "~>"
|
39
39
|
- !ruby/object:Gem::Version
|
40
|
-
version:
|
40
|
+
version: 1.6.4
|
41
41
|
- !ruby/object:Gem::Dependency
|
42
42
|
name: rspec
|
43
43
|
requirement: !ruby/object:Gem::Requirement
|
44
44
|
requirements:
|
45
|
-
- - "
|
45
|
+
- - "~>"
|
46
|
+
- !ruby/object:Gem::Version
|
47
|
+
version: 3.4.0
|
48
|
+
type: :development
|
49
|
+
prerelease: false
|
50
|
+
version_requirements: !ruby/object:Gem::Requirement
|
51
|
+
requirements:
|
52
|
+
- - "~>"
|
53
|
+
- !ruby/object:Gem::Version
|
54
|
+
version: 3.4.0
|
55
|
+
- !ruby/object:Gem::Dependency
|
56
|
+
name: rspec-its
|
57
|
+
requirement: !ruby/object:Gem::Requirement
|
58
|
+
requirements:
|
59
|
+
- - "~>"
|
60
|
+
- !ruby/object:Gem::Version
|
61
|
+
version: 1.2.0
|
62
|
+
type: :development
|
63
|
+
prerelease: false
|
64
|
+
version_requirements: !ruby/object:Gem::Requirement
|
65
|
+
requirements:
|
66
|
+
- - "~>"
|
67
|
+
- !ruby/object:Gem::Version
|
68
|
+
version: 1.2.0
|
69
|
+
- !ruby/object:Gem::Dependency
|
70
|
+
name: rspec-collection_matchers
|
71
|
+
requirement: !ruby/object:Gem::Requirement
|
72
|
+
requirements:
|
73
|
+
- - "~>"
|
74
|
+
- !ruby/object:Gem::Version
|
75
|
+
version: 1.1.2
|
76
|
+
type: :development
|
77
|
+
prerelease: false
|
78
|
+
version_requirements: !ruby/object:Gem::Requirement
|
79
|
+
requirements:
|
80
|
+
- - "~>"
|
81
|
+
- !ruby/object:Gem::Version
|
82
|
+
version: 1.1.2
|
83
|
+
- !ruby/object:Gem::Dependency
|
84
|
+
name: guard-rspec
|
85
|
+
requirement: !ruby/object:Gem::Requirement
|
86
|
+
requirements:
|
87
|
+
- - "~>"
|
88
|
+
- !ruby/object:Gem::Version
|
89
|
+
version: 4.6.4
|
90
|
+
type: :development
|
91
|
+
prerelease: false
|
92
|
+
version_requirements: !ruby/object:Gem::Requirement
|
93
|
+
requirements:
|
94
|
+
- - "~>"
|
95
|
+
- !ruby/object:Gem::Version
|
96
|
+
version: 4.6.4
|
97
|
+
- !ruby/object:Gem::Dependency
|
98
|
+
name: pry
|
99
|
+
requirement: !ruby/object:Gem::Requirement
|
100
|
+
requirements:
|
101
|
+
- - "~>"
|
102
|
+
- !ruby/object:Gem::Version
|
103
|
+
version: 0.10.3
|
104
|
+
type: :development
|
105
|
+
prerelease: false
|
106
|
+
version_requirements: !ruby/object:Gem::Requirement
|
107
|
+
requirements:
|
108
|
+
- - "~>"
|
109
|
+
- !ruby/object:Gem::Version
|
110
|
+
version: 0.10.3
|
111
|
+
- !ruby/object:Gem::Dependency
|
112
|
+
name: pry-nav
|
113
|
+
requirement: !ruby/object:Gem::Requirement
|
114
|
+
requirements:
|
115
|
+
- - "~>"
|
116
|
+
- !ruby/object:Gem::Version
|
117
|
+
version: 0.2.4
|
118
|
+
type: :development
|
119
|
+
prerelease: false
|
120
|
+
version_requirements: !ruby/object:Gem::Requirement
|
121
|
+
requirements:
|
122
|
+
- - "~>"
|
123
|
+
- !ruby/object:Gem::Version
|
124
|
+
version: 0.2.4
|
125
|
+
- !ruby/object:Gem::Dependency
|
126
|
+
name: rabbitt-githooks
|
127
|
+
requirement: !ruby/object:Gem::Requirement
|
128
|
+
requirements:
|
129
|
+
- - "~>"
|
46
130
|
- !ruby/object:Gem::Version
|
47
|
-
version:
|
131
|
+
version: 1.6.1
|
48
132
|
type: :development
|
49
133
|
prerelease: false
|
50
134
|
version_requirements: !ruby/object:Gem::Requirement
|
51
135
|
requirements:
|
52
|
-
- - "
|
136
|
+
- - "~>"
|
53
137
|
- !ruby/object:Gem::Version
|
54
|
-
version:
|
55
|
-
description:
|
56
|
-
|
57
|
-
|
138
|
+
version: 1.6.1
|
139
|
+
description: |2
|
140
|
+
FqdnFacts allows you to create fact handlers for different FQDN formats. This is primarily intended for
|
141
|
+
use with Puppet/Facter to facilitate dynamic fact generation based on FQDNs.
|
58
142
|
email:
|
59
143
|
- rabbitt@gmail.com
|
60
144
|
executables: []
|
@@ -63,6 +147,7 @@ extra_rdoc_files: []
|
|
63
147
|
files:
|
64
148
|
- ".gitignore"
|
65
149
|
- ".rspec"
|
150
|
+
- ".rubocop.yml"
|
66
151
|
- ".travis.yml"
|
67
152
|
- Gemfile
|
68
153
|
- LICENSE.txt
|
@@ -96,7 +181,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
96
181
|
version: '0'
|
97
182
|
requirements: []
|
98
183
|
rubyforge_project:
|
99
|
-
rubygems_version: 2.
|
184
|
+
rubygems_version: 2.4.3
|
100
185
|
signing_key:
|
101
186
|
specification_version: 4
|
102
187
|
summary: Provides a DSL for generating FQDN specific facts that can be used with Facter
|