nexus_cli 0.0.5 → 0.1.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 CHANGED
@@ -1 +1 @@
1
- 0.0.5
1
+ 0.1.0
@@ -32,7 +32,7 @@ module NexusCli
32
32
  status_code(102)
33
33
  end
34
34
 
35
- class MissingSettingsFile < NexusCliError
35
+ class MissingSettingsFileException < NexusCliError
36
36
  def message
37
37
  "The .nexus_cli file is missing or corrupt."
38
38
  end
@@ -45,4 +45,28 @@ module NexusCli
45
45
  end
46
46
  status_code(104)
47
47
  end
48
+
49
+ class CouldNotConnectToNexusException < NexusCliError
50
+ def message
51
+ "Could not connect to Nexus. Please ensure the url in .nexus_cli is reachable."
52
+ end
53
+ status_code(105)
54
+ end
55
+
56
+ class PermissionsException < NexusCliError
57
+ def message
58
+ "Your request was denied by the Nexus server due to a permissions error. You will need to administer the Nexus or use a different user/password in .nexus_cli."
59
+ end
60
+ status_code(106)
61
+ end
62
+
63
+ class BadUploadRequestException < NexusCliError
64
+ def message
65
+ %{Your request was denied by the Nexus server due to a bad request and your artifact has not been uploaded.
66
+ This could mean several things:
67
+ Your .nexus_cli['repository'] is invalid.
68
+ The artifact with this identifier alread exists inside the repository and that repository does not allow multiple deployments.}
69
+ end
70
+ status_code(107)
71
+ end
48
72
  end
@@ -16,7 +16,7 @@ module NexusCli
16
16
  begin
17
17
  config = YAML::load_file(File.expand_path("~/.nexus_cli"))
18
18
  rescue Errno::ENOENT
19
- raise MissingSettingsFile
19
+ raise MissingSettingsFileException
20
20
  end
21
21
  validate_config(config)
22
22
  @configuration = config
@@ -44,7 +44,7 @@ module NexusCli
44
44
  File.expand_path(artifact.path)
45
45
  end
46
46
 
47
- def push_artifact(artifact, file, insecure)
47
+ def push_artifact(artifact, file, insecure, override_repository)
48
48
  #Build up the pieces that will make up the PUT request
49
49
  split_artifact = artifact.split(":")
50
50
  if(split_artifact.size < 4)
@@ -54,13 +54,21 @@ module NexusCli
54
54
  group_id = split_artifact[1].gsub(".", "/")
55
55
  version = split_artifact[2]
56
56
  file_name = "#{split_artifact[1]}-#{version}.#{split_artifact[3]}"
57
-
58
- put_string = "content/repositories/releases/#{artifact_id}/#{group_id}/#{version}/#{file_name}"
59
- Open3.popen3("curl #{insecure ? "-k" : ""} -T #{file} #{configuration['url']}#{put_string} -u #{configuration['username']}:#{configuration['password']}") do |stdin, stdout, stderr, wait_thr|
57
+ repository = override_repository.nil? ? configuration['repository'] : override_repository
58
+ put_string = "content/repositories/#{repository}/#{artifact_id}/#{group_id}/#{version}/#{file_name}"
59
+ Open3.popen3("curl -I #{insecure ? "-k" : ""} -T #{file} #{File.join(configuration['url'], put_string)} -u #{configuration['username']}:#{configuration['password']}") do |stdin, stdout, stderr, wait_thr|
60
60
  exit_code = wait_thr.value.exitstatus
61
+ standard_out = stdout.read
62
+ if (standard_out.match('403 Forbidden') || standard_out.match('401 Unauthorized'))
63
+ raise PermissionsException
64
+ elsif standard_out.match('400 Bad Request')
65
+ raise BadUploadRequestException
66
+ end
61
67
  case exit_code
62
68
  when 60
63
69
  raise NonSecureConnectionException
70
+ when 7
71
+ raise CouldNotConnectToNexusException
64
72
  end
65
73
  end
66
74
  end
@@ -75,7 +83,7 @@ module NexusCli
75
83
  version = split_artifact[2]
76
84
 
77
85
  delete_string = "content/repositories/releases/#{artifact_id}/#{group_id}/#{version}"
78
- Kernel.quietly {`curl --request DELETE #{configuration['url']}#{delete_string} -u #{configuration['username']}:#{configuration['password']}`}
86
+ Kernel.quietly {`curl --request DELETE #{File.join(configuration['url'], delete_string)} -u #{configuration['username']}:#{configuration['password']}`}
79
87
  end
80
88
 
81
89
  def get_artifact_info(artifact)
@@ -6,8 +6,11 @@ module NexusCli
6
6
  base.send :include, ::Thor::Actions
7
7
  base.class_eval do
8
8
 
9
+ method_option :destination,
10
+ :type => :string,
11
+ :default => nil,
12
+ :desc => "A different folder other than the current working directory."
9
13
  desc "pull_artifact artifact", "Pulls an artifact from Nexus and places it on your machine."
10
- method_option :destination, :default => nil # defaults to the current working directory
11
14
  def pull_artifact(artifact)
12
15
  begin
13
16
  path_to_artifact = Remote.pull_artifact(artifact, options[:destination])
@@ -18,11 +21,18 @@ module NexusCli
18
21
  end
19
22
  end
20
23
 
24
+ method_option :insecure,
25
+ :type => :boolean,
26
+ :default => false,
27
+ :desc => "Overrides any failures because of an 'insecure' SSL conncetion."
28
+ method_option :repository,
29
+ :type => :string,
30
+ :default => nil,
31
+ :desc => "A String of a repository that will override the value in the .nexus_cli config file."
21
32
  desc "push_artifact artifact file", "Pushes an artifact from your machine onto the Nexus."
22
- method_options :insecure => false
23
33
  def push_artifact(artifact, file)
24
34
  begin
25
- Remote.push_artifact(artifact, file, options[:insecure])
35
+ Remote.push_artifact(artifact, file, options[:insecure], options[:repository])
26
36
  say "Artifact #{artifact} has been successfully pushed to Nexus.", :green
27
37
  rescue NexusCliError => e
28
38
  say e.message, :red
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: nexus_cli
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.5
4
+ version: 0.1.0
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -9,7 +9,7 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2012-06-21 00:00:00.000000000 Z
12
+ date: 2012-06-27 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: thor
@@ -147,12 +147,18 @@ required_ruby_version: !ruby/object:Gem::Requirement
147
147
  - - ! '>='
148
148
  - !ruby/object:Gem::Version
149
149
  version: '0'
150
+ segments:
151
+ - 0
152
+ hash: -2766397999758953733
150
153
  required_rubygems_version: !ruby/object:Gem::Requirement
151
154
  none: false
152
155
  requirements:
153
156
  - - ! '>='
154
157
  - !ruby/object:Gem::Version
155
158
  version: '0'
159
+ segments:
160
+ - 0
161
+ hash: -2766397999758953733
156
162
  requirements: []
157
163
  rubyforge_project:
158
164
  rubygems_version: 1.8.21