Skip to content

Commit 96cbfd6

Browse files
committed
FM-7590 - strings
1 parent 48d89de commit 96cbfd6

File tree

143 files changed

+3228
-5312
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

143 files changed

+3228
-5312
lines changed

README.md

+16-3,116
Large diffs are not rendered by default.

REFERENCE.md

+1,944-1,471
Large diffs are not rendered by default.

lib/facter/facter_dot_d.rb

+24-3
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
1-
# A Facter plugin that loads facts from /etc/facter/facts.d
2-
# and /etc/puppetlabs/facter/facts.d.
1+
# @summary
2+
# A Facter plugin that loads facts from /etc/facter/facts.d
3+
# and /etc/puppetlabs/facter/facts.d.
34
#
45
# Facts can be in the form of JSON, YAML or Text files
56
# and any executable that returns key=value pairs.
@@ -13,20 +14,23 @@
1314
# fact scripts more often than is needed
1415
class Facter::Util::DotD
1516
require 'yaml'
16-
17+
# These will be nil if Puppet is not available.
1718
def initialize(dir = '/etc/facts.d', cache_file = File.join(Puppet[:libdir], 'facts_dot_d.cache'))
1819
@dir = dir
1920
@cache_file = cache_file
2021
@cache = nil
2122
@types = { '.txt' => :txt, '.json' => :json, '.yaml' => :yaml }
2223
end
2324

25+
# entries
2426
def entries
2527
Dir.entries(@dir).reject { |f| f =~ %r{^\.|\.ttl$} }.sort.map { |f| File.join(@dir, f) }
2628
rescue
2729
[]
2830
end
2931

32+
# fact_type
33+
# @param file
3034
def fact_type(file)
3135
extension = File.extname(file)
3236

@@ -37,6 +41,8 @@ def fact_type(file)
3741
type
3842
end
3943

44+
# txt_parser
45+
# @param file
4046
def txt_parser(file)
4147
File.readlines(file).each do |line|
4248
next unless line =~ %r{^([^=]+)=(.+)$}
@@ -51,6 +57,8 @@ def txt_parser(file)
5157
Facter.warn("Failed to handle #{file} as text facts: #{e.class}: #{e}")
5258
end
5359

60+
# json_parser
61+
# @param file
5462
def json_parser(file)
5563
begin
5664
require 'json'
@@ -68,6 +76,8 @@ def json_parser(file)
6876
Facter.warn("Failed to handle #{file} as json facts: #{e.class}: #{e}")
6977
end
7078

79+
# yaml_parser
80+
# @param file
7181
def yaml_parser(file)
7282
require 'yaml'
7383

@@ -80,6 +90,8 @@ def yaml_parser(file)
8090
Facter.warn("Failed to handle #{file} as yaml facts: #{e.class}: #{e}")
8191
end
8292

93+
# script_parser
94+
# @param file
8395
def script_parser(file)
8496
result = cache_lookup(file)
8597
ttl = cache_time(file)
@@ -110,19 +122,24 @@ def script_parser(file)
110122
Facter.debug(e.backtrace.join("\n\t"))
111123
end
112124

125+
# cache_save
113126
def cache_save!
114127
cache = load_cache
115128
File.open(@cache_file, 'w', 0o600) { |f| f.write(YAML.dump(cache)) }
116129
rescue # rubocop:disable Lint/HandleExceptions
117130
end
118131

132+
# cache_store
133+
# @param file
119134
def cache_store(file, data)
120135
load_cache
121136

122137
@cache[file] = { :data => data, :stored => Time.now.to_i }
123138
rescue # rubocop:disable Lint/HandleExceptions
124139
end
125140

141+
# cache_lookup
142+
# @param file
126143
def cache_lookup(file)
127144
cache = load_cache
128145

@@ -140,6 +157,8 @@ def cache_lookup(file)
140157
return nil
141158
end
142159

160+
# cache_time
161+
# @param file
143162
def cache_time(file)
144163
meta = file + '.ttl'
145164

@@ -148,6 +167,7 @@ def cache_time(file)
148167
return 0
149168
end
150169

170+
# load_cache
151171
def load_cache
152172
@cache ||= if File.exist?(@cache_file)
153173
YAML.load_file(@cache_file)
@@ -161,6 +181,7 @@ def load_cache
161181
return @cache
162182
end
163183

184+
# create
164185
def create
165186
entries.each do |fact|
166187
type = fact_type(fact)

lib/facter/package_provider.rb

+2
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,9 @@
1010
require 'puppet/type'
1111
require 'puppet/type/package'
1212

13+
# These will be nil if Puppet is not available.
1314
Facter.add(:package_provider) do
15+
# Instantiates a dummy package resource and return the provider
1416
setcode do
1517
if defined? Gem && Gem::Version.new(Facter.value(:puppetversion).split(' ')[0]) >= Gem::Version.new('3.6')
1618
Puppet::Type.type(:package).newpackage(:name => 'dummy', :allow_virtual => 'true')[:provider].to_s

