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 to add nexus user to additional groups #142

Merged
merged 2 commits into from
Feb 6, 2024
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
5 changes: 4 additions & 1 deletion Gemfile
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,12 @@ source 'https://rubygems.org'

group :unit_test do
gem 'chef', '= 17.9.46'
gem 'chefspec', '>= 9.3.6'
gem 'fakefs', '>= 2.5.0'
gem 'webmock', '>= 3.13.0'

# TODO: Unpin chefspec and remove rspec pin once chefspec integrates breaking rspec-expectations change
gem 'chefspec', '= 9.3.6'
gem 'rspec-expectations', '= 3.12.3'
end

group :integration do
Expand Down
3 changes: 3 additions & 0 deletions attributes/default.rb
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,9 @@
default['nexus3']['user'] = 'nexus'
default['nexus3']['uid'] = nil
default['nexus3']['gid'] = nil
# Additional groups to add nexus user to, for example when sharing a license file between users.
# Groups listed must already exist.
default['nexus3']['additional_groups'] = []

default['nexus3']['properties_variables']['application-port'] = '8081'
default['nexus3']['properties_variables']['application-host'] = '0.0.0.0'
Expand Down
11 changes: 11 additions & 0 deletions resources/default.rb
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
property :nexus3_uid, [String, Integer, NilClass], default: lazy { node['nexus3']['uid'] }
property :nexus3_group, [String, NilClass], default: lazy { node['nexus3']['group'] }
property :nexus3_gid, [String, Integer, NilClass], default: lazy { node['nexus3']['gid'] }
property :nexus3_additional_groups, [Array, NilClass], default: lazy { node['nexus3']['additional_groups'] }
property :nexus3_password, String, sensitive: true, default: lazy { node['nexus3']['api']['password'] } # Admin password
property :version, String, default: lazy { node['nexus3']['version'] }
property :url, [String, NilClass], default: lazy { node['nexus3']['url'] }
Expand Down Expand Up @@ -34,6 +35,16 @@
uid new_resource.nexus3_uid unless new_resource.nexus3_uid.nil?
end

new_resource.nexus3_additional_groups.to_a.each do |gr|
group "add #{new_resource.nexus3_user} user to #{gr} group" do
group_name gr
action :modify
append true
members [new_resource.nexus3_user]
not_if { platform?('windows') }
end
end

# Install Nexus3 software
ark "nexus-#{new_resource.version}" do
action :put
Expand Down
3 changes: 3 additions & 0 deletions test/fixtures/cookbooks/nexus3_test/recipes/default.rb
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
openjdk_pkg_install '8' unless platform_family?('windows')

group 'nexusall'

package 'curl'

# Installation with default settings
Expand All @@ -16,6 +18,7 @@
nexus3_group 'nexusbar'
nexus3_uid 1234
nexus3_gid 5678
nexus3_additional_groups ['nexusall']
nexus3_home '/home/nexusbar'
nexus3_password 'humdiddle'
properties_variables(node['nexus3']['properties_variables'].merge('application-port': '8082'))
Expand Down
1 change: 1 addition & 0 deletions test/integration/default/inspec/default_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,7 @@
it { should exist }
its('uid') { should eq 1234 }
its('group') { should eq 'nexusbar' }
its('groups') { should include 'nexusall' }
its('gid') { should eq 5678 }
end

Expand Down