nexus_api 1.4.1 → 2.0.1

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 1524dfad12c5d501e3d8d6c90a7cd712c8ded00a526093239c04aff862323546
4
- data.tar.gz: a1c22bcdd81c450a79cbabf5adeab806eef96f2ae0b70fbe8401f5042f23e0d0
3
+ metadata.gz: 680f17c06a69fe75f28949eda5fa16454ca8e71ad3eb4f3672a44a334dd78b0e
4
+ data.tar.gz: '008405bea89567a5e1843fc4e742c2951c2a55a2d150d06893ed159fda43bda9'
5
5
  SHA512:
6
- metadata.gz: 52ee4482ce15c00b1eae0064c0445c6862cd4bc876e915335c923bc2f1f024bd0cb0cdee09ac41d917fe7d1abfe3a5f4dbcc717894e36e8e5a016eb54605b82e
7
- data.tar.gz: ff03e64fdeb4e9c28ffcc94329ca79e2526411982ae36f40177dab99dbef6279810e5bebdfbae5fb50ec324f7f61fc64b6d8a3218b93e726ba44e44183fd3f5a
6
+ metadata.gz: 84a7ac3b47b5a6fdd06af0db9e9dc60e0d344dfc0408e9d1ddba5e5c7f76e300d57fca066170f009d72dfb4647d27a2287b3d8b991ea910d59482e3f2e5e5843
7
+ data.tar.gz: 395b05f6af8559f4a0e6ac7c0f80206af0fd16366338fc2d6153f74a5f30b6086138de054af142770e3b641e9f0fb4e1fc37948970769de80ddde652c73033b6
@@ -5,6 +5,52 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
5
5
  and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).
6
6
 
7
7
 