lib/facter/pe_version.rb

+5
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88
#
99
# Caveats:
1010
#
11+
# Fact: pe_version
1112
Facter.add('pe_version') do
1213
setcode do
1314
puppet_ver = Facter.value('puppetversion')
@@ -20,6 +21,7 @@
2021
end
2122
end
2223

24+
# Fact: is_pe
2325
Facter.add('is_pe') do
2426
setcode do
2527
if Facter.value(:pe_version).to_s.empty?
@@ -30,6 +32,7 @@
3032
end
3133
end
3234

35+
# Fact: pe_major_version
3336
Facter.add('pe_major_version') do
3437
confine :is_pe => true
3538
setcode do
@@ -40,6 +43,7 @@
4043
end
4144
end
4245

46+
# Fact: pe_minor_version
4347
Facter.add('pe_minor_version') do
4448
confine :is_pe => true
4549
setcode do
@@ -50,6 +54,7 @@
5054
end
5155
end
5256

57+
# Fact: pe_patch_version
5358
Facter.add('pe_patch_version') do
5459
confine :is_pe => true
5560
setcode do

lib/facter/puppet_settings.rb

+3-1
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@
1616
load rb_file if File.exist?(rb_file) || raise(e)
1717
end
1818

19-
# These will be nil if Puppet is not available.
19+
# Facter fact returns the value of the Puppet vardir
2020
Facter.add(:puppet_vardir) do
2121
setcode do
2222
Facter::Util::PuppetSettings.with_puppet do
@@ -25,6 +25,7 @@
2525
end
2626
end
2727

28+
# Facter fact returns the value of the Puppet environment path
2829
Facter.add(:puppet_environmentpath) do
2930
setcode do
3031
Facter::Util::PuppetSettings.with_puppet do
@@ -33,6 +34,7 @@
3334
end
3435
end
3536

37+
# Facter fact returns the value of the Puppet server
3638
Facter.add(:puppet_server) do
3739
setcode do
3840
Facter::Util::PuppetSettings.with_puppet do

lib/facter/root_home.rb

+6-3
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,11 @@
1-
# A facter fact to determine the root home directory.
2-
# This varies on PE supported platforms and may be
3-
# reconfigured by the end user.
1+
# root_home.rb
42
module Facter::Util::RootHome
3+
# @summary
4+
# A facter fact to determine the root home directory.
5+
# This varies on PE supported platforms and may be
6+
# reconfigured by the end user.
57
class << self
8+
# determines the root home directory
69
def returnt_root_home
710
root_ent = Facter::Util::Resolution.exec('getent passwd root')
811
# The home directory is the sixth element in the passwd entry

lib/puppet/functions/deprecation.rb

+3-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
# @summary
21
# Function to print deprecation warnings, Logs a warning once for a given key.
32
#
43
# The uniqueness key - can appear once.
@@ -9,6 +8,9 @@
98
# (default, outputs a warning) *Type*: String, String.
109
#
1110
Puppet::Functions.create_function(:deprecation) do
11+
# @param key
12+
# @param message
13+
# @return deprecated warnings
1214
dispatch :deprecation do
1315
param 'String', :key
1416
param 'String', :message

lib/puppet/functions/fact.rb

+1-1
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@
1515
# fact('vmware."VRA.version"')
1616
#
1717
Puppet::Functions.create_function(:fact) do
18-
# @param [String] fact_name
18+
# @param fact_name
1919
# The name of the fact to check
2020
#
2121
# @return

lib/puppet/functions/is_string.rb

+1-1
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
# @param args
88
# Any additional values that are to be passed to the wrapped method
99
#
10-
# @return [Boolea]
10+
# @return [Boolean]
1111
# A boolean value returned from the called 3.x function.
1212
dispatch :deprecation_gen do
1313
param 'Any', :scope

lib/puppet/functions/os_version_gte.rb

+9-4
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,16 @@
1-
# Checks if the OS version is at least a certain version. Note that only the
2-
# major version is taken into account.
3-
#
4-
# Example usage:
1+
# @summary
2+
# Checks if the OS version is at least a certain version.
3+
# > *Note:*
4+
# Only the major version is taken into account.
55
#
6+
# @example Example usage:#
67
# if os_version_gte('Debian', '9') { }
78
# if os_version_gte('Ubuntu', '18.04') { }
89
Puppet::Functions.create_function(:os_version_gte) do
10+
# @param os operating system
11+
# @param version
12+
#
13+
# @return [Boolean] `true` or `false
914
dispatch :os_version_gte do
1015
param 'String[1]', :os
1116
param 'String[1]', :version

lib/puppet/functions/seeded_rand_string.rb

