nexus_cli 1.0.2 → 2.0.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.
Files changed (35) hide show
  1. data/.gitignore +4 -1
  2. data/.travis.yml +5 -0
  3. data/Gemfile +40 -0
  4. data/Guardfile +27 -0
  5. data/README.md +20 -23
  6. data/Thorfile +66 -0
  7. data/VERSION +1 -1
  8. data/{pro → features/pro}/nexus_custom_metadata.feature +0 -0
  9. data/{pro → features/pro}/nexus_pro.feature +0 -0
  10. data/features/support/env.rb +41 -32
  11. data/lib/nexus_cli.rb +26 -10
  12. data/lib/nexus_cli/base_remote.rb +32 -0
  13. data/lib/nexus_cli/configuration.rb +24 -5
  14. data/lib/nexus_cli/connection.rb +81 -0
  15. data/lib/nexus_cli/mixins/artifact_actions.rb +186 -0
  16. data/lib/nexus_cli/mixins/global_settings_actions.rb +64 -0
  17. data/lib/nexus_cli/mixins/logging_actions.rb +45 -0
  18. data/lib/nexus_cli/{nexus_pro_remote.rb → mixins/pro/custom_metadata_actions.rb} +5 -199
  19. data/lib/nexus_cli/mixins/pro/smart_proxy_actions.rb +214 -0
  20. data/lib/nexus_cli/mixins/repository_actions.rb +245 -0
  21. data/lib/nexus_cli/mixins/user_actions.rb +125 -0
  22. data/lib/nexus_cli/remote/oss_remote.rb +11 -0
  23. data/lib/nexus_cli/remote/pro_remote.rb +59 -0
  24. data/lib/nexus_cli/remote_factory.rb +24 -0
  25. data/lib/nexus_cli/tasks.rb +3 -3
  26. data/spec/fixtures/nexus.config +4 -0
  27. data/spec/spec_helper.rb +14 -2
  28. data/spec/{configuration_spec.rb → unit/nexus_cli/configuration_spec.rb} +0 -0
  29. data/spec/{oss_remote_spec.rb → unit/nexus_cli/oss_remote_spec.rb} +15 -5
  30. data/spec/{pro_remote_spec.rb → unit/nexus_cli/pro_remote_spec.rb} +6 -1
  31. metadata +32 -17
  32. data/Gemfile.lock +0 -65
  33. data/lib/nexus_cli/kernel.rb +0 -33
  34. data/lib/nexus_cli/nexus_oss_remote.rb +0 -636
  35. data/lib/nexus_cli/nexus_remote_factory.rb +0 -65
