-
Notifications
You must be signed in to change notification settings - Fork 613
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
First draft of new postgresql_conf provider
- Loading branch information
1 parent
ffd99c6
commit 7191732
Showing
3 changed files
with
50 additions
and
46 deletions.
There are no files selected for viewing
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,49 @@ | ||
Puppet::Type.type(:postgresql_conf).provide(:ruby) do | ||
desc 'Set key/values in a postgresql config file.' | ||
|
||
confine exists: target | ||
|
||
# file parsing in a seperate function | ||
def parse_config(target) | ||
file = File.open(target) | ||
active_settings = [] | ||
active_values_regex = %r{^\s*(?<key>[\w.]+)\s*=?\s*(?<value>.*?)(?:\s*#\s*(?<comment>.*))?\s*$} | ||
file = File.open('/etc/postgresql/14/main/postgresql.conf') | ||
|
||
File.foreach(file).with_index do |line, line_number| | ||
if matches = line.match(active_values_regex) | ||
attributes_hash = { line_number: line_number, key: matches[:key], ensure: 'present', value: matches[:value], comment: matches[:comment] } | ||
active_settings.push(attributes_hash) | ||
end | ||
end | ||
active_settings | ||
end | ||
|
||
#write config file | ||
def write_config(target, lines) | ||
File.open(target, 'w') { |file| file.write(lines.join) } | ||
end | ||
|
||
# check, if resource exists. | ||
def exists? | ||
@result = parse_config(target).each { |setting| setting[:key] == resource[:key] } | ||
end | ||
|
||
# remove resource | ||
def destroy | ||
|
||
end | ||
|
||
# create resource | ||
def create | ||
end | ||
|
||
# getter - get value | ||
def value | ||
end | ||
|
||
# setter - set value | ||
def value=(_value) | ||
end | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters