module NexusCli::SmartProxyActions

@author Kyle Allan <kallan@riotgames.com>

Public Instance Methods

add_trusted_key(certificate, description, path=true) click to toggle source

Adds a trusted key to Nexus for use with Smart Proxy. By default, the [certificate] parameter will point to a path of a certificate file. As an alternative, call with path=false to pass a certificate in directly.

@param certificate [String] a path to or the actual certificate String @param description [String] a brief description of the key; usually the name of the server the key belongs to @param path=true [Boolean] by default uses [certificate] as a path to a file, when false, [certificate] is treated as a String

@return [Boolean] true when the certificate is added, false otherwise

# File lib/nexus_cli/mixins/pro/smart_proxy_actions.rb, line 128
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
delete_trusted_key(key_id) click to toggle source

Deletes a trusted key from the Nexus server.

@param key_id [String] the key to delete

@return [Boolean] true if the key has been deleted, false otherwise

# File lib/nexus_cli/mixins/pro/smart_proxy_actions.rb, line 145
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
disable_artifact_publish(repository_id) click to toggle source

Disables artifact publishing for the given [repository_id].

@param repository_id [String] the repository to disable artifact publishing on

@return [Boolean] true if the artifact is now disabled for publishing artifacts, false otherwise

# File lib/nexus_cli/mixins/pro/smart_proxy_actions.rb, line 37
def disable_artifact_publish(repository_id)
  params = {:repositoryId => repository_id}
  params[:publish] = false
  artifact_publish(repository_id, params)
end
disable_artifact_subscribe(repository_id) click to toggle source

Disables artifact subscribing for the given [repository_id].

@param repository_id [String] the repository to disable artifact subscribing on

@return [Boolean] true if the repository is disabled, false otherwise

# File lib/nexus_cli/mixins/pro/smart_proxy_actions.rb, line 63
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
disable_smart_proxy() click to toggle source

Disables Smart Proxy on the Nexus server.

@return [Boolean] true if Smart Proxy is disabled, false otherwise

# File lib/nexus_cli/mixins/pro/smart_proxy_actions.rb, line 88
def disable_smart_proxy
  params = {:enabled => false}
  smart_proxy(params)
end
enable_artifact_publish(repository_id) click to toggle source

Enables artifact publishing for the given [repository_id].

@param repository_id [String] the repository to enable artifact publishing on

@return [Boolean] true if the artifact is now publishing artifacts, false otherwise

# File lib/nexus_cli/mixins/pro/smart_proxy_actions.rb, line 26
def enable_artifact_publish(repository_id)
  params = {:repositoryId => repository_id}
  params[:publish] = true
  artifact_publish(repository_id, params)
end
enable_artifact_subscribe(repository_id, preemptive_fetch) click to toggle source

Enables artifact subscribing for the given [repository_id].

@param repository_id [String] the repository to enable artifact subscribe on @param preemptive_fetch [Boolean] true if the repository should prefetch artifacts, false otherwise

@return [Boolean] true if the repository is now subscribing, false otherwise

# File lib/nexus_cli/mixins/pro/smart_proxy_actions.rb, line 49
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
enable_smart_proxy(host=nil, port=nil) click to toggle source

Enables Smart Proxy on the Nexus server.

@param host=nil [String] an optional host to listen on for Smart Proxy @param port=nil [Fixnum] an optional port to listen on for Smart Proxy

@return [Boolean] true if Smart Proxy is enabled, false otherwise

# File lib/nexus_cli/mixins/pro/smart_proxy_actions.rb, line 77
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
get_pub_sub(repository_id) click to toggle source

Gets Smart Proxy related information about the given [repository_id].

@param repository_id [String] the repository to get information about

@return [String] a String of XML about the given repository

# File lib/nexus_cli/mixins/pro/smart_proxy_actions.rb, line 11
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
get_smart_proxy_key() click to toggle source

@deprecated this method might not be used.

# File lib/nexus_cli/mixins/pro/smart_proxy_actions.rb, line 109
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
get_smart_proxy_settings() click to toggle source

Gets the current Smart Proxy settings of the Nexus server.

@return [String] a String of JSON with information about Smart Proxy

# File lib/nexus_cli/mixins/pro/smart_proxy_actions.rb, line 98
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
get_trusted_keys() click to toggle source

Gets information about the current list of trusted keys in the Nexus server. A large amount of JSON will be printed because this resource returns the actual certificates.

@return [String] a String of JSON from Nexus about the current list of trusted keys

# File lib/nexus_cli/mixins/pro/smart_proxy_actions.rb, line 160
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

Private Instance Methods

artifact_publish(repository_id, params) click to toggle source
# File lib/nexus_cli/mixins/pro/smart_proxy_actions.rb, line 194
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
artifact_subscribe(repository_id, params) click to toggle source
# File lib/nexus_cli/mixins/pro/smart_proxy_actions.rb, line 184
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
create_add_trusted_key_json(params) click to toggle source
# File lib/nexus_cli/mixins/pro/smart_proxy_actions.rb, line 172
def create_add_trusted_key_json(params)
  JSON.dump(:data => params)
end
create_pub_sub_json(params) click to toggle source
# File lib/nexus_cli/mixins/pro/smart_proxy_actions.rb, line 180
def create_pub_sub_json(params)
  JSON.dump(:data => params)
end
create_smart_proxy_settings_json(params) click to toggle source
# File lib/nexus_cli/mixins/pro/smart_proxy_actions.rb, line 176
def create_smart_proxy_settings_json(params)
  JSON.dump(:data => params)
end
is_proxy_repository?(repository_xml) click to toggle source
# File lib/nexus_cli/mixins/pro/smart_proxy_actions.rb, line 215
def is_proxy_repository?(repository_xml)
  REXML::Document.new(repository_xml).elements["/repository/data/repoType"].text == "proxy"
end
smart_proxy(params) click to toggle source
# File lib/nexus_cli/mixins/pro/smart_proxy_actions.rb, line 204
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