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

OSS LDAP configuration #115

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
Open
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
4 changes: 4 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,8 @@ nexus-cli enable_smart_proxy #
nexus-cli get_artifact_custom_info coordinates # Gets and returns the custom metadata in XML format about a particular artifact.
nexus-cli get_artifact_info coordinates # Gets and returns the metadata in XML format about a particular artifact.
nexus-cli get_global_settings # Prints out your Nexus' current setttings and saves them to a file.
nexus-cli get_oss_ldap_conn_settings # Prints out your Nexus' OSS LDAP connection setttings and saves them to a file.
nexus-cli get_oss_ldap_user_group_settings # Prints out your Nexus' OSS LDAP user and group setttings and saves them to a file.
nexus-cli get_group_repository group_id # Gets information about the given group repository.
nexus-cli get_license_info # Returns the license information of the server.
nexus-cli get_logging_info # Gets the log4j Settings of the Nexus server.
Expand All @@ -74,6 +76,8 @@ nexus-cli transfer_artifact coordinates from_repository to_repository #
nexus-cli update_artifact_custom_info coordinates param1 param2 ... # Updates the artifact custom metadata with the given key-value pairs.
nexus-cli update_user user_id # Updates a user's details. Leave fields blank for them to remain their current values.
nexus-cli upload_global_settings # Uploads a global_settings.json file to your Nexus to update its settings.
nexus-cli upload_oss_ldap_conn_settings # Uploads a oss_ldap_conn_settings.json file to your Nexus to update its OSS LDAP connection settings.
nexus-cli upload_oss_ldap_user_group_settings # Uploads a oss_ldap_user_group_settings.json file to your Nexus to update its OSS LDAP user and group settings.
```

Each command can be prefaced with `help` to get more information about the command. For example - `nexus-cli help get_users`
Expand Down
3 changes: 2 additions & 1 deletion lib/nexus_cli.rb
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ module NexusCli
DEFAULT_ACCEPT_HEADER = {
"Accept" => "application/json"
}.freeze

DEFAULT_CONTENT_TYPE_HEADER = {
"Content-Type" => "application/json"
}.freeze
Expand All @@ -26,6 +26,7 @@ module NexusCli
autoload :N3Metadata, 'nexus_cli/n3_metadata'
autoload :ArtifactActions, 'nexus_cli/mixins/artifact_actions'
autoload :GlobalSettingsActions, 'nexus_cli/mixins/global_settings_actions'
autoload :OssLdapSettingsActions, 'nexus_cli/mixins/oss_ldap_settings_actions'
autoload :UserActions, 'nexus_cli/mixins/user_actions'
autoload :RepositoryActions, 'nexus_cli/mixins/repository_actions'
autoload :LoggingActions, 'nexus_cli/mixins/logging_actions'
Expand Down
122 changes: 122 additions & 0 deletions lib/nexus_cli/mixins/oss_ldap_settings_actions.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,122 @@
require 'json'

module NexusCli
# @author Kyle Allan <[email protected]>
module OssLdapSettingsActions

# Retrieves the oss_ldap connection settings of the Nexus server
#
# @return [File] a File with the oss_ldap settings.
def get_oss_ldap_conn_settings
json = get_oss_ldap_conn_settings_json
pretty_json = JSON.pretty_generate(JSON.parse(json))
Dir.mkdir(File.expand_path("~/.nexus")) unless Dir.exists?(File.expand_path("~/.nexus"))
destination = File.join(File.expand_path("~/.nexus"), "oss_ldap_conn_settings.json")
artifact_file = File.open(destination, 'wb') do |file|
file.write(pretty_json)
end
end

def get_oss_ldap_conn_settings_json
response = nexus.get(nexus_url("service/local/ldap/conn_info"), :header => DEFAULT_ACCEPT_HEADER)
case response.status
when 200
return response.content
else
raise UnexpectedStatusCodeException.new(response.status)
end
end

def upload_oss_ldap_conn_settings(json=nil)
oss_ldap_conn_settings = nil
if json == nil
oss_ldap_conn_settings = File.read(File.join(File.expand_path("~/.nexus"), "oss_ldap_conn_settings.json"))
else
oss_ldap_conn_settings = json
end
response = nexus.put(nexus_url("service/local/ldap/conn_info"), :body => oss_ldap_conn_settings, :header => DEFAULT_CONTENT_TYPE_HEADER)
case response.status
when 204
return true
when 400
raise BadSettingsException.new(response.content)
end
end

def reset_oss_ldap_conn_settings
response = nexus.get(nexus_url("service/local/ldap/conn_info"), :header => DEFAULT_ACCEPT_HEADER)
case response.status
when 200
default_json = response.content
else
raise UnexpectedStatusCodeException.new(response.status)
end

response = nexus.put(nexus_url("service/local/ldap/conn_info"), :body => default_json, :header => DEFAULT_CONTENT_TYPE_HEADER)
case response.status
when 204
return true
else
raise UnexpectedStatusCodeException.new(response.status)
end
end

# Retrieves the oss_ldap user and group settings of the Nexus server
#
# @return [File] a File with the oss_ldap settings.
def get_oss_ldap_user_group_settings
json = get_oss_ldap_user_group_settings_json
pretty_json = JSON.pretty_generate(JSON.parse(json))
Dir.mkdir(File.expand_path("~/.nexus")) unless Dir.exists?(File.expand_path("~/.nexus"))
destination = File.join(File.expand_path("~/.nexus"), "oss_ldap_user_group_settings.json")
artifact_file = File.open(destination, 'wb') do |file|
file.write(pretty_json)
end
end

def get_oss_ldap_user_group_settings_json
response = nexus.get(nexus_url("service/local/ldap/user_group_conf"), :header => DEFAULT_ACCEPT_HEADER)
case response.status
when 200
return response.content
else
raise UnexpectedStatusCodeException.new(response.status)
end
end

def upload_oss_ldap_user_group_settings(json=nil)
oss_ldap_user_group_settings = nil
if json == nil
oss_ldap_user_group_settings = File.read(File.join(File.expand_path("~/.nexus"), "oss_ldap_user_group_settings.json"))
else
oss_ldap_user_group_settings = json
end
response = nexus.put(nexus_url("service/local/ldap/user_group_conf"), :body => oss_ldap_user_group_settings, :header => DEFAULT_CONTENT_TYPE_HEADER)
case response.status
when 204
return true
when 400
raise BadSettingsException.new(response.content)
end
end

def reset_oss_ldap_user_group_settings
response = nexus.get(nexus_url("service/local/ldap/user_group_conf"), :header => DEFAULT_ACCEPT_HEADER)
case response.status
when 200
default_json = response.content
else
raise UnexpectedStatusCodeException.new(response.status)
end

response = nexus.put(nexus_url("service/local/ldap/user_group_conf"), :body => default_json, :header => DEFAULT_CONTENT_TYPE_HEADER)
case response.status
when 204
return true
else
raise UnexpectedStatusCodeException.new(response.status)
end
end

end
end
3 changes: 2 additions & 1 deletion lib/nexus_cli/remote/oss_remote.rb
Original file line number Diff line number Diff line change
Expand Up @@ -7,5 +7,6 @@ class OSSRemote < BaseRemote
include LoggingActions
include RepositoryActions
include UserActions
include OssLdapSettingsActions
end
end
end
32 changes: 32 additions & 0 deletions lib/nexus_cli/tasks.rb
Original file line number Diff line number Diff line change
Expand Up @@ -127,6 +127,38 @@ def reset_global_settings
say "Your Nexus global settings have been reset to their default values", :blue
end

desc "get_oss_ldap_conn_settings", "Prints out your Nexus' OSS LDAP connection setttings and saves them to a file."
def get_oss_ldap_conn_settings
nexus_remote.get_oss_ldap_conn_settings
say "Your current Nexus OSS LDAP connection settings have been written to the file: ~/.nexus/oss_ldap_conn_settings.json", :blue
end

method_option :json,
:type => :string,
:default => nil,
:desc => "A String of the JSON you wish to upload."
desc "upload_oss_ldap_conn_settings", "Uploads a oss_ldap_conn_settings.json file to your Nexus to update its OSS LDAP connection settings."
def upload_oss_ldap_conn_settings
nexus_remote.upload_oss_ldap_conn_settings
say "Your oss_ldap_conn_settings.json file has been uploaded to Nexus", :blue
end

desc "get_oss_ldap_user_group_settings", "Prints out your Nexus' OSS LDAP user and group setttings and saves them to a file."
def get_oss_ldap_user_group_settings
nexus_remote.get_oss_ldap_user_group_settings
say "Your current Nexus OSS LDAP user and group settings have been written to the file: ~/.nexus/oss_ldap_user_group_settings.json", :blue
end

method_option :json,
:type => :string,
:default => nil,
:desc => "A String of the JSON you wish to upload."
desc "upload_oss_ldap_user_group_settings", "Uploads a oss_ldap_user_group_settings.json file to your Nexus to update its OSS LDAP user and group settings."
def upload_oss_ldap_user_group_settings
nexus_remote.upload_oss_ldap_user_group_settings
say "Your oss_ldap_user_group_settings.json file has been uploaded to Nexus", :blue
end

method_option :id,
:type => :string,
:desc => "The id of the repository to use."
Expand Down