Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
2 changed files
with
86 additions
and
0 deletions.
There are no files selected for viewing
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,62 @@ | ||
Puppet::Type.newtype(:sshd_config_host) do | ||
@doc = "Manages Host groups in an OpenSSH sshd_config file." | ||
|
||
ensurable do | ||
defaultvalues | ||
|
||
newvalue(:positioned) do | ||
current = self.retrieve | ||
if current == :absent | ||
provider.create | ||
elsif !provider.in_position? | ||
provider.destroy | ||
provider.create | ||
end | ||
end | ||
|
||
def insync?(is) | ||
return true if should == :positioned and is == :present and provider.in_position? | ||
super | ||
end | ||
end | ||
|
||
newparam(:name) do | ||
isnamevar | ||
desc "The name of the Host group" | ||
end | ||
|
||
newparam(:target) do | ||
isnamevar | ||
desc "The file in which to the pg_hba rule" | ||
end | ||
|
||
def self.title_patterns | ||
identity = lambda { |x| x } | ||
[ | ||
[ | ||
/^(\S*)\s+in\s+(\S+)$/, | ||
[ | ||
[ :name, identity ], | ||
[ :target, identity ], | ||
] | ||
], | ||
[ | ||
/(.*)/, | ||
[ | ||
[ :name, identity ], | ||
] | ||
] | ||
] | ||
end | ||
|
||
newparam(:position) do | ||
desc "Where to place the new entry" | ||
validate do |value| | ||
raise "Wrong position statement '#{value}'" unless value =~ /^(before|after)/ | ||
end | ||
end | ||
|
||
autorequire(:file) do | ||
self[:target] | ||
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
#!/usr/bin/env rspec | ||
|
||
require 'spec_helper' | ||
|
||
sshd_config_host_type = Puppet::Type.type(:sshd_config_host) | ||
|
||
describe sshd_config_host_type do | ||
context 'when setting parameters' do | ||
it 'should accept a name parameter' do | ||
resource = sshd_config_host_type.new :name => 'foo' | ||
expect(resource[:name]).to eq('foo') | ||
end | ||
|
||
it 'should accept a target parameter' do | ||
resource = sshd_config_host_type.new :name => 'foo', :target => '/foo/bar' | ||
expect(resource[:target]).to eq('/foo/bar') | ||
end | ||
|
||
it 'should accept a position parameter' do | ||
resource = sshd_config_host_type.new :name => 'foo', :position => 'before Host bar' | ||
expect(resource[:position]).to eq('before Host bar') | ||
end | ||
end | ||
end |