8
+ ## [2.0.1](https://github.com/Cisco-AMP/nexus_api/compare/v2.0.0...v2.0.1) - 2020-09-08
9
+ ### Security
10
+ - Use `rake` version `12.3.3` or later to avoid an [OS Command Injection](https://github.com/advisories/GHSA-jppv-gw3r-w3q8)
11
+
12
+
13
+ ## [2.0.0](https://github.com/Cisco-AMP/nexus_api/compare/v1.6.1...v2.0.0) - 2020-07-27
14
+ ### Added
15
+ - Fully implemented create methods for group, hosted, and proxy type repository in the following formats:
16
+ - docker
17
+ - maven
18
+ - npm
19
+ - pypi
20
+ - raw
21
+ - rubygems
22
+ - yum
23
+
24
+
25
+ ### Changed
26
+ - Method signature for `NexusAPI::API.create_repository_docker_hosted()`
27
+ - Method signature for `NexusAPI::API.create_repository_maven_hosted()`
28
+ - Method signature for `NexusAPI::API.create_repository_npm_hosted()`
29
+ - Method signature for `NexusAPI::API.create_repository_pypi_hosted()`
30
+ - Method signature for `NexusAPI::API.create_repository_raw_hosted()`
31
+ - Method signature for `NexusAPI::API.create_repository_rubygems_hosted()`
32
+ - Method signature for `NexusAPI::API.create_repository_yum_hosted()`
33
+
34
+
35
+ ## [1.6.1](https://github.com/Cisco-AMP/nexus_api/compare/v1.6.0...v1.6.1) - 2020-07-20
36
+ ### Fixed
37
+ - Parameters for tag creation were being JSON encoded twice resulting in data Nexus could not parse
38
+
39
+
40
+ ## [1.6.0](https://github.com/Cisco-AMP/nexus_api/compare/v1.5.0...v1.6.0) - 2020-07-20
41
+ ### Added
42
+ - `create_repository_raw_hosted()`
43
+ - `create_repository_rubygems_hosted()`
44
+
45
+
46
+ ## [1.5.0](https://github.com/Cisco-AMP/nexus_api/compare/v1.4.1...v1.5.0) - 2020-06-10
47
+ ### Added
48
+ - New methods around the `privileges` endpoint
49
+ - New methods around the `roles` endpoint
50
+ - New methods around the `users` endpoint
51
+ - New `list_all_*` methods for endpoints that paginate so the user doesn't have to page through results themselves if they just want all the raw data
52
+
53
+
8
54
  ## [1.4.1](https://github.com/Cisco-AMP/nexus_api/compare/v1.4.0...v1.4.1) - 2020-05-08
9
55
  ### Changed
10
56
  - Error reporting to be more descriptive
@@ -1,12 +1,12 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- nexus_api (1.4.1)
4
+ nexus_api (2.0.1)
5
5
  bundler (~> 2)
6
6
  docker-api (~> 1.34.2)
7
7
  dotenv (~> 2.7.5)
8
8
  pry (~> 0.12.2)
9
- rake (~> 10.0)
9
+ rake (>= 12.3.3)
10
10
  rest-client (~> 2.1.0)
11
11
  thor (~> 0.20.3)
12
12
 
@@ -15,18 +15,18 @@ GEM
15
15
  specs:
16
16
  addressable (2.7.0)
17
17
  public_suffix (>= 2.0.2, < 5.0)
18
- coderay (1.1.2)
18
+ coderay (1.1.3)
19
19
  crack (0.4.3)
20
20
  safe_yaml (~> 1.0.0)
21
- diff-lcs (1.3)
21
+ diff-lcs (1.4.4)
22
22
  docile (1.3.2)
23
23
  docker-api (1.34.2)
24
24
  excon (>= 0.47.0)
25
25
  multi_json
26
26
  domain_name (0.5.20190701)
27
27
  unf (>= 0.0.5, < 1.0.0)
28
- dotenv (2.7.5)
29
- excon (0.73.0)
28
+ dotenv (2.7.6)
29
+ excon (0.76.0)
30
30
  hashdiff (1.0.1)
31
31
  http-accept (1.7.0)
32
32
  http-cookie (1.0.3)
@@ -34,14 +34,14 @@ GEM
34
34
  method_source (0.9.2)
35
35
  mime-types (3.3.1)
36
36
  mime-types-data (~> 3.2015)
37
- mime-types-data (3.2020.0425)
38
- multi_json (1.14.1)
37
+ mime-types-data (3.2020.0512)
38
+ multi_json (1.15.0)
39
39
  netrc (0.11.0)
40
40
  pry (0.12.2)
41
41
  coderay (~> 1.1.0)
42
42
  method_source (~> 0.9.0)
43
- public_suffix (4.0.4)
44
- rake (10.5.0)
43
+ public_suffix (4.0.6)
44
+ rake (13.0.1)
45
45
  rest-client (2.1.0)
46
46
  http-accept (>= 1.7.0, < 2.0)
47
47
  http-cookie (>= 1.0.2, < 2.0)
@@ -51,17 +51,17 @@ GEM
51
51
  rspec-core (~> 3.9.0)
52
52
  rspec-expectations (~> 3.9.0)
53
53
  rspec-mocks (~> 3.9.0)
54
- rspec-core (3.9.0)
55
- rspec-support (~> 3.9.0)
56
- rspec-expectations (3.9.0)
54
+ rspec-core (3.9.2)
55
+ rspec-support (~> 3.9.3)
56
+ rspec-expectations (3.9.2)
57
57
  diff-lcs (>= 1.2.0, < 2.0)
58
58
  rspec-support (~> 3.9.0)
59
- rspec-mocks (3.9.0)
59
+ rspec-mocks (3.9.1)
60
60
  diff-lcs (>= 1.2.0, < 2.0)
61
61
  rspec-support (~> 3.9.0)
62
- rspec-support (3.9.0)
62
+ rspec-support (3.9.3)
63
63
  safe_yaml (1.0.5)
64
- simplecov (0.18.5)
64
+ simplecov (0.19.0)
65
65
  docile (~> 1.1)
66
66
  simplecov-html (~> 0.11)
67
67
  simplecov-html (0.12.2)
@@ -84,4 +84,4 @@ DEPENDENCIES
84
84
  webmock (~> 3.8)
85
85
 
86
86
  BUNDLED WITH
87
- 2.0.2
87
+ 2.1.4
data/README.md CHANGED
@@ -5,10 +5,10 @@ A ruby gem that wraps the [Sonatype Nexus Repository Manager 3](https://help.son
5
5
  ## Latest Version Tested
6
6
  Title | Value
7
7
  ---|---
8
- **Version** | `3.22.0-02`
8
+ **Version** | `3.24.0-02`
9
9
  **Edition** | `PRO`
10
- **Build Revision** | `140e045ce3cdd3f35e6f9d13127d7299d21f7251`
11
- **Build Timestamp** | `2020-03-27-1616-27700`
10
+ **Build Revision** | `302d6f23f1414581162efaf0fa7b4d81dbf9b251`
11
+ **Build Timestamp** | `2020-06-03-2332-51567`
12
12
 
13
13
 
14
14
  ## Installation
@@ -59,38 +59,177 @@ api = NexusAPI::API.new(
59
59
  username: NEXUS_USERNAME,
60
60
  password: NEXUS_PASSWORD,
61
61
  hostname: NEXUS_HOSTNAME,
62
- docker_pull_hostname: DOCKER_PUSH_HOSTNAME, # Optional
63
- docker_push_hostname: DOCKER_PULL_HOSTNAME, # Optional
62
+ docker_pull_hostname: DOCKER_PULL_HOSTNAME, # Optional
63
+ docker_push_hostname: DOCKER_PUSH_HOSTNAME, # Optional
64
64
  config: "team_configs/#{CONFIG_NAME}", # Optional
65
65
  )
66
66
  # NOTE: All Docker commands will fail if the docker hostnames are not initialized
67
67
 
68
+
69
+ # You can create various types of repositories in different formats
70
+ api.create_repository_docker_group(
71
+ name: REPOSITORY_NAME,
72
+ members: REPOSITORY_MEMBERS,
73
+ options: HASH_OF_REPOSITORY_OPTIONS # Optional
74
+ )
75
+ api.create_repository_docker_hosted(
76
+ name: REPOSITORY_NAME,
77
+ options: HASH_OF_REPOSITORY_OPTIONS # Optional
78
+ )
79
+ api.create_repository_docker_proxy(
80
+ name: REPOSITORY_NAME,
81
+ remote_url: URL_TO_PROXY,
82
+ options: HASH_OF_REPOSITORY_OPTIONS # Optional
83
+ )
84
+
85
+ api.create_repository_maven_group(
86
+ name: REPOSITORY_NAME,
87
+ members: REPOSITORY_MEMBERS,
88
+ options: HASH_OF_REPOSITORY_OPTIONS # Optional
89
+ )
90
+ api.create_repository_maven_hosted(
91
+ name: REPOSITORY_NAME,
92
+ options: HASH_OF_REPOSITORY_OPTIONS # Optional
93
+ )
94
+ api.create_repository_maven_proxy(
95
+ name: REPOSITORY_NAME,
96
+ remote_url: URL_TO_PROXY,
97
+ options: HASH_OF_REPOSITORY_OPTIONS # Optional
98
+ )
99
+
100
+ api.create_repository_npm_group(
101
+ name: REPOSITORY_NAME,
102
+ members: REPOSITORY_MEMBERS,
103
+ options: HASH_OF_REPOSITORY_OPTIONS # Optional
104
+ )
105
+ api.create_repository_npm_hosted(
106
+ name: REPOSITORY_NAME,
107
+ options: HASH_OF_REPOSITORY_OPTIONS # Optional
108
+ )
109
+ api.create_repository_npm_proxy(
110
+ name: REPOSITORY_NAME,
111
+ remote_url: URL_TO_PROXY,
112
+ options: HASH_OF_REPOSITORY_OPTIONS # Optional
113
+ )
114
+
115
+ api.create_repository_pypi_group(
116
+ name: REPOSITORY_NAME,
117
+ members: REPOSITORY_MEMBERS,
118
+ options: HASH_OF_REPOSITORY_OPTIONS # Optional
119
+ )
120
+ api.create_repository_pypi_hosted(
121
+ name: REPOSITORY_NAME,
122
+ options: HASH_OF_REPOSITORY_OPTIONS # Optional
123
+ )
124
+ api.create_repository_pypi_proxy(
125
+ name: REPOSITORY_NAME,
126
+ remote_url: URL_TO_PROXY,
127
+ options: HASH_OF_REPOSITORY_OPTIONS # Optional
128
+ )
129
+
130
+ api.create_repository_raw_group(
131
+ name: REPOSITORY_NAME,
132
+ members: REPOSITORY_MEMBERS,
133
+ options: HASH_OF_REPOSITORY_OPTIONS # Optional
134
+ )
135
+ api.create_repository_raw_hosted(
136
+ name: REPOSITORY_NAME,
137
+ options: HASH_OF_REPOSITORY_OPTIONS # Optional
138
+ )
139
+ api.create_repository_raw_proxy(
140
+ name: REPOSITORY_NAME,
141
+ remote_url: URL_TO_PROXY,
142
+ options: HASH_OF_REPOSITORY_OPTIONS # Optional
143
+ )
144
+
145
+ api.create_repository_rubygems_group(
146
+ name: REPOSITORY_NAME,
147
+ members: REPOSITORY_MEMBERS,
148
+ options: HASH_OF_REPOSITORY_OPTIONS # Optional
149
+ )
150
+ api.create_repository_rubygems_hosted(
151
+ name: REPOSITORY_NAME,
152
+ options: HASH_OF_REPOSITORY_OPTIONS # Optional
153
+ )
154
+ api.create_repository_rubygems_proxy(
155
+ name: REPOSITORY_NAME,
156
+ remote_url: URL_TO_PROXY,
157
+ options: HASH_OF_REPOSITORY_OPTIONS # Optional
158
+ )
159
+
160
+ api.create_repository_yum_group(
161
+ name: REPOSITORY_NAME,
162
+ members: REPOSITORY_MEMBERS,
163
+ options: HASH_OF_REPOSITORY_OPTIONS # Optional
164
+ )
165
+ api.create_repository_yum_hosted(
166
+ name: REPOSITORY_NAME,
167
+ options: HASH_OF_REPOSITORY_OPTIONS # Optional
168
+ )
169
+ api.create_repository_yum_proxy(
170
+ name: REPOSITORY_NAME,
171
+ remote_url: URL_TO_PROXY,
172
+ options: HASH_OF_REPOSITORY_OPTIONS # Optional
173
+ )
174
+
175
+
68
176
  # You can query information through the list methods
69
- api.list_repositories
70
- api.list_repository_names
71
- api.list_assets(repository: REPOSITORY_NAME)
177
+ api.list_all_assets(repository: REPOSITORY_NAME)
178
+ api.list_assets(repository: REPOSITORY_NAME, paginate: BOOLEAN)
72
179
  api.list_asset(id: ASSET_ID)
73
- api.list_components(repository: REPOSITORY_NAME)
180
+
181
+ api.list_all_components(repository: REPOSITORY_NAME)
182
+ api.list_components(repository: REPOSITORY_NAME, paginate: BOOLEAN)
74
183
  api.list_component(id: ASSET_ID)
184
+
185
+ api.list_privileges
186
+ api.list_privilege(privilege_id: ID)
187
+
188
+ api.list_repositories
189
+ api.list_repository_names
190
+
191
+ api.list_roles
192
+ api.list_role(id: ROLE_ID)
193
+
75
194
  api.list_scripts
76
- api.list_tags
195
+
196
+ api.list_all_tags
197
+ api.list_tags(paginate: BOOLEAN)
198
+
199
+ api.list_users
200
+
77
201
 
78
202
  # You can search for an asset by its name
79
203
  # Optionally, you can pass in additional fields to filter the results
204
+ api.search_all_assets(
205
+ name: ASSET_NAME,
206
+ format: REPOSITORY_FORMAT, # Optional
207
+ repository: REPOSITORY_NAME, # Optional
208
+ sha1: SHA1, # Optional
209
+ version: VERSION, # Optional
210
+ )
211
+ # You can also paginate through the results if you want to do some additional filtering
80
212
  api.search_asset(
81
213
  name: ASSET_NAME,
82
214
  format: REPOSITORY_FORMAT, # Optional
83
215
  repository: REPOSITORY_NAME, # Optional
84
216
  sha1: SHA1, # Optional
85
217
  version: VERSION, # Optional
218
+ paginate: BOOLEAN # Optional
86
219
  )
87
220
 
221
+
88
222
  # The following endpoints will paginate:
89
223
  # - list_assets
90
224
  # - list_components
91
225
  # - list_tags
92
226
  # - search_asset
93
- # You can use the following pattern to page through each method:
227
+ # Or you can use the following methods to automatically gather data from all pages for you:
228
+ # - list_all_assets
229
+ # - list_all_components
230
+ # - list_all_tags
231
+ # - search_all_assets
232
+ # Or you can use the following pattern to page through if additional processing is desired:
94
233
  set = Array.new.tap do |set|
95
234
  loop do
96
235
  set.concat(api.METHOD_YOU_WANT(ARGUMENTS, paginate: true))
@@ -98,9 +237,11 @@ set = Array.new.tap do |set|
98
237
  end
99
238
  end
100
239
 
240
+
101
241
  # You can move all components that are tagged to a new destination
102
242
  api.move_components_to(destination: DESTINATION, tag: TAG)
103
243
 
244
+
104
245
  # You can download an asset by using its asset_id
105
246
  # Optionally, you can rename the file on download
106
247
  api.download(
@@ -108,6 +249,7 @@ api.download(
108
249
  name: NEW_FILE_NAME, # Optional
109
250
  )
110
251
 
252
+
111
253
  # Different asset types require differing information to be uploaded
112
254
  # Optionally, you can tag the component provided the tag already exists
113
255
  api.upload_maven_component(
@@ -146,12 +288,14 @@ api.upload_yum_component(
146
288
  tag: TAG, # Optional
147
289
  )
148
290
 
291
+
149
292
  # Docker is a special case and uses the local Docker daemon
150
293
  # If this daemon is not installed and running these methods will fail
151
294
  # NOTE: Docker login/logout is handled as part of the docker methods
152
295
  api.download_docker_component(image: IMAGE_NAME, tag: DOCKER_TAG)
153
296
  api.upload_docker_component(image: IMAGE_NAME, tag: DOCKER_TAG)
154
297
 
298
+
155
299
  # You can create/delete tags and associate/disassociate them from components
156
300
  # (we use the SHA1 rather than the file name because the Nexus search is inconsistent)
157
301
  api.create_tag(name: TAG)
@@ -159,10 +303,12 @@ api.associate_tag(name: TAG, sha1: SHA1_SUM, repository: REPOSITORY_NAME)
159
303
  api.delete_associated_tag(name: TAG, sha1: SHA1_SUM, repository: REPOSITORY_NAME)
160
304
  api.delete_tag(name: TAG)
161
305
 
306
+
162
307
  # You can query the Nexus status
163
308
  api.status
164
309
  api.status_writable
165
310
 
311
+
166
312
  # Using an asset's URL you can gather its filesize as a String
167
313
  api.get_asset_size(asset_url: URL)
168
314
  ```
data/bin/test CHANGED
@@ -1,2 +1,3 @@
1
1
  #!/usr/bin/env bash
2
- bundle exec rake test
2
+
3
+ bundle exec rspec ${1:+$1}
@@ -6,6 +6,15 @@ module NexusAPI
6
6
  @connection.get_response(endpoint: "assets?repository=#{repository}", paginate: paginate)
7
7
  end
8
8
 
9
+ def list_all_assets(repository: nil)
10
+ Array.new.tap do |assets|
11
+ loop do
12
+ assets.concat(list_assets(repository: repository, paginate: true))
13
+ break unless paginate?
14
+ end
15
+ end
16
+ end
17
+
9
18
  # GET /service/rest/v1/assets/{id}
10
19
  def list_asset(id:)
11
20
  @connection.get_response(endpoint: "assets/#{id}")
@@ -6,6 +6,15 @@ module NexusAPI
6
6
  @connection.get_response(endpoint: "components?repository=#{repository}", paginate: paginate)
7
7
  end
8
8
 
9
+ def list_all_components(repository: nil)
10
+ Array.new.tap do |components|
11
+ loop do
12
+ components.concat(list_components(repository: repository, paginate: true))
13
+ break unless paginate?
14
+ end
15
+ end
16
+ end
17
+
9
18
  # POST /service/rest/v1/components
10
19
  def upload_maven_component(filename:, group_id:, artifact_id:, version:, repository: nil, tag: nil)
11
20
  repository ||= @team_config.maven_repository
@@ -1,8 +1,20 @@
1
1
  module NexusAPI
2
2
  class API
3
3
  # GET /service/rest/beta/security/privileges
4
+ def list_privileges
5
+ @connection.get_response(endpoint: 'security/privileges', api_version: 'beta')
6
+ end
7
+
4
8
  # GET /service/rest/beta/security/privileges/{privilegeId}
9
+ def list_privilege(privilege_id:)
10
+ @connection.get_response(endpoint: "security/privileges/#{privilege_id}", api_version: 'beta')
11
+ end
12
+
5
13
  # DELETE /service/rest/beta/security/privileges/{privilegeId}
14
+ def delete_privilege(privilege_id:)
15
+ @connection.delete(endpoint: "security/privileges/#{privilege_id}", api_version: 'beta')
16
+ end
17
+
6
18
  # POST /service/rest/beta/security/privileges/application
7
19
  # PUT /service/rest/beta/security/privileges/application/{privilegeId}
8
20
  # POST /service/rest/beta/security/privileges/repository-admin
@@ -10,6 +22,21 @@ module NexusAPI
10
22
  # POST /service/rest/beta/security/privileges/repository-content-selector
11
23
  # PUT /service/rest/beta/security/privileges/repository-content-selector/{privilegeId}
12
24
  # POST /service/rest/beta/security/privileges/repository-view
25
+ def create_privilege_repository_view(name:, description: nil, actions: ['READ'], format: '*', repository: '*')
26
+ parameters = {
27
+ # The name is also used as the privilege_id
28
+ 'name' => name,
29
+ 'description' => description,
30
+ # READ, BROWSE, EDIT, ADD, DELETE, RUN, ASSOCIATE, DISASSOCIATE, ALL
31
+ 'actions' => actions,
32
+ # The repository format (i.e 'nuget', 'npm') this privilege will grant access to (or * for all)
33
+ 'format' => format,
34
+ # The name of the repository this privilege will grant access to (or * for all)
35
+ 'repository' => repository
36
+ }
37
+ @connection.post(endpoint: 'security/privileges/repository-view', parameters: parameters, api_version: 'beta')
38
+ end
39
+
13
40
  # PUT /service/rest/beta/security/privileges/repository-view/{privilegeId}
14
41
  # POST /service/rest/beta/security/privileges/script
15
42
  # PUT /service/rest/beta/security/privileges/script/{privilegeId}