+2-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
1-
# Generates a consistent random string of specific length based on provided seed.
1+
# @summary
2+
# Generates a consistent random string of specific length based on provided seed.
23
#
34
# @example Generate a consistently random string of length 8 with a seed:
45
# seeded_rand_string(8, "${module_name}::redis_password")

lib/puppet/functions/sprintf_hash.rb

+2-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
1-
# Uses sprintf with named references.
1+
# @summary
2+
# Uses sprintf with named references.
23
#
34
# The first parameter is format string describing how the rest of the parameters in the hash
45
# should be formatted. See the documentation for the `Kernel::sprintf` function in Ruby for

lib/puppet/functions/stdlib/ip_in_range.rb

+2-3
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,8 @@
44
# @example ip_in_range(<IPv4 Address>, <IPv4 CIDR>)
55
# stdlib::ip_in_range('10.10.10.53', '10.10.10.0/24') => true
66
Puppet::Functions.create_function(:'stdlib::ip_in_range') do
7-
# @param [String] ipaddress The IP address to check
8-
# @param [Variant[String, Array]] range One CIDR or an array of CIDRs
7+
# @param ipaddress The IP address to check
8+
# @param range One CIDR or an array of CIDRs
99
# defining the range(s) to check against
1010
#
1111
# @return [Boolean] True or False
@@ -16,7 +16,6 @@
1616
end
1717

1818
require 'ipaddr'
19-
2019
def ip_in_range(ipaddress, range)
2120
ip = IPAddr.new(ipaddress)
2221

lib/puppet/functions/to_json.rb

+6-4
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,6 @@
1-
# Take a data structure and output it as JSON
1+
require 'json'
2+
# @summary
3+
# Convert a data structure and output to JSON
24
#
35
# @example how to output JSON
46
# # output json to a file
@@ -7,10 +9,10 @@
79
# content => to_json($myhash),
810
# }
911
#
10-
#
11-
require 'json'
12-
1312
Puppet::Functions.create_function(:to_json) do
13+
# @param data
14+
# data structure which needs to be converted into JSON
15+
# @return converted data to json
1416
dispatch :to_json do
1517
param 'Any', :data
1618
end

lib/puppet/functions/to_json_pretty.rb

+12-8
Original file line numberDiff line numberDiff line change
@@ -1,25 +1,29 @@
1-
# Take a data structure and output it as pretty JSON
1+
require 'json'
2+
# @summary
3+
# Convert data structure and output to pretty JSON
24
#
3-
# @example how to output pretty JSON
4-
# # output pretty json to a file
5+
# @example **Usage**
6+
# * how to output pretty JSON to file
57
# file { '/tmp/my.json':
68
# ensure => file,
79
# content => to_json_pretty($myhash),
810
# }
911
#
10-
# @example how to output pretty JSON skipping over keys with undef values
11-
# # output pretty JSON to a file skipping over undef values
12+
# * how to output pretty JSON skipping over keys with undef values
1213
# file { '/tmp/my.json':
1314
# ensure => file,
1415
# content => to_json_pretty({
1516
# param_one => 'value',
1617
# param_two => undef,
1718
# }),
1819
# }
19-
#
20-
require 'json'
21-
2220
Puppet::Functions.create_function(:to_json_pretty) do
21+
# @param data
22+
# data structure which needs to be converted to pretty json
23+
# @param skip_undef
24+
# value `true` or `false`
25+
# @return
26+
# converted data to pretty json
2327
dispatch :to_json_pretty do
2428
param 'Variant[Hash, Array]', :data
2529
optional_param 'Boolean', :skip_undef

lib/puppet/functions/to_yaml.rb

+6-5
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,17 @@
1-
# Take a data structure and output it as YAML
1+
require 'yaml'
2+
# @summary
3+
# Convert a data structure and output it as YAML
24
#
35
# @example how to output YAML
46
# # output yaml to a file
57
# file { '/tmp/my.yaml':
68
# ensure => file,
79
# content => to_yaml($myhash),
810
# }
9-
#
10-
#
11-
require 'yaml'
12-
1311
Puppet::Functions.create_function(:to_yaml) do
12+
# @param data
13+
#
14+
# @return [String]
1415
dispatch :to_yaml do
1516
param 'Any', :data
1617
end

lib/puppet/functions/type_of.rb

+6-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
1-
# Returns the type when passed a value.
1+
# @summary
2+
# Returns the type of the passed value.
23
#
34
# @example how to compare values' types
45
# # compare the types of two values
@@ -13,6 +14,10 @@
1314
# The built-in type() function in puppet is generally preferred over this function
1415
# this function is provided for backwards compatibility.
1516
Puppet::Functions.create_function(:type_of) do
17+
# @return [String]
18+
# the type of the passed value
19+
#
20+
# @param value
1621
def type_of(value)
1722
Puppet::Pops::Types::TypeCalculator.infer_set(value)
1823
end

0 commit comments

Comments
 (0)