Skip to content

Commit d053e38

Browse files
First draft of new postgresql_conf provider
1 parent ffd99c6 commit d053e38

File tree

3 files changed

+49
-46
lines changed

3 files changed

+49
-46
lines changed

lib/puppet/provider/postgresql_conf/parsed.rb

-45
This file was deleted.
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,48 @@
1+
# frozen_string_literal: true
2+
3+
Puppet::Type.type(:postgresql_conf).provide(:ruby) do
4+
desc 'Set key/values in a postgresql config file.'
5+
6+
confine exists: target
7+
8+
# file parsing in a seperate function
9+
def parse_config(target)
10+
active_settings = []
11+
active_values_regex = %r{^\s*(?<key>[\w.]+)\s*=?\s*(?<value>.*?)(?:\s*#\s*(?<comment>.*))?\s*$}
12+
file = File.open(target)
13+
14+
File.foreach(file).with_index do |line, line_number|
15+
matches = line.match(active_values_regex)
16+
if matches
17+
attributes_hash = { line_number: line_number, key: matches[:key], ensure: 'present', value: matches[:value], comment: matches[:comment] }
18+
active_settings.push(attributes_hash)
19+
end
20+
end
21+
active_settings
22+
end
23+
24+
# write config file
25+
def write_config(target, lines)
26+
File.write(target, lines.join)
27+
end
28+
29+
# check, if resource exists.
30+
def exists?
31+
@result = parse_config(target).each do |setting|
32+
setting[:key]
33+
resource[:key]
34+
end
35+
end
36+
37+
# remove resource
38+
def destroy; end
39+
40+
# create resource
41+
def create; end
42+
43+
# getter - get value
44+
def value; end
45+
46+
# setter - set value
47+
def value=(_value); end
48+
end

lib/puppet/type/postgresql_conf.rb

+1-1
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,6 @@
2020

2121
newproperty(:target) do
2222
desc 'The path to the postgresql config file'
23-
newvalues(%r{^\/[a-z0-9]+[a-z0-9(\/)(\-)]*[\w]+.conf$})
23+
newvalues(%r{^/[a-z0-9]+[a-z0-9(/)-]*\w+.conf$})
2424
end
2525
end

0 commit comments

Comments
 (0)