Class: Puppet::DataProviders::HieraConfig
Constant Summary
collapse
- DEFAULT_CONFIG =
{
'version' => 4,
'datadir' => 'data',
'hierarchy' => [
{
'name' => 'common',
'backend' => 'yaml'
}
]
}.freeze
Plugins::DataProviders::ENV_DATA_PROVIDERS_KEY, Plugins::DataProviders::ENV_DATA_PROVIDERS_TYPE, Plugins::DataProviders::MODULE_DATA_PROVIDERS_KEY, Plugins::DataProviders::MODULE_DATA_PROVIDERS_TYPE, Plugins::DataProviders::PATH_BASED_DATA_PROVIDER_FACTORIES_KEY, Plugins::DataProviders::PATH_BASED_DATA_PROVIDER_FACTORIES_TYPE, Plugins::DataProviders::PER_MODULE_DATA_PROVIDER_KEY, Plugins::DataProviders::PER_MODULE_DATA_PROVIDER_TYPE
Instance Attribute Summary collapse
Class Method Summary
collapse
Instance Method Summary
collapse
#interpolate
Constructor Details
#initialize(config_root) ⇒ HieraConfig
Creates a new HieraConfig from the given config_root. This is where the ‘hiera.yaml’ is expected to be found and is also the base location used when resolving relative paths.
61
62
63
64
65
66
67
68
69
70
71
72
|
# File 'lib/puppet/data_providers/hiera_config.rb', line 61
def initialize(config_root)
@config_root = config_root
@config_path = config_root + 'hiera.yaml'
if @config_path.exist?
@config = validate_config(HieraConfig.symkeys_to_string(YAML.load_file(@config_path)))
@config['hierarchy'] ||= DEFAULT_CONFIG['hierarchy']
@config['datadir'] ||= DEFAULT_CONFIG['datadir']
else
@config = DEFAULT_CONFIG
end
@version = @config['version']
end
|
Instance Attribute Details
#config_path ⇒ Object
54
55
56
|
# File 'lib/puppet/data_providers/hiera_config.rb', line 54
def config_path
@config_path
end
|
54
55
56
|
# File 'lib/puppet/data_providers/hiera_config.rb', line 54
def version
@version
end
|
Class Method Details
.config_type ⇒ Object
20
21
22
|
# File 'lib/puppet/data_providers/hiera_config.rb', line 20
def self.config_type
@@CONFIG_TYPE ||= create_config_type
end
|
.symkeys_to_string(struct) ⇒ Object
24
25
26
27
28
29
30
31
32
33
34
35
|
# File 'lib/puppet/data_providers/hiera_config.rb', line 24
def self.symkeys_to_string(struct)
case(struct)
when Hash
Hash[struct.map { |k,v| [k.to_s, symkeys_to_string(v)] }]
when Array
struct.map { |v| symkeys_to_string(v) }
when nil
{}
else
struct
end
end
|
Instance Method Details
This method is part of a private API.
You should avoid using this method if possible, as it may be removed or be changed in the future.
Creates the data providers for this config
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
|
# File 'lib/puppet/data_providers/hiera_config.rb', line 86
def create_configured_data_providers(lookup_invocation, parent_data_provider)
injector = Puppet.lookup(:injector)
service_type = Registry.hash_of_path_based_data_provider_factories
default_datadir = @config['datadir']
data_providers = {}
@config['hierarchy'].each do |he|
name = he['name']
raise Puppet::DataBinding::LookupError, "#{path}: Name '#{name}' defined more than once" if data_providers.include?(name)
original_paths = he['paths']
if original_paths.nil?
single_path = he['path']
single_path = name if single_path.nil?
original_paths = [single_path]
end
paths = original_paths.map { |path| interpolate(path, lookup_invocation, false)}
provider_name = he['backend']
provider_factory = injector.lookup(nil, service_type, PATH_BASED_DATA_PROVIDER_FACTORIES_KEY)[provider_name]
raise Puppet::DataBinding::LookupError, "#{@config_path}: No data provider is registered for backend '#{provider_name}' " unless provider_factory
datadir = @config_root + (he['datadir'] || default_datadir)
data_providers[name] = create_data_provider(parent_data_provider, provider_factory, name,
provider_factory.resolve_paths(datadir, original_paths, paths, lookup_invocation))
end
data_providers.values
end
|
#create_data_providers(lookup_invocation) ⇒ Object
74
75
76
77
|
# File 'lib/puppet/data_providers/hiera_config.rb', line 74
def create_data_providers(lookup_invocation)
Puppet.deprecation_warning('Method HieraConfig#create_data_providers is deprecated. Use create_configured_data_providers instead')
create_configured_data_providers(lookup_invocation, nil)
end
|