nexus_cli 0.7.3 → 0.8.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- data/VERSION +1 -1
- data/bin/nexus-cli +0 -4
- data/features/nexus_oss.feature +26 -0
- data/lib/nexus_cli.rb +4 -0
- data/lib/nexus_cli/errors.rb +15 -1
- data/lib/nexus_cli/n3_metadata.rb +39 -56
- data/lib/nexus_cli/nexus_oss_remote.rb +262 -181
- data/lib/nexus_cli/nexus_pro_remote.rb +207 -190
- data/lib/nexus_cli/nexus_remote_factory.rb +30 -12
- data/lib/nexus_cli/tasks.rb +17 -18
- data/nexus_cli.gemspec +1 -1
- data/pro/nexus_custom_metadata.feature +97 -0
- data/pro/nexus_pro.feature +0 -99
- data/spec/oss_remote_spec.rb +6 -2
- data/spec/pro_remote_spec.rb +66 -6
- metadata +6 -5
data/VERSION
CHANGED
@@ -1 +1 @@
|
|
1
|
-
0.
|
1
|
+
0.8.0
|
data/bin/nexus-cli
CHANGED
data/features/nexus_oss.feature
CHANGED
@@ -19,6 +19,7 @@ Feature: Use the Nexus CLI
|
|
19
19
|
"""
|
20
20
|
And the exit status should be 0
|
21
21
|
|
22
|
+
@pull
|
22
23
|
Scenario: Pull an artifact
|
23
24
|
When I call the nexus "pull com.test:mytest:1.0.0:tgz" command
|
24
25
|
Then the output should contain:
|
@@ -161,4 +162,29 @@ Feature: Use the Nexus CLI
|
|
161
162
|
"""
|
162
163
|
<userId>cucumber</userId>
|
163
164
|
"""
|
165
|
+
And the exit status should be 0
|
166
|
+
|
167
|
+
Scenario: Get Logging Info
|
168
|
+
When I call the nexus "get_logging_info" command
|
169
|
+
Then the output should contain:
|
170
|
+
"""
|
171
|
+
\"rootLoggerLevel\":\"INFO\"
|
172
|
+
"""
|
173
|
+
And the exit status should be 0
|
174
|
+
|
175
|
+
Scenario: Change the logging level to DEBUG
|
176
|
+
When I call the nexus "set_logger_level debug" command
|
177
|
+
And I call the nexus "get_logging_info" command
|
178
|
+
Then the output should contain:
|
179
|
+
"""
|
180
|
+
\"rootLoggerLevel\":\"DEBUG\"
|
181
|
+
"""
|
182
|
+
And the exit status should be 0
|
183
|
+
|
184
|
+
Scenario: Change the logging level back to INFO
|
185
|
+
When I call the nexus "set_logger_level info" command
|
186
|
+
Then the output should contain:
|
187
|
+
"""
|
188
|
+
The logging level of Nexus has been set to INFO
|
189
|
+
"""
|
164
190
|
And the exit status should be 0
|
data/lib/nexus_cli.rb
CHANGED
@@ -9,6 +9,10 @@ require 'nexus_cli/configuration'
|
|
9
9
|
require 'nexus_cli/n3_metadata'
|
10
10
|
|
11
11
|
module NexusCli
|
12
|
+
|
13
|
+
DEFAULT_ACCEPT_HEADER = {"Accept" => "application/json"}
|
14
|
+
DEFAULT_CONTENT_TYPE_HEADER = {"Content-Type" => "application/json"}
|
15
|
+
|
12
16
|
class << self
|
13
17
|
def root
|
14
18
|
@root ||= Pathname.new(File.expand_path('../', File.dirname(__FILE__)))
|
data/lib/nexus_cli/errors.rb
CHANGED
@@ -172,7 +172,7 @@ The output from the server was:
|
|
172
172
|
end
|
173
173
|
status_code(118)
|
174
174
|
end
|
175
|
-
|
175
|
+
|
176
176
|
class UpdateUserException < NexusCliError
|
177
177
|
def initialize(body)
|
178
178
|
@server_response = JSON.pretty_generate(JSON.parse(body))
|
@@ -209,4 +209,18 @@ The output from the server was:
|
|
209
209
|
end
|
210
210
|
status_code(122)
|
211
211
|
end
|
212
|
+
|
213
|
+
class InvalidLoggingLevelException < NexusCliError
|
214
|
+
def message
|
215
|
+
"Logging level must be set to one of either INFO, DEBUG, or ERROR."
|
216
|
+
end
|
217
|
+
status_code(123)
|
218
|
+
end
|
219
|
+
|
220
|
+
class N3NotFoundException < NexusCliError
|
221
|
+
def message
|
222
|
+
"The artifact does not have any custom metadata added yet."
|
223
|
+
end
|
224
|
+
status_code(124)
|
225
|
+
end
|
212
226
|
end
|
@@ -1,87 +1,70 @@
|
|
1
1
|
require 'nokogiri'
|
2
|
+
require 'base64'
|
2
3
|
|
3
4
|
module NexusCli
|
4
5
|
module N3Metadata
|
5
6
|
class << self
|
6
|
-
|
7
|
-
|
8
|
-
end
|
9
|
-
|
7
|
+
# Checks if the custom metadata key is valid.
|
8
|
+
# Valid characters are alphanumeric with no special characeters.
|
10
9
|
def valid_n3_key?(element)
|
11
|
-
return !element.match(/^[a-zA-Z0-9]+$/).nil? ? true : false
|
10
|
+
return !element.nil? && !element.match(/^[a-zA-Z0-9]+$/).nil? ? true : false
|
12
11
|
end
|
13
12
|
|
13
|
+
# Checks if the custom metadata value is valid.
|
14
|
+
# Valid characters are anything but quotes.
|
14
15
|
def valid_n3_value?(element)
|
15
|
-
return !element.match(/^[^"'\\]*$/).nil? ? true : false
|
16
|
+
return !element.nil? && !element.match(/^[^"'\\]*$/).nil? ? true : false
|
16
17
|
end
|
17
18
|
|
19
|
+
# Check if the custom metadata search type is valid.
|
18
20
|
def valid_n3_search_type?(element)
|
19
|
-
return ["equal", "notequal", "matches", "bounded"].include?(element)
|
21
|
+
return !element.nil? && ["equal", "notequal", "matches", "bounded"].include?(element)
|
20
22
|
end
|
21
23
|
|
22
|
-
#
|
23
|
-
def
|
24
|
-
return "
|
24
|
+
# Creates a custom metadata subject for HTTP requests.
|
25
|
+
def create_base64_subject(group_id, artifact_id, version, extension)
|
26
|
+
return Base64.urlsafe_encode64("urn:maven/artifact##{group_id}:#{artifact_id}:#{version}::#{extension}")
|
25
27
|
end
|
26
28
|
|
27
|
-
#
|
28
|
-
|
29
|
-
|
30
|
-
|
31
|
-
|
32
|
-
tag, value = parse_n3_item(line)
|
33
|
-
# Delete the nexus key if the local key has no value.
|
34
|
-
if n3_user_urns.has_key?(tag) && value.empty?
|
35
|
-
n3_user_urns.delete(tag)
|
36
|
-
else
|
37
|
-
n3_user_urns[tag] = generate_n3_item(tag, value) unless tag.empty? || value.empty?
|
38
|
-
end
|
39
|
-
end
|
29
|
+
# Parses the regular custom metadata xml into a simpler format containing only the custom metadata.
|
30
|
+
def convert_result_to_simple_xml(custom_metadata)
|
31
|
+
request = []
|
32
|
+
Nokogiri::XML(custom_metadata).root.search("//customMetadataResponse/data/customMetadata[namespace=\"urn:nexus/user#\"]").each do |row|
|
33
|
+
request.push(create_tag(row.at("key").text.strip, row.at("value").text.strip))
|
40
34
|
end
|
41
|
-
return
|
35
|
+
return Nokogiri::XML("<artifact-resolution><data>#{request.join}</data></artifact-resolution>").root.to_xml(:indent => 4)
|
42
36
|
end
|
43
37
|
|
44
|
-
|
45
|
-
|
46
|
-
|
47
|
-
|
48
|
-
|
49
|
-
else
|
50
|
-
n3_user_urns[tag] = generate_n3_item(tag, value) unless tag.empty? || value.empty?
|
51
|
-
end
|
38
|
+
# Parses the regular custom metadata xml into a hash containing only the custom metadata.
|
39
|
+
def convert_result_to_hash(custom_metadata)
|
40
|
+
request = {}
|
41
|
+
Nokogiri::XML(custom_metadata).root.search("//customMetadataResponse/data/customMetadata[namespace=\"urn:nexus/user#\"]").each do |row|
|
42
|
+
request[row.at("key").text.strip] = row.at("value").text.strip
|
52
43
|
end
|
53
|
-
return
|
44
|
+
return request
|
54
45
|
end
|
55
46
|
|
56
|
-
#
|
57
|
-
|
58
|
-
|
47
|
+
# Create the request from the specified list of custom metadata key:value pairs
|
48
|
+
# @info If the target hash contains empty values for a key that exist in source, the metadata will be deleted
|
49
|
+
# @param [Hash] source The source hash of custom metadata key:value pairs
|
50
|
+
# @param [Hash] target The target hash to merge with the source hash (optional)
|
51
|
+
# @result [Hash] The resulting merge of the source and target hashes
|
52
|
+
def create_metadata_hash(source, target={})
|
53
|
+
request = []
|
54
|
+
source.merge(target).each do |key, value|
|
55
|
+
request.push({:namespace => "urn:nexus/user#", :key => key, :value => value, :readOnly => false}) unless value.empty?
|
56
|
+
end
|
57
|
+
return request
|
59
58
|
end
|
60
59
|
|
61
|
-
|
62
|
-
|
63
|
-
builder = Nokogiri::XML::Builder.new do |xml|
|
64
|
-
xml.send("artifact-resolution") {
|
65
|
-
xml.data {
|
66
|
-
n3.each_line do |line|
|
67
|
-
tag, value = parse_n3_item(line)
|
68
|
-
xml.send(tag, value) unless tag.empty? || value.empty?
|
69
|
-
end
|
70
|
-
}
|
71
|
-
}
|
72
|
-
end
|
73
|
-
return builder.doc.root.to_s
|
60
|
+
def missing_custom_metadata?(custom_metadata)
|
61
|
+
return !custom_metadata.match(/<data[ ]*\/>/).nil? ? true : false
|
74
62
|
end
|
75
63
|
|
76
64
|
private
|
77
|
-
def parse_n3_item(line)
|
78
|
-
tag = line.match(/#(\w*)>/) ? "#{$1}" : ""
|
79
|
-
value = line.match(/"([^"]*)"/) ? "#{$1}" : ""
|
80
|
-
return tag, value
|
81
|
-
end
|
82
65
|
|
83
|
-
def
|
84
|
-
return "
|
66
|
+
def create_tag(tag, value)
|
67
|
+
return "<#{tag}>#{value}</#{tag}>"
|
85
68
|
end
|
86
69
|
end
|
87
70
|
end
|
@@ -1,4 +1,4 @@
|
|
1
|
-
require '
|
1
|
+
require 'httpclient'
|
2
2
|
require 'nokogiri'
|
3
3
|
require 'yaml'
|
4
4
|
require 'json'
|
@@ -6,7 +6,6 @@ require 'jsonpath'
|
|
6
6
|
|
7
7
|
module NexusCli
|
8
8
|
class OSSRemote
|
9
|
-
|
10
9
|
def initialize(overrides)
|
11
10
|
@configuration = Configuration::parse(overrides)
|
12
11
|
end
|
@@ -16,85 +15,120 @@ module NexusCli
|
|
16
15
|
end
|
17
16
|
|
18
17
|
def nexus
|
19
|
-
|
18
|
+
client = HTTPClient.new
|
19
|
+
client.send_timeout = 600
|
20
|
+
client.receive_timeout = 600
|
21
|
+
# https://github.com/nahi/httpclient/issues/63
|
22
|
+
client.set_auth(nil, configuration['username'], configuration['password'])
|
23
|
+
client.www_auth.basic_auth.challenge(configuration['url'])
|
24
|
+
return client
|
25
|
+
end
|
26
|
+
|
27
|
+
def nexus_url(url)
|
28
|
+
File.join(configuration['url'], url)
|
20
29
|
end
|
21
30
|
|
22
31
|
def status
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
-
|
30
|
-
|
31
|
-
|
32
|
+
response = nexus.get(nexus_url("service/local/status"))
|
33
|
+
case response.status
|
34
|
+
when 200
|
35
|
+
doc = Nokogiri::XML(response.content).xpath("/status/data")
|
36
|
+
data = Hash.new
|
37
|
+
data['app_name'] = doc.xpath("appName")[0].text
|
38
|
+
data['version'] = doc.xpath("version")[0].text
|
39
|
+
data['edition_long'] = doc.xpath("editionLong")[0].text
|
40
|
+
data['state'] = doc.xpath("state")[0].text
|
41
|
+
data['started_at'] = doc.xpath("startedAt")[0].text
|
42
|
+
data['base_url'] = doc.xpath("baseUrl")[0].text
|
43
|
+
return data
|
44
|
+
when 401
|
45
|
+
raise PermissionsException
|
46
|
+
when 503
|
47
|
+
raise CouldNotConnectToNexusException
|
48
|
+
else
|
49
|
+
raise UnexpectedStatusCodeException.new(response.status)
|
50
|
+
end
|
51
|
+
end
|
52
|
+
|
53
|
+
def running_nexus_pro?
|
54
|
+
status['edition_long'] == "Professional"
|
32
55
|
end
|
33
56
|
|
34
57
|
def pull_artifact(artifact, destination)
|
35
|
-
# Using net/http because restclient dies on large files.
|
36
58
|
group_id, artifact_id, version, extension = parse_artifact_string(artifact)
|
37
|
-
uri = URI(File.join(configuration["url"], "service/local/artifact/maven/redirect"))
|
38
|
-
params = {:g => group_id, :a => artifact_id, :v => version, :e => extension, :r => configuration["repository"]}.collect {|k,v| "#{k}=#{URI::escape(v.to_s)}"}.join("&")
|
39
59
|
version = Nokogiri::XML(get_artifact_info(artifact)).xpath("//version").first.content() if version.casecmp("latest")
|
40
60
|
destination = File.join(File.expand_path(destination || "."), "#{artifact_id}-#{version}.#{extension}")
|
41
|
-
|
42
|
-
|
43
|
-
|
44
|
-
|
45
|
-
|
46
|
-
|
47
|
-
|
48
|
-
end
|
49
|
-
artifact_file = File.open(destination, "wb") do |io|
|
50
|
-
response.read_body do |chunk|
|
51
|
-
io.write(chunk)
|
52
|
-
end
|
61
|
+
response = nexus.get(nexus_url("service/local/artifact/maven/redirect"), :query => {:g => group_id, :a => artifact_id, :v => version, :e => extension, :r => configuration['repository']})
|
62
|
+
case response.status
|
63
|
+
when 301
|
64
|
+
# Follow redirect and stream in chunks.
|
65
|
+
artifact_file = File.open(destination, "wb") do |io|
|
66
|
+
nexus.get(response.content.gsub(/If you are not automatically redirected use this url: /, "")) do |chunk|
|
67
|
+
io.write(chunk)
|
53
68
|
end
|
54
69
|
end
|
70
|
+
when 404
|
71
|
+
raise ArtifactNotFoundException
|
72
|
+
else
|
73
|
+
raise UnexpectedStatusCodeException.new(response.status)
|
55
74
|
end
|
56
75
|
File.expand_path(destination)
|
57
76
|
end
|
58
77
|
|
59
78
|
def push_artifact(artifact, file)
|
60
79
|
group_id, artifact_id, version, extension = parse_artifact_string(artifact)
|
61
|
-
nexus
|
62
|
-
|
63
|
-
|
64
|
-
|
65
|
-
|
66
|
-
|
67
|
-
|
68
|
-
|
69
|
-
|
70
|
-
|
71
|
-
|
72
|
-
|
80
|
+
response = nexus.post(nexus_url("service/local/artifact/maven/content"), {:hasPom => false, :g => group_id, :a => artifact_id, :v => version, :e => extension, :p => extension, :r => configuration['repository'], :file => File.open(file)})
|
81
|
+
case response.status
|
82
|
+
when 201
|
83
|
+
return true
|
84
|
+
when 400
|
85
|
+
raise BadUploadRequestException
|
86
|
+
when 401
|
87
|
+
raise PermissionsException
|
88
|
+
when 403
|
89
|
+
raise PermissionsException
|
90
|
+
when 404
|
91
|
+
raise CouldNotConnectToNexusException
|
92
|
+
else
|
93
|
+
raise UnexpectedStatusCodeException.new(response.status)
|
73
94
|
end
|
74
95
|
end
|
75
96
|
|
76
97
|
def delete_artifact(artifact)
|
77
98
|
group_id, artifact_id, version = parse_artifact_string(artifact)
|
78
|
-
|
79
|
-
|
99
|
+
response = nexus.delete(nexus_url("content/repositories/#{configuration['repository']}/#{group_id.gsub(".", "/")}/#{artifact_id.gsub(".", "/")}/#{version}"))
|
100
|
+
case response.status
|
101
|
+
when 204
|
102
|
+
return true
|
103
|
+
else
|
104
|
+
raise UnexpectedStatusCodeException.new(response.status)
|
105
|
+
end
|
80
106
|
end
|
81
107
|
|
82
108
|
def get_artifact_info(artifact)
|
83
109
|
group_id, artifact_id, version, extension = parse_artifact_string(artifact)
|
84
|
-
|
85
|
-
|
86
|
-
|
87
|
-
|
88
|
-
|
110
|
+
response = nexus.get(nexus_url("service/local/artifact/maven/resolve"), :query => {:g => group_id, :a => artifact_id, :v => version, :e => extension, :r => configuration['repository']})
|
111
|
+
case response.status
|
112
|
+
when 200
|
113
|
+
return response.content
|
114
|
+
when 404
|
89
115
|
raise ArtifactNotFoundException
|
116
|
+
when 503
|
117
|
+
raise CouldNotConnectToNexusException
|
118
|
+
else
|
119
|
+
raise UnexpectedStatusCodeException.new(response.status)
|
90
120
|
end
|
91
121
|
end
|
92
122
|
|
93
123
|
def search_for_artifacts(artifact)
|
94
124
|
group_id, artifact_id = artifact.split(":")
|
95
|
-
nexus
|
96
|
-
|
125
|
+
response = nexus.get(nexus_url("service/local/data_index"), :query => {:g => group_id, :a => artifact_id})
|
126
|
+
case response.status
|
127
|
+
when 200
|
128
|
+
doc = Nokogiri::XML(response.content)
|
97
129
|
return format_search_results(doc, group_id, artifact_id)
|
130
|
+
else
|
131
|
+
raise UnexpectedStatusCodeException.new(response.status)
|
98
132
|
end
|
99
133
|
end
|
100
134
|
|
@@ -108,6 +142,16 @@ module NexusCli
|
|
108
142
|
end
|
109
143
|
end
|
110
144
|
|
145
|
+
def get_global_settings_json
|
146
|
+
response = nexus.get(nexus_url("service/local/global_settings/current"), :header => DEFAULT_ACCEPT_HEADER)
|
147
|
+
case response.status
|
148
|
+
when 200
|
149
|
+
return response.content
|
150
|
+
else
|
151
|
+
raise UnexpectedStatusCodeException.new(response.status)
|
152
|
+
end
|
153
|
+
end
|
154
|
+
|
111
155
|
def upload_global_settings(json=nil)
|
112
156
|
global_settings = nil
|
113
157
|
if json == nil
|
@@ -115,78 +159,95 @@ module NexusCli
|
|
115
159
|
else
|
116
160
|
global_settings = json
|
117
161
|
end
|
118
|
-
nexus
|
119
|
-
|
120
|
-
|
121
|
-
|
122
|
-
|
162
|
+
response = nexus.put(nexus_url("service/local/global_settings/current"), :body => global_settings, :header => DEFAULT_CONTENT_TYPE_HEADER)
|
163
|
+
case response.status
|
164
|
+
when 204
|
165
|
+
return true
|
166
|
+
when 400
|
167
|
+
raise BadSettingsException.new(response.content)
|
123
168
|
end
|
124
169
|
end
|
125
170
|
|
126
|
-
def get_global_settings_json
|
127
|
-
nexus['service/local/global_settings/current'].get(:accept => "application/json")
|
128
|
-
end
|
129
|
-
|
130
171
|
def reset_global_settings
|
131
|
-
|
132
|
-
|
172
|
+
response = nexus.get(nexus_url("service/local/global_settings/default"), :header => DEFAULT_ACCEPT_HEADER)
|
173
|
+
case response.status
|
174
|
+
when 200
|
175
|
+
default_json = response.content
|
176
|
+
else
|
177
|
+
raise UnexpectedStatusCodeException.new(response.status)
|
178
|
+
end
|
179
|
+
|
180
|
+
response = nexus.put(nexus_url("service/local/global_settings/current"), :body => default_json, :header => DEFAULT_CONTENT_TYPE_HEADER)
|
181
|
+
case response.status
|
182
|
+
when 204
|
183
|
+
return true
|
184
|
+
else
|
185
|
+
raise UnexpectedStatusCodeException.new(response.status)
|
186
|
+
end
|
133
187
|
end
|
134
188
|
|
135
189
|
def create_repository(name, proxy, url)
|
136
190
|
json = if proxy
|
137
|
-
|
138
|
-
|
139
|
-
|
140
|
-
|
141
|
-
nexus
|
142
|
-
|
143
|
-
|
144
|
-
|
145
|
-
|
146
|
-
|
147
|
-
|
148
|
-
|
149
|
-
end
|
191
|
+
create_proxy_repository_json(name, url)
|
192
|
+
else
|
193
|
+
create_hosted_repository_json(name)
|
194
|
+
end
|
195
|
+
response = nexus.post(nexus_url("service/local/repositories"), :body => json, :header => DEFAULT_CONTENT_TYPE_HEADER)
|
196
|
+
case response.status
|
197
|
+
when 201
|
198
|
+
return true
|
199
|
+
when 400
|
200
|
+
raise CreateRepsitoryException.new(response.content)
|
201
|
+
else
|
202
|
+
raise UnexpectedStatusCodeException.new(response.status)
|
150
203
|
end
|
151
204
|
end
|
152
205
|
|
153
206
|
def delete_repository(name)
|
154
|
-
nexus
|
155
|
-
|
156
|
-
|
157
|
-
|
158
|
-
|
159
|
-
|
160
|
-
|
161
|
-
|
162
|
-
end
|
207
|
+
response = nexus.delete(nexus_url("service/local/repositories/#{name.downcase}"))
|
208
|
+
case response.status
|
209
|
+
when 204
|
210
|
+
return true
|
211
|
+
when 404
|
212
|
+
raise RepositoryDoesNotExistException
|
213
|
+
else
|
214
|
+
raise UnexpectedStatusCodeException.new(response.status)
|
163
215
|
end
|
164
216
|
end
|
165
217
|
|
166
218
|
def get_repository_info(name)
|
167
|
-
|
168
|
-
|
169
|
-
|
170
|
-
|
171
|
-
|
219
|
+
response = nexus.get(nexus_url("service/local/repositories/#{name.gsub(" ", "_").downcase}"))
|
220
|
+
case response.status
|
221
|
+
when 200
|
222
|
+
return response.content
|
223
|
+
when 404
|
172
224
|
raise RepositoryNotFoundException
|
225
|
+
when 503
|
226
|
+
raise CouldNotConnectToNexusException
|
227
|
+
else
|
228
|
+
raise UnexpectedStatusCodeException.new(response.status)
|
173
229
|
end
|
174
230
|
end
|
175
231
|
|
176
232
|
def get_users
|
177
|
-
nexus
|
233
|
+
response = nexus.get(nexus_url("service/local/users"))
|
234
|
+
case response.status
|
235
|
+
when 200
|
236
|
+
return response.content
|
237
|
+
else
|
238
|
+
raise UnexpectedStatusCodeException.new(response.status)
|
239
|
+
end
|
178
240
|
end
|
179
241
|
|
180
242
|
def create_user(params)
|
181
|
-
nexus
|
182
|
-
|
183
|
-
|
184
|
-
|
185
|
-
|
186
|
-
|
187
|
-
|
188
|
-
|
189
|
-
end
|
243
|
+
response = nexus.post(nexus_url("service/local/users"), :body => create_user_json(params), :header => DEFAULT_CONTENT_TYPE_HEADER)
|
244
|
+
case response.status
|
245
|
+
when 201
|
246
|
+
return true
|
247
|
+
when 400
|
248
|
+
raise CreateUserException.new(response.content)
|
249
|
+
else
|
250
|
+
raise UnexpectedStatusCodeException.new(reponse.code)
|
190
251
|
end
|
191
252
|
end
|
192
253
|
|
@@ -198,116 +259,136 @@ module NexusCli
|
|
198
259
|
params.each do |key, value|
|
199
260
|
modified_json.gsub!("$..#{key}"){|v| value} unless key == "userId" || value.blank?
|
200
261
|
end
|
201
|
-
|
202
|
-
nexus
|
203
|
-
|
204
|
-
|
205
|
-
|
206
|
-
|
207
|
-
|
208
|
-
|
209
|
-
|
210
|
-
end
|
262
|
+
|
263
|
+
response = nexus.put(nexus_url("service/local/users/#{params[:userId]}"), :body => JSON.dump(modified_json.to_hash), :header => DEFAULT_CONTENT_TYPE_HEADER)
|
264
|
+
case response.status
|
265
|
+
when 200
|
266
|
+
return true
|
267
|
+
when 400
|
268
|
+
raise UpdateUserException.new(response.content)
|
269
|
+
else
|
270
|
+
raise UnexpectedStatusCodeException.new(response.status)
|
211
271
|
end
|
212
272
|
end
|
213
273
|
|
214
274
|
def get_user(user)
|
215
|
-
nexus
|
216
|
-
|
217
|
-
|
218
|
-
|
219
|
-
|
220
|
-
|
221
|
-
|
222
|
-
|
223
|
-
end
|
275
|
+
response = nexus.get(nexus_url("service/local/users/#{user}"), :header => DEFAULT_ACCEPT_HEADER)
|
276
|
+
case response.status
|
277
|
+
when 200
|
278
|
+
return JSON.parse(response.content)
|
279
|
+
when 404
|
280
|
+
raise UserNotFoundException.new(user)
|
281
|
+
else
|
282
|
+
raise UnexpectedStatusCodeException.new(response.status)
|
224
283
|
end
|
225
284
|
end
|
226
285
|
|
227
286
|
def change_password(params)
|
228
|
-
nexus
|
229
|
-
|
230
|
-
|
231
|
-
|
232
|
-
|
233
|
-
|
234
|
-
|
287
|
+
response = nexus.post(nexus_url("service/local/users_changepw"), :body => create_change_password_json(params), :header => DEFAULT_CONTENT_TYPE_HEADER)
|
288
|
+
case response.status
|
289
|
+
when 202
|
290
|
+
return true
|
291
|
+
when 400
|
292
|
+
raise InvalidCredentialsException
|
293
|
+
else
|
294
|
+
raise UnexpectedStatusCodeException.new(response.status)
|
235
295
|
end
|
236
296
|
end
|
237
297
|
|
238
298
|
def delete_user(user_id)
|
239
|
-
nexus
|
240
|
-
|
241
|
-
|
242
|
-
|
243
|
-
|
244
|
-
|
245
|
-
|
246
|
-
|
247
|
-
end
|
299
|
+
response = nexus.delete(nexus_url("service/local/users/#{user_id}"))
|
300
|
+
case response.status
|
301
|
+
when 204
|
302
|
+
return true
|
303
|
+
when 404
|
304
|
+
raise UserNotFoundException.new(user_id)
|
305
|
+
else
|
306
|
+
raise UnexpectedStatusCodeException.new(response.status)
|
248
307
|
end
|
249
308
|
end
|
250
309
|
|
251
|
-
def
|
252
|
-
|
310
|
+
def get_logging_info
|
311
|
+
response = nexus.get(nexus_url("service/local/log/config"), :header => DEFAULT_ACCEPT_HEADER)
|
312
|
+
case response.status
|
313
|
+
when 200
|
314
|
+
return response.content
|
315
|
+
else
|
316
|
+
raise UnexpectedStatusCodeException.new(response.status)
|
317
|
+
end
|
318
|
+
end
|
319
|
+
|
320
|
+
def set_logger_level(level)
|
321
|
+
raise InvalidLoggingLevelException unless ["INFO", "DEBUG", "ERROR"].include?(level.upcase)
|
322
|
+
response = nexus.put(nexus_url("service/local/log/config"), :body => create_logger_level_json(level), :header => DEFAULT_CONTENT_TYPE_HEADER)
|
323
|
+
case response.status
|
324
|
+
when 200
|
325
|
+
return true
|
326
|
+
else
|
327
|
+
raise UnexpectedStatusCodeException.new(response.status)
|
328
|
+
end
|
253
329
|
end
|
254
330
|
|
255
331
|
private
|
256
332
|
|
257
|
-
|
258
|
-
|
259
|
-
|
260
|
-
|
261
|
-
|
262
|
-
|
263
|
-
|
264
|
-
end
|
333
|
+
def format_search_results(doc, group_id, artifact_id)
|
334
|
+
versions = doc.xpath("//version").inject([]) {|array,node| array << "#{node.content()}"}
|
335
|
+
indent_size = versions.max{|a,b| a.length <=> b.length}.size+4
|
336
|
+
formated_results = ['Found Versions:']
|
337
|
+
versions.inject(formated_results) do |array,version|
|
338
|
+
temp_version = version + ":"
|
339
|
+
array << "#{temp_version.ljust(indent_size)} `nexus-cli pull #{group_id}:#{artifact_id}:#{version}:tgz`"
|
265
340
|
end
|
341
|
+
end
|
266
342
|
|
267
|
-
|
268
|
-
|
269
|
-
|
270
|
-
|
271
|
-
end
|
272
|
-
group_id, artifact_id, version, extension = split_artifact
|
273
|
-
version.upcase! if version.casecmp("latest")
|
274
|
-
return group_id, artifact_id, version, extension
|
343
|
+
def parse_artifact_string(artifact)
|
344
|
+
split_artifact = artifact.split(":")
|
345
|
+
if(split_artifact.size < 4)
|
346
|
+
raise ArtifactMalformedException
|
275
347
|
end
|
348
|
+
group_id, artifact_id, version, extension = split_artifact
|
349
|
+
version.upcase! if version.casecmp("latest")
|
350
|
+
return group_id, artifact_id, version, extension
|
351
|
+
end
|
276
352
|
|
277
|
-
|
278
|
-
|
279
|
-
|
280
|
-
|
281
|
-
|
282
|
-
|
283
|
-
|
284
|
-
|
285
|
-
|
286
|
-
|
287
|
-
|
353
|
+
def create_hosted_repository_json(name)
|
354
|
+
params = {:provider => "maven2"}
|
355
|
+
params[:providerRole] = "org.sonatype.nexus.proxy.repository.Repository"
|
356
|
+
params[:exposed] = true
|
357
|
+
params[:repoType] = "hosted"
|
358
|
+
params[:repoPolicy] = "RELEASE"
|
359
|
+
params[:name] = name
|
360
|
+
params[:id] = name.gsub(" ", "_").downcase
|
361
|
+
params[:format] = "maven2"
|
362
|
+
JSON.dump(:data => params)
|
363
|
+
end
|
288
364
|
|
289
|
-
|
290
|
-
|
291
|
-
|
292
|
-
|
293
|
-
|
294
|
-
|
295
|
-
|
296
|
-
|
297
|
-
|
298
|
-
|
299
|
-
|
300
|
-
|
301
|
-
|
302
|
-
|
303
|
-
|
365
|
+
def create_proxy_repository_json(name, url)
|
366
|
+
params = {:provider => "maven2"}
|
367
|
+
params[:providerRole] = "org.sonatype.nexus.proxy.repository.Repository"
|
368
|
+
params[:exposed] = true
|
369
|
+
params[:repoType] = "proxy"
|
370
|
+
params[:repoPolicy] = "RELEASE"
|
371
|
+
params[:checksumPolicy] = "WARN"
|
372
|
+
params[:writePolicy] = "READ_ONLY"
|
373
|
+
params[:downloadRemoteIndexes] = true
|
374
|
+
params[:autoBlockActive] = true
|
375
|
+
params[:name] = name
|
376
|
+
params[:id] = name.gsub(" ", "_").downcase
|
377
|
+
params[:remoteStorage] = {:remoteStorageUrl => url.nil? ? "http://change-me.com/" : url}
|
378
|
+
JSON.dump(:data => params)
|
379
|
+
end
|
304
380
|
|
305
|
-
|
306
|
-
|
307
|
-
|
381
|
+
def create_user_json(params)
|
382
|
+
JSON.dump(:data => params)
|
383
|
+
end
|
308
384
|
|
309
|
-
|
310
|
-
|
311
|
-
|
385
|
+
def create_change_password_json(params)
|
386
|
+
JSON.dump(:data => params)
|
387
|
+
end
|
388
|
+
|
389
|
+
def create_logger_level_json(level)
|
390
|
+
params = {:rootLoggerLevel => level.upcase}
|
391
|
+
JSON.dump(:data => params)
|
392
|
+
end
|
312
393
|
end
|
313
394
|
end
|