Skip to content

Commit

Permalink
Merge remote-tracking branch 'upstream/master'
Browse files Browse the repository at this point in the history
* upstream/master: (21 commits)
  Release 1.11.1
  Allow augeasproviders_shellvar 4
  Fix tests on Puppet 6
  msync
  Prepare release 1.11.0
  Allow stdlib 5 & 6
  Correcting issue camptocamp#15 (camptocamp#56)
  Fix puppet error if the account is not yet created (camptocamp#41)
  Allow augeasproviders_shellvar 3.x
  Add additional prerequisite (camptocamp#53)
  added expiry parameter (camptocamp#55)
  Merge group arrays instead of rightmost precedence (camptocamp#65)
  Allow ssh_options for accounts being created through accounts::usergroups as well (camptocamp#66)
  Use loop instead of recursion
  Fixes camptocamp#61 - Pass through managehome on absent
  Do not use legacy puppet-lint-absolute_classname-check plugin
  Fix beaker version to ~>3.13
  Update to add the system option to account.pp
  Update with modulesync
  Release 1.10.0
  ...
  • Loading branch information
nettucu committed Aug 9, 2019
2 parents 9ff879b + bbba208 commit 659d568
Show file tree
Hide file tree
Showing 11 changed files with 213 additions and 48 deletions.
2 changes: 2 additions & 0 deletions .fixtures.yml
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
fixtures:
repositories:
stdlib: https://github.com/puppetlabs/puppetlabs-stdlib.git
forge_modules:
sshkeys_core: puppetlabs/sshkeys_core
symlinks:
accounts: "#{source_dir}"
10 changes: 6 additions & 4 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -13,10 +13,12 @@ script: ["bundle exec rake validate", "bundle exec rake lint", "bundle exec rake
matrix:
fast_finish: true
include:
- rvm: 2.1.10
- rvm: 2.1
env: PUPPET_GEM_VERSION="~> 4.0"
- rvm: 2.3.4
env: PUPPET_GEM_VERSION="~> 4"
- rvm: 2.4
env: PUPPET_GEM_VERSION="~> 5.0"
- rvm: 2.5
env: PUPPET_GEM_VERSION="~> 6.0"
notifications:
email: false
deploy:
Expand All @@ -29,4 +31,4 @@ deploy:
# all_branches is required to use tags
all_branches: true
# Only publish if our main Ruby target builds
rvm: 2.1.10
rvm: 2.4
24 changes: 24 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,27 @@
## 2019-07-30 - Release 1.11.1

- Allow augeasproviders_shellvar 4

## 2019-07-30 - Release 1.11.0

- Add system option to accounts::account (#60)
- Fix beaker version
- Do not use legacy puppet-lint-absolute_classname-check plugin
- Pass through managehome on absent (#62) (fix #61)
- strformat function: use loop instead of recursion (#64)
- Allow ssh_options for accounts being created through accounts::usergroups as well (#66)
- Merge group arrays instead of rightmost precedence (#65)
- Add expiry parameter (#55)
- Add additional prerequisite (#53)
- Allow augeasproviders_shellvar 3.x
- Fix puppet error if the account is not yet created (#41)
- Allow stdlib 5 & 6
- Fix tests on Puppet 6

## 2018-01-03 - Release 1.10.0

Remove absent keys when user resource not managed by module

## 2017-05-22 - Release 1.9.3

Really fix automated release system...
Expand Down
51 changes: 25 additions & 26 deletions Gemfile
Original file line number Diff line number Diff line change
@@ -1,35 +1,34 @@
source ENV['GEM_SOURCE'] || "https://rubygems.org"

ruby_version_segments = Gem::Version.new(RUBY_VERSION.dup).segments
minor_version = ruby_version_segments[0..1].join('.')

group :development, :unit_tests do
gem 'rake', :require => false
gem 'rspec', :require => false
gem 'rspec-puppet', :require => false
gem 'puppetlabs_spec_helper', :require => false
gem 'metadata-json-lint', :require => false
gem 'puppet-lint', :require => false
gem 'puppet-lint-unquoted_string-check', :require => false
gem 'puppet-lint-empty_string-check', :require => false
gem 'puppet-lint-spaceship_operator_without_tag-check', :require => false
gem 'puppet-lint-absolute_classname-check', :require => false
gem 'puppet-lint-undef_in_function-check', :require => false
gem 'puppet-lint-leading_zero-check', :require => false
gem 'puppet-lint-trailing_comma-check', :require => false
gem 'puppet-lint-file_ensure-check', :require => false
gem 'puppet-lint-version_comparison-check', :require => false
gem 'puppet-lint-file_source_rights-check', :require => false
gem 'puppet-lint-alias-check', :require => false
gem 'rspec-puppet-facts', :require => false
gem 'ruby-augeas', :require => false
gem 'puppet-blacksmith', :require => false if RUBY_VERSION !~ /^1\./
gem 'json_pure', '< 2.0.2', :require => false
gem "rake", :require => false
gem "rspec", :require => false
gem "rspec-puppet", :require => false
gem "puppetlabs_spec_helper", :require => false
gem "metadata-json-lint", :require => false
gem "puppet-lint", :require => false
gem "puppet-lint-unquoted_string-check", :require => false
gem "puppet-lint-empty_string-check", :require => false
gem "puppet-lint-spaceship_operator_without_tag-check", :require => false
gem "puppet-lint-undef_in_function-check", :require => false
gem "puppet-lint-leading_zero-check", :require => false
gem "puppet-lint-trailing_comma-check", :require => false
gem "puppet-lint-file_ensure-check", :require => false
gem "puppet-lint-version_comparison-check", :require => false
gem "puppet-lint-file_source_rights-check", :require => false
gem "puppet-lint-alias-check", :require => false
gem "rspec-puppet-facts", :require => false
gem "ruby-augeas", :require => false
gem "puppet-blacksmith", :require => false if RUBY_VERSION !~ /^1\./
gem "json_pure", '< 2.0.2', :require => false
end

group :system_tests do
gem 'beaker', :require => false
gem 'beaker-rspec', '> 5', :require => false
gem 'beaker_spec_helper', :require => false
gem 'serverspec', :require => false
gem 'specinfra', :require => false
gem "puppet-module-posix-system-r#{minor_version}", :require => false
gem "beaker-hostgenerator", :require => false, :git => 'https://github.com/mcanevet/beaker-hostgenerator.git', :branch => 'fix_debian9'
end

if facterversion = ENV['FACTER_GEM_VERSION']
Expand Down
9 changes: 4 additions & 5 deletions lib/puppet/parser/functions/strformat.rb
Original file line number Diff line number Diff line change
Expand Up @@ -14,10 +14,9 @@
raise(Puppet::ParseError, "strformat(): Wrong number of arguments given") if args.size != 1
raise(Puppet::ParseError, "strformat(): First parameter must be a string") if args[0].class != String

def strformat(format, arg)
new = format.gsub(/%\{([^%\[\}]+)([^%\}]*)\}/) { eval("arg[$1]#{$2}") }
(new =~ /%/) ? strformat(new, arg) : new
result = args[0]
while result =~ /%/
result = result.gsub(/%\{([^%\[\}]+)([^%\}]*)\}/) { eval("self[$1]#{$2}") }
end

strformat(args[0], self.to_hash)
result
end
13 changes: 10 additions & 3 deletions manifests/account.pp
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
$ensure = present,
$comment = undef,
$user = $name,
$expiry = undef,
$groups = [],
$groups_membership = $::accounts::groups_membership,
$authorized_keys = [],
Expand All @@ -16,6 +17,7 @@
$password = undef,
$uid = undef,
$gid = undef,
$system = undef,
$ssh_options = undef,
) {
$account = $user # for strformat mapping...
Expand All @@ -40,6 +42,8 @@
password => $password,
uid => $uid,
gid => $gid,
ssh_options => $ssh_options,
system => $system,
}
)
} else {
Expand All @@ -61,7 +65,6 @@
{
ensure => $ensure,
comment => $comment,
groups => $groups,
home => $_home,
password => $password,
managehome => $managehome,
Expand All @@ -70,8 +73,11 @@
shell => $shell,
uid => $uid,
gid => $gid,
expiry => $expiry,
system => $system,
},
$::accounts::users[$name]
$::accounts::users[$name],
{ groups => $groups.concat($::accounts::users[$name][groups].pick([])).flatten.unique }
)

if versioncmp($::puppetversion, '3.6.0') >= 0 {
Expand Down Expand Up @@ -139,11 +145,12 @@
exec { "put ssh private key ${name} for user ${user}":
command => "/bin/echo '${::accounts::ssh_keys[$name]['private']}' > ~${user}/.ssh/id_rsa; /bin/chown ${user} ~${user}/.ssh/id_rsa; /bin/chmod 600 ~${user}/.ssh/id_rsa",
unless => "/usr/bin/test -f ~${user}/.ssh/id_rsa",
onlyif => "/usr/bin/test -d ~${user}/.ssh",
}
}
}

if ! $purge_ssh_keys {
if ! $purge_ssh_keys or ! has_key($::accounts::users, $user) {
$keys_to_remove = suffix(keys(absents($::accounts::ssh_keys)), "-on-${name}")
accounts::authorized_key { $keys_to_remove:
ensure => absent,
Expand Down
2 changes: 1 addition & 1 deletion manifests/authorized_key.pp
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@
ssh_authorized_key { $_ssh_authorized_key_title:
ensure => $ensure,
key => $::accounts::ssh_keys[$ssh_key]['public'],
options => $options,
options => $::accounts::ssh_keys[$ssh_key]['options'],
target => $_target,
type => $::accounts::ssh_keys[$ssh_key]['type'],
user => $_user,
Expand Down
1 change: 1 addition & 0 deletions manifests/init.pp
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@
$absent_users = keys(absents($users))
user { $absent_users:
ensure => absent,
managehome => $managehome,
forcelocal => $forcelocal,
}
}
15 changes: 11 additions & 4 deletions metadata.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "camptocamp-accounts",
"version": "1.9.3",
"version": "1.11.1",
"author": "camptocamp",
"summary": "Puppet module for Managing SSH keys, users and groups",
"license": "Apache-2.0",
Expand All @@ -10,7 +10,11 @@
"dependencies": [
{
"name": "puppetlabs/stdlib",
"version_requirement": ">=3.2.0 <5.0.0"
"version_requirement": ">=3.2.0 <7.0.0"
},
{
"name": "herculesteam/augeasproviders_shellvar",
"version_requirement": ">=2.2.1 < 5.0.0"
}
],
"requirements": [
Expand All @@ -25,15 +29,18 @@
"operatingsystemrelease": [
"6",
"7",
"8"
"8",
"9"
]
},
{
"operatingsystem": "Ubuntu",
"operatingsystemrelease": [
"10.04",
"12.04",
"14.04"
"14.04",
"16.04",
"18.04"
]
},
{
Expand Down
115 changes: 110 additions & 5 deletions spec/defines/accounts__account_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,19 @@ class { 'accounts':
'ensure' => 'absent',
'type' => 'ssh-rsa',
'public' => "An_Ankou's_Key",
}
},
'brad' => {
'type' => 'ssh-rsa',
'public' => "Brad's_Key",
},
'robin' => {
'type' => 'ssh-rsa',
'public' => "Robin's_Key",
},
'clarence' => {
'type' => 'ssh-rsa',
'public' => "Clarence's_Key",
},
},
users => {
'luke' => {
Expand Down Expand Up @@ -104,12 +116,35 @@ class { 'accounts':
'comment' => 'Matt M.',
'uid' => 1009,
},
'brad' => {
'comment' => 'Brad K.',
'uid' => 1010,
'groups' => [ 'testgroup2' ]
},
'robin' => {
'comment' => 'Robin K.',
'uid' => 1011,
'groups' => [ 'testgroup1' ]
},
'clarence' => {
'comment' => 'Clarence T.',
'uid' => 1012
},
},
groups => {
testgroup1 => {
gid => 3000
},
testgroup2 => {
gid => 3001
},
},
usergroups => {
'management' => [ 'luke', 'nigel', 'bill', ],
'directors' => [ 'puneet', 'kevin', 'luke', 'raghu', 'kenny', ],
'observers' => [ 'karim', 'phil', 'matt', ],
'advisors' => [ 'beth', 'sharmila', ],
'vicepresidents' => [ 'brad', 'robin', 'clarence', ],
'management' => [ 'luke', 'nigel', 'bill', ],
'directors' => [ 'puneet', 'kevin', 'luke', 'raghu', 'kenny', ],
'observers' => [ 'karim', 'phil', 'matt', ],
'advisors' => [ 'beth', 'sharmila', ],
},
}
EOS
Expand Down Expand Up @@ -340,6 +375,76 @@ class { 'accounts':
:user => 'bill',
})}
end

context 'when creating accounts for @vicepresidents with accounts:groups' do
let(:title) { '@vicepresidents' }
let(:params) {{
:groups => [ 'testgroup1' ]
}}
it { is_expected.to compile.with_all_deps }
it { is_expected.to have_user_resource_count(3) }
it { is_expected.to contain_user('brad').with({
:name => 'brad',
:ensure => 'present',
:comment => 'Brad K.',
:groups => [ 'testgroup1', 'testgroup2' ],
:home => '/home/brad',
:managehome => true,
:uid => 1010,
})}
it { is_expected.to contain_user('robin').with({
:name => 'robin',
:ensure => 'present',
:comment => 'Robin K.',
:groups => [ 'testgroup1' ],
:home => '/home/robin',
:managehome => true,
:uid => 1011,
})}
it { is_expected.to contain_user('clarence').with({
:name => 'clarence',
:ensure => 'present',
:comment => 'Clarence T.',
:groups => [ 'testgroup1' ],
:home => '/home/clarence',
:managehome => true,
:uid => 1012,
})}
end

context 'when creating accounts for @vicepresidents without accounts:groups' do
let(:title) { '@vicepresidents' }
it { is_expected.to compile.with_all_deps }
it { is_expected.to have_user_resource_count(3) }
it { is_expected.to contain_user('brad').with({
:name => 'brad',
:ensure => 'present',
:comment => 'Brad K.',
:groups => [ 'testgroup2' ],
:home => '/home/brad',
:managehome => true,
:uid => 1010,
})}
it { is_expected.to contain_user('robin').with({
:name => 'robin',
:ensure => 'present',
:comment => 'Robin K.',
:groups => [ 'testgroup1' ],
:home => '/home/robin',
:managehome => true,
:uid => 1011,
})}
it { is_expected.to contain_user('clarence').with({
:name => 'clarence',
:ensure => 'present',
:comment => 'Clarence T.',
:groups => [],
:home => '/home/clarence',
:managehome => true,
:uid => 1012,
})}
end

end
end
end
Loading

0 comments on commit 659d568

Please sign in to comment.