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

add proxy repository authentication #112

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
21 changes: 14 additions & 7 deletions lib/nexus_cli/mixins/repository_actions.rb
Original file line number Diff line number Diff line change
Expand Up @@ -12,11 +12,13 @@ module RepositoryActions
# @param id [String] the id of repository
# @param policy [String] repository policy (RELEASE|SNAPSHOT)
# @param provider [String] repo provider (maven2 by default)
# @param username [String]
# @param password [String]
#
# @return [Boolean] returns true on success
def create_repository(name, proxy, url, id, policy, provider)
def create_repository(name, proxy, url, id, policy, provider, username, password)
json = if proxy
create_proxy_repository_json(name, url, id, policy, provider)
create_proxy_repository_json(name, url, id, policy, provider, username, password)
else
create_hosted_repository_json(name, id, policy, provider)
end
Expand Down Expand Up @@ -186,14 +188,14 @@ def create_hosted_repository_json(name, id, policy, provider)
params[:browseable] = true
params[:indexable] = true
params[:repoType] = "hosted"
params[:repoPolicy] = policy.nil? ? "RELEASE" : ["RELEASE", "SNAPSHOT"].include?(policy) ? policy : "RELEASE"
params[:name] = name
params[:repoPolicy] = policy.nil? ? "RELEASE" : ["RELEASE", "SNAPSHOT"].include?(policy) ? policy : "RELEASE"
params[:name] = name.nil? ? id : name
params[:id] = id.nil? ? sanitize_for_id(name) : sanitize_for_id(id)
params[:format] = "maven2"
JSON.dump(:data => params)
end

def create_proxy_repository_json(name, url, id, policy, provider)
def create_proxy_repository_json(name, url, id, policy, provider, username, password)
params = {:provider => provider.nil? ? "maven2" : provider}
params[:providerRole] = "org.sonatype.nexus.proxy.repository.Repository"
params[:exposed] = true
Expand All @@ -205,15 +207,20 @@ def create_proxy_repository_json(name, url, id, policy, provider)
params[:writePolicy] = "READ_ONLY"
params[:downloadRemoteIndexes] = true
params[:autoBlockActive] = false
params[:name] = name
params[:name] = name.nil? ? id : name
params[:id] = id.nil? ? sanitize_for_id(name) : sanitize_for_id(id)
params[:remoteStorage] = {:remoteStorageUrl => url.nil? ? "http://change-me.com/" : url}
if (username) && (password)
params[:remoteStorage] = {:remoteStorageUrl => url.nil? ? "http://change-me.com/" : url, :authentication => {"username" => username ,"password" => password}}
else
params[:remoteStorage] = {:remoteStorageUrl => url.nil? ? "http://change-me.com/" : url}
end
JSON.dump(:data => params)
end

def create_group_repository_json(name, id, provider)
params = {:id => id.nil? ? sanitize_for_id(name) : sanitize_for_id(id)}
params[:name] = name
params[:name] = name.nil? ? id : name
params[:provider] = provider.nil? ? "maven2" : provider
params[:exposed] = true
JSON.dump(:data => params)
Expand Down
8 changes: 7 additions & 1 deletion lib/nexus_cli/tasks.rb
Original file line number Diff line number Diff line change
Expand Up @@ -142,9 +142,15 @@ def reset_global_settings
method_option :url,
:type => :string,
:desc => "The url of the actual repository for the proxy repository to use."
method_option :username,
:type => :string,
:desc => "The username for the remote proxy repository."
method_option :password,
:type => :string,
:desc => "The password for the remote proxy repository."
desc "create_repository name", "Creates a new Repository with the provided name."
def create_repository(name)
if nexus_remote.create_repository(name, options[:proxy], options[:url], options[:id], options[:policy], options[:provider])
if nexus_remote.create_repository(name, options[:proxy], options[:url], options[:id], options[:policy], options[:provider], options[:username], options[:password])
say "A new Repository named #{name} has been created.", :blue
end
end
Expand Down