module NexusCli::SmartProxyActions
def add_trusted_key(certificate, description, path=true)
-
(Boolean)
- true when the certificate is added, false otherwise
Parameters:
-
path=true
(Boolean
) -- by default uses [certificate] as a path to a file, when false, [certificate] is treated as a String -
description
(String
) -- a brief description of the key; usually the name of the server the key belongs to -
certificate
(String
) -- a path to or the actual certificate String
def add_trusted_key(certificate, description, path=true) params = {:description => description} params[:certificate] = path ? File.read(File.expand_path(certificate)) : certificate response = nexus.post(nexus_url("service/local/smartproxy/trusted-keys"), :body => create_add_trusted_key_json(params), :header => DEFAULT_CONTENT_TYPE_HEADER) case response.status when 201 return true else raise UnexpectedStatusCodeException.new(response.status) end end
def artifact_publish(repository_id, params)
def artifact_publish(repository_id, params) response = nexus.put(nexus_url("service/local/smartproxy/pub-sub/#{sanitize_for_id(repository_id)}"), :body => create_pub_sub_json(params), :header => DEFAULT_CONTENT_TYPE_HEADER) case response.status when 200 return true else raise UnexpectedStatusCodeException.new(response.status) end end
def artifact_subscribe(repository_id, params)
def artifact_subscribe(repository_id, params) response = nexus.put(nexus_url("service/local/smartproxy/pub-sub/#{sanitize_for_id(repository_id)}"), :body => create_pub_sub_json(params), :header => DEFAULT_CONTENT_TYPE_HEADER) case response.status when 200 return true else raise UnexpectedStatusCodeException.new(response.status) end end
def create_add_trusted_key_json(params)
def create_add_trusted_key_json(params) JSON.dump(:data => params) end
def create_pub_sub_json(params)
def create_pub_sub_json(params) JSON.dump(:data => params) end
def create_smart_proxy_settings_json(params)
def create_smart_proxy_settings_json(params) JSON.dump(:data => params) end
def delete_trusted_key(key_id)
-
(Boolean)
- true if the key has been deleted, false otherwise
Parameters:
-
key_id
(String
) -- the key to delete
def delete_trusted_key(key_id) response = nexus.delete(nexus_url("service/local/smartproxy/trusted-keys/#{key_id}")) case response.status when 204 return true else raise UnexpectedStatusCodeException.new(response.status) end end
def disable_artifact_publish(repository_id)
-
(Boolean)
- true if the artifact is now disabled for publishing artifacts, false otherwise
Parameters:
-
repository_id
(String
) -- the repository to disable artifact publishing on
def disable_artifact_publish(repository_id) params = {:repositoryId => repository_id} params[:publish] = false artifact_publish(repository_id, params) end
def disable_artifact_subscribe(repository_id)
-
(Boolean)
- true if the repository is disabled, false otherwise
Parameters:
-
repository_id
(String
) -- the repository to disable artifact subscribing on
def disable_artifact_subscribe(repository_id) raise NotProxyRepositoryException.new(repository_id) unless is_proxy_repository?(get_repository_info(repository_id)) params = {:repositoryId => repository_id} params[:subscribe] = false artifact_subscribe(repository_id, params) end
def disable_smart_proxy
-
(Boolean)
- true if Smart Proxy is disabled, false otherwise
def disable_smart_proxy params = {:enabled => false} smart_proxy(params) end
def enable_artifact_publish(repository_id)
-
(Boolean)
- true if the artifact is now publishing artifacts, false otherwise
Parameters:
-
repository_id
(String
) -- the repository to enable artifact publishing on
def enable_artifact_publish(repository_id) params = {:repositoryId => repository_id} params[:publish] = true artifact_publish(repository_id, params) end
def enable_artifact_subscribe(repository_id, preemptive_fetch)
-
(Boolean)
- true if the repository is now subscribing, false otherwise
Parameters:
-
preemptive_fetch
(Boolean
) -- true if the repository should prefetch artifacts, false otherwise -
repository_id
(String
) -- the repository to enable artifact subscribe on
def enable_artifact_subscribe(repository_id, preemptive_fetch) raise NotProxyRepositoryException.new(repository_id) unless is_proxy_repository?(get_repository_info(repository_id)) params = {:repositoryId => repository_id} params[:subscribe] = true params[:preemptiveFetch] = preemptive_fetch artifact_subscribe(repository_id, params) end
def enable_smart_proxy(host=nil, port=nil)
-
(Boolean)
- true if Smart Proxy is enabled, false otherwise
Parameters:
-
port=nil
(Fixnum
) -- an optional port to listen on for Smart Proxy -
host=nil
(String
) -- an optional host to listen on for Smart Proxy
def enable_smart_proxy(host=nil, port=nil) params = {:enabled => true} params[:host] = host unless host.nil? params[:port] = port unless port.nil? smart_proxy(params) end
def get_pub_sub(repository_id)
-
(String)
- a String of XML about the given repository
Parameters:
-
repository_id
(String
) -- the repository to get information about
def get_pub_sub(repository_id) response = nexus.get(nexus_url("service/local/smartproxy/pub-sub/#{repository_id}")) case response.status when 200 return response.content else raise UnexpectedStatusCodeException.new(response.status) end end
def get_smart_proxy_key
- this method might not be used.
def get_smart_proxy_key response = nexus.get(nexus_url("service/local/smartproxy/settings"), :header => DEFAULT_ACCEPT_HEADER) case response.status when 200 return response.content else raise UnexpectedStatusCodeException.new(response.status) end end
def get_smart_proxy_settings
-
(String)
- a String of JSON with information about Smart Proxy
def get_smart_proxy_settings response = nexus.get(nexus_url("service/local/smartproxy/settings"), :header => DEFAULT_ACCEPT_HEADER) case response.status when 200 return response.content else raise UnexpectedStatusCodeException.new(response.status) end end
def get_trusted_keys
-
(String)
- a String of JSON from Nexus about the current list of trusted keys
def get_trusted_keys response = nexus.get(nexus_url("service/local/smartproxy/trusted-keys"), :header => DEFAULT_ACCEPT_HEADER) case response.status when 200 return response.content else raise UnexpectedStatusCodeException.new(response.status) end end
def is_proxy_repository?(repository_xml)
def is_proxy_repository?(repository_xml) REXML::Document.new(repository_xml).elements["/repository/data/repoType"].text == "proxy" end
def smart_proxy(params)
def smart_proxy(params) response = nexus.put(nexus_url("service/local/smartproxy/settings"), :body => create_smart_proxy_settings_json(params), :header => DEFAULT_CONTENT_TYPE_HEADER) case response.status when 200 return true else raise UnexpectedStatusCodeException.new(response.status) end end