Skip to content

Commit

Permalink
First draft of new postgresql_conf provider
Browse files Browse the repository at this point in the history
  • Loading branch information
SimonHoenscheid committed Aug 2, 2023
1 parent ffd99c6 commit 7191732
Show file tree
Hide file tree
Showing 3 changed files with 50 additions and 46 deletions.
45 changes: 0 additions & 45 deletions lib/puppet/provider/postgresql_conf/parsed.rb

This file was deleted.

49 changes: 49 additions & 0 deletions lib/puppet/provider/postgresql_conf/ruby.rb
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
2 changes: 1 addition & 1 deletion lib/puppet/type/postgresql_conf.rb
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,6 @@

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

0 comments on commit 7191732

Please sign in to comment.