-
Notifications
You must be signed in to change notification settings - Fork 613
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Extend postgresql_conf to support multiple config files using ParsedFile #1542
base: main
Are you sure you want to change the base?
Conversation
newparam(:key) do | ||
desc 'The Postgresql parameter to manage.' | ||
|
||
newparam(:key, namevar: true) do |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I kept key
instead of name
to force me to implement ParsedFile
agnostic of the name
parameter. At this point I think it could revert back to name
.
# TODO: make target optional | ||
#[ /^([\w.]+)$/m, [ [:key] ] ], |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I didn't have time to figure out how title_patterns
works with matching, but it probably isn't hard.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
that really depends on the point of view :D
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It comes down to understanding https://github.com/puppetlabs/puppet/blob/945beb6ef0200b1bc7879b62131282a61fc9a935/lib/puppet/resource.rb#L625-L663 and finding the right combination.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ok, couldn't help myself. I think the commented code should work. The reason it's commented is that I didn't know if it would really work. But this part suggests the patterns are correct:
require 'test/unit'
TITLE_PATTERNS = [
[ /^(.+\.conf):([\w.]+)$/m, [ [:target], [:key] ] ],
[ /^([\w.]+)$/m, [ [:key] ] ],
]
def match(title)
h = {}
TITLE_PATTERNS.each do |regexp, symbols_and_lambdas|
captures = regexp.match(title.to_s)
if captures
symbols_and_lambdas.zip(captures[1..-1]).each do |symbol_and_lambda,capture|
symbol, proc = symbol_and_lambda
# Many types pass "identity" as the proc; we might as well give
# them a shortcut to delivering that without the extra cost.
#
# Especially because the global type defines title_patterns and
# uses the identity patterns.
#
# This was worth about 8MB of memory allocation saved in my
# testing, so is worth the complexity for the API.
if proc then
h[symbol] = proc.call(capture)
else
h[symbol] = capture
end
end
return h
end
end
end
class MatcherTest < Test::Unit::TestCase
def test_with_conf
assert_equal({target: '/postgresql.conf', key: 'foo'}, match('/postgresql.conf:foo'))
end
def test_without_conf
assert_equal({key: 'foo'}, match('foo'))
end
end
$ ruby title_patterns.rb
Loaded suite title_patterns
Started
Finished in 0.000252056 seconds.
--------------------------------------------------------------------------------------
2 tests, 2 assertions, 0 failures, 0 errors, 0 pendings, 0 omissions, 0 notifications
100% passed
--------------------------------------------------------------------------------------
7934.74 tests/s, 7934.74 assertions/s
To avoid a custom postgresql_conf implementation, this reverts back to ParsedFile. It relies on puppetlabs/puppet#9130 since there were bugs in it, which is why it's now a draft.