Skip to content

Commit

Permalink
Merge 1e2a617 into bfd69b4
Browse files Browse the repository at this point in the history
  • Loading branch information
raphink committed Mar 30, 2015
2 parents bfd69b4 + 1e2a617 commit ca7477b
Show file tree
Hide file tree
Showing 2 changed files with 86 additions and 0 deletions.
62 changes: 62 additions & 0 deletions lib/puppet/type/sshd_config_host.rb
@@ -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
24 changes: 24 additions & 0 deletions spec/unit/puppet/type/sshd_config_host_spec.rb
@@ -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

0 comments on commit ca7477b

Please sign in to comment.