Skip to content

Commit

Permalink
Add support for managing user ID and comment
Browse files Browse the repository at this point in the history
  • Loading branch information
bastelfreak committed Oct 30, 2024
1 parent 67d9f5c commit 98b6430
Show file tree
Hide file tree
Showing 4 changed files with 41 additions and 6 deletions.
18 changes: 18 additions & 0 deletions REFERENCE.md
Original file line number Diff line number Diff line change
Expand Up @@ -125,6 +125,8 @@ The following parameters are available in the `consul` class:
* [`enable_beta_ui`](#-consul--enable_beta_ui)
* [`allow_binding_to_root_ports`](#-consul--allow_binding_to_root_ports)
* [`log_file`](#-consul--log_file)
* [`comment`](#-consul--comment)
* [`uid`](#-consul--uid)

##### <a name="-consul--acls"></a>`acls`

Expand Down Expand Up @@ -592,6 +594,22 @@ where should the log file be located

Default value: `'/var/log/consul'`

##### <a name="-consul--comment"></a>`comment`

Data type: `Optional[String[1]]`

the comment for the consul user, will be added to /etc/passwd

Default value: `undef`

##### <a name="-consul--uid"></a>`uid`

Data type: `Optional[Integer[1]]`

the ID for the consul user

Default value: `undef`

## Defined types

### <a name="consul--check"></a>`consul::check`
Expand Down
4 changes: 4 additions & 0 deletions manifests/init.pp
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,8 @@
# You can enable it by setting this variable to true. Defaults to false
# @param allow_binding_to_root_ports enables CAP_NET_BIND_SERVICE if true. This is currently only implemented on systemd nodes
# @param log_file where should the log file be located
# @param comment the comment for the consul user, will be added to /etc/passwd
# @param uid the ID for the consul user
#
# @example simple consul setup
# class { 'consul':
Expand Down Expand Up @@ -142,6 +144,8 @@
Optional[String[1]] $shell = $consul::params::shell,
Boolean $enable_beta_ui = false,
Boolean $allow_binding_to_root_ports = false,
Optional[String[1]] $comment = undef,
Optional[Integer[1]] $uid = undef,
) inherits consul::params {
$real_download_url = pick(
$download_url,
Expand Down
12 changes: 7 additions & 5 deletions manifests/install.pp
Original file line number Diff line number Diff line change
Expand Up @@ -102,11 +102,13 @@
}

user { $consul::user_real:
ensure => 'present',
system => true,
groups => $consul::extra_groups,
shell => $consul::shell,
home => $consul_user_home,
ensure => 'present',
system => true,
groups => $consul::extra_groups,
shell => $consul::shell,
home => $consul_user_home,
uid => $consul::uid,
comment => $consul::comment,
}

if ($consul::manage_group) and ($consul::install_method != 'docker' ) {
Expand Down
13 changes: 12 additions & 1 deletion spec/classes/init_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -242,7 +242,7 @@
end

context 'By default, a user and group should be installed' do
it { is_expected.to contain_user('consul').with(ensure: :present) }
it { is_expected.to contain_user('consul').with(ensure: :present).without_uid.without_comment }
it { is_expected.to contain_group('consul').with(ensure: :present) }
end

Expand All @@ -256,6 +256,17 @@
it { is_expected.to contain_user('consul').with(ensure: :present).without_home }
end

context 'with user_uid and user_comment' do
let :params do
{
uid: 2,
comment: 'this is a comment',
}

Check failure on line 265 in spec/classes/init_spec.rb

View workflow job for this annotation

GitHub Actions / Puppet / Static validations

Layout/EmptyLinesAroundBlockBody: Extra empty line detected at block body end. (https://rubystyle.guide#empty-lines-around-bodies)
end

Check failure on line 266 in spec/classes/init_spec.rb

View workflow job for this annotation

GitHub Actions / Puppet / Static validations

RSpec/EmptyLineAfterFinalLet: Add an empty line after the last `let`. (https://rspec.rubystyle.guide/#empty-line-after-let, https://www.rubydoc.info/gems/rubocop-rspec/RuboCop/Cop/RSpec/EmptyLineAfterFinalLet)
it { is_expected.to contain_user('consul').with(ensure: :present).with_uid(2).with_comment('this is a comment') }
end

context 'When data_dir is provided' do
let(:params) do
{
Expand Down

0 comments on commit 98b6430

Please sign in to comment.