nexus_api 1.2.1 → 1.6.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: 2379edda3e2f2845f6151d103bab5ddb73431fab4a32c1a8509f02348848fc81
4
- data.tar.gz: 787df5287d2626911972936c63686482b7a4eee20043a23d8fa505cdfb4f5b90
3
+ metadata.gz: 7b981b77e2fa8974130a33a27630ce244b53b687b97a2114bc63105711801da8
4
+ data.tar.gz: a3f630982cbc1f490d96972873c60754993b801b57a3a039e59a82d9b3a2058b
5
5
  SHA512:
6
- metadata.gz: a6693a438c77406ca6a4b38cf57f55c24f6c590a0f4897bba86c34af20521f88a0a3db7cc18ff10aa200e85929849dc648bdc8a46769d97457df4447cdb35a26
7
- data.tar.gz: 8feb5be1d4860e6ab89f3f061a047d6ee1bb8bd10a153ab288d8dd56866c9cfcef73da51ca734e18fae287bd559a6055434761f8c80b205a97f883531dba985e
6
+ metadata.gz: 30d6669a51b4efdce8cfb1590b1ad2ba768772c74f932e515c7191f300fbb78ed4bf600e33a26c9513055e7ca4dbb5a508a7963d862354ce564a9a3ed1d6c5e7
7
+ data.tar.gz: 979cc37ee0887b22a2cb7fca2c4cbe2bd102c0cd0e4423e95aad068720bc27b40e76294fe7519e277d300710dd0774e7141bd2b64bf9c36250423546cb2906fc
@@ -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.0](https://github.com/Cisco-AMP/nexus_api/compare/v1.5.0...v1.6.0) - 2020-07-20
9
+ ### Added
10
+ - `create_repository_raw_hosted()`
11
+ - `create_repository_rubygems_hosted()`
12
+
13
+
14
+ ## [1.5.0](https://github.com/Cisco-AMP/nexus_api/compare/v1.4.1...v1.5.0) - 2020-06-10
15
+ ### Added
16
+ - New methods around the `privileges` endpoint
17
+ - New methods around the `roles` endpoint
18
+ - New methods around the `users` endpoint
19
+ - 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
20
+
21
+
22
+ ## [1.4.1](https://github.com/Cisco-AMP/nexus_api/compare/v1.4.0...v1.4.1) - 2020-05-08
23
+ ### Changed
24
+ - Error reporting to be more descriptive
25
+
26
+
27
+ ## [1.4.0](https://github.com/Cisco-AMP/nexus_api/compare/v1.3.0...v1.4.0) - 2020-05-05
28
+ ### Added
29
+ - Optional `tag` parameter to `associate_tag()` and `delete_associated_tag()` methods
30
+
31
+ ### Changed
32
+ - Made `sha1` parameter optional for `associate_tag()` and `delete_associated_tag()` methods
33
+
34
+
35
+ ## [1.3.0](https://github.com/Cisco-AMP/nexus_api/compare/v1.2.1...v1.3.0) - 2020-04-30
36
+ ### Added
37
+ - Optional source and general keyword match into staging endpoint method (`move_components_to()`)
38
+
39
+
8
40
  ## [1.2.1](https://github.com/Cisco-AMP/nexus_api/compare/v1.2.0...v1.2.1) - 2020-04-29
9
41
  ### Fixed
10
42
  - Correctly building request URLs when pagination is the only argument
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- nexus_api (1.2.1)
4
+ nexus_api (1.6.0)
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.2)
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.2019.1009)
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
@@ -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,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}
@@ -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
@@ -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
@@ -2,8 +2,11 @@ module NexusAPI
2
2
  class API
3
3
  # POST /service/rest/v1/staging/delete
4
4
  # POST /service/rest/v1/staging/move/{destination}
5
- def move_components_to(destination:, tag:)
6
- @connection.post(endpoint: "staging/move/#{destination}?tag=#{tag}")
5
+ def move_components_to(destination:, tag:, source: nil, keyword: nil)
6
+ endpoint = "staging/move/#{destination}?tag=#{tag}"
7
+ endpoint += "&repository=#{source}" unless source.nil?
8
+ endpoint += "&q=#{keyword}" unless keyword.nil?
9
+ @connection.post(endpoint: endpoint)
7
10
  end
8
11
  end
9
12
  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({
@@ -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:, repository: nil)
33
+ def associate_tag(name:, sha1: nil, repository: nil, tag: nil)
25
34
  repository ||= @team_config.tag_repository
26
- search_query =
27
- "?"\
28
- "wait=true&"\
29
- "repository=#{repository}&"\
30
- "sha1=#{sha1}"
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:, repository: nil)
49
+ def delete_associated_tag(name:, sha1: nil, repository: nil, tag: nil)
36
50
  repository ||= @team_config.tag_repository
37
- search_query =
38
- "?"\
39
- "repository=#{repository}&"\
40
- "sha1=#{sha1}"
41
- @connection.delete(endpoint: "tags/associate/#{name}" + search_query)
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
@@ -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
- image = @docker.pull_image(@username, @password, image_name)
19
- rescue Docker::Error::NotFoundError => error
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
- puts error.description if error.is_a?(RestClient::Response)
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
- response = send_request(
136
+ send_request(
128
137
  :get,
129
138
  endpoint,
130
139
  headers: headers,
@@ -1,4 +1,4 @@
1
1
  module NexusAPI
2
- VERSION = '1.2.1'
2
+ VERSION = '1.6.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,31 @@ module NexusAPI
70
70
  'strictContentTypeValidation' => true,
71
71
  'writePolicy' => write_policy
72
72
  }
73
- }.to_json
73
+ }
74
+ end
75
+
76
+ def self.raw_hosted(name, write_policy: ALLOW_ONCE)
77
+ {
78
+ 'name' => name,
79
+ 'online' => true,
80
+ 'storage' => {
81
+ 'blobStoreName' => 'default',
82
+ 'strictContentTypeValidation' => true,
83
+ 'writePolicy' => write_policy
84
+ }
85
+ }
86
+ end
87
+
88
+ def self.rubygems_hosted(name, write_policy: ALLOW_ONCE)
89
+ {
90
+ 'name' => name,
91
+ 'online' => true,
92
+ 'storage' => {
93
+ 'blobStoreName' => 'default',
94
+ 'strictContentTypeValidation' => true,
95
+ 'writePolicy' => write_policy
96
+ }
97
+ }
74
98
  end
75
99
 
76
100
  def self.yum_hosted(name, depth, write_policy: ALLOW_ONCE, deploy_policy: STRICT)
@@ -86,7 +110,7 @@ module NexusAPI
86
110
  'repodataDepth' => depth,
87
111
  'deployPolicy' => deploy_policy
88
112
  }
89
- }.to_json
113
+ }
90
114
  end
91
115
  end
92
116
  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.2.1
4
+ version: 1.6.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Francis Levesque