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
data/.gitignore CHANGED
@@ -5,4 +5,7 @@
5
5
  tmp/
6
6
  pkg/
7
7
  *.gem
8
- global_settings.json
8
+ global_settings.json
9
+ Gemfile.lock
10
+ doc/
11
+ .yardoc/
data/.travis.yml ADDED
@@ -0,0 +1,5 @@
1
+ script: "bundle exec thor spec:unit"
2
+ language: ruby
3
+ rvm:
4
+ - 1.9.2
5
+ - 1.9.3
data/Gemfile CHANGED
@@ -1,2 +1,42 @@
1
+ source :rubygems
2
+
1
3
  gemspec
2
4
 
5
+ group :development do
6
+ gem 'yard'
7
+ gem 'spork'
8
+ gem 'guard'
9
+ gem 'guard-cucumber'
10
+ gem 'guard-yard'
11
+ gem 'guard-rspec'
12
+ gem 'guard-spork', platforms: :ruby
13
+ gem 'coolline'
14
+ gem 'redcarpet'
15
+
16
+ require 'rbconfig'
17
+
18
+ if RbConfig::CONFIG['target_os'] =~ /darwin/i
19
+ gem 'growl', require: false
20
+ gem 'rb-fsevent', require: false
21
+
22
+ if `uname`.strip == 'Darwin' && `sw_vers -productVersion`.strip >= '10.8'
23
+ gem 'terminal-notifier-guard', '~> 1.5.3', require: false
24
+ end rescue Errno::ENOENT
25
+
26
+ elsif RbConfig::CONFIG['target_os'] =~ /linux/i
27
+ gem 'libnotify', '~> 0.8.0', require: false
28
+ gem 'rb-inotify', require: false
29
+
30
+ elsif RbConfig::CONFIG['target_os'] =~ /mswin|mingw/i
31
+ gem 'win32console', require: false
32
+ gem 'rb-notifu', '>= 0.0.4', require: false
33
+ gem 'wdm', require: false
34
+ end
35
+ end
36
+
37
+ group :test do
38
+ gem 'thor'
39
+ gem 'rake', '>= 0.9.2.2'
40
+ gem 'rspec'
41
+ gem 'fuubar'
42
+ end
data/Guardfile ADDED
@@ -0,0 +1,27 @@
1
+ notification :off
2
+
3
+ guard 'spork' do
4
+ watch('Gemfile')
5
+ watch('spec/spec_helper.rb') { :rspec }
6
+ watch(%r{^spec/support/.+\.rb$}) { :rspec }
7
+ end
8
+
9
+ guard 'yard', stdout: '/dev/null', stderr: '/dev/null' do
10
+ watch(%r{app/.+\.rb})
11
+ watch(%r{lib/.+\.rb})
12
+ watch(%r{ext/.+\.c})
13
+ end
14
+
15
+ guard 'rspec', cli: "--color --drb --format Fuubar", all_on_start: false, all_after_pass: false do
16
+ watch(%r{^spec/unit/.+_spec\.rb$})
17
+
18
+ watch(%r{^lib/(.+)\.rb$}) { |m| "spec/unit/#{m[1]}_spec.rb" }
19
+ watch('spec/spec_helper.rb') { "spec" }
20
+ watch(%r{^spec/support/.+\.rb$}) { "spec" }
21
+ end
22
+
23
+ guard 'cucumber', cli: "--drb --format pretty --tags ~@no_run --tags ~@wip", all_on_start: false, all_after_pass: false do
24
+ watch(%r{^features/.+\.feature$})
25
+ watch(%r{^features/support/.+$}) { 'features' }
26
+ watch(%r{^features/step_definitions/(.+)_steps\.rb$}) { |m| Dir[File.join("**/#{m[1]}.feature")][0] || 'features' }
27
+ end
data/README.md CHANGED
@@ -1,15 +1,13 @@
1
- Description
2
- ===========
1
+ # Nexus CLI
2
+ [![Build Status](https://travis-ci.org/RiotGames/nexus_cli.png)](https://travis-ci.org/RiotGames/nexus_cli)
3
3
 
4
4
  A CLI wrapper around Sonatype Nexus REST calls.
5
5
 
6
- Requirements
7
- ============
6
+ # Requirements
8
7
 
9
8
  * Ruby
10
9
 
11
- Installation
12
- ============
10
+ # Installation
13
11
 
14
12
  1. Install the Gem
15
13
  2. Create a file in your user's home directory named `.nexus_cli`
@@ -22,37 +20,36 @@ username: "username"
22
20
  password: "password"
23
21
  ```
24
22
 
25
- Usage
26
- =====
23
+ # Usage
27
24
 
28
25
  There are two calls that can be made. push\_artifact and pull\_artifact. Both calls will push or pull artifacts from Nexus using the Maven-flavored syntax: `groupId:artifactId:version:extension`
29
26
 
30
- Pull Artifact Example
31
- ---------------------
27
+ ## Pull Artifact Example
28
+
32
29
  ```
33
30
  nexus-cli pull_artifact com.mycompany.artifacts:myartifact:1.0.0:tgz
34
31
  ```
35
- Push Artifact Example
36
- ---------------------
32
+
33
+ ## Push Artifact Example
34
+
37
35
  ```
38
36
  nexus-cli push_artifact com.mycompany.artifacts:myartifact:1.0.0:tgz ~/path/to/file/to/push/myartifact.tgz
39
37
  ```
40
38
 
41
- License and Author
42
- ==================
39
+ # License and Author
43
40
 
44
41
  Author:: Kyle Allan (<kallan@riotgames.com>)
45
42
 
46
43
  Copyright:: 2012 Riot Games Inc.
47
44
 
48
- Licensed under the Apache License, Version 2.0 (the "License");
49
- you may not use this file except in compliance with the License.
50
- You may obtain a copy of the License at
45
+ Licensed under the Apache License, Version 2.0 (the "License");
46
+ you may not use this file except in compliance with the License.
47
+ You may obtain a copy of the License at
51
48
 
52
- http://www.apache.org/licenses/LICENSE-2.0
49
+ http://www.apache.org/licenses/LICENSE-2.0
53
50
 
54
- Unless required by applicable law or agreed to in writing, software
55
- distributed under the License is distributed on an "AS IS" BASIS,
56
- WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
57
- See the License for the specific language governing permissions and
58
- limitations under the License.
51
+ Unless required by applicable law or agreed to in writing, software
52
+ distributed under the License is distributed on an "AS IS" BASIS,
53
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
54
+ See the License for the specific language governing permissions and
55
+ limitations under the License.
data/Thorfile ADDED
@@ -0,0 +1,66 @@
1
+ # encoding: utf-8
2
+ $:.push File.expand_path("../lib", __FILE__)
3
+
4
+ require 'bundler'
5
+ require 'bundler/setup'
6
+
7
+ require 'thor/rake_compat'
8
+ require 'nexus_cli'
9
+
10
+ class Default < Thor
11
+ include Thor::RakeCompat
12
+ Bundler::GemHelper.install_tasks
13
+
14
+ desc "build", "Build nexus-cli-#{NexusCli.version}.gem into the pkg directory"
15
+ def build
16
+ Rake::Task["build"].execute
17
+ end
18
+
19
+ desc "install", "Build and install nexus-cli-#{NexusCli.version}.gem into system gems"
20
+ def install
21
+ Rake::Task["install"].execute
22
+ end
23
+
24
+ desc "release", "Create tag v#{NexusCli.version} and build and push nexus-cli-#{NexusCli.version}.gem to Rubygems"
25
+ def release
26
+ Rake::Task["release"].execute
27
+ end
28
+
29
+ class Spec < Thor
30
+ include Thor::Actions
31
+
32
+ namespace :spec
33
+ default_task :all
34
+
35
+ desc "all", "run all tests"
36
+ def all
37
+ unless run_unit && run_acceptance
38
+ exit 1
39
+ end
40
+ end
41
+
42
+ desc "unit", "run only unit tests"
43
+ def unit
44
+ unless run_unit
45
+ exit 1
46
+ end
47
+ end
48
+
49
+ desc "acceptance", "Run acceptance tests"
50
+ def acceptance
51
+ unless run_acceptance
52
+ exit 1
53
+ end
54
+ end
55
+
56
+ no_tasks do
57
+ def run_unit
58
+ run "rspec --color --format=documentation spec"
59
+ end
60
+
61
+ def run_acceptance
62
+ run "cucumber --color --format pretty"
63
+ end
64
+ end
65
+ end
66
+ end
data/VERSION CHANGED
@@ -1 +1 @@
1
- 1.0.2
1
+ 2.0.0
File without changes
File without changes
@@ -1,7 +1,6 @@
1
- require 'aruba/cucumber'
2
- $:.push "#{File.dirname(__FILE__)}/../../lib/"
3
- require 'nexus_cli'
4
- require 'rspec'
1
+ require 'rubygems'
2
+ require 'bundler'
3
+ require 'spork'
5
4
 
6
5
  module ArubaOverrides
7
6
  def detect_ruby(cmd)
@@ -14,42 +13,52 @@ module ArubaOverrides
14
13
  end
15
14
  end
16
15
 
17
- World(ArubaOverrides)
16
+ Spork.prefork do
17
+ require 'aruba/cucumber'
18
+ require 'nexus_cli'
19
+ require 'rspec'
18
20
 
19
- Before do
20
- @aruba_timeout_seconds = 10
21
- end
21
+ World(ArubaOverrides)
22
22
 
23
- def get_overrides_string
24
- @overrides_string ||= "url:http://localhost:8081/nexus repository:releases username:admin password:admin123"
25
- end
23
+ Before do
24
+ @aruba_timeout_seconds = 10
25
+ end
26
26
 
27
- def get_overrides
28
- @overrides ||= {'url' => 'http://localhost:8081/nexus', 'repository' => 'releases', 'username' => 'admin', 'password' => 'admin123'}
29
- end
27
+ def get_overrides_string
28
+ @overrides_string ||= "url:http://localhost:8081/nexus repository:releases username:admin password:admin123"
29
+ end
30
30
 
31
- def create_step_overrides(overrides)
32
- overrides_hash = overrides.split(" ").inject({}) do |overrides_hash, override|
33
- key, value = override.split(":")
34
- overrides_hash[key] = value
35
- overrides_hash
31
+ def get_overrides
32
+ @overrides ||= {'url' => 'http://localhost:8081/nexus', 'repository' => 'releases', 'username' => 'admin', 'password' => 'admin123'}
36
33
  end
37
34
 
38
- step_overrides = get_overrides.merge(overrides_hash)
39
- step_overrides.to_a.inject("") do |overrides_string, pair|
40
- overrides_string << pair.join(":")
41
- overrides_string << " "
35
+ def create_step_overrides(overrides)
36
+ overrides_hash = overrides.split(" ").inject({}) do |overrides_hash, override|
37
+ key, value = override.split(":")
38
+ overrides_hash[key] = value
39
+ overrides_hash
40
+ end
41
+
42
+ step_overrides = get_overrides.merge(overrides_hash)
43
+ step_overrides.to_a.inject("") do |overrides_string, pair|
44
+ overrides_string << pair.join(":")
45
+ overrides_string << " "
46
+ end
42
47
  end
43
- end
44
48
 
45
- def temp_dir
46
- @tmpdir ||= Dir.mktmpdir
47
- end
49
+ def temp_dir
50
+ @tmpdir ||= Dir.mktmpdir
51
+ end
48
52
 
49
- def nexus_remote
50
- @nexus_remote ||= NexusCli::Factory.create(get_overrides)
53
+ def nexus_remote
54
+ @nexus_remote ||= NexusCli::RemoteFactory.create(get_overrides)
55
+ end
56
+
57
+ at_exit do
58
+ FileUtils.rm_rf(temp_dir)
59
+ end
51
60
  end
52
61
 
53
- at_exit do
54
- FileUtils.rm_rf(temp_dir)
55
- end
62
+ Spork.each_run do
63
+ require 'nexus_cli'
64
+ end
data/lib/nexus_cli.rb CHANGED
@@ -1,17 +1,33 @@
1
- require 'nexus_cli/tasks'
2
- require 'nexus_cli/cli'
1
+ require 'httpclient'
3
2
  require 'nexus_cli/errors'
4
- require 'nexus_cli/kernel'
5
- require 'nexus_cli/nexus_remote_factory'
6
- require 'nexus_cli/nexus_oss_remote'
7
- require 'nexus_cli/nexus_pro_remote'
8
- require 'nexus_cli/configuration'
9
- require 'nexus_cli/n3_metadata'
3
+ require 'nokogiri'
4
+ require 'yaml'
10
5
 
11
6
  module NexusCli
7
+ DEFAULT_ACCEPT_HEADER = {
8
+ "Accept" => "application/json"
9
+ }.freeze
10
+
11
+ DEFAULT_CONTENT_TYPE_HEADER = {
12
+ "Content-Type" => "application/json"
13
+ }.freeze
12
14
 
13
- DEFAULT_ACCEPT_HEADER = {"Accept" => "application/json"}
14
- DEFAULT_CONTENT_TYPE_HEADER = {"Content-Type" => "application/json"}
15
+ autoload :Tasks, 'nexus_cli/tasks'
16
+ autoload :Cli, 'nexus_cli/cli'
17
+ autoload :Connection, 'nexus_cli/connection'
18
+ autoload :RemoteFactory, 'nexus_cli/remote_factory'
19
+ autoload :BaseRemote, 'nexus_cli/base_remote'
20
+ autoload :OSSRemote, 'nexus_cli/remote/oss_remote'
21
+ autoload :ProRemote, 'nexus_cli/remote/pro_remote'
22
+ autoload :Configuration, 'nexus_cli/configuration'
23
+ autoload :N3Metadata, 'nexus_cli/n3_metadata'
24
+ autoload :ArtifactActions, 'nexus_cli/mixins/artifact_actions'
25
+ autoload :GlobalSettingsActions, 'nexus_cli/mixins/global_settings_actions'
26
+ autoload :UserActions, 'nexus_cli/mixins/user_actions'
27
+ autoload :RepositoryActions, 'nexus_cli/mixins/repository_actions'
28
+ autoload :LoggingActions, 'nexus_cli/mixins/logging_actions'
29
+ autoload :CustomMetadataActions, 'nexus_cli/mixins/pro/custom_metadata_actions'
30
+ autoload :SmartProxyActions, 'nexus_cli/mixins/pro/smart_proxy_actions'
15
31
 
16
32
  class << self
17
33
  def root
@@ -0,0 +1,32 @@
1
+ module NexusCli
2
+ class BaseRemote
3
+ attr_reader :configuration
4
+ attr_reader :connection
5
+
6
+ extend Forwardable
7
+ def_delegators :@connection, :status, :nexus_url, :nexus, :sanitize_for_id
8
+
9
+ # @param [Hash] overrides
10
+ # @param [Boolean] ssl_verify
11
+ def initialize(overrides, ssl_verify=true)
12
+ @configuration = Configuration::parse(overrides)
13
+ @connection = Connection.new(configuration, ssl_verify)
14
+ end
15
+
16
+ # Parses a given artifact string into its
17
+ # four, distinct, Maven pieces.
18
+ #
19
+ # @param artifact [String] the Maven identifier
20
+ #
21
+ # @return [Array<String>] an Array with four elements
22
+ def parse_artifact_string(artifact)
23
+ split_artifact = artifact.split(":")
24
+ if(split_artifact.size < 4)
25
+ raise ArtifactMalformedException
26
+ end
27
+ group_id, artifact_id, version, extension = split_artifact
28
+ version.upcase! if version.casecmp("latest")
29
+ return group_id, artifact_id, version, extension
30
+ end
31
+ end
32
+ end
@@ -2,15 +2,34 @@ require 'extlib'
2
2
 
3
3
  module NexusCli
4
4
  module Configuration
5
+ DEFAULT_FILE = "~/.nexus_cli".freeze
6
+
5
7
  class << self
6
- def parse(overrides)
7
- config_path = File.expand_path("~/.nexus_cli")
8
- config = File.exists?(config_path) ? YAML::load_file(config_path) : Hash.new
8
+ attr_writer :path
9
+
10
+ # The filepath to the nexus cli configuration file
11
+ #
12
+ # @return [String]
13
+ def path
14
+ @path || File.expand_path(ENV['NEXUS_CONFIG'] || DEFAULT_FILE)
15
+ end
16
+
17
+ # @param [Hash] overrides
18
+ #
19
+ # @return [Hash]
20
+ def parse(overrides = {})
21
+ config = File.exists?(self.path) ? YAML::load_file(self.path) : Hash.new
22
+
9
23
  if config.nil? && (overrides.nil? || overrides.empty?)
10
24
  raise MissingSettingsFileException
11
25
  end
12
- overrides.each{|key, value| config[key] = value} unless overrides.nil? || overrides.empty?
26
+
27
+ unless overrides.nil? || overrides.empty?
28
+ overrides.each { |key, value| config[key] = value }
29
+ end
30
+
13
31
  validate_config(config)
32
+
14
33
  config["repository"] = config["repository"].gsub(" ", "_").downcase
15
34
  config
16
35
  end
@@ -22,4 +41,4 @@ module NexusCli
22
41
  end
23
42
  end
24
43
  end
25
- end
44
+ end