@@ -1,33 +0,0 @@
1
- # From ActiveSupport: https://github.com/rails/rails/blob/c2c8ef57d6f00d1c22743dc43746f95704d67a95/activesupport/lib/active_support/core_ext/kernel/reporting.rb#L39
2
-
3
- require 'rbconfig'
4
-
5
- module Kernel
6
- # Silences any stream for the duration of the block.
7
- #
8
- # silence_stream(STDOUT) do
9
- # puts 'This will never be seen'
10
- # end
11
- #
12
- # puts 'But this will'
13
- def silence_stream(stream)
14
- old_stream = stream.dup
15
- stream.reopen(RbConfig::CONFIG['host_os'] =~ /mswin|mingw/ ? 'NUL:' : '/dev/null')
16
- stream.sync = true
17
- yield
18
- ensure
19
- stream.reopen(old_stream)
20
- end
21
-
22
- # Silences both STDOUT and STDERR, even for subprocesses.
23
- #
24
- # quietly { system 'bundle install' }
25
- #
26
- def quietly
27
- silence_stream(STDOUT) do
28
- silence_stream(STDERR) do
29
- yield
30
- end
31
- end
32
- end
33
- end
@@ -1,636 +0,0 @@
1
- require 'erb'
2
- require 'httpclient'
3
- require 'json'
4
- require 'jsonpath'
5
- require 'nokogiri'
6
- require 'tempfile'
7
- require 'yaml'
8
-
9
- module NexusCli
10
- # @author Kyle Allan <kallan@riotgames.com>
11
- class OSSRemote
12
- # @param [Hash] overrides
13
- # @param [Boolean] ssl_verify
14
- def initialize(overrides, ssl_verify=true)
15
- @configuration = Configuration::parse(overrides)
16
- @ssl_verify = ssl_verify
17
- end
18
-
19
- def configuration
20
- return @configuration if @configuration
21
- end
22
-
23
- # Returns an HTTPClient instance with settings to connect
24
- # to a Nexus server.
25
- #
26
- # @return [HTTPClient]
27
- def nexus
28
- client = HTTPClient.new
29
- client.send_timeout = 6000
30
- client.receive_timeout = 6000
31
- # https://github.com/nahi/httpclient/issues/63
32
- client.set_auth(nil, configuration['username'], configuration['password'])
33
- client.www_auth.basic_auth.challenge(configuration['url'])
34
- client.ssl_config.verify_mode = OpenSSL::SSL::VERIFY_NONE unless @ssl_verify
35
- return client
36
- end
37
-
38
- # Joins a given url to the current url stored in the configuraiton
39
- # and returns the combined String.
40
- #
41
- # @param [String] url
42
- #
43
- # @return [String]
44
- def nexus_url(url)
45
- File.join(configuration['url'], url)
46
- end
47
-
48
- # Gets that current status of the Nexus server. On a non-error
49
- # status code, returns a Hash of values from the server.
50
- #
51
- # @return [Hash]
52
- def status
53
- response = nexus.get(nexus_url("service/local/status"))
54
- case response.status
55
- when 200
56
- doc = Nokogiri::XML(response.content).xpath("/status/data")
57
- data = Hash.new
58
- data['app_name'] = doc.xpath("appName")[0].text
59
- data['version'] = doc.xpath("version")[0].text
60
- data['edition_long'] = doc.xpath("editionLong")[0].text
61
- data['state'] = doc.xpath("state")[0].text
62
- data['started_at'] = doc.xpath("startedAt")[0].text
63
- data['base_url'] = doc.xpath("baseUrl")[0].text
64
- return data
65
- when 401
66
- raise PermissionsException
67
- when 503
68
- raise CouldNotConnectToNexusException
69
- else
70
- raise UnexpectedStatusCodeException.new(response.status)
71
- end
72
- end
73
-
74
- # Determines whether or not the Nexus server being
75
- # connected to is running Nexus Pro.
76
- def running_nexus_pro?
77
- status['edition_long'] == "Professional"
78
- end
79
-
80
- # Retrieves a file from the Nexus server using the given [String] artifact
81
- # identifier. Optionally provide a destination [String].
82
- #
83
- # @param [String] artifact
84
- # @param [String] destination
85
- #
86
- # @return [File]
87
- def pull_artifact(artifact, destination=nil)
88
- group_id, artifact_id, version, extension = parse_artifact_string(artifact)
89
- version = Nokogiri::XML(get_artifact_info(artifact)).xpath("//version").first.content() if version.casecmp("latest")
90
- destination = File.join(File.expand_path(destination || "."), "#{artifact_id}-#{version}.#{extension}")
91
- response = nexus.get(nexus_url("service/local/artifact/maven/redirect"), :query => {:g => group_id, :a => artifact_id, :v => version, :e => extension, :r => configuration['repository']})
92
- case response.status
93
- when 301, 307
94
- # Follow redirect and stream in chunks.
95
- artifact_file = File.open(destination, "wb") do |io|
96
- nexus.get(response.content.gsub(/If you are not automatically redirected use this url: /, "")) do |chunk|
97
- io.write(chunk)
98
- end
99
- end
100
- when 404
101
- raise ArtifactNotFoundException
102
- else
103
- raise UnexpectedStatusCodeException.new(response.status)
104
- end
105
- File.expand_path(destination)
106
- end
107
-
108
-
109
- # Pushes the given [file] to the Nexus server
110
- # under the given [artifact] identifier.
111
- #
112
- # @param artifact [String] the Maven identifier
113
- # @param file [type] the path to the file
114
- #
115
- # @return [Boolean] returns true when successful
116
- def push_artifact(artifact, file)
117
- group_id, artifact_id, version, extension = parse_artifact_string(artifact)
118
- file_name = "#{artifact_id}-#{version}.#{extension}"
119
- put_string = "content/repositories/#{configuration['repository']}/#{group_id.gsub(".", "/")}/#{artifact_id.gsub(".", "/")}/#{version}/#{file_name}"
120
- response = nexus.put(nexus_url(put_string), File.open(file))
121
-
122
- case response.status
123
- when 201
124
- pom_name = "#{artifact_id}-#{version}.pom"
125
- put_string = "content/repositories/#{configuration['repository']}/#{group_id.gsub(".", "/")}/#{artifact_id.gsub(".", "/")}/#{version}/#{pom_name}"
126
- pom_file = generate_fake_pom(pom_name, group_id, artifact_id, version, extension)
127
- nexus.put(nexus_url(put_string), File.open(pom_file))
128
- delete_string = "/service/local/metadata/repositories/#{configuration['repository']}/content/#{group_id.gsub(".", "/")}/#{artifact_id.gsub(".", "/")}"
129
- nexus.delete(nexus_url(delete_string))
130
- return true
131
- when 400
132
- raise BadUploadRequestException
133
- when 401
134
- raise PermissionsException
135
- when 403
136
- raise PermissionsException
137
- when 404
138
- raise NexusHTTP404.new(response.content)
139
- else
140
- raise UnexpectedStatusCodeException.new(response.status)
141
- end
142
- end
143
-
144
- def delete_artifact(artifact)
145
- group_id, artifact_id, version = parse_artifact_string(artifact)
146
- response = nexus.delete(nexus_url("content/repositories/#{configuration['repository']}/#{group_id.gsub(".", "/")}/#{artifact_id.gsub(".", "/")}/#{version}"))
147
- case response.status
148
- when 204
149
- return true
150
- else
151
- raise UnexpectedStatusCodeException.new(response.status)
152
- end
153
- end
154
-
155
- def get_artifact_info(artifact)
156
- group_id, artifact_id, version, extension = parse_artifact_string(artifact)
157
- response = nexus.get(nexus_url("service/local/artifact/maven/resolve"), :query => {:g => group_id, :a => artifact_id, :v => version, :e => extension, :r => configuration['repository']})
158
- case response.status
159
- when 200
160
- return response.content
161
- when 404
162
- raise ArtifactNotFoundException
163
- when 503
164
- raise CouldNotConnectToNexusException
165
- else
166
- raise UnexpectedStatusCodeException.new(response.status)
167
- end
168
- end
169
-
170
-
171
- # Searches for an artifact using the given identifier.
172
- #
173
- # @param artifact [String] the Maven identifier
174
- # @example com.artifact:my-artifact
175
- #
176
- # @return [Array<String>] a formatted Array of results
177
- # @example
178
- # 1.0.0 `nexus-cli pull com.artifact:my-artifact:1.0.0:tgz`
179
- # 2.0.0 `nexus-cli pull com.artifact:my-artifact:2.0.0:tgz`
180
- # 3.0.0 `nexus-cli pull com.artifact:my-artifact:3.0.0:tgz`
181
- def search_for_artifacts(artifact)
182
- group_id, artifact_id = artifact.split(":")
183
- response = nexus.get(nexus_url("service/local/data_index"), :query => {:g => group_id, :a => artifact_id})
184
- case response.status
185
- when 200
186
- doc = Nokogiri::XML(response.content)
187
- return format_search_results(doc, group_id, artifact_id)
188
- else
189
- raise UnexpectedStatusCodeException.new(response.status)
190
- end
191
- end
192
-
193
-
194
- # Retrieves the global settings of the Nexus server
195
- #
196
- # @return [File] a File with the global settings.
197
- def get_global_settings
198
- json = get_global_settings_json
199
- pretty_json = JSON.pretty_generate(JSON.parse(json))
200
- Dir.mkdir(File.expand_path("~/.nexus")) unless Dir.exists?(File.expand_path("~/.nexus"))
201
- destination = File.join(File.expand_path("~/.nexus"), "global_settings.json")
202
- artifact_file = File.open(destination, 'wb') do |file|
203
- file.write(pretty_json)
204
- end
205
- end
206
-
207
- def get_global_settings_json
208
- response = nexus.get(nexus_url("service/local/global_settings/current"), :header => DEFAULT_ACCEPT_HEADER)
209
- case response.status
210
- when 200
211
- return response.content
212
- else
213
- raise UnexpectedStatusCodeException.new(response.status)
214
- end
215
- end
216
-
217
- def upload_global_settings(json=nil)
218
- global_settings = nil
219
- if json == nil
220
- global_settings = File.read(File.join(File.expand_path("~/.nexus"), "global_settings.json"))
221
- else
222
- global_settings = json
223
- end
224
- response = nexus.put(nexus_url("service/local/global_settings/current"), :body => global_settings, :header => DEFAULT_CONTENT_TYPE_HEADER)
225
- case response.status
226
- when 204
227
- return true
228
- when 400
229
- raise BadSettingsException.new(response.content)
230
- end
231
- end
232
-
233
- def reset_global_settings
234
- response = nexus.get(nexus_url("service/local/global_settings/default"), :header => DEFAULT_ACCEPT_HEADER)
235
- case response.status
236
- when 200
237
- default_json = response.content
238
- else
239
- raise UnexpectedStatusCodeException.new(response.status)
240
- end
241
-
242
- response = nexus.put(nexus_url("service/local/global_settings/current"), :body => default_json, :header => DEFAULT_CONTENT_TYPE_HEADER)
243
- case response.status
244
- when 204
245
- return true
246
- else
247
- raise UnexpectedStatusCodeException.new(response.status)
248
- end
249
- end
250
-
251
-
252
- # Creates a repository that the Nexus uses to hold artifacts.
253
- #
254
- # @param name [String] the name of the repository to create
255
- # @param proxy [Boolean] true if this is a proxy repository
256
- # @param url [String] the url for the proxy repository to point to
257
- # @param id [String] the id of repository
258
- # @param policy [String] repository policy (RELEASE|SNAPSHOT)
259
- # @param provider [String] repo provider (maven2 by default)
260
- #
261
- # @return [Boolean] returns true on success
262
- def create_repository(name, proxy, url, id, policy, provider)
263
- json = if proxy
264
- create_proxy_repository_json(name, url, id, policy, provider)
265
- else
266
- create_hosted_repository_json(name, id, policy, provider)
267
- end
268
- response = nexus.post(nexus_url("service/local/repositories"), :body => json, :header => DEFAULT_CONTENT_TYPE_HEADER)
269
- case response.status
270
- when 201
271
- return true
272
- when 400
273
- raise CreateRepsitoryException.new(response.content)
274
- else
275
- raise UnexpectedStatusCodeException.new(response.status)
276
- end
277
- end
278
-
279
- def delete_repository(name)
280
- response = nexus.delete(nexus_url("service/local/repositories/#{sanitize_for_id(name)}"))
281
- case response.status
282
- when 204
283
- return true
284
- when 404
285
- raise RepositoryDoesNotExistException
286
- else
287
- raise UnexpectedStatusCodeException.new(response.status)
288
- end
289
- end
290
-
291
- def get_repository_info(name)
292
- response = nexus.get(nexus_url("service/local/repositories/#{sanitize_for_id(name)}"))
293
- case response.status
294
- when 200
295
- return response.content
296
- when 404
297
- raise RepositoryNotFoundException
298
- when 503
299
- raise CouldNotConnectToNexusException
300
- else
301
- raise UnexpectedStatusCodeException.new(response.status)
302
- end
303
- end
304
-
305
- def get_users
306
- response = nexus.get(nexus_url("service/local/users"))
307
- case response.status
308
- when 200
309
- return response.content
310
- else
311
- raise UnexpectedStatusCodeException.new(response.status)
312
- end
313
- end
314
-
315
- def create_user(params)
316
- response = nexus.post(nexus_url("service/local/users"), :body => create_user_json(params), :header => DEFAULT_CONTENT_TYPE_HEADER)
317
- case response.status
318
- when 201
319
- return true
320
- when 400
321
- raise CreateUserException.new(response.content)
322
- else
323
- raise UnexpectedStatusCodeException.new(reponse.code)
324
- end
325
- end
326
-
327
- def update_user(params)
328
- params[:roles] = [] if params[:roles] == [""]
329
- user_json = get_user(params[:userId])
330
-
331
- modified_json = JsonPath.for(user_json)
332
- params.each do |key, value|
333
- modified_json.gsub!("$..#{key}"){|v| value} unless key == "userId" || value.blank?
334
- end
335
-
336
- response = nexus.put(nexus_url("service/local/users/#{params[:userId]}"), :body => JSON.dump(modified_json.to_hash), :header => DEFAULT_CONTENT_TYPE_HEADER)
337
- case response.status
338
- when 200
339
- return true
340
- when 400
341
- raise UpdateUserException.new(response.content)
342
- else
343
- raise UnexpectedStatusCodeException.new(response.status)
344
- end
345
- end
346
-
347
- def get_user(user)
348
- response = nexus.get(nexus_url("service/local/users/#{user}"), :header => DEFAULT_ACCEPT_HEADER)
349
- case response.status
350
- when 200
351
- return JSON.parse(response.content)
352
- when 404
353
- raise UserNotFoundException.new(user)
354
- else
355
- raise UnexpectedStatusCodeException.new(response.status)
356
- end
357
- end
358
-
359
-
360
- # Changes the password of a user
361
- #
362
- # @param params [Hash] a hash given to update the users password
363
- #
364
- # @return [type] [description]
365
- def change_password(params)
366
- response = nexus.post(nexus_url("service/local/users_changepw"), :body => create_change_password_json(params), :header => DEFAULT_CONTENT_TYPE_HEADER)
367
- case response.status
368
- when 202
369
- return true
370
- when 400
371
- raise InvalidCredentialsException
372
- else
373
- raise UnexpectedStatusCodeException.new(response.status)
374
- end
375
- end
376
-
377
- def delete_user(user_id)
378
- response = nexus.delete(nexus_url("service/local/users/#{user_id}"))
379
- case response.status
380
- when 204
381
- return true
382
- when 404
383
- raise UserNotFoundException.new(user_id)
384
- else
385
- raise UnexpectedStatusCodeException.new(response.status)
386
- end
387
- end
388
-
389
- def get_logging_info
390
- response = nexus.get(nexus_url("service/local/log/config"), :header => DEFAULT_ACCEPT_HEADER)
391
- case response.status
392
- when 200
393
- return response.content
394
- else
395
- raise UnexpectedStatusCodeException.new(response.status)
396
- end
397
- end
398
-
399
- def set_logger_level(level)
400
- raise InvalidLoggingLevelException unless ["INFO", "DEBUG", "ERROR"].include?(level.upcase)
401
- response = nexus.put(nexus_url("service/local/log/config"), :body => create_logger_level_json(level), :header => DEFAULT_CONTENT_TYPE_HEADER)
402
- case response.status
403
- when 200
404
- return true
405
- else
406
- raise UnexpectedStatusCodeException.new(response.status)
407
- end
408
- end
409
-
410
- def create_group_repository(name, id, provider)
411
- response = nexus.post(nexus_url("service/local/repo_groups"), :body => create_group_repository_json(name, id, provider), :header => DEFAULT_CONTENT_TYPE_HEADER)
412
- case response.status
413
- when 201
414
- return true
415
- when 400
416
- raise CreateRepsitoryException.new(response.content)
417
- else
418
- raise UnexpectedStatusCodeException.new(response.status)
419
- end
420
- end
421
-
422
- def get_group_repository(group_id)
423
- response = nexus.get(nexus_url("service/local/repo_groups/#{sanitize_for_id(group_id)}"), :header => DEFAULT_ACCEPT_HEADER)
424
- case response.status
425
- when 200
426
- return response.content
427
- when 404
428
- raise RepositoryNotFoundException
429
- else
430
- raise UnexpectedStatusCodeException.new(response.status)
431
- end
432
- end
433
-
434
- def repository_in_group?(group_id, repository_to_check)
435
- group_repository = JSON.parse(get_group_repository(group_id))
436
- repositories_in_group = group_repository["data"]["repositories"]
437
-
438
- repositories_in_group.find{|repository| repository["id"] == sanitize_for_id(repository_to_check)}
439
- end
440
-
441
- def add_to_group_repository(group_id, repository_to_add_id)
442
- raise RepositoryInGroupException if repository_in_group?(group_id, repository_to_add_id)
443
- response = nexus.put(nexus_url("service/local/repo_groups/#{sanitize_for_id(group_id)}"), :body => create_add_to_group_repository_json(group_id, repository_to_add_id), :header => DEFAULT_CONTENT_TYPE_HEADER)
444
- case response.status
445
- when 200
446
- return true
447
- when 400
448
- raise RepositoryNotFoundException
449
- else
450
- raise UnexpectedStatusCodeException.new(response.status)
451
- end
452
- end
453
-
454
- def remove_from_group_repository(group_id, repository_to_remove_id)
455
- raise RepositoryNotInGroupException unless repository_in_group?(group_id, repository_to_remove_id)
456
- response = nexus.put(nexus_url("service/local/repo_groups/#{sanitize_for_id(group_id)}"), :body => create_remove_from_group_repository_json(group_id, repository_to_remove_id), :header => DEFAULT_CONTENT_TYPE_HEADER)
457
- case response.status
458
- when 200
459
- return true
460
- else
461
- raise UnexpectedStatusCodeException.new(response.status)
462
- end
463
- end
464
-
465
- def delete_group_repository(group_id)
466
- response = nexus.delete(nexus_url("service/local/repo_groups/#{sanitize_for_id(group_id)}"))
467
- case response.status
468
- when 204
469
- return true
470
- when 404
471
- raise RepositoryNotFoundException
472
- else
473
- raise UnexpectedStatusCodeException.new(response.status)
474
- end
475
- end
476
-
477
- def transfer_artifact(artifact, from_repository, to_repository)
478
- do_transfer_artifact(artifact, from_repository, to_repository)
479
- end
480
-
481
- private
482
-
483
-
484
- # Transforms a given [String] into a sanitized version by
485
- # replacing spaces with underscores and downcasing.
486
- #
487
- # @param unsanitized_string [String] the String to sanitize
488
- #
489
- # @return [String] the sanitized String
490
- def sanitize_for_id(unsanitized_string)
491
- unsanitized_string.gsub(" ", "_").downcase
492
- end
493
-
494
-
495
- # Transfers an artifact from one repository
496
- # to another. Sometimes called a `promotion`
497
- #
498
- # @param artifact [String] a Maven identifier
499
- # @param from_repository [String] the name of the from repository
500
- # @param to_repository [String] the name of the to repository
501
- #
502
- # @return [Boolean] returns true when successful
503
- def do_transfer_artifact(artifact, from_repository, to_repository)
504
- Dir.mktmpdir do |temp_dir|
505
- configuration["repository"] = sanitize_for_id(from_repository)
506
- artifact_file = pull_artifact(artifact, temp_dir)
507
- configuration["repository"] = sanitize_for_id(to_repository)
508
- push_artifact(artifact, artifact_file)
509
- end
510
- end
511
-
512
-
513
- # Formats the given XML into an [Array<String>] so it
514
- # can be displayed nicely.
515
- #
516
- # @param doc [Nokogiri::XML] the xml search results
517
- # @param group_id [String] the group id
518
- # @param artifact_id [String] the artifact id
519
- #
520
- # @return [type] [description]
521
- def format_search_results(doc, group_id, artifact_id)
522
- versions = doc.xpath("//version").inject([]) {|array,node| array << "#{node.content()}"}
523
- if versions.length > 0
524
- indent_size = versions.max{|a,b| a.length <=> b.length}.size+4
525
- formated_results = ['Found Versions:']
526
- versions.inject(formated_results) do |array,version|
527
- temp_version = version + ":"
528
- array << "#{temp_version.ljust(indent_size)} `nexus-cli pull #{group_id}:#{artifact_id}:#{version}:tgz`"
529
- end
530
- else
531
- formated_results = ['No Versions Found.']
532
- end
533
- end
534
-
535
-
536
- # Parses a given artifact string into its
537
- # four, distinct, Maven pieces.
538
- #
539
- # @param artifact [String] the Maven identifier
540
- #
541
- # @return [Array<String>] an Array with four elements
542
- def parse_artifact_string(artifact)
543
- split_artifact = artifact.split(":")
544
- if(split_artifact.size < 4)
545
- raise ArtifactMalformedException
546
- end
547
- group_id, artifact_id, version, extension = split_artifact
548
- version.upcase! if version.casecmp("latest")
549
- return group_id, artifact_id, version, extension
550
- end
551
-
552
- def create_hosted_repository_json(name, id, policy, provider)
553
- params = {:provider => provider.nil? ? "maven2": provider}
554
- params[:providerRole] = "org.sonatype.nexus.proxy.repository.Repository"
555
- params[:exposed] = true
556
- params[:browseable] = true
557
- params[:indexable] = true
558
- params[:repoType] = "hosted"
559
- params[:repoPolicy] = policy.nil? ? "RELEASE" : ["RELEASE", "SNAPSHOT"].include?(policy) ? policy : "RELEASE"
560
- params[:name] = name
561
- params[:id] = id.nil? ? sanitize_for_id(name) : sanitize_for_id(id)
562
- params[:format] = "maven2"
563
- JSON.dump(:data => params)
564
- end
565
-
566
- def create_proxy_repository_json(name, url, id, policy, provider)
567
- params = {:provider => provider.nil? ? "maven2" : provider}
568
- params[:providerRole] = "org.sonatype.nexus.proxy.repository.Repository"
569
- params[:exposed] = true
570
- params[:browseable] = true
571
- params[:indexable] = true
572
- params[:repoType] = "proxy"
573
- params[:repoPolicy] = policy.nil? ? "RELEASE" : ["RELEASE", "SNAPSHOT"].include?(policy) ? policy : "RELEASE"
574
- params[:checksumPolicy] = "WARN"
575
- params[:writePolicy] = "READ_ONLY"
576
- params[:downloadRemoteIndexes] = true
577
- params[:autoBlockActive] = false
578
- params[:name] = name
579
- params[:id] = id.nil? ? sanitize_for_id(name) : sanitize_for_id(id)
580
- params[:remoteStorage] = {:remoteStorageUrl => url.nil? ? "http://change-me.com/" : url}
581
- JSON.dump(:data => params)
582
- end
583
-
584
- def create_user_json(params)
585
- JSON.dump(:data => params)
586
- end
587
-
588
- def create_change_password_json(params)
589
- JSON.dump(:data => params)
590
- end
591
-
592
- def create_logger_level_json(level)
593
- params = {:rootLoggerLevel => level.upcase}
594
- JSON.dump(:data => params)
595
- end
596
-
597
- def create_group_repository_json(name, id, provider)
598
- params = {:id => id.nil? ? sanitize_for_id(name) : sanitize_for_id(id)}
599
- params[:name] = name
600
- params[:provider] = provider.nil? ? "maven2" : provider
601
- params[:exposed] = true
602
- JSON.dump(:data => params)
603
- end
604
-
605
- def create_add_to_group_repository_json(group_id, repository_to_add_id)
606
- group_repository_json = JSON.parse(get_group_repository(group_id))
607
- repositories = group_repository_json["data"]["repositories"]
608
- repositories << {:id => sanitize_for_id(repository_to_add_id)}
609
- params = {:repositories => repositories}
610
- params[:id] = group_repository_json["data"]["id"]
611
- params[:name] = group_repository_json["data"]["name"]
612
- params[:exposed] = group_repository_json["data"]["exposed"]
613
- JSON.dump(:data => params)
614
- end
615
-
616
- def create_remove_from_group_repository_json(group_id, repository_to_remove_id)
617
- group_repository_json = JSON.parse(get_group_repository(group_id))
618
- repositories = group_repository_json["data"]["repositories"]
619
-
620
- repositories.delete(repository_in_group?(group_id, repository_to_remove_id))
621
-
622
- params = {:repositories => repositories}
623
- params[:id] = group_repository_json["data"]["id"]
624
- params[:name] = group_repository_json["data"]["name"]
625
- JSON.dump(:data => params)
626
- end
627
-
628
- def generate_fake_pom(pom_name, group_id, artifact_id, version, extension)
629
- Tempfile.open(pom_name) do |file|
630
- template_path = File.join(NexusCli.root, "data", "pom.xml.erb")
631
- file.puts ERB.new(File.read(template_path)).result(binding)
632
- file
633
- end
634
- end
635
- end
636
- end