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

Lines changed: 0 additions & 45 deletions
This file was deleted.
Lines changed: 48 additions & 0 deletions
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

Lines changed: 1 addition & 1 deletion
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)
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy