nexus_api 1.3.0 → 1.6.1
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.
- checksums.yaml +4 -4
- data/CHANGELOG.md +32 -0
- data/Gemfile.lock +4 -4
- data/README.md +16 -8
- data/lib/endpoints/assets.rb +9 -0
- data/lib/endpoints/components.rb +9 -0
- data/lib/endpoints/privileges.rb +27 -0
- data/lib/endpoints/repositories.rb +36 -0
- data/lib/endpoints/roles.rb +22 -0
- data/lib/endpoints/search.rb +17 -0
- data/lib/endpoints/tags.rb +46 -14
- data/lib/endpoints/users.rb +21 -0
- data/lib/nexus_api/cli_commands/list.rb +15 -0
- data/lib/nexus_api/docker_manager.rb +2 -2
- data/lib/nexus_api/nexus_connection.rb +11 -2
- data/lib/nexus_api/version.rb +1 -1
- data/lib/utilities/parameter_builder.rb +29 -7
- metadata +1 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 2f708328c5c5cc947266bf002b345c88177e4780a1d25796ec1b918d682439b4
|
4
|
+
data.tar.gz: 8006685084aaabb5fd3d9db2d87d7b6d3ee838db88eec94320145860ece8a30d
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 46adf2cec475f1b3f19a9088f6b9efaec6aaa6b368933889e640b5ffed24c91f3190c5c9a36c7e1de49be9c3225a2444b44cc14b0dc74014c524d5755e6995ae
|
7
|
+
data.tar.gz: c5e9670c1f4532d5ba268bead70b71bfc5626593b3addd260e80e7bc320faf392910b4db88dab910ba843e4ac9dd05afce04c88e76ea067ba966a02ec3ac6548
|
data/CHANGELOG.md
CHANGED
@@ -5,6 +5,38 @@ 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
|
+
## [1.6.1](https://github.com/Cisco-AMP/nexus_api/compare/v1.6.0...v1.6.1) - 2020-07-20
|
9
|
+
### Fixed
|
10
|
+
- Parameters for tag creation were being JSON encoded twice resulting in data Nexus could not parse
|
11
|
+
|
12
|
+
|
13
|
+
## [1.6.0](https://github.com/Cisco-AMP/nexus_api/compare/v1.5.0...v1.6.0) - 2020-07-20
|
14
|
+
### Added
|
15
|
+
- `create_repository_raw_hosted()`
|
16
|
+
- `create_repository_rubygems_hosted()`
|
17
|
+
|
18
|
+
|
19
|
+
## [1.5.0](https://github.com/Cisco-AMP/nexus_api/compare/v1.4.1...v1.5.0) - 2020-06-10
|
20
|
+
### Added
|
21
|
+
- New methods around the `privileges` endpoint
|
22
|
+
- New methods around the `roles` endpoint
|
23
|
+
- New methods around the `users` endpoint
|
24
|
+
- 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
|
25
|
+
|
26
|
+
|
27
|
+
## [1.4.1](https://github.com/Cisco-AMP/nexus_api/compare/v1.4.0...v1.4.1) - 2020-05-08
|
28
|
+
### Changed
|
29
|
+
- Error reporting to be more descriptive
|
30
|
+
|
31
|
+
|
32
|
+
## [1.4.0](https://github.com/Cisco-AMP/nexus_api/compare/v1.3.0...v1.4.0) - 2020-05-05
|
33
|
+
### Added
|
34
|
+
- Optional `tag` parameter to `associate_tag()` and `delete_associated_tag()` methods
|
35
|
+
|
36
|
+
### Changed
|
37
|
+
- Made `sha1` parameter optional for `associate_tag()` and `delete_associated_tag()` methods
|
38
|
+
|
39
|
+
|
8
40
|
## [1.3.0](https://github.com/Cisco-AMP/nexus_api/compare/v1.2.1...v1.3.0) - 2020-04-30
|
9
41
|
### Added
|
10
42
|
- Optional source and general keyword match into staging endpoint method (`move_components_to()`)
|
data/Gemfile.lock
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
PATH
|
2
2
|
remote: .
|
3
3
|
specs:
|
4
|
-
nexus_api (1.
|
4
|
+
nexus_api (1.6.1)
|
5
5
|
bundler (~> 2)
|
6
6
|
docker-api (~> 1.34.2)
|
7
7
|
dotenv (~> 2.7.5)
|
@@ -15,7 +15,7 @@ GEM
|
|
15
15
|
specs:
|
16
16
|
addressable (2.7.0)
|
17
17
|
public_suffix (>= 2.0.2, < 5.0)
|
18
|
-
coderay (1.1.
|
18
|
+
coderay (1.1.3)
|
19
19
|
crack (0.4.3)
|
20
20
|
safe_yaml (~> 1.0.0)
|
21
21
|
diff-lcs (1.3)
|
@@ -34,7 +34,7 @@ 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.
|
37
|
+
mime-types-data (3.2020.0512)
|
38
38
|
multi_json (1.14.1)
|
39
39
|
netrc (0.11.0)
|
40
40
|
pry (0.12.2)
|
@@ -84,4 +84,4 @@ DEPENDENCIES
|
|
84
84
|
webmock (~> 3.8)
|
85
85
|
|
86
86
|
BUNDLED WITH
|
87
|
-
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.
|
8
|
+
**Version** | `3.24.0-02`
|
9
9
|
**Edition** | `PRO`
|
10
|
-
**Build Revision** | `
|
11
|
-
**Build Timestamp** | `2020-03-
|
10
|
+
**Build Revision** | `302d6f23f1414581162efaf0fa7b4d81dbf9b251`
|
11
|
+
**Build Timestamp** | `2020-06-03-2332-51567`
|
12
12
|
|
13
13
|
|
14
14
|
## Installation
|
@@ -59,21 +59,24 @@ api = NexusAPI::API.new(
|
|
59
59
|
username: NEXUS_USERNAME,
|
60
60
|
password: NEXUS_PASSWORD,
|
61
61
|
hostname: NEXUS_HOSTNAME,
|
62
|
-
docker_pull_hostname:
|
63
|
-
docker_push_hostname:
|
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
68
|
# You can query information through the list methods
|
69
|
-
api.list_repositories
|
70
|
-
api.list_repository_names
|
71
69
|
api.list_assets(repository: REPOSITORY_NAME)
|
72
70
|
api.list_asset(id: ASSET_ID)
|
73
71
|
api.list_components(repository: REPOSITORY_NAME)
|
74
72
|
api.list_component(id: ASSET_ID)
|
73
|
+
api.list_privileges
|
74
|
+
api.list_repositories
|
75
|
+
api.list_repository_names
|
76
|
+
api.list_roles
|
75
77
|
api.list_scripts
|
76
78
|
api.list_tags
|
79
|
+
api.list_users
|
77
80
|
|
78
81
|
# You can search for an asset by its name
|
79
82
|
# Optionally, you can pass in additional fields to filter the results
|
@@ -90,7 +93,12 @@ api.search_asset(
|
|
90
93
|
# - list_components
|
91
94
|
# - list_tags
|
92
95
|
# - search_asset
|
93
|
-
# You can use the following
|
96
|
+
# You can use the following methods to automatically gather data from all pages for you:
|
97
|
+
# - list_all_assets
|
98
|
+
# - list_all_components
|
99
|
+
# - list_all_tags
|
100
|
+
# - search_all_assets
|
101
|
+
# Or you can use the following pattern to page through if additional processing is desired:
|
94
102
|
set = Array.new.tap do |set|
|
95
103
|
loop do
|
96
104
|
set.concat(api.METHOD_YOU_WANT(ARGUMENTS, paginate: true))
|
data/lib/endpoints/assets.rb
CHANGED
@@ -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
|
+
assets = 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}")
|
data/lib/endpoints/components.rb
CHANGED
@@ -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
|
+
components = 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
|
data/lib/endpoints/privileges.rb
CHANGED
@@ -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}
|
@@ -31,6 +31,8 @@ module NexusAPI
|
|
31
31
|
# PUT /service/rest/beta/repositories/bower/hosted/{repositoryName}
|
32
32
|
# POST /service/rest/beta/repositories/bower/proxy
|
33
33
|
# PUT /service/rest/beta/repositories/bower/proxy/{repositoryName}
|
34
|
+
# POST /service/rest/beta/repositories/cocoapods/proxy
|
35
|
+
# PUT /service/rest/beta/repositories/cocoapods/proxy/{repositoryName}
|
34
36
|
# POST /service/rest/beta/repositories/conan/proxy
|
35
37
|
# PUT /service/rest/beta/repositories/conan/proxy/{repositoryName}
|
36
38
|
# POST /service/rest/beta/repositories/docker/group
|
@@ -54,6 +56,8 @@ module NexusAPI
|
|
54
56
|
# PUT /service/rest/beta/repositories/helm/hosted/{repositoryName}
|
55
57
|
# POST /service/rest/beta/repositories/helm/proxy
|
56
58
|
# PUT /service/rest/beta/repositories/helm/proxy/{repositoryName}
|
59
|
+
# POST /service/rest/beta/repositories/maven/group
|
60
|
+
# PUT /service/rest/beta/repositories/maven/group/{repositoryName}
|
57
61
|
# POST /service/rest/beta/repositories/maven/hosted
|
58
62
|
def create_repository_maven_hosted(name:)
|
59
63
|
parameters = ParameterBuilder.maven_hosted(name)
|
@@ -93,6 +97,36 @@ module NexusAPI
|
|
93
97
|
# PUT /service/rest/beta/repositories/pypi/hosted/{repositoryName}
|
94
98
|
# POST /service/rest/beta/repositories/pypi/proxy
|
95
99
|
# PUT /service/rest/beta/repositories/pypi/proxy/{repositoryName}
|
100
|
+
# POST /service/rest/beta/repositories/r/group
|
101
|
+
# PUT /service/rest/beta/repositories/r/group/{repositoryName}
|
102
|
+
# POST /service/rest/beta/repositories/r/hosted
|
103
|
+
# PUT /service/rest/beta/repositories/r/hosted/{repositoryName}
|
104
|
+
# POST /service/rest/beta/repositories/r/proxy
|
105
|
+
# PUT /service/rest/beta/repositories/r/proxy/{repositoryName}
|
106
|
+
# POST /service/rest/beta/repositories/raw/group
|
107
|
+
# PUT /service/rest/beta/repositories/raw/group/{repositoryName}
|
108
|
+
# POST /service/rest/beta/repositories/raw/hosted
|
109
|
+
def create_repository_raw_hosted(name:)
|
110
|
+
parameters = ParameterBuilder.raw_hosted(name)
|
111
|
+
@connection.post(endpoint: 'repositories/raw/hosted', parameters: parameters, api_version: 'beta')
|
112
|
+
end
|
113
|
+
|
114
|
+
# PUT /service/rest/beta/repositories/raw/hosted/{repositoryName}
|
115
|
+
# POST /service/rest/beta/repositories/raw/proxy
|
116
|
+
# PUT /service/rest/beta/repositories/raw/proxy/{repositoryName}
|
117
|
+
# POST /service/rest/beta/repositories/rubygems/group
|
118
|
+
# PUT /service/rest/beta/repositories/rubygems/group/{repositoryName}
|
119
|
+
# POST /service/rest/beta/repositories/rubygems/hosted
|
120
|
+
def create_repository_rubygems_hosted(name:)
|
121
|
+
parameters = ParameterBuilder.rubygems_hosted(name)
|
122
|
+
@connection.post(endpoint: 'repositories/rubygems/hosted', parameters: parameters, api_version: 'beta')
|
123
|
+
end
|
124
|
+
|
125
|
+
# PUT /service/rest/beta/repositories/rubygems/hosted/{repositoryName}
|
126
|
+
# POST /service/rest/beta/repositories/rubygems/proxy
|
127
|
+
# PUT /service/rest/beta/repositories/rubygems/proxy/{repositoryName}
|
128
|
+
# POST /service/rest/beta/repositories/yum/group
|
129
|
+
# PUT /service/rest/beta/repositories/yum/group/{repositoryName}
|
96
130
|
# POST /service/rest/beta/repositories/yum/hosted
|
97
131
|
def create_repository_yum_hosted(name:, depth:)
|
98
132
|
parameters = ParameterBuilder.yum_hosted(name, depth)
|
@@ -100,5 +134,7 @@ module NexusAPI
|
|
100
134
|
end
|
101
135
|
|
102
136
|
# PUT /service/rest/beta/repositories/yum/hosted/{repositoryName}
|
137
|
+
# POST /service/rest/beta/repositories/yum/proxy
|
138
|
+
# PUT /service/rest/beta/repositories/yum/proxy/{repositoryName}
|
103
139
|
end
|
104
140
|
end
|
data/lib/endpoints/roles.rb
CHANGED
@@ -1,9 +1,31 @@
|
|
1
1
|
module NexusAPI
|
2
2
|
class API
|
3
3
|
# GET /service/rest/beta/security/roles
|
4
|
+
def list_roles
|
5
|
+
@connection.get_response(endpoint: 'security/roles', api_version: 'beta')
|
6
|
+
end
|
7
|
+
|
4
8
|
# POST /service/rest/beta/security/roles
|
9
|
+
def create_role(id:, name:, description: nil, privileges: [], roles: [])
|
10
|
+
parameters = {
|
11
|
+
'id' => id,
|
12
|
+
'name' => name,
|
13
|
+
'description' => description,
|
14
|
+
'privileges' => privileges,
|
15
|
+
'roles' => roles
|
16
|
+
}
|
17
|
+
@connection.post(endpoint: 'security/roles', parameters: parameters, api_version: 'beta')
|
18
|
+
end
|
19
|
+
|
5
20
|
# GET /service/rest/beta/security/roles/{id}
|
21
|
+
def list_role(id:)
|
22
|
+
@connection.get_response(endpoint: "security/roles/#{id}?source=default", api_version: 'beta')
|
23
|
+
end
|
24
|
+
|
6
25
|
# PUT /service/rest/beta/security/roles/{id}
|
7
26
|
# DELETE /service/rest/beta/security/roles/{id}
|
27
|
+
def delete_role(id:)
|
28
|
+
@connection.delete(endpoint: "security/roles/#{id}", api_version: 'beta')
|
29
|
+
end
|
8
30
|
end
|
9
31
|
end
|
data/lib/endpoints/search.rb
CHANGED
@@ -13,6 +13,23 @@ module NexusAPI
|
|
13
13
|
@connection.get_response(endpoint: endpoint, paginate: paginate)
|
14
14
|
end
|
15
15
|
|
16
|
+
def search_all_assets(name:, format: nil, repository: nil, sha1: nil, version: nil)
|
17
|
+
results = Array.new.tap do |results|
|
18
|
+
loop do
|
19
|
+
results.concat(
|
20
|
+
search_asset(
|
21
|
+
name: name,
|
22
|
+
format: format,
|
23
|
+
repository: repository,
|
24
|
+
sha1: sha1,
|
25
|
+
version: version,
|
26
|
+
paginate: true
|
27
|
+
))
|
28
|
+
break unless paginate?
|
29
|
+
end
|
30
|
+
end
|
31
|
+
end
|
32
|
+
|
16
33
|
# GET /service/rest/v1/search/assets/download
|
17
34
|
end
|
18
35
|
end
|
data/lib/endpoints/tags.rb
CHANGED
@@ -5,11 +5,20 @@ module NexusAPI
|
|
5
5
|
@connection.get_response(endpoint: 'tags', paginate: paginate)
|
6
6
|
end
|
7
7
|
|
8
|
+
def list_all_tags
|
9
|
+
tags = Array.new.tap do |tags|
|
10
|
+
loop do
|
11
|
+
tags.concat(list_tags(paginate: true))
|
12
|
+
break unless paginate?
|
13
|
+
end
|
14
|
+
end
|
15
|
+
end
|
16
|
+
|
8
17
|
# POST /service/rest/v1/tags
|
9
18
|
def create_tag(name:)
|
10
|
-
parameters =
|
19
|
+
parameters = {
|
11
20
|
'name' => name,
|
12
|
-
}
|
21
|
+
}
|
13
22
|
@connection.post(endpoint: 'tags', parameters: parameters)
|
14
23
|
end
|
15
24
|
|
@@ -21,24 +30,47 @@ module NexusAPI
|
|
21
30
|
end
|
22
31
|
|
23
32
|
# POST /service/rest/v1/tags/associate/{tagName}
|
24
|
-
def associate_tag(name:, sha1
|
33
|
+
def associate_tag(name:, sha1: nil, repository: nil, tag: nil)
|
25
34
|
repository ||= @team_config.tag_repository
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
-
|
30
|
-
|
35
|
+
if sha1.nil? && repository.nil? && tag.nil?
|
36
|
+
puts_error(__method__)
|
37
|
+
return false
|
38
|
+
end
|
39
|
+
|
40
|
+
search_query = "?wait=true"
|
41
|
+
search_query += "&sha1=#{sha1}" unless sha1.nil?
|
42
|
+
search_query += "&repository=#{repository}" unless repository.nil?
|
43
|
+
search_query += "&tag=#{tag}" unless tag.nil?
|
44
|
+
|
31
45
|
@connection.post(endpoint: "tags/associate/#{name}" + search_query)
|
32
46
|
end
|
33
47
|
|
34
48
|
# DELETE /service/rest/v1/tags/associate/{tagName}
|
35
|
-
def delete_associated_tag(name:, sha1
|
49
|
+
def delete_associated_tag(name:, sha1: nil, repository: nil, tag: nil)
|
36
50
|
repository ||= @team_config.tag_repository
|
37
|
-
|
38
|
-
|
39
|
-
|
40
|
-
|
41
|
-
|
51
|
+
parameters = {}
|
52
|
+
parameters['sha1'] = sha1 unless sha1.nil?
|
53
|
+
parameters['repository'] = repository unless repository.nil?
|
54
|
+
parameters['tag'] = tag unless tag.nil?
|
55
|
+
if parameters.empty?
|
56
|
+
puts_error(__method__)
|
57
|
+
return false
|
58
|
+
end
|
59
|
+
|
60
|
+
search_query = parameters.map do |parameter, value|
|
61
|
+
"#{parameter}=#{value}"
|
62
|
+
end.join("&")
|
63
|
+
|
64
|
+
@connection.delete(endpoint: "tags/associate/#{name}?" + search_query)
|
65
|
+
end
|
66
|
+
|
67
|
+
|
68
|
+
private
|
69
|
+
|
70
|
+
def puts_error(method)
|
71
|
+
puts "ERROR: NexusAPI::API::#{method}() requires AT LEAST one optional parameter to"
|
72
|
+
puts " be set otherwise ALL assets in Nexus will be tagged. If this is desired"
|
73
|
+
puts " please open an issue or a PR to add a new method to handle this case."
|
42
74
|
end
|
43
75
|
end
|
44
76
|
end
|
data/lib/endpoints/users.rb
CHANGED
@@ -1,9 +1,30 @@
|
|
1
1
|
module NexusAPI
|
2
2
|
class API
|
3
3
|
# GET /service/rest/beta/security/users
|
4
|
+
def list_users
|
5
|
+
@connection.get_response(endpoint: 'security/users', api_version: 'beta')
|
6
|
+
end
|
7
|
+
|
4
8
|
# POST /service/rest/beta/security/users
|
9
|
+
def create_user(user_id:, first_name:, last_name:, email:, password:, roles:)
|
10
|
+
parameters = {
|
11
|
+
'userId' => user_id,
|
12
|
+
'firstName' => first_name,
|
13
|
+
'lastName' => last_name,
|
14
|
+
'emailAddress' => email,
|
15
|
+
'password' => password,
|
16
|
+
'status' => 'active',
|
17
|
+
'roles' => roles,
|
18
|
+
}
|
19
|
+
@connection.post(endpoint: 'security/users', parameters: parameters, api_version: 'beta')
|
20
|
+
end
|
21
|
+
|
5
22
|
# PUT /service/rest/beta/security/users/{userId}
|
6
23
|
# DELETE /service/rest/beta/security/users/{userId}
|
24
|
+
def delete_user(user_id:)
|
25
|
+
@connection.delete(endpoint: "security/users/#{user_id}", api_version: 'beta')
|
26
|
+
end
|
27
|
+
|
7
28
|
# PUT /service/rest/beta/security/users/{userId}/change-password
|
8
29
|
# DELETE /service/rest/beta/security/users/{userId}/user-token
|
9
30
|
end
|
@@ -51,16 +51,31 @@ module NexusAPI
|
|
51
51
|
print_paginating_set(action: :list_components, params: {repository: options[:repository]}, filter: 'name', proc: proc)
|
52
52
|
end
|
53
53
|
|
54
|
+
desc 'privileges', 'Prints out a list of all privileges'
|
55
|
+
def privileges
|
56
|
+
print_set(action: :list_privileges, filter: 'name')
|
57
|
+
end
|
58
|
+
|
54
59
|
desc 'repositories', 'Prints out a list of all repositories'
|
55
60
|
def repositories
|
56
61
|
print_set(action: :list_repositories, filter: 'name')
|
57
62
|
end
|
58
63
|
|
64
|
+
desc 'roles', 'Prints out a list of all roles'
|
65
|
+
def roles
|
66
|
+
print_set(action: :list_roles, filter: 'name')
|
67
|
+
end
|
68
|
+
|
59
69
|
desc 'status', 'Prints out if the Nexus server can respond to read and write requests'
|
60
70
|
def status
|
61
71
|
setup
|
62
72
|
puts "Nexus can respond to read requests: #{@api.status}"
|
63
73
|
puts "Nexus can respond to write requests: #{@api.status_writable}"
|
64
74
|
end
|
75
|
+
|
76
|
+
desc 'users', 'Prints out a list of all users'
|
77
|
+
def users
|
78
|
+
print_set(action: :list_users, filter: 'emailAddress')
|
79
|
+
end
|
65
80
|
end
|
66
81
|
end
|
@@ -15,8 +15,8 @@ module NexusAPI
|
|
15
15
|
return false unless docker_valid?
|
16
16
|
image_name = image_name(@pull_host, image_name, tag)
|
17
17
|
begin
|
18
|
-
|
19
|
-
rescue Docker::Error::NotFoundError
|
18
|
+
@docker.pull_image(@username, @password, image_name)
|
19
|
+
rescue Docker::Error::NotFoundError
|
20
20
|
puts "ERROR: Failed to pull Docker image #{image_name}.\nDoes it exist in Nexus?"
|
21
21
|
return false
|
22
22
|
end
|
@@ -88,7 +88,11 @@ module NexusAPI
|
|
88
88
|
|
89
89
|
def handle(error)
|
90
90
|
puts "ERROR: Request failed"
|
91
|
-
|
91
|
+
if error.is_a?(RestClient::Response)
|
92
|
+
puts error.description
|
93
|
+
else
|
94
|
+
puts error.to_s
|
95
|
+
end
|
92
96
|
end
|
93
97
|
|
94
98
|
def catch_connection_error
|
@@ -98,8 +102,12 @@ module NexusAPI
|
|
98
102
|
return handle(error)
|
99
103
|
rescue RestClient::Unauthorized => error
|
100
104
|
return handle(error)
|
105
|
+
rescue RestClient::Exceptions::ReadTimeout => error
|
106
|
+
return handle(error)
|
101
107
|
rescue RestClient::ExceptionWithResponse => error
|
102
108
|
return handle(error.response)
|
109
|
+
rescue StandardError => error
|
110
|
+
return handle(error)
|
103
111
|
end
|
104
112
|
end
|
105
113
|
|
@@ -108,6 +116,7 @@ module NexusAPI
|
|
108
116
|
end
|
109
117
|
|
110
118
|
def send_request(connection_method, endpoint, parameters: '', headers: {}, api_version: 'v1')
|
119
|
+
parameters = parameters.to_json if headers['Content-Type'] == 'application/json'
|
111
120
|
url = "https://#{@hostname}/service/rest/#{api_version}/#{endpoint}"
|
112
121
|
catch_connection_error do
|
113
122
|
RestClient::Request.execute(
|
@@ -124,7 +133,7 @@ module NexusAPI
|
|
124
133
|
# paginate answers is the user requesting pagination, paginate? answers does a continuation token exist
|
125
134
|
# if an empty continuation token is included in the request we'll get an ArrayIndexOutOfBoundsException
|
126
135
|
endpoint += "#{url_marker}continuationToken=#{@continuation_token}" if paginate && paginate?
|
127
|
-
|
136
|
+
send_request(
|
128
137
|
:get,
|
129
138
|
endpoint,
|
130
139
|
headers: headers,
|
data/lib/nexus_api/version.rb
CHANGED
@@ -1,5 +1,3 @@
|
|
1
|
-
require 'json'
|
2
|
-
|
3
1
|
module NexusAPI
|
4
2
|
class ParameterBuilder
|
5
3
|
# Write Policies
|
@@ -30,7 +28,7 @@ module NexusAPI
|
|
30
28
|
'forceBasicAuth' => true,
|
31
29
|
'httpPort' => port
|
32
30
|
}
|
33
|
-
}
|
31
|
+
}
|
34
32
|
end
|
35
33
|
|
36
34
|
def self.maven_hosted(name, write_policy: ALLOW_ONCE, version_policy: RELEASE, layout_policy: STRICT)
|
@@ -46,7 +44,7 @@ module NexusAPI
|
|
46
44
|
'versionPolicy' => version_policy,
|
47
45
|
'layoutPolicy' => layout_policy
|
48
46
|
}
|
49
|
-
}
|
47
|
+
}
|
50
48
|
end
|
51
49
|
|
52
50
|
def self.npm_hosted(name, write_policy: ALLOW_ONCE)
|
@@ -58,7 +56,7 @@ module NexusAPI
|
|
58
56
|
'strictContentTypeValidation' => true,
|
59
57
|
'writePolicy' => write_policy
|
60
58
|
}
|
61
|
-
}
|
59
|
+
}
|
62
60
|
end
|
63
61
|
|
64
62
|
def self.pypi_hosted(name, write_policy: ALLOW_ONCE)
|
@@ -70,7 +68,31 @@ module NexusAPI
|
|
70
68
|
'strictContentTypeValidation' => true,
|
71
69
|
'writePolicy' => write_policy
|
72
70
|
}
|
73
|
-
}
|
71
|
+
}
|
72
|
+
end
|
73
|
+
|
74
|
+
def self.raw_hosted(name, write_policy: ALLOW_ONCE)
|
75
|
+
{
|
76
|
+
'name' => name,
|
77
|
+
'online' => true,
|
78
|
+
'storage' => {
|
79
|
+
'blobStoreName' => 'default',
|
80
|
+
'strictContentTypeValidation' => true,
|
81
|
+
'writePolicy' => write_policy
|
82
|
+
}
|
83
|
+
}
|
84
|
+
end
|
85
|
+
|
86
|
+
def self.rubygems_hosted(name, write_policy: ALLOW_ONCE)
|
87
|
+
{
|
88
|
+
'name' => name,
|
89
|
+
'online' => true,
|
90
|
+
'storage' => {
|
91
|
+
'blobStoreName' => 'default',
|
92
|
+
'strictContentTypeValidation' => true,
|
93
|
+
'writePolicy' => write_policy
|
94
|
+
}
|
95
|
+
}
|
74
96
|
end
|
75
97
|
|
76
98
|
def self.yum_hosted(name, depth, write_policy: ALLOW_ONCE, deploy_policy: STRICT)
|
@@ -86,7 +108,7 @@ module NexusAPI
|
|
86
108
|
'repodataDepth' => depth,
|
87
109
|
'deployPolicy' => deploy_policy
|
88
110
|
}
|
89
|
-
}
|
111
|
+
}
|
90
112
|
end
|
91
113
|
end
|
92
114
|
end
|