Module: NexusCli::SmartProxyActions

Included in:
ProRemote
Defined in:
lib/nexus_cli/mixins/pro/smart_proxy_actions.rb

Overview

Author:

Instance Method Summary collapse

Instance Method Details

#add_trusted_key(certificate, description, path = true) ⇒ Boolean

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.

Parameters:

  • certificate (String)

    a path to or the actual certificate String

  • description (String)

    a brief description of the key; usually the name of the server the key belongs to

  • path=true (Boolean)

    by default uses [certificate] as a path to a file, when false, [certificate] is treated as a String

Returns:

  • (Boolean)

    true when the certificate is added, false otherwise



128
129
130
131
132
133
134
135
136
137
138
# 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) ⇒ Boolean

Deletes a trusted key from the Nexus server.

Parameters:

  • key_id (String)

    the key to delete

Returns:

  • (Boolean)

    true if the key has been deleted, false otherwise



145
146
147
148
149
150
151
152
153
# 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) ⇒ Boolean

Disables artifact publishing for the given [repository_id].

Parameters:

  • repository_id (String)

    the repository to disable artifact publishing on

Returns:

  • (Boolean)

    true if the artifact is now disabled for publishing artifacts, false otherwise



37
38
39
40
41
# 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) ⇒ Boolean

Disables artifact subscribing for the given [repository_id].

Parameters:

  • repository_id (String)

    the repository to disable artifact subscribing on

Returns:

  • (Boolean)

    true if the repository is disabled, false otherwise

Raises:



63
64
65
66
67
68
69
# 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_proxyBoolean

Disables Smart Proxy on the Nexus server.

Returns:

  • (Boolean)

    true if Smart Proxy is disabled, false otherwise



88
89
90
91
# 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) ⇒ Boolean

Enables artifact publishing for the given [repository_id].

Parameters:

  • repository_id (String)

    the repository to enable artifact publishing on

Returns:

  • (Boolean)

    true if the artifact is now publishing artifacts, false otherwise



26
27
28
29
30
# 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) ⇒ Boolean

Enables artifact subscribing for the given [repository_id].

Parameters:

  • repository_id (String)

    the repository to enable artifact subscribe on

  • preemptive_fetch (Boolean)

    true if the repository should prefetch artifacts, false otherwise

Returns:

  • (Boolean)

    true if the repository is now subscribing, false otherwise

Raises:



49
50
51
52
53
54
55
56
# 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) ⇒ Boolean

Enables Smart Proxy on the Nexus server.

Parameters:

  • host=nil (String)

    an optional host to listen on for Smart Proxy

  • port=nil (Fixnum)

    an optional port to listen on for Smart Proxy

Returns:

  • (Boolean)

    true if Smart Proxy is enabled, false otherwise



77
78
79
80
81
82
# 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) ⇒ String

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

Parameters:

  • repository_id (String)

    the repository to get information about

Returns:

  • (String)

    a String of XML about the given repository



11
12
13
14
15
16
17
18
19
# 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_keyObject

Deprecated.

this method might not be used.



109
110
111
112
113
114
115
116
117
# 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_settingsString

Gets the current Smart Proxy settings of the Nexus server.

Returns:

  • (String)

    a String of JSON with information about Smart Proxy



98
99
100
101
102
103
104
105
106
# 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_keysString

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.

Returns:

  • (String)

    a String of JSON from Nexus about the current list of trusted keys



160
161
162
163
164
165
166
167
168
# 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