Skip to content

Commit

Permalink
Extend postgresql_conf to support multiple config files
Browse files Browse the repository at this point in the history
  • Loading branch information
ekohl committed Oct 23, 2023
1 parent d4054b4 commit d4e1c70
Show file tree
Hide file tree
Showing 3 changed files with 36 additions and 8 deletions.
20 changes: 20 additions & 0 deletions examples/multiple_confs.pp
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
postgresql_conf { '/tmp/first-postgresql.conf:other':
value => 'bla',
}

postgresql_conf { '/tmp/first-postgresql.conf:port':
value => 5432,
}

postgresql_conf { '/tmp/second-postgresql.conf:other':
value => 'bla',
}

postgresql_conf { '/tmp/second-postgresql.conf:port':
value => 5433,
}

# TODO: make target optional
#postgresql_conf { 'port':
# value => 5434,
#}
8 changes: 4 additions & 4 deletions lib/puppet/provider/postgresql_conf/parsed.rb
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
text_line :blank, match: %r{^\s*$}

record_line :parsed,
fields: ['name', 'value', 'comment'],
fields: ['key', 'value', 'comment'],
optional: ['comment'],
match: %r{^\s*([\w.]+)\s*=?\s*(.*?)(?:\s*#\s*(.*))?\s*$},
to_line: proc { |h|
Expand All @@ -28,9 +28,9 @@
h[:value]
end
dontneedquote = val.match(%r{^(\d+.?\d+|\w+)$})
dontneedequal = h[:name].match(%r{^(include|include_if_exists)$}i)
dontneedequal = h[:key].match(%r{^(include|include_if_exists)$}i)

str = h[:name].downcase # normalize case
str = h[:key].downcase # normalize case
str += dontneedequal ? ' ' : ' = '
str += "'" unless dontneedquote && !dontneedequal
str += val
Expand All @@ -39,7 +39,7 @@
str
},
post_parse: proc { |h|
h[:name].downcase! # normalize case
h[:key].downcase! # normalize case
h[:value].gsub!(%r{(^'|'$)}, '') # strip out quotes
}
end
16 changes: 12 additions & 4 deletions lib/puppet/type/postgresql_conf.rb
Original file line number Diff line number Diff line change
Expand Up @@ -5,18 +5,26 @@

ensurable

newparam(:name) do
desc 'The postgresql parameter name to manage.'
isnamevar
def self.title_patterns
[

Check failure on line 9 in lib/puppet/type/postgresql_conf.rb

View workflow job for this annotation

GitHub Actions / Spec / Spec tests (Puppet: ~> 7.24, Ruby Ver: 2.7)

Layout/IndentationWidth: Use 2 (not 0) spaces for indentation. (https://rubystyle.guide#spaces-indentation)

Check failure on line 9 in lib/puppet/type/postgresql_conf.rb

View workflow job for this annotation

GitHub Actions / Spec / Spec tests (Puppet: ~> 8.0, Ruby Ver: 3.2)

Layout/IndentationWidth: Use 2 (not 0) spaces for indentation. (https://rubystyle.guide#spaces-indentation)
[ /^(.+\.conf):([\w.]+)$/m, [ [:target], [:key] ] ],

Check failure on line 10 in lib/puppet/type/postgresql_conf.rb

View workflow job for this annotation

GitHub Actions / Spec / Spec tests (Puppet: ~> 7.24, Ruby Ver: 2.7)

Style/RegexpLiteral: Use `%r` around regular expression. (https://rubystyle.guide#percent-r)

Check failure on line 10 in lib/puppet/type/postgresql_conf.rb

View workflow job for this annotation

GitHub Actions / Spec / Spec tests (Puppet: ~> 8.0, Ruby Ver: 3.2)

Style/RegexpLiteral: Use `%r` around regular expression. (https://rubystyle.guide#percent-r)
# TODO: make target optional
#[ /^([\w.]+)$/m, [ [:key] ] ],

Check failure on line 12 in lib/puppet/type/postgresql_conf.rb

View workflow job for this annotation

GitHub Actions / Spec / Spec tests (Puppet: ~> 7.24, Ruby Ver: 2.7)

Layout/LeadingCommentSpace: Missing space after `#`. (https://rubystyle.guide#hash-space)

Check failure on line 12 in lib/puppet/type/postgresql_conf.rb

View workflow job for this annotation

GitHub Actions / Spec / Spec tests (Puppet: ~> 8.0, Ruby Ver: 3.2)

Layout/LeadingCommentSpace: Missing space after `#`. (https://rubystyle.guide#hash-space)
]
end


Check failure on line 16 in lib/puppet/type/postgresql_conf.rb

View workflow job for this annotation

GitHub Actions / Spec / Spec tests (Puppet: ~> 7.24, Ruby Ver: 2.7)

Layout/EmptyLines: Extra blank line detected. (https://rubystyle.guide#two-or-more-empty-lines)

Check failure on line 16 in lib/puppet/type/postgresql_conf.rb

View workflow job for this annotation

GitHub Actions / Spec / Spec tests (Puppet: ~> 8.0, Ruby Ver: 3.2)

Layout/EmptyLines: Extra blank line detected. (https://rubystyle.guide#two-or-more-empty-lines)
newparam(:key, namevar: true) do
desc 'The postgresql parameter name to manage.'
isrequired
newvalues(%r{^[\w.]+$})
end

newproperty(:value) do
desc 'The value to set for this parameter.'
end

newproperty(:target) do
newparam(:target, namevar: true) do
desc 'The path to postgresql.conf'
defaultto do
if @resource.class.defaultprovider.ancestors.include?(Puppet::Provider::ParsedFile)
Expand Down

0 comments on commit d4e1c70

Please sign in to comment.