Skip to content
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

Allow overriding UID during user creation #108

Merged
merged 2 commits into from
Aug 4, 2016
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 0 additions & 3 deletions Gemfile.lock
Original file line number Diff line number Diff line change
Expand Up @@ -223,6 +223,3 @@ DEPENDENCIES
rake
stove
test-kitchen

BUNDLED WITH
1.10.6
8 changes: 8 additions & 0 deletions attributes/default.rb
Original file line number Diff line number Diff line change
Expand Up @@ -68,10 +68,18 @@
# Should node['kafka']['user'] and node['kafka']['group'] be created?
default['kafka']['manage_user'] = true

#
# Override UID for User for directories, configuration files and running Kafka.
default['kafka']['uid'] = nil

#
# Group for directories, configuration files and running Kafka.
default['kafka']['group'] = 'kafka'

#
# Override GID for Group for directories, configuration files and running Kafka.
default['kafka']['gid'] = nil

#
# JVM heap options for Kafka.
default['kafka']['heap_opts'] = '-Xmx1G -Xms1G'
Expand Down
4 changes: 3 additions & 1 deletion recipes/_setup.rb
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,13 @@
#

group node['kafka']['group'] do
gid node['kafka']['gid'] if node['kafka']['gid']
only_if { node['kafka']['manage_user'] }
end

user node['kafka']['user'] do
gid node['kafka']['group']
gid node['kafka']['gid'] if node['kafka']['gid']
uid node['kafka']['uid'] if node['kafka']['uid']
home '/var/empty/kafka'
shell '/sbin/nologin'
only_if { node['kafka']['manage_user'] }
Expand Down
22 changes: 19 additions & 3 deletions spec/recipes/setup_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -19,10 +19,27 @@
expect(chef_run).to create_group('kafka')
end

it 'creates a kafka user' do
expect(chef_run).to create_user('kafka').with({
shell: '/sbin/nologin'
})
end
end

context 'when uid and gid' do
let :kafka_attrs do
{uid: 1234, gid: 5678}
end

it 'creates a kafka group' do
expect(chef_run).to create_group('kafka')
end

it 'creates a kafka user' do
expect(chef_run).to create_user('kafka').with({
shell: '/sbin/nologin',
gid: 'kafka'
gid: 5678,
uid: 1234
})
end
end
Expand Down Expand Up @@ -55,8 +72,7 @@

it 'creates a user with set name' do
expect(chef_run).to create_user('spec').with({
shell: '/sbin/nologin',
gid: 'spec'
shell: '/sbin/nologin'
})
end
end
Expand Down