Class: NexusAPI::API
- Inherits:
-
Object
- Object
- NexusAPI::API
- Defined in:
- lib/nexus_api.rb,
lib/endpoints/iq.rb,
lib/endpoints/ssl.rb,
lib/endpoints/ldap.rb,
lib/endpoints/saml.rb,
lib/endpoints/tags.rb,
lib/endpoints/email.rb,
lib/endpoints/roles.rb,
lib/endpoints/tasks.rb,
lib/endpoints/users.rb,
lib/endpoints/assets.rb,
lib/endpoints/realms.rb,
lib/endpoints/script.rb,
lib/endpoints/search.rb,
lib/endpoints/status.rb,
lib/endpoints/formats.rb,
lib/endpoints/license.rb,
lib/endpoints/staging.rb,
lib/endpoints/support.rb,
lib/endpoints/blobstore.rb,
lib/endpoints/lifecycle.rb,
lib/endpoints/read-only.rb,
lib/endpoints/components.rb,
lib/endpoints/privileges.rb,
lib/endpoints/user-tokens.rb,
lib/endpoints/repositories.rb,
lib/endpoints/user-sources.rb,
lib/endpoints/routing-rules.rb,
lib/endpoints/content-selectors.rb
Constant Summary collapse
- TEAM_CONFIG =
File.join(File.dirname(__dir__), 'team_configs/default.yaml').freeze
Instance Attribute Summary collapse
-
#connection ⇒ Object
Returns the value of attribute connection.
-
#docker ⇒ Object
Returns the value of attribute docker.
-
#team_config ⇒ Object
Returns the value of attribute team_config.
Instance Method Summary collapse
-
#associate_tag(name:, sha1: nil, repository: nil, tag: nil) ⇒ Object
POST /service/rest/v1/tags/associate/tagName.
-
#create_privilege_repository_view(name:, description: nil, actions: ['READ'], format: '*', repository: '*') ⇒ Object
POST /service/rest/beta/security/privileges/application PUT /service/rest/beta/security/privileges/application/privilegeId POST /service/rest/beta/security/privileges/repository-admin PUT /service/rest/beta/security/privileges/repository-admin/privilegeId POST /service/rest/beta/security/privileges/repository-content-selector PUT /service/rest/beta/security/privileges/repository-content-selector/privilegeId POST /service/rest/beta/security/privileges/repository-view.
-
#create_repository_docker_hosted(name:, port:) ⇒ Object
POST /service/rest/beta/repositories/repositoryName/health-check DELETE /service/rest/beta/repositories/repositoryName/health-check POST /service/rest/beta/repositories/repositoryName/invalidate-cache POST /service/rest/beta/repositories/repositoryName/rebuild-index POST /service/rest/beta/repositories/apt/hosted PUT /service/rest/beta/repositories/apt/hosted/repositoryName POST /service/rest/beta/repositories/apt/proxy PUT /service/rest/beta/repositories/apt/proxy/repositoryName POST /service/rest/beta/repositories/bower/group PUT /service/rest/beta/repositories/bower/group/repositoryName POST /service/rest/beta/repositories/bower/hosted PUT /service/rest/beta/repositories/bower/hosted/repositoryName POST /service/rest/beta/repositories/bower/proxy PUT /service/rest/beta/repositories/bower/proxy/repositoryName POST /service/rest/beta/repositories/conan/proxy PUT /service/rest/beta/repositories/conan/proxy/repositoryName POST /service/rest/beta/repositories/docker/group PUT /service/rest/beta/repositories/docker/group/repositoryName POST /service/rest/beta/repositories/docker/hosted.
-
#create_repository_maven_hosted(name:) ⇒ Object
PUT /service/rest/beta/repositories/docker/hosted/repositoryName POST /service/rest/beta/repositories/docker/proxy PUT /service/rest/beta/repositories/docker/proxy/repositoryName POST /service/rest/beta/repositories/gitlfs/hosted PUT /service/rest/beta/repositories/gitlfs/hosted/repositoryName POST /service/rest/beta/repositories/go/group PUT /service/rest/beta/repositories/go/group/repositoryName POST /service/rest/beta/repositories/go/proxy PUT /service/rest/beta/repositories/go/proxy/repositoryName POST /service/rest/beta/repositories/helm/hosted PUT /service/rest/beta/repositories/helm/hosted/repositoryName POST /service/rest/beta/repositories/helm/proxy PUT /service/rest/beta/repositories/helm/proxy/repositoryName POST /service/rest/beta/repositories/maven/hosted.
-
#create_repository_npm_hosted(name:) ⇒ Object
PUT /service/rest/beta/repositories/maven/hosted/repositoryName POST /service/rest/beta/repositories/maven/proxy PUT /service/rest/beta/repositories/maven/proxy/repositoryName POST /service/rest/beta/repositories/npm/group PUT /service/rest/beta/repositories/npm/group/repositoryName POST /service/rest/beta/repositories/npm/hosted.
-
#create_repository_pypi_hosted(name:) ⇒ Object
PUT /service/rest/beta/repositories/npm/hosted/repositoryName POST /service/rest/beta/repositories/npm/proxy PUT /service/rest/beta/repositories/npm/proxy/repositoryName POST /service/rest/beta/repositories/nuget/group PUT /service/rest/beta/repositories/nuget/group/repositoryName POST /service/rest/beta/repositories/nuget/hosted PUT /service/rest/beta/repositories/nuget/hosted/repositoryName POST /service/rest/beta/repositories/nuget/proxy PUT /service/rest/beta/repositories/nuget/proxy/repositoryName POST /service/rest/beta/repositories/p2/proxy PUT /service/rest/beta/repositories/p2/proxy/repositoryName POST /service/rest/beta/repositories/pypi/group PUT /service/rest/beta/repositories/pypi/group/repositoryName POST /service/rest/beta/repositories/pypi/hosted.
-
#create_repository_yum_hosted(name:, depth:) ⇒ Object
PUT /service/rest/beta/repositories/pypi/hosted/repositoryName POST /service/rest/beta/repositories/pypi/proxy PUT /service/rest/beta/repositories/pypi/proxy/repositoryName POST /service/rest/beta/repositories/yum/hosted.
-
#create_role(id:, name:, description: nil, privileges: [], roles: []) ⇒ Object
POST /service/rest/beta/security/roles.
-
#create_tag(name:) ⇒ Object
POST /service/rest/v1/tags.
-
#create_user(user_id:, first_name:, last_name:, email:, password:, roles:) ⇒ Object
POST /service/rest/beta/security/users.
-
#delete_associated_tag(name:, sha1: nil, repository: nil, tag: nil) ⇒ Object
DELETE /service/rest/v1/tags/associate/tagName.
- #delete_local_docker_image(image:, tag:) ⇒ Object
-
#delete_privilege(privilege_id:) ⇒ Object
DELETE /service/rest/beta/security/privileges/privilegeId.
-
#delete_repository(name:) ⇒ Object
DELETE /service/rest/beta/repositories/repositoryName.
-
#delete_role(id:) ⇒ Object
PUT /service/rest/beta/security/roles/id DELETE /service/rest/beta/security/roles/id.
-
#delete_script(name:) ⇒ Object
GET /service/rest/v1/script/name PUT /service/rest/v1/script/name DELETE /service/rest/v1/script/name.
-
#delete_tag(name:) ⇒ Object
GET /service/rest/v1/tags/name PUT /service/rest/v1/tags/name DELETE /service/rest/v1/tags/name.
-
#delete_user(user_id:) ⇒ Object
PUT /service/rest/beta/security/users/userId DELETE /service/rest/beta/security/users/userId.
- #docker_ready? ⇒ Boolean
- #download(id:, name: nil) ⇒ Object
- #download_docker_component(image:, tag:) ⇒ Object
- #get_asset_size(asset_url:) ⇒ Object
-
#initialize(username:, password:, hostname:, docker_pull_hostname: nil, docker_push_hostname: nil, team_config: nil) ⇒ API
constructor
A new instance of API.
- #list_all_assets(repository: nil) ⇒ Object
- #list_all_components(repository: nil) ⇒ Object
- #list_all_tags ⇒ Object
-
#list_asset(id:) ⇒ Object
GET /service/rest/v1/assets/id.
-
#list_assets(repository: nil, paginate: false) ⇒ Object
GET /service/rest/v1/assets.
-
#list_component(id:) ⇒ Object
GET /service/rest/v1/components/id.
-
#list_components(repository: nil, paginate: false) ⇒ Object
GET /service/rest/v1/components.
-
#list_privilege(privilege_id:) ⇒ Object
GET /service/rest/beta/security/privileges/privilegeId.
-
#list_privileges ⇒ Object
GET /service/rest/beta/security/privileges.
-
#list_repositories ⇒ Object
GET /service/rest/v1/repositories (This endpoint does not paginate) GET /service/rest/beta/repositories.
- #list_repository_names ⇒ Object
-
#list_role(id:) ⇒ Object
GET /service/rest/beta/security/roles/id.
-
#list_roles ⇒ Object
GET /service/rest/beta/security/roles.
-
#list_scripts ⇒ Object
GET /service/rest/v1/script.
-
#list_tags(paginate: false) ⇒ Object
GET /service/rest/v1/tags.
-
#list_users ⇒ Object
GET /service/rest/beta/security/users.
- #local_docker_image_exists?(image:, tag:) ⇒ Boolean
-
#move_components_to(destination:, tag:, source: nil, keyword: nil) ⇒ Object
POST /service/rest/v1/staging/delete POST /service/rest/v1/staging/move/destination.
- #paginate? ⇒ Boolean
-
#run_script(name:) ⇒ Object
POST /service/rest/v1/script/name/run.
- #search_all_assets(name:, format: nil, repository: nil, sha1: nil, version: nil) ⇒ Object
-
#search_asset(name:, format: nil, repository: nil, sha1: nil, version: nil, paginate: false) ⇒ Object
GET /service/rest/v1/search/assets.
-
#status ⇒ Object
GET /service/rest/v1/status.
-
#status_writable ⇒ Object
GET /service/rest/v1/status/writable.
- #upload_docker_component(image:, tag:) ⇒ Object
-
#upload_maven_component(filename:, group_id:, artifact_id:, version:, repository: nil, tag: nil) ⇒ Object
POST /service/rest/v1/components.
- #upload_npm_component(filename:, repository: nil, tag: nil) ⇒ Object
- #upload_pypi_component(filename:, repository: nil, tag: nil) ⇒ Object
- #upload_raw_component(filename:, directory:, repository: nil, tag: nil) ⇒ Object
- #upload_rubygems_component(filename:, repository: nil, tag: nil) ⇒ Object
-
#upload_script(filename:) ⇒ Object
POST /service/rest/v1/script.
- #upload_yum_component(filename:, directory:, repository: nil, tag: nil) ⇒ Object
Constructor Details
#initialize(username:, password:, hostname:, docker_pull_hostname: nil, docker_push_hostname: nil, team_config: nil) ⇒ API
Returns a new instance of API.
20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 |
# File 'lib/nexus_api.rb', line 20 def initialize(username:, password:, hostname:, docker_pull_hostname: nil, docker_push_hostname: nil, team_config: nil) @connection = NexusAPI::NexusConnection.new( username: username, password: password, hostname: hostname, ) if docker_pull_hostname.nil? || docker_push_hostname.nil? @docker = nil else @docker = NexusAPI::DockerManager.new( docker: NexusAPI::DockerShell.new, options: { 'username' => username, 'password' => password, 'pull_host' => docker_pull_hostname, 'push_host' => docker_push_hostname, } ) end team_config ||= TEAM_CONFIG @team_config = NexusAPI::ConfigManager.new(config_path: team_config) end |
Instance Attribute Details
#connection ⇒ Object
Returns the value of attribute connection.
14 15 16 |
# File 'lib/nexus_api.rb', line 14 def connection @connection end |
#docker ⇒ Object
Returns the value of attribute docker.
15 16 17 |
# File 'lib/nexus_api.rb', line 15 def docker @docker end |
#team_config ⇒ Object
Returns the value of attribute team_config.
16 17 18 |
# File 'lib/nexus_api.rb', line 16 def team_config @team_config end |
Instance Method Details
#associate_tag(name:, sha1: nil, repository: nil, tag: nil) ⇒ Object
POST /service/rest/v1/tags/associate/tagName
33 34 35 36 37 38 39 40 41 42 43 44 45 46 |
# File 'lib/endpoints/tags.rb', line 33 def associate_tag(name:, sha1: nil, repository: nil, tag: nil) repository ||= @team_config.tag_repository if sha1.nil? && repository.nil? && tag.nil? puts_error(__method__) return false end search_query = "?wait=true" search_query += "&sha1=#{sha1}" unless sha1.nil? search_query += "&repository=#{repository}" unless repository.nil? search_query += "&tag=#{tag}" unless tag.nil? @connection.post(endpoint: "tags/associate/#{name}" + search_query) end |
#create_privilege_repository_view(name:, description: nil, actions: ['READ'], format: '*', repository: '*') ⇒ Object
POST /service/rest/beta/security/privileges/application PUT /service/rest/beta/security/privileges/application/privilegeId POST /service/rest/beta/security/privileges/repository-admin PUT /service/rest/beta/security/privileges/repository-admin/privilegeId POST /service/rest/beta/security/privileges/repository-content-selector PUT /service/rest/beta/security/privileges/repository-content-selector/privilegeId POST /service/rest/beta/security/privileges/repository-view
25 26 27 28 29 30 31 32 33 34 35 36 37 38 |
# File 'lib/endpoints/privileges.rb', line 25 def create_privilege_repository_view(name:, description: nil, actions: ['READ'], format: '*', repository: '*') parameters = { # The name is also used as the privilege_id 'name' => name, 'description' => description, # READ, BROWSE, EDIT, ADD, DELETE, RUN, ASSOCIATE, DISASSOCIATE, ALL 'actions' => actions, # The repository format (i.e 'nuget', 'npm') this privilege will grant access to (or * for all) 'format' => format, # The name of the repository this privilege will grant access to (or * for all) 'repository' => repository } @connection.post(endpoint: 'security/privileges/repository-view', parameters: parameters, api_version: 'beta') end |
#create_repository_docker_hosted(name:, port:) ⇒ Object
POST /service/rest/beta/repositories/repositoryName/health-check DELETE /service/rest/beta/repositories/repositoryName/health-check POST /service/rest/beta/repositories/repositoryName/invalidate-cache POST /service/rest/beta/repositories/repositoryName/rebuild-index POST /service/rest/beta/repositories/apt/hosted PUT /service/rest/beta/repositories/apt/hosted/repositoryName POST /service/rest/beta/repositories/apt/proxy PUT /service/rest/beta/repositories/apt/proxy/repositoryName POST /service/rest/beta/repositories/bower/group PUT /service/rest/beta/repositories/bower/group/repositoryName POST /service/rest/beta/repositories/bower/hosted PUT /service/rest/beta/repositories/bower/hosted/repositoryName POST /service/rest/beta/repositories/bower/proxy PUT /service/rest/beta/repositories/bower/proxy/repositoryName POST /service/rest/beta/repositories/conan/proxy PUT /service/rest/beta/repositories/conan/proxy/repositoryName POST /service/rest/beta/repositories/docker/group PUT /service/rest/beta/repositories/docker/group/repositoryName POST /service/rest/beta/repositories/docker/hosted
39 40 41 42 |
# File 'lib/endpoints/repositories.rb', line 39 def create_repository_docker_hosted(name:, port:) parameters = ParameterBuilder.docker_hosted(name, port) @connection.post(endpoint: 'repositories/docker/hosted', parameters: parameters, api_version: 'beta') end |
#create_repository_maven_hosted(name:) ⇒ Object
PUT /service/rest/beta/repositories/docker/hosted/repositoryName POST /service/rest/beta/repositories/docker/proxy PUT /service/rest/beta/repositories/docker/proxy/repositoryName POST /service/rest/beta/repositories/gitlfs/hosted PUT /service/rest/beta/repositories/gitlfs/hosted/repositoryName POST /service/rest/beta/repositories/go/group PUT /service/rest/beta/repositories/go/group/repositoryName POST /service/rest/beta/repositories/go/proxy PUT /service/rest/beta/repositories/go/proxy/repositoryName POST /service/rest/beta/repositories/helm/hosted PUT /service/rest/beta/repositories/helm/hosted/repositoryName POST /service/rest/beta/repositories/helm/proxy PUT /service/rest/beta/repositories/helm/proxy/repositoryName POST /service/rest/beta/repositories/maven/hosted
58 59 60 61 |
# File 'lib/endpoints/repositories.rb', line 58 def create_repository_maven_hosted(name:) parameters = ParameterBuilder.maven_hosted(name) @connection.post(endpoint: 'repositories/maven/hosted', parameters: parameters, api_version: 'beta') end |
#create_repository_npm_hosted(name:) ⇒ Object
PUT /service/rest/beta/repositories/maven/hosted/repositoryName POST /service/rest/beta/repositories/maven/proxy PUT /service/rest/beta/repositories/maven/proxy/repositoryName POST /service/rest/beta/repositories/npm/group PUT /service/rest/beta/repositories/npm/group/repositoryName POST /service/rest/beta/repositories/npm/hosted
69 70 71 72 |
# File 'lib/endpoints/repositories.rb', line 69 def create_repository_npm_hosted(name:) parameters = ParameterBuilder.npm_hosted(name) @connection.post(endpoint: 'repositories/npm/hosted', parameters: parameters, api_version: 'beta') end |
#create_repository_pypi_hosted(name:) ⇒ Object
PUT /service/rest/beta/repositories/npm/hosted/repositoryName POST /service/rest/beta/repositories/npm/proxy PUT /service/rest/beta/repositories/npm/proxy/repositoryName POST /service/rest/beta/repositories/nuget/group PUT /service/rest/beta/repositories/nuget/group/repositoryName POST /service/rest/beta/repositories/nuget/hosted PUT /service/rest/beta/repositories/nuget/hosted/repositoryName POST /service/rest/beta/repositories/nuget/proxy PUT /service/rest/beta/repositories/nuget/proxy/repositoryName POST /service/rest/beta/repositories/p2/proxy PUT /service/rest/beta/repositories/p2/proxy/repositoryName POST /service/rest/beta/repositories/pypi/group PUT /service/rest/beta/repositories/pypi/group/repositoryName POST /service/rest/beta/repositories/pypi/hosted
88 89 90 91 |
# File 'lib/endpoints/repositories.rb', line 88 def create_repository_pypi_hosted(name:) parameters = ParameterBuilder.pypi_hosted(name) @connection.post(endpoint: 'repositories/pypi/hosted', parameters: parameters, api_version: 'beta') end |
#create_repository_yum_hosted(name:, depth:) ⇒ Object
PUT /service/rest/beta/repositories/pypi/hosted/repositoryName POST /service/rest/beta/repositories/pypi/proxy PUT /service/rest/beta/repositories/pypi/proxy/repositoryName POST /service/rest/beta/repositories/yum/hosted
97 98 99 100 |
# File 'lib/endpoints/repositories.rb', line 97 def create_repository_yum_hosted(name:, depth:) parameters = ParameterBuilder.yum_hosted(name, depth) @connection.post(endpoint: 'repositories/yum/hosted', parameters: parameters, api_version: 'beta') end |
#create_role(id:, name:, description: nil, privileges: [], roles: []) ⇒ Object
POST /service/rest/beta/security/roles
9 10 11 12 13 14 15 16 17 18 |
# File 'lib/endpoints/roles.rb', line 9 def create_role(id:, name:, description: nil, privileges: [], roles: []) parameters = { 'id' => id, 'name' => name, 'description' => description, 'privileges' => privileges, 'roles' => roles } @connection.post(endpoint: 'security/roles', parameters: parameters, api_version: 'beta') end |
#create_tag(name:) ⇒ Object
POST /service/rest/v1/tags
18 19 20 21 22 23 |
# File 'lib/endpoints/tags.rb', line 18 def create_tag(name:) parameters = JSON.dump({ 'name' => name, }) @connection.post(endpoint: 'tags', parameters: parameters) end |
#create_user(user_id:, first_name:, last_name:, email:, password:, roles:) ⇒ Object
POST /service/rest/beta/security/users
9 10 11 12 13 14 15 16 17 18 19 20 |
# File 'lib/endpoints/users.rb', line 9 def create_user(user_id:, first_name:, last_name:, email:, password:, roles:) parameters = { 'userId' => user_id, 'firstName' => first_name, 'lastName' => last_name, 'emailAddress' => email, 'password' => password, 'status' => 'active', 'roles' => roles, } @connection.post(endpoint: 'security/users', parameters: parameters, api_version: 'beta') end |
#delete_associated_tag(name:, sha1: nil, repository: nil, tag: nil) ⇒ Object
DELETE /service/rest/v1/tags/associate/tagName
49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 |
# File 'lib/endpoints/tags.rb', line 49 def delete_associated_tag(name:, sha1: nil, repository: nil, tag: nil) repository ||= @team_config.tag_repository parameters = {} parameters['sha1'] = sha1 unless sha1.nil? parameters['repository'] = repository unless repository.nil? parameters['tag'] = tag unless tag.nil? if parameters.empty? puts_error(__method__) return false end search_query = parameters.map do |parameter, value| "#{parameter}=#{value}" end.join("&") @connection.delete(endpoint: "tags/associate/#{name}?" + search_query) end |
#delete_local_docker_image(image:, tag:) ⇒ Object
67 68 69 |
# File 'lib/nexus_api.rb', line 67 def delete_local_docker_image(image:, tag:) @docker.delete(image_name: image, tag: tag) if docker_ready? end |
#delete_privilege(privilege_id:) ⇒ Object
DELETE /service/rest/beta/security/privileges/privilegeId
14 15 16 |
# File 'lib/endpoints/privileges.rb', line 14 def delete_privilege(privilege_id:) @connection.delete(endpoint: "security/privileges/#{privilege_id}", api_version: 'beta') end |
#delete_repository(name:) ⇒ Object
DELETE /service/rest/beta/repositories/repositoryName
16 17 18 |
# File 'lib/endpoints/repositories.rb', line 16 def delete_repository(name:) @connection.delete(endpoint: "repositories/#{name}", api_version: 'beta') end |
#delete_role(id:) ⇒ Object
PUT /service/rest/beta/security/roles/id DELETE /service/rest/beta/security/roles/id
27 28 29 |
# File 'lib/endpoints/roles.rb', line 27 def delete_role(id:) @connection.delete(endpoint: "security/roles/#{id}", api_version: 'beta') end |
#delete_script(name:) ⇒ Object
GET /service/rest/v1/script/name PUT /service/rest/v1/script/name DELETE /service/rest/v1/script/name
18 19 20 |
# File 'lib/endpoints/script.rb', line 18 def delete_script(name:) @connection.delete(endpoint: "script/#{name}") end |
#delete_tag(name:) ⇒ Object
GET /service/rest/v1/tags/name PUT /service/rest/v1/tags/name DELETE /service/rest/v1/tags/name
28 29 30 |
# File 'lib/endpoints/tags.rb', line 28 def delete_tag(name:) @connection.delete(endpoint: "tags/#{name}") end |
#delete_user(user_id:) ⇒ Object
PUT /service/rest/beta/security/users/userId DELETE /service/rest/beta/security/users/userId
24 25 26 |
# File 'lib/endpoints/users.rb', line 24 def delete_user(user_id:) @connection.delete(endpoint: "security/users/#{user_id}", api_version: 'beta') end |
#docker_ready? ⇒ Boolean
47 48 49 50 51 52 53 |
# File 'lib/nexus_api.rb', line 47 def docker_ready? if @docker.nil? raise 'Docker push and pull endpoints not initialized!' return false end true end |
#download(id:, name: nil) ⇒ Object
71 72 73 74 75 76 77 78 79 80 81 82 83 |
# File 'lib/nexus_api.rb', line 71 def download(id:, name: nil) asset = list_asset(id: id) return false if asset == '' || asset.empty? return false if asset["downloadUrl"].nil? url = asset["downloadUrl"] response = @connection.download(url: url) if name File.write(name, response.body) else File.write(url.split('/').last, response.body) end true end |
#download_docker_component(image:, tag:) ⇒ Object
55 56 57 |
# File 'lib/nexus_api.rb', line 55 def download_docker_component(image:, tag:) @docker.download(image_name: image, tag: tag) if docker_ready? end |
#get_asset_size(asset_url:) ⇒ Object
43 44 45 |
# File 'lib/nexus_api.rb', line 43 def get_asset_size(asset_url:) @connection.content_length(asset_url: asset_url) end |
#list_all_assets(repository: nil) ⇒ Object
9 10 11 12 13 14 15 16 |
# File 'lib/endpoints/assets.rb', line 9 def list_all_assets(repository: nil) assets = Array.new.tap do |assets| loop do assets.concat(list_assets(repository: repository, paginate: true)) break unless paginate? end end end |
#list_all_components(repository: nil) ⇒ Object
9 10 11 12 13 14 15 16 |
# File 'lib/endpoints/components.rb', line 9 def list_all_components(repository: nil) components = Array.new.tap do |components| loop do components.concat(list_components(repository: repository, paginate: true)) break unless paginate? end end end |
#list_all_tags ⇒ Object
8 9 10 11 12 13 14 15 |
# File 'lib/endpoints/tags.rb', line 8 def = Array.new.tap do || loop do .concat((paginate: true)) break unless paginate? end end end |
#list_asset(id:) ⇒ Object
GET /service/rest/v1/assets/id
19 20 21 |
# File 'lib/endpoints/assets.rb', line 19 def list_asset(id:) @connection.get_response(endpoint: "assets/#{id}") end |
#list_assets(repository: nil, paginate: false) ⇒ Object
GET /service/rest/v1/assets
4 5 6 7 |
# File 'lib/endpoints/assets.rb', line 4 def list_assets(repository: nil, paginate: false) repository ||= @team_config.assets_repository @connection.get_response(endpoint: "assets?repository=#{repository}", paginate: paginate) end |
#list_component(id:) ⇒ Object
GET /service/rest/v1/components/id
82 83 84 |
# File 'lib/endpoints/components.rb', line 82 def list_component(id:) @connection.get_response(endpoint: "components/#{id}") end |
#list_components(repository: nil, paginate: false) ⇒ Object
GET /service/rest/v1/components
4 5 6 7 |
# File 'lib/endpoints/components.rb', line 4 def list_components(repository: nil, paginate: false) repository ||= @team_config.components_repository @connection.get_response(endpoint: "components?repository=#{repository}", paginate: paginate) end |
#list_privilege(privilege_id:) ⇒ Object
GET /service/rest/beta/security/privileges/privilegeId
9 10 11 |
# File 'lib/endpoints/privileges.rb', line 9 def list_privilege(privilege_id:) @connection.get_response(endpoint: "security/privileges/#{privilege_id}", api_version: 'beta') end |
#list_privileges ⇒ Object
GET /service/rest/beta/security/privileges
4 5 6 |
# File 'lib/endpoints/privileges.rb', line 4 def list_privileges @connection.get_response(endpoint: 'security/privileges', api_version: 'beta') end |
#list_repositories ⇒ Object
GET /service/rest/v1/repositories (This endpoint does not paginate) GET /service/rest/beta/repositories
7 8 9 |
# File 'lib/endpoints/repositories.rb', line 7 def list_repositories @connection.get_response(endpoint: 'repositories', api_version: 'beta') end |
#list_repository_names ⇒ Object
11 12 13 |
# File 'lib/endpoints/repositories.rb', line 11 def list_repository_names list_repositories.map { |repo| repo['name'] } end |
#list_role(id:) ⇒ Object
GET /service/rest/beta/security/roles/id
21 22 23 |
# File 'lib/endpoints/roles.rb', line 21 def list_role(id:) @connection.get_response(endpoint: "security/roles/#{id}?source=default", api_version: 'beta') end |
#list_roles ⇒ Object
GET /service/rest/beta/security/roles
4 5 6 |
# File 'lib/endpoints/roles.rb', line 4 def list_roles @connection.get_response(endpoint: 'security/roles', api_version: 'beta') end |
#list_scripts ⇒ Object
GET /service/rest/v1/script
4 5 6 |
# File 'lib/endpoints/script.rb', line 4 def list_scripts @connection.get_response(endpoint: "script") end |
#list_tags(paginate: false) ⇒ Object
GET /service/rest/v1/tags
4 5 6 |
# File 'lib/endpoints/tags.rb', line 4 def (paginate: false) @connection.get_response(endpoint: 'tags', paginate: paginate) end |
#list_users ⇒ Object
GET /service/rest/beta/security/users
4 5 6 |
# File 'lib/endpoints/users.rb', line 4 def list_users @connection.get_response(endpoint: 'security/users', api_version: 'beta') end |
#local_docker_image_exists?(image:, tag:) ⇒ Boolean
63 64 65 |
# File 'lib/nexus_api.rb', line 63 def local_docker_image_exists?(image:, tag:) @docker.exists?(image_name: image, tag: tag) if docker_ready? end |
#move_components_to(destination:, tag:, source: nil, keyword: nil) ⇒ Object
POST /service/rest/v1/staging/delete POST /service/rest/v1/staging/move/destination
5 6 7 8 9 10 |
# File 'lib/endpoints/staging.rb', line 5 def move_components_to(destination:, tag:, source: nil, keyword: nil) endpoint = "staging/move/#{destination}?tag=#{tag}" endpoint += "&repository=#{source}" unless source.nil? endpoint += "&q=#{keyword}" unless keyword.nil? @connection.post(endpoint: endpoint) end |
#paginate? ⇒ Boolean
85 86 87 |
# File 'lib/nexus_api.rb', line 85 def paginate? @connection.paginate? end |
#run_script(name:) ⇒ Object
POST /service/rest/v1/script/name/run
23 24 25 26 |
# File 'lib/endpoints/script.rb', line 23 def run_script(name:) puts_deprecated_notice @connection.post(endpoint: "script/#{name}/run", headers: {'Content-Type' => 'text/plain'}) end |
#search_all_assets(name:, format: nil, repository: nil, sha1: nil, version: nil) ⇒ Object
16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 |
# File 'lib/endpoints/search.rb', line 16 def search_all_assets(name:, format: nil, repository: nil, sha1: nil, version: nil) results = Array.new.tap do |results| loop do results.concat( search_asset( name: name, format: format, repository: repository, sha1: sha1, version: version, paginate: true )) break unless paginate? end end end |
#search_asset(name:, format: nil, repository: nil, sha1: nil, version: nil, paginate: false) ⇒ Object
GET /service/rest/v1/search/assets
6 7 8 9 10 11 12 13 14 |
# File 'lib/endpoints/search.rb', line 6 def search_asset(name:, format: nil, repository: nil, sha1: nil, version: nil, paginate: false) repository ||= @team_config.search_repository endpoint = "search/assets?q=#{name}" endpoint += "&format=#{format}" unless format.nil? endpoint += "&repository=#{repository}" unless repository.nil? endpoint += "&sha1=#{sha1}" unless sha1.nil? endpoint += "&version=#{version}" unless version.nil? @connection.get_response(endpoint: endpoint, paginate: paginate) end |
#status ⇒ Object
GET /service/rest/v1/status
4 5 6 |
# File 'lib/endpoints/status.rb', line 4 def status @connection.get(endpoint: 'status') end |
#status_writable ⇒ Object
GET /service/rest/v1/status/writable
11 12 13 |
# File 'lib/endpoints/status.rb', line 11 def status_writable @connection.get(endpoint: 'status/writable') end |
#upload_docker_component(image:, tag:) ⇒ Object
59 60 61 |
# File 'lib/nexus_api.rb', line 59 def upload_docker_component(image:, tag:) @docker.upload(image_name: image, tag: tag) if docker_ready? end |
#upload_maven_component(filename:, group_id:, artifact_id:, version:, repository: nil, tag: nil) ⇒ Object
POST /service/rest/v1/components
19 20 21 22 23 24 25 26 27 28 29 30 |
# File 'lib/endpoints/components.rb', line 19 def upload_maven_component(filename:, group_id:, artifact_id:, version:, repository: nil, tag: nil) repository ||= @team_config.maven_repository parameters = { 'maven2.groupId' => group_id, 'maven2.artifactId' => artifact_id, 'maven2.version' => version, 'maven2.asset1' => File.open(filename, 'r'), 'maven2.asset1.extension' => filename.split('.').last, } parameters['maven2.tag'] = tag if tag @connection.post(endpoint: "components?repository=#{repository}", parameters: parameters, headers: {}) end |
#upload_npm_component(filename:, repository: nil, tag: nil) ⇒ Object
32 33 34 35 36 37 38 39 |
# File 'lib/endpoints/components.rb', line 32 def upload_npm_component(filename:, repository: nil, tag: nil) repository ||= @team_config.npm_repository parameters = { 'npm.asset' => File.open(filename, 'r'), } parameters['npm.tag'] = tag if tag @connection.post(endpoint: "components?repository=#{repository}", parameters: parameters, headers: {}) end |
#upload_pypi_component(filename:, repository: nil, tag: nil) ⇒ Object
41 42 43 44 45 46 47 48 |
# File 'lib/endpoints/components.rb', line 41 def upload_pypi_component(filename:, repository: nil, tag: nil) repository ||= @team_config.pypi_repository parameters = { 'pypi.asset' => File.open(filename, 'r'), } parameters['pypi.tag'] = tag if tag @connection.post(endpoint: "components?repository=#{repository}", parameters: parameters, headers: {}) end |
#upload_raw_component(filename:, directory:, repository: nil, tag: nil) ⇒ Object
50 51 52 53 54 55 56 57 58 59 |
# File 'lib/endpoints/components.rb', line 50 def upload_raw_component(filename:, directory:, repository: nil, tag: nil) repository ||= @team_config.raw_repository parameters = { 'raw.directory' => directory, 'raw.asset1' => File.open(filename, 'r'), 'raw.asset1.filename' => filename.split('/').last, } parameters['raw.tag'] = tag if tag @connection.post(endpoint: "components?repository=#{repository}", parameters: parameters, headers: {}) end |
#upload_rubygems_component(filename:, repository: nil, tag: nil) ⇒ Object
61 62 63 64 65 66 67 68 |
# File 'lib/endpoints/components.rb', line 61 def upload_rubygems_component(filename:, repository: nil, tag: nil) repository ||= @team_config.rubygems_repository parameters = { 'rubygems.asset' => File.open(filename, 'r'), } parameters['rubygems.tag'] = tag if tag @connection.post(endpoint: "components?repository=#{repository}", parameters: parameters, headers: {}) end |
#upload_script(filename:) ⇒ Object
POST /service/rest/v1/script
9 10 11 12 13 |
# File 'lib/endpoints/script.rb', line 9 def upload_script(filename:) puts_deprecated_notice file = File.read(filename) @connection.post(endpoint: "script", parameters: file) end |
#upload_yum_component(filename:, directory:, repository: nil, tag: nil) ⇒ Object
70 71 72 73 74 75 76 77 78 79 |
# File 'lib/endpoints/components.rb', line 70 def upload_yum_component(filename:, directory:, repository: nil, tag: nil) repository ||= @team_config.yum_repository parameters = { 'yum.directory' => directory, 'yum.asset' => File.open(filename, 'r'), 'yum.asset.filename' => filename.split('/').last, } parameters['yum.tag'] = tag if tag @connection.post(endpoint: "components?repository=#{repository}", parameters: parameters, headers: {}) end |