Skip to content

Commit 7191732

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

File tree

3 files changed

+50
-46
lines changed

3 files changed

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