Skip to content

Commit

Permalink
Allow to add nexus user to additional groups
Browse files Browse the repository at this point in the history
This will allow to provide a license file to be used by
different instances or a single one without the need
to manage it directly in the nexus cookbook.
  • Loading branch information
jeremy-clerc committed Feb 5, 2024
1 parent bba1b5d commit a8a0f2d
Show file tree
Hide file tree
Showing 4 changed files with 18 additions and 0 deletions.
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

0 comments on commit a8a0f2d

Please sign in to comment.