-
Notifications
You must be signed in to change notification settings - Fork 17
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Via system property path so we do not require a restart on new install or upgrade: cf: https://help.sonatype.com/en/installing-and-updating-licenses.html#installing-or-updating-a-license-using-a-system-property But also via the API directly for when the license needs to be updated as the system property path does not care if about a new license if there is already on installed
- Loading branch information
1 parent
ee404d5
commit 8f65d4b
Showing
5 changed files
with
99 additions
and
16 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -6,3 +6,4 @@ Gemfile.lock | |
.kitchen/ | ||
.kitchen.local.yml | ||
.bundle/ | ||
bundle/ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,61 @@ | ||
property :path, [String, NilClass], default: lazy { node['nexus3']['properties_variables']['nexus.licenseFile'] } | ||
property :nexus3_group, [String, NilClass], default: lazy { node['nexus3']['group'] } | ||
property :fingerprint, String, default: lazy { node['nexus3']['license_fingerprint'] } | ||
property :license, String, sensitive: true, default: lazy { node['nexus3']['license'] } | ||
property :api_client, ::Nexus3::Api, identity: true, desired_state: false, default: lazy { ::Nexus3::Api.default(node) } | ||
|
||
# def request(method, path, content_type: 'application/json', data: nil, query: nil) | ||
load_current_value do |_desired| | ||
begin | ||
config = api_client.request(:get, 'system/license') | ||
current_value_does_not_exist! if config.nil? | ||
fingerprint config['fingerprint'] | ||
# Nexus returns a 402 Payment Required when there is no license installed, we get an ApiError | ||
rescue ::LoadError, ::Nexus3::ApiError => e | ||
::Chef::Log.warn "A '#{e.class}' occured: #{e.message}" | ||
current_value_does_not_exist! | ||
end | ||
end | ||
|
||
action :install do | ||
directory "license directory for #{new_resource.instance_name}" do | ||
path(lazy { ::File.dirname(new_resource.path) }) | ||
recursive true | ||
owner 'root' | ||
group 'root' | ||
mode '0755' | ||
only_if { new_resource.license && new_resource.path } | ||
end | ||
|
||
file "license for #{new_resource.instance_name}" do | ||
action :create | ||
owner 'root' | ||
group new_resource.nexus3_group | ||
mode '0640' | ||
sensitive true | ||
content(lazy { ::Base64.decode64(new_resource.license) }) | ||
only_if { new_resource.license && new_resource.path } | ||
end | ||
end | ||
|
||
action :update do | ||
converge_if_changed :fingerprint do | ||
converge_by('Uploading license') do | ||
new_resource.api_client.request(:post, 'system/license', data: new_resource.license, content_type: 'application/octet-stream') | ||
end | ||
end | ||
end | ||
|
||
action :delete do | ||
unless current_resource.nil? | ||
converge_by('Unregistering license') do | ||
new_resource.api_client.request(:delete, 'system/license') | ||
end | ||
end | ||
end | ||
|
||
action_class do | ||
def whyrun_supported? | ||
true | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters