nexus_client 0.3.0 → 0.4.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.gitignore +2 -0
- data/CHANGELOG.md +9 -0
- data/README.md +17 -17
- data/bin/nexus-client +6 -5
- data/lib/nexus_client.rb +26 -20
- data/lib/nexus_client/version.rb +1 -1
- data/spec/unit/nexus_client_spec.rb +12 -0
- metadata +16 -15
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: f1aa13ab069a7d692e1d984bfc032211c0c2e376
|
4
|
+
data.tar.gz: ed00d1010ef7b19de4910ea988741867623cb87c
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 2ab3cb3a35c1f87b958568f386b6ff3bb46d52e303ee4985767f888d4c936d118522e84074ca6ea8db720c105e0f0b986b82bfb6181c1989ac482f95ed6e9f2a
|
7
|
+
data.tar.gz: d037c0957ec63e3a49557f3ac5e34aed1f91c1996ef25d1ca8b799de0f90934fd86019b24925a919013b3b847f8ecf39ea622a8189f1dcdc7447dc6671128301
|
data/.gitignore
CHANGED
data/CHANGELOG.md
ADDED
data/README.md
CHANGED
@@ -1,12 +1,12 @@
|
|
1
1
|
[![Build Status](https://travis-ci.org/logicminds/nexus-client.svg)](https://travis-ci.org/logicminds/nexus-client)
|
2
|
-
|
2
|
+
[![Gem Version](https://badge.fury.io/rb/nexus_client.svg)](http://badge.fury.io/rb/nexus_client)
|
3
3
|
|
4
4
|
# NexusClient
|
5
5
|
The nexus client is a ruby wrapper around the nexus REST API for downloading maven artifacts.
|
6
6
|
It features the ability to cache artifacts and also performs artifact checksums to ensure you only
|
7
7
|
download the artifact once. This gem was originally designed for use with configuration management software like puppet.
|
8
8
|
|
9
|
-
This gem does not require maven or any of the maven settings files. It was originally created to use with
|
9
|
+
This gem does not require maven or any of the maven settings files. It was originally created to use with
|
10
10
|
configuration management software to download artifacts to hundreds of servers. A CLI tool was created for this purpose
|
11
11
|
to ease downloading of artifacts on any system.
|
12
12
|
|
@@ -32,28 +32,28 @@ artifact on the same system. However, the cache feature was built to be used ac
|
|
32
32
|
so if multiple systems are downloading the same artifact you can reduce the time and bandwidth needed to download large
|
33
33
|
artifacts. This feature alone is like having a mini nexus proxy on your network!
|
34
34
|
|
35
|
-
### Automatic artifact checksums
|
36
|
-
This gem will grab the sha1 checksum from the nexus server and compare the checksum
|
35
|
+
### Automatic artifact checksums
|
36
|
+
This gem will grab the sha1 checksum from the nexus server and compare the checksum
|
37
37
|
with the downloaded artifact. If the checksums are different and error will be raised. If the checksums match, a file
|
38
38
|
will be created with a extension of sha1 after the artifact is downloaded. This sha1 file additionally contains the sha1 checksum of the file.
|
39
39
|
This sha1 file is created as a trigger mechanism for configuration management software and also to speed up sha1 computation time of the artifact.
|
40
40
|
```shell
|
41
|
-
|
41
|
+
MacBook-Pro-2:tmp$ nexus-client --nexus-host https://repository.jboss.org/nexus -e -c /tmp/cache -g 'org.glassfish.main.external:ant:4.0:central::pom' -d /tmp
|
42
42
|
Coreys-MacBook-Pro-2:tmp$ ls -l
|
43
43
|
-rw-r--r-- 1 user1 wheel 8853 Oct 22 14:26 ant-4.0.pom
|
44
44
|
-rw-r--r-- 1 user1 wheel 40 Oct 22 14:26 ant-4.0.pom.sha1
|
45
|
-
|
46
|
-
|
45
|
+
|
46
|
+
CMacBook-Pro-2:tmp$ more ant-4.0.pom.sha1
|
47
47
|
387951c0aa333024b25085d76a8ad77441b9e55f
|
48
48
|
```
|
49
49
|
|
50
|
-
### Smart Artifact Retrieval
|
50
|
+
### Smart Artifact Retrieval
|
51
51
|
This gem will use artifact checksums to ensure the artifact is only downloaded once. This
|
52
52
|
is really important during configuration management runtime when the artifact downloading process is expected run multiple times.
|
53
53
|
This is even more important when you use artifact snapshots. Artifacts that are snapshots can contain different checksums
|
54
54
|
at any time so its important that we download only when a new snapshot is detected by comparing the checksums.
|
55
55
|
|
56
|
-
### Cache Analytics(Experimental)
|
56
|
+
### Cache Analytics(Experimental)
|
57
57
|
This feature records the cache usage and shows just how much bandwidth has been saved and what
|
58
58
|
artifacts are currently cached. This feature is experimental and is not feature complete. It was originally designed
|
59
59
|
to show historically analysis of artifacts and make this information available to shell scripts, graphite and other reporting mechanisms.
|
@@ -84,21 +84,24 @@ Options:
|
|
84
84
|
--enable-cache, -e: Enable cache
|
85
85
|
--nexus-host, -n <s>: Nexus host url, if left blank reads from ~/.nexus_host
|
86
86
|
--enable-analytics, -a: Enable cache analytics, requires sqlite3 gem (experimental!)
|
87
|
+
--disable-prefix, -p: Disable appending '/nexus' in the host connection url
|
88
|
+
|
87
89
|
--help, -h: Show this message
|
88
|
-
|
90
|
+
|
89
91
|
nexus-client --nexus-host https://repository.jboss.org/nexus -e -c /tmp/cache -g 'org.glassfish.main.external:ant:4.0:central::pom' -d /tmp
|
90
92
|
```
|
91
93
|
|
94
|
+
|
92
95
|
## Tips
|
93
96
|
|
94
|
-
Create a nexus host file to store the nexus host url. This can
|
97
|
+
Create a nexus host file to store the nexus host url. This can save time if your nexus host url is the same. By default
|
95
98
|
the nexus-client CLI will override the stored url in your nexus_host file when passing in the --nexus-host argument.
|
96
99
|
|
97
100
|
```shell
|
98
|
-
|
101
|
+
MacBook-Pro-2:~$ pwd
|
99
102
|
/Users/user1
|
100
|
-
|
101
|
-
|
103
|
+
MacBook-Pro-2: echo 'https://repository.jboss.org' > ~/.nexus_host
|
104
|
+
MacBook-Pro-2:~$ more .nexus_host
|
102
105
|
https://repository.jboss.org/nexus
|
103
106
|
```
|
104
107
|
## TODO
|
@@ -124,6 +127,3 @@ If you use this gem on windows please let me know so I can update this doc.
|
|
124
127
|
|
125
128
|
|
126
129
|
## Examples
|
127
|
-
|
128
|
-
|
129
|
-
|
data/bin/nexus-client
CHANGED
@@ -22,17 +22,18 @@ opts = Trollop::options do
|
|
22
22
|
opt :enable_cache, "Enable cache", :default => false, :type => :boolean
|
23
23
|
opt :nexus_host, "Nexus host url, if left blank reads from ~/.nexus_host", :type => :string
|
24
24
|
opt :enable_analytics, "Enable cache analytics, requires sqlite3 gem (experimental!)", :type => :boolean, :default => false
|
25
|
+
opt :disable_prefix, "Disable appending '/nexus' in the host connection url", :type => :boolean, default: false, short: 'p'
|
25
26
|
end
|
26
27
|
|
27
28
|
if opts[:nexus_host].nil? or opts[:nexus_host].empty?
|
28
29
|
opts[:nexus_host] = read_host
|
29
30
|
end
|
30
31
|
|
32
|
+
path_prefix = opts[:disable_prefix] ? nil : '/nexus'
|
33
|
+
|
31
34
|
value = Nexus::Client.download(opts[:destination], opts[:gav_string],
|
32
35
|
opts[:cache_dir], opts[:enable_cache],
|
33
|
-
opts[:enable_analytics], opts[:nexus_host])
|
36
|
+
opts[:enable_analytics], opts[:nexus_host], path_prefix)
|
34
37
|
|
35
|
-
|
36
|
-
|
37
|
-
end
|
38
|
-
exit(1)
|
38
|
+
exit(1) unless value
|
39
|
+
exit(0)
|
data/lib/nexus_client.rb
CHANGED
@@ -11,13 +11,14 @@ require 'fileutils'
|
|
11
11
|
module Nexus
|
12
12
|
class Client
|
13
13
|
attr_reader :host, :cache
|
14
|
-
attr_accessor :use_cache, :log
|
14
|
+
attr_accessor :use_cache, :log, :path_prefix
|
15
15
|
|
16
|
-
def initialize(nexus_host=nil, cache_dir='/tmp/cache', enable_cache=true, enable_analytics=false,logger=nil)
|
16
|
+
def initialize(nexus_host=nil, cache_dir='/tmp/cache', enable_cache=true, enable_analytics=false,logger=nil, path_prefix='/nexus')
|
17
17
|
@log = logger
|
18
18
|
@host = nexus_host || default_host
|
19
19
|
@host = @host.gsub(/\/nexus$/, '') # just in case user enters /nexus
|
20
20
|
@use_cache = enable_cache
|
21
|
+
@path_prefix = path_prefix
|
21
22
|
if @use_cache
|
22
23
|
@cache_base = cache_dir
|
23
24
|
@cache = Nexus::Cache.new(@cache_base, enable_analytics, log)
|
@@ -48,35 +49,40 @@ module Nexus
|
|
48
49
|
@log
|
49
50
|
end
|
50
51
|
|
51
|
-
def
|
52
|
-
|
52
|
+
def host_url
|
53
|
+
"#{host}#{path_prefix}"
|
54
|
+
end
|
55
|
+
|
56
|
+
def self.download(destination, gav_str, cache_dir='/tmp/cache', enable_cache=false,enable_analytics=false,host=nil,path_prefix='/nexus')
|
57
|
+
client = Nexus::Client.new(host, cache_dir, enable_cache,enable_analytics, nil, path_prefix)
|
53
58
|
client.download_gav(destination, gav_str)
|
54
59
|
end
|
55
60
|
|
56
61
|
def download_gav(destination, gav_str)
|
62
|
+
log.info("Downloading #{gav_str} from #{host_url} to #{destination}" )
|
57
63
|
gav = Nexus::Gav.new(gav_str)
|
58
64
|
download(destination, gav)
|
59
65
|
end
|
60
66
|
|
61
|
-
|
62
|
-
|
63
|
-
|
64
|
-
|
65
|
-
|
66
|
-
|
67
|
-
|
67
|
+
def create_target(destination)
|
68
|
+
destination = File.expand_path(destination)
|
69
|
+
if ! File.directory?(destination)
|
70
|
+
begin
|
71
|
+
FileUtils.mkdir_p(destination) if not File.exists?(destination)
|
72
|
+
rescue SystemCallError => e
|
73
|
+
raise e, 'Cannot create directory'
|
74
|
+
end
|
68
75
|
end
|
69
|
-
end
|
70
76
|
|
71
|
-
|
77
|
+
end
|
72
78
|
|
73
79
|
# retrieves the attributes of the gav
|
74
80
|
def gav_data(gav)
|
75
81
|
res = {}
|
76
82
|
request = Typhoeus::Request.new(
|
77
|
-
|
78
|
-
|
79
|
-
|
83
|
+
"#{host_url}/service/local/artifact/maven/resolve",
|
84
|
+
:params => gav.to_hash,:connecttimeout => 5,
|
85
|
+
:headers => { 'Accept' => 'application/json' }
|
80
86
|
)
|
81
87
|
request.on_failure do |response|
|
82
88
|
raise("Failed to get gav data for #{gav.to_s}")
|
@@ -159,10 +165,10 @@ module Nexus
|
|
159
165
|
cache.record_hit(gav)
|
160
166
|
else
|
161
167
|
request = Typhoeus::Request.new(
|
162
|
-
|
163
|
-
|
164
|
-
|
165
|
-
|
168
|
+
"#{host_url}/service/local/artifact/maven/redirect",
|
169
|
+
:params => gav.to_hash,
|
170
|
+
:connecttimeout => 5,
|
171
|
+
:followlocation => true
|
166
172
|
)
|
167
173
|
request.on_failure do |response|
|
168
174
|
raise("Failed to download #{gav.to_s}")
|
data/lib/nexus_client/version.rb
CHANGED
@@ -34,6 +34,18 @@ describe Nexus::Client do
|
|
34
34
|
it { expect(client.host).to eq('http://mynexus.example.com:8080')}
|
35
35
|
end
|
36
36
|
|
37
|
+
context 'no path prefix' do
|
38
|
+
#nexus_host=nil, cache_dir='/tmp/cache', enable_cache=true, enable_analytics=false,logger=nil, path_prefix='/nexus'
|
39
|
+
subject(:client) { Nexus::Client.new('http://mynexus.example.com:8080/nexus', '/tmp/cache', 'enable_cache', false, nil, nil) }
|
40
|
+
it { expect(client.host_url).to eq('http://mynexus.example.com:8080')}
|
41
|
+
end
|
42
|
+
|
43
|
+
context 'path prefix' do
|
44
|
+
#nexus_host=nil, cache_dir='/tmp/cache', enable_cache=true, enable_analytics=false,logger=nil, path_prefix='/nexus'
|
45
|
+
subject(:client) { Nexus::Client.new('http://mynexus.example.com:8080/nexus', '/tmp/cache', 'enable_cache', false, nil) }
|
46
|
+
it { expect(client.host_url).to eq('http://mynexus.example.com:8080/nexus')}
|
47
|
+
end
|
48
|
+
|
37
49
|
context 'sha1 works' do
|
38
50
|
subject(:client) { Nexus::Client.new }
|
39
51
|
it {expect(client.sha('/home/user1/.nexus_host')).to eq('87a331f91896d3363e699b828d1cccd37dd07740') }
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: nexus_client
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.4.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Jason Thigpen
|
@@ -9,7 +9,7 @@ authors:
|
|
9
9
|
autorequire:
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
|
-
date:
|
12
|
+
date: 2017-05-31 00:00:00.000000000 Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: trollop
|
@@ -57,56 +57,56 @@ dependencies:
|
|
57
57
|
name: sqlite3
|
58
58
|
requirement: !ruby/object:Gem::Requirement
|
59
59
|
requirements:
|
60
|
-
- -
|
60
|
+
- - ~>
|
61
61
|
- !ruby/object:Gem::Version
|
62
62
|
version: '1.3'
|
63
63
|
type: :development
|
64
64
|
prerelease: false
|
65
65
|
version_requirements: !ruby/object:Gem::Requirement
|
66
66
|
requirements:
|
67
|
-
- -
|
67
|
+
- - ~>
|
68
68
|
- !ruby/object:Gem::Version
|
69
69
|
version: '1.3'
|
70
70
|
- !ruby/object:Gem::Dependency
|
71
71
|
name: bundler
|
72
72
|
requirement: !ruby/object:Gem::Requirement
|
73
73
|
requirements:
|
74
|
-
- -
|
74
|
+
- - ~>
|
75
75
|
- !ruby/object:Gem::Version
|
76
76
|
version: '1.3'
|
77
77
|
type: :development
|
78
78
|
prerelease: false
|
79
79
|
version_requirements: !ruby/object:Gem::Requirement
|
80
80
|
requirements:
|
81
|
-
- -
|
81
|
+
- - ~>
|
82
82
|
- !ruby/object:Gem::Version
|
83
83
|
version: '1.3'
|
84
84
|
- !ruby/object:Gem::Dependency
|
85
85
|
name: rake
|
86
86
|
requirement: !ruby/object:Gem::Requirement
|
87
87
|
requirements:
|
88
|
-
- -
|
88
|
+
- - ~>
|
89
89
|
- !ruby/object:Gem::Version
|
90
90
|
version: '10.3'
|
91
91
|
type: :development
|
92
92
|
prerelease: false
|
93
93
|
version_requirements: !ruby/object:Gem::Requirement
|
94
94
|
requirements:
|
95
|
-
- -
|
95
|
+
- - ~>
|
96
96
|
- !ruby/object:Gem::Version
|
97
97
|
version: '10.3'
|
98
98
|
- !ruby/object:Gem::Dependency
|
99
99
|
name: rspec
|
100
100
|
requirement: !ruby/object:Gem::Requirement
|
101
101
|
requirements:
|
102
|
-
- -
|
102
|
+
- - ~>
|
103
103
|
- !ruby/object:Gem::Version
|
104
104
|
version: '2.99'
|
105
105
|
type: :development
|
106
106
|
prerelease: false
|
107
107
|
version_requirements: !ruby/object:Gem::Requirement
|
108
108
|
requirements:
|
109
|
-
- -
|
109
|
+
- - ~>
|
110
110
|
- !ruby/object:Gem::Version
|
111
111
|
version: '2.99'
|
112
112
|
- !ruby/object:Gem::Dependency
|
@@ -132,8 +132,9 @@ executables:
|
|
132
132
|
extensions: []
|
133
133
|
extra_rdoc_files: []
|
134
134
|
files:
|
135
|
-
-
|
136
|
-
-
|
135
|
+
- .gitignore
|
136
|
+
- .travis.yml
|
137
|
+
- CHANGELOG.md
|
137
138
|
- Gemfile
|
138
139
|
- LICENSE
|
139
140
|
- README.md
|
@@ -165,17 +166,17 @@ require_paths:
|
|
165
166
|
- lib
|
166
167
|
required_ruby_version: !ruby/object:Gem::Requirement
|
167
168
|
requirements:
|
168
|
-
- -
|
169
|
+
- - '>='
|
169
170
|
- !ruby/object:Gem::Version
|
170
171
|
version: '0'
|
171
172
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
172
173
|
requirements:
|
173
|
-
- -
|
174
|
+
- - '>='
|
174
175
|
- !ruby/object:Gem::Version
|
175
176
|
version: '0'
|
176
177
|
requirements: []
|
177
178
|
rubyforge_project:
|
178
|
-
rubygems_version: 2.
|
179
|
+
rubygems_version: 2.0.14.1
|
179
180
|
signing_key:
|
180
181
|
specification_version: 4
|
181
182
|
summary: Simple Nexus Ruby Client
|