nexus_api 1.4.1 → 1.5.0

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: ae2066e62934bcfeed3480aa351da4ad8053d258c762b4ed8cfc006a64eae7c3
4
+ data.tar.gz: 597ba898fabbf3efcb1c2ab22f0557875d33cb6af24fd8a9338cf7be4c83b942
5
5
  SHA512:
6
- metadata.gz: 52ee4482ce15c00b1eae0064c0445c6862cd4bc876e915335c923bc2f1f024bd0cb0cdee09ac41d917fe7d1abfe3a5f4dbcc717894e36e8e5a016eb54605b82e
7
- data.tar.gz: ff03e64fdeb4e9c28ffcc94329ca79e2526411982ae36f40177dab99dbef6279810e5bebdfbae5fb50ec324f7f61fc64b6d8a3218b93e726ba44e44183fd3f5a
6
+ metadata.gz: 3015d930671ca0f18b89647f55a2fda2496c5ddd5c3df9540cd2d0012530a8ecf379f9aeaead6ab7a8a132e45c825cf89d25a78efb2b58b999343698a6d6531d
7
+ data.tar.gz: f217d6c26156c2dc7960ce5f393b211bdc560134ede1cb95658a7c0e4b54c4f6b02f8ff4e055f2d573c0082e487f223cd90018966ef97249d390e8d0c8ad386b
@@ -5,6 +5,14 @@ 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.5.0](https://github.com/Cisco-AMP/nexus_api/compare/v1.4.1...v1.5.0) - 2020-06-10
9
+ ### Added
10
+ - New methods around the `privileges` endpoint
11
+ - New methods around the `roles` endpoint
12
+ - New methods around the `users` endpoint
13
+ - 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
14
+
15
+
8
16
  ## [1.4.1](https://github.com/Cisco-AMP/nexus_api/compare/v1.4.0...v1.4.1) - 2020-05-08
9
17
  ### Changed
10
18
  - Error reporting to be more descriptive
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- nexus_api (1.4.1)
4
+ nexus_api (1.5.0)
5
5
  bundler (~> 2)
6
6
  docker-api (~> 1.34.2)
7
7
  dotenv (~> 2.7.5)
@@ -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.0425)
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.0.2
87
+ 2.1.4
data/README.md CHANGED
@@ -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: 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
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 pattern to page through each method:
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))
@@ -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}")
@@ -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
@@ -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}
@@ -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
@@ -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
@@ -5,6 +5,15 @@ 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
19
  parameters = JSON.dump({
@@ -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
@@ -116,6 +116,7 @@ module NexusAPI
116
116
  end
117
117
 
118
118
  def send_request(connection_method, endpoint, parameters: '', headers: {}, api_version: 'v1')
119
+ parameters = parameters.to_json if headers['Content-Type'] == 'application/json'
119
120
  url = "https://#{@hostname}/service/rest/#{api_version}/#{endpoint}"
120
121
  catch_connection_error do
121
122
  RestClient::Request.execute(
@@ -1,4 +1,4 @@
1
1
  module NexusAPI
2
- VERSION = '1.4.1'
2
+ VERSION = '1.5.0'
3
3
  end
4
4
 
@@ -30,7 +30,7 @@ module NexusAPI
30
30
  'forceBasicAuth' => true,
31
31
  'httpPort' => port
32
32
  }
33
- }.to_json
33
+ }
34
34
  end
35
35
 
36
36
  def self.maven_hosted(name, write_policy: ALLOW_ONCE, version_policy: RELEASE, layout_policy: STRICT)
@@ -46,7 +46,7 @@ module NexusAPI
46
46
  'versionPolicy' => version_policy,
47
47
  'layoutPolicy' => layout_policy
48
48
  }
49
- }.to_json
49
+ }
50
50
  end
51
51
 
52
52
  def self.npm_hosted(name, write_policy: ALLOW_ONCE)
@@ -58,7 +58,7 @@ module NexusAPI
58
58
  'strictContentTypeValidation' => true,
59
59
  'writePolicy' => write_policy
60
60
  }
61
- }.to_json
61
+ }
62
62
  end
63
63
 
64
64
  def self.pypi_hosted(name, write_policy: ALLOW_ONCE)
@@ -70,7 +70,7 @@ module NexusAPI
70
70
  'strictContentTypeValidation' => true,
71
71
  'writePolicy' => write_policy
72
72
  }
73
- }.to_json
73
+ }
74
74
  end
75
75
 
76
76
  def self.yum_hosted(name, depth, write_policy: ALLOW_ONCE, deploy_policy: STRICT)
@@ -86,7 +86,7 @@ module NexusAPI
86
86
  'repodataDepth' => depth,
87
87
  'deployPolicy' => deploy_policy
88
88
  }
89
- }.to_json
89
+ }
90
90
  end
91
91
  end
92
92
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: nexus_api
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.4.1
4
+ version: 1.5.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Francis Levesque