nexus_api 1.0.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA256:
3
+ metadata.gz: 43c4bf623cf99d259425df8a92508fb1b9e1bbd98e03b0e8948c097299dc93e7
4
+ data.tar.gz: 49c4165e7dfa58462e21fbd090690aa16bd298c2b753bbd1b3b928cae9739822
5
+ SHA512:
6
+ metadata.gz: 1a468e192d95cbfb24d9dba45c8023de9959ea6f8c160103201624f95c20c6885300948b874ec0c327aa93341b42071ac94c3d93b9c1c786b7727b8fe3582417
7
+ data.tar.gz: 998126a0d520aeee32ecbcfe91796b98a5595af18c47320f450c8bd3785130530c1730264a4fd157925402756a3d1f56a3a2bcffc36cc4d2a371005feb58400e
data/.env.template ADDED
@@ -0,0 +1,5 @@
1
+ NEXUS_USERNAME=NEXUS_USERNAME
2
+ NEXUS_PASSWORD=NEXUS_PASSWORD
3
+ NEXUS_HOSTNAME=NEXUS_HOSTNAME
4
+ DOCKER_PULL_HOSTNAME=DOCKER_PULL_HOSTNAME
5
+ DOCKER_PUSH_HOSTNAME=DOCKER_PUSH_HOSTNAME
data/.gitignore ADDED
@@ -0,0 +1,17 @@
1
+ .DS_Store
2
+
3
+ /.bundle/
4
+ /.yardoc
5
+ /_yardoc/
6
+ /coverage/
7
+ /doc/
8
+ /pkg/
9
+ /spec/reports/
10
+ /tmp/
11
+
12
+ # rspec failure tracking
13
+ .rspec_status
14
+
15
+ # environment variables
16
+ .env*
17
+ !.env.template
data/.rspec ADDED
@@ -0,0 +1,3 @@
1
+ --format documentation
2
+ --color
3
+ --require spec_helper
data/.ruby-version ADDED
@@ -0,0 +1 @@
1
+ 2.6.5
data/CHANGELOG.md ADDED
@@ -0,0 +1,10 @@
1
+ # Changelog
2
+ All notable changes to this project will be documented in this file.
3
+
4
+ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
5
+ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).
6
+
7
+
8
+ ## [1.0.0](https://github.com/Cisco-AMP/nexus_api/compare/master...v1.0.0) - 2019-12-04
9
+ ### Added
10
+ - Released open source version of this project
data/Gemfile ADDED
@@ -0,0 +1,2 @@
1
+ # Specify your gem's dependencies in nexus_api.gemspec
2
+ gemspec
data/Gemfile.lock ADDED
@@ -0,0 +1,68 @@
1
+ PATH
2
+ remote: .
3
+ specs:
4
+ nexus_api (1.0.0)
5
+ bundler (~> 2)
6
+ docker-api (~> 1.34.2)
7
+ dotenv (~> 2.7.5)
8
+ pry (~> 0.12.2)
9
+ rake (~> 10.0)
10
+ rest-client (~> 2.1.0)
11
+ thor (~> 0.20.3)
12
+
13
+ GEM
14
+ specs:
15
+ coderay (1.1.2)
16
+ diff-lcs (1.3)
17
+ docker-api (1.34.2)
18
+ excon (>= 0.47.0)
19
+ multi_json
20
+ domain_name (0.5.20190701)
21
+ unf (>= 0.0.5, < 1.0.0)
22
+ dotenv (2.7.5)
23
+ excon (0.68.0)
24
+ http-accept (1.7.0)
25
+ http-cookie (1.0.3)
26
+ domain_name (~> 0.5)
27
+ method_source (0.9.2)
28
+ mime-types (3.3)
29
+ mime-types-data (~> 3.2015)
30
+ mime-types-data (3.2019.1009)
31
+ multi_json (1.14.1)
32
+ netrc (0.11.0)
33
+ pry (0.12.2)
34
+ coderay (~> 1.1.0)
35
+ method_source (~> 0.9.0)
36
+ rake (10.5.0)
37
+ rest-client (2.1.0)
38
+ http-accept (>= 1.7.0, < 2.0)
39
+ http-cookie (>= 1.0.2, < 2.0)
40
+ mime-types (>= 1.16, < 4.0)
41
+ netrc (~> 0.8)
42
+ rspec (3.9.0)
43
+ rspec-core (~> 3.9.0)
44
+ rspec-expectations (~> 3.9.0)
45
+ rspec-mocks (~> 3.9.0)
46
+ rspec-core (3.9.0)
47
+ rspec-support (~> 3.9.0)
48
+ rspec-expectations (3.9.0)
49
+ diff-lcs (>= 1.2.0, < 2.0)
50
+ rspec-support (~> 3.9.0)
51
+ rspec-mocks (3.9.0)
52
+ diff-lcs (>= 1.2.0, < 2.0)
53
+ rspec-support (~> 3.9.0)
54
+ rspec-support (3.9.0)
55
+ thor (0.20.3)
56
+ unf (0.1.4)
57
+ unf_ext
58
+ unf_ext (0.0.7.6)
59
+
60
+ PLATFORMS
61
+ ruby
62
+
63
+ DEPENDENCIES
64
+ nexus_api!
65
+ rspec (~> 3.0)
66
+
67
+ BUNDLED WITH
68
+ 2.0.2
data/LICENSE.txt ADDED
@@ -0,0 +1,21 @@
1
+ The MIT License (MIT)
2
+
3
+ Copyright (c) 2019 Francis Levesque
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in
13
+ all copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
21
+ THE SOFTWARE.
data/README.md ADDED
@@ -0,0 +1,185 @@
1
+ # Nexus API
2
+ A ruby gem that wraps the [Sonatype Nexus Repository Manager 3](https://help.sonatype.com/repomanager3)'s [REST API](https://help.sonatype.com/repomanager3/rest-and-integration-api), allowing users to interact with Nexus without having to write new connection code every time.
3
+
4
+
5
+ ## Latest Version Tested
6
+ Title | Value
7
+ ---|---
8
+ **Version** | `3.18.1-01`
9
+ **Edition** | `PRO`
10
+ **Build Revision** | `72e5414c4f3fb232e32cbfc9fca740111c94d07f`
11
+ **Build Timestamp** | `2019-08-06-1749-11540`
12
+
13
+
14
+ ## Installation
15
+ Add this line to your application's Gemfile:
16
+
17
+ ```ruby
18
+ gem 'nexus_api'
19
+ ```
20
+
21
+ And then execute:
22
+
23
+ $ bundle
24
+
25
+ Or install it yourself as:
26
+
27
+ $ gem install nexus_api
28
+
29
+
30
+ ## Usage
31
+ You can either use the [CLI](bin/nexus_api) to query Nexus directly or require the `nexus_api` gem in your code to interact with it programatically.
32
+
33
+
34
+ ### Default Repositories
35
+ Both the CLI and the `NexusAPI::API` class support being passed a config which provides a default set of repositories for all commands that require one be specifed. You can look at the [template config](team_configs/template.yaml) for the list of supported methods, and create any number of configs for yourself or other users and teams. Global defaults can be set in the [default config](team_configs/default.yaml) which is used if no other config is specified.
36
+
37
+ *NOTE*: Not every config item needs to be set, just the ones you want to use. If no default repository is set and none is passed in, you will simply receive an error.
38
+
39
+
40
+ ### Using the CLI
41
+ Copy `.env.template` from the root directory into `.env` and fill in the values. You can view the help by running the following:
42
+ ```
43
+ bin/nexus_api
44
+ ```
45
+
46
+
47
+ ### Using the Class
48
+ Documentation is never perfect. Use this section as a reference, but [lib/nexus_api.rb](lib/nexus_api.rb) should be regarded as the source of truth.
49
+
50
+
51
+ ```ruby
52
+ # Require the gem
53
+ require 'nexus_api'
54
+
55
+ # Create an instance of the API class
56
+ # Optionally, you can provide Docker push and pull endpoints
57
+ # (if configured in Nexus) or provide a team configuration file
58
+ api = NexusAPI::API.new(
59
+ username: NEXUS_USERNAME,
60
+ password: NEXUS_PASSWORD,
61
+ hostname: NEXUS_HOSTNAME,
62
+ docker_pull_hostname: DOCKER_PUSH_HOSTNAME, # Optional
63
+ docker_push_hostname: DOCKER_PULL_HOSTNAME, # Optional
64
+ config: "team_configs/#{CONFIG_NAME}", # Optional
65
+ )
66
+ # NOTE: All Docker commands will fail if the docker hostnames are not initialized
67
+
68
+ # You can query information through the list methods
69
+ api.list_repositories
70
+ api.list_repository_names
71
+ api.list_assets(repository: REPOSITORY_NAME)
72
+ api.list_asset(id: ASSET_ID)
73
+ api.list_components(repository: REPOSITORY_NAME)
74
+ api.list_component(id: ASSET_ID)
75
+ api.list_scripts
76
+ api.list_tags
77
+
78
+ # You can search for an asset by its name
79
+ # Optionally, you can pass in additional fields to filter the results
80
+ api.search_asset(
81
+ name: ASSET_NAME,
82
+ format: REPOSITORY_FORMAT, # Optional
83
+ repository: REPOSITORY_NAME, # Optional
84
+ sha1: SHA1, # Optional
85
+ version: VERSION, # Optional
86
+ )
87
+
88
+ # The following endpoints will paginate:
89
+ # - list_assets
90
+ # - list_components
91
+ # - list_tags
92
+ # - search_asset
93
+ # You can use the following pattern to page through each method:
94
+ set = Array.new.tap do |set|
95
+ loop do
96
+ set.concat(api.METHOD_YOU_WANT(ARGUMENTS, paginate: true))
97
+ break unless api.paginate?
98
+ end
99
+ end
100
+
101
+ # You can download an asset by using its asset_id
102
+ # Optionally, you can rename the file on download
103
+ api.download(
104
+ id: ASSET_ID,
105
+ name: NEW_FILE_NAME, # Optional
106
+ )
107
+
108
+ # Different asset types require differing information to be uploaded
109
+ # Optionally, you can tag the component provided the tag already exists
110
+ api.upload_maven_component(
111
+ filename: MAVEN_FILENAME,
112
+ group_id: GROUP_ID,
113
+ artifact_id: ARTIFACT_ID,
114
+ version: VERSION,
115
+ repository: REPOSITORY_NAME,
116
+ tag: TAG, # Optional
117
+ )
118
+ api.upload_npm_component(
119
+ filename: NPM_FILENAME,
120
+ repository: REPOSITORY_NAME,
121
+ tag: TAG, # Optional
122
+ )
123
+ api.upload_pypi_component(
124
+ filename: PYPI_FILENAME,
125
+ repository: REPOSITORY_NAME,
126
+ tag: TAG, # Optional
127
+ )
128
+ api.upload_raw_component(
129
+ filename: NPM_FILENAME,
130
+ directory: PATH_IN_NEXUS,
131
+ repository: REPOSITORY_NAME,
132
+ tag: TAG, # Optional
133
+ )
134
+ api.upload_rubygems_component(
135
+ filename: RUBYGEMS_FILENAME,
136
+ repository: REPOSITORY_NAME,
137
+ tag: TAG, # Optional
138
+ )
139
+ api.upload_yum_component(
140
+ filename: YUM_FILENAME,
141
+ directory: PATH_IN_NEXUS,
142
+ repository: REPOSITORY_NAME,
143
+ tag: TAG, # Optional
144
+ )
145
+
146
+ # Docker is a special case and uses the local Docker daemon
147
+ # If this daemon is not installed and running these methods will fail
148
+ # NOTE: Docker login/logout is handled as part of the docker methods
149
+ api.download_docker_component(image: IMAGE_NAME, tag: DOCKER_TAG)
150
+ api.upload_docker_component(image: IMAGE_NAME, tag: DOCKER_TAG)
151
+
152
+ # You can create/delete tags and associate/disassociate them from components
153
+ # (we use the SHA1 rather than the file name because the Nexus search is inconsistent)
154
+ api.create_tag(name: TAG)
155
+ api.associate_tag(name: TAG, sha1: SHA1_SUM, repository: REPOSITORY_NAME)
156
+ api.delete_associated_tag(name: TAG, sha1: SHA1_SUM, repository: REPOSITORY_NAME)
157
+ api.delete_tag(name: TAG)
158
+
159
+ # You can upload, list, run, and delete custom Nexus scripts
160
+ api.upload_script(filename: LOCAL_FILENAME)
161
+ api.list_scripts
162
+ api.run_script(name: SCRIPT_NAME)
163
+ api.delete_script(name: SCRIPT_NAME)
164
+
165
+ # You can query the Nexus status
166
+ api.status
167
+ api.status_writable
168
+
169
+ # Using an asset's URL you can gather its filesize as a String
170
+ api.get_asset_size(asset_url: URL)
171
+ ```
172
+
173
+
174
+ ## Development
175
+ After checking out the repo, run `bin/setup` to install dependencies. Then, run `rake test` to run the tests.
176
+
177
+ To install this gem onto your local machine, run `bundle exec rake install`. To release a new version, update the version number in `version.rb`, and then run `bundle exec rake release`, which will create a git tag for the version, push git commits and tags.
178
+
179
+
180
+ ## Contributing
181
+ Bug reports and pull requests are welcome on GitHub at https://github.com/Cisco-AMP/nexus_api.
182
+
183
+
184
+ ## License
185
+ This gem is available as open source under the terms of the [MIT License](https://opensource.org/licenses/MIT).
data/Rakefile ADDED
@@ -0,0 +1,15 @@
1
+ require "bundler/gem_tasks"
2
+
3
+ begin
4
+ require 'rspec/core/rake_task'
5
+
6
+ desc "Run RSpec unit tests"
7
+ task :test do
8
+ RSpec::Core::RakeTask.new(:spec) do |test|
9
+ test.pattern = 'spec/**{,/*/**}/*_spec.rb'
10
+ end
11
+ Rake::Task["spec"].execute
12
+ end
13
+ rescue LoadError
14
+ puts "Failed to load rspec"
15
+ end
data/bin/nexus_api ADDED
@@ -0,0 +1,7 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ $LOAD_PATH.unshift(File.join(__dir__, '../lib'))
4
+ require 'nexus_api'
5
+ require 'nexus_api/cli'
6
+
7
+ NexusAPI::CLI.start(ARGV)
data/bin/setup ADDED
@@ -0,0 +1,8 @@
1
+ #!/usr/bin/env bash
2
+ set -euo pipefail
3
+ IFS=$'\n\t'
4
+ set -vx
5
+
6
+ bundle install
7
+
8
+ # Do any other automated setup that you need to do here
data/bin/test ADDED
@@ -0,0 +1,2 @@
1
+ #!/usr/bin/env bash
2
+ rake test
@@ -0,0 +1,29 @@
1
+ require 'thor'
2
+ require 'nexus_api/cli_utils'
3
+ require 'nexus_api/cli_commands/commands'
4
+
5
+ module NexusAPI
6
+ class CLI < ::Thor
7
+ # WARNING: If any sub-commands use any of the aliases defined here they will not work
8
+ class_option :nexus_config, :aliases => '-c', :default => '.env', :desc => 'Relative path to Nexus config file'
9
+ class_option :team_config, :aliases => '-e', :desc => 'Relative path to team config file'
10
+
11
+ desc 'download FORMAT', 'Download a FORMAT type file'
12
+ subcommand 'download', Download
13
+
14
+ desc 'list TYPE', 'Print a list of every item in Nexus that matches TYPE'
15
+ subcommand 'list', List
16
+
17
+ desc 'script COMMAND', 'Manipulate scripts in Nexus'
18
+ subcommand 'script', Script
19
+
20
+ desc 'search TYPE', 'Print a list of every TYPE item in Nexus that matches the search'
21
+ subcommand 'search', Search
22
+
23
+ desc 'tag COMMAND', 'Manipulate tags in Nexus'
24
+ subcommand 'tag', Tag
25
+
26
+ desc 'upload FORMAT', 'Upload a FORMAT type file'
27
+ subcommand 'upload', Upload
28
+ end
29
+ end
@@ -0,0 +1,6 @@
1
+ require 'nexus_api/cli_commands/download.rb'
2
+ require 'nexus_api/cli_commands/list.rb'
3
+ require 'nexus_api/cli_commands/script.rb'
4
+ require 'nexus_api/cli_commands/search.rb'
5
+ require 'nexus_api/cli_commands/tag.rb'
6
+ require 'nexus_api/cli_commands/upload.rb'
@@ -0,0 +1,23 @@
1
+ module NexusAPI
2
+ class Download < ::Thor
3
+ attr_accessor :api
4
+
5
+ include NexusAPI::CLIUtils
6
+
7
+ desc 'docker', 'Download a docker image'
8
+ option :image, :aliases => '-i', :desc => 'Docker image to download', :required => true
9
+ option :docker_tag, :aliases => '-t', :desc => 'Docker tag', :required => true
10
+ def docker
11
+ setup
12
+ @api.download_docker_component(image: options[:image], tag: options[:docker_tag])
13
+ end
14
+
15
+ desc 'file', 'Download a file'
16
+ option :nexus_id, :aliases => '-i', :desc => 'Nexus ID of file to download', :required => true
17
+ option :new_name, :aliases => '-n', :desc => 'Rename the file locally after downloading; can also be used to change the path'
18
+ def file
19
+ setup
20
+ @api.download(id: options[:nexus_id], name: options[:new_name])
21
+ end
22
+ end
23
+ end
@@ -0,0 +1,66 @@
1
+ module NexusAPI
2
+ class List < ::Thor
3
+ attr_accessor :api
4
+
5
+ include NexusAPI::CLIUtils
6
+ class_option :full, :aliases => '-f', :desc => 'Print full JSON output'
7
+
8
+ desc 'asset', 'Prints out details for an asset that matches the supplied ID'
9
+ option :id, :aliases => '-i', :desc => 'Asset ID to look for', :required => true
10
+ def asset
11
+ print_element(action: :list_asset, params: {id: options[:id]}, filter: 'path')
12
+ end
13
+
14
+ desc 'asset_size', 'Prints out the size for an asset using its download URL'
15
+ option :url, :aliases => '-u', :desc => 'Asset URL', :required => true
16
+ def asset_size
17
+ setup
18
+ puts @api.get_asset_size(asset_url: options[:url])
19
+ end
20
+
21
+ desc 'assets', 'Prints out a list of all assets in a repository'
22
+ option :repository, :aliases => '-r', :desc => 'Name of repository to list assets from; Overrides -e/--team-config; Required if -e not provided'
23
+ def assets
24
+ return false unless repository_set?
25
+ print_paginating_set(action: :list_assets, params: {repository: options[:repository]}, filter: 'path')
26
+ end
27
+
28
+ desc 'component', 'Prints out details for an component that matches the supplied ID'
29
+ option :id, :aliases => '-i', :desc => 'Asset ID to look for', :required => true
30
+ def component
31
+ print_element(action: :list_component, params: {id: options[:id]}, filter: 'name')
32
+ end
33
+
34
+ desc 'components', 'Prints out a list of all components in a repository'
35
+ option :assets, :aliases => '-a', :desc => 'List assets for each component'
36
+ option :repository, :aliases => '-r', :desc => 'Name of repository to list components from; Overrides -e/--team-config; Required if -e not provided'
37
+ def components
38
+ return false unless repository_set?
39
+ proc = Proc.new do |components|
40
+ components.map do |component|
41
+ version = component['version'].nil? ? 'version is nil' : component['version']
42
+ line = "#{component['name']} (#{version})\n"
43
+ if options[:assets]
44
+ component['assets'].each do |asset|
45
+ line += " #{asset['path']}\n"
46
+ end
47
+ end
48
+ line
49
+ end
50
+ end
51
+ print_paginating_set(action: :list_components, params: {repository: options[:repository]}, filter: 'name', proc: proc)
52
+ end
53
+
54
+ desc 'repositories', 'Prints out a list of all repositories'
55
+ def repositories
56
+ print_set(action: :list_repositories, filter: 'name')
57
+ end
58
+
59
+ desc 'status', 'Prints out if the Nexus server can respond to read and write requests'
60
+ def status
61
+ setup
62
+ puts "Nexus can respond to read requests: #{@api.status}"
63
+ puts "Nexus can respond to write requests: #{@api.status_writable}"
64
+ end
65
+ end
66
+ end
@@ -0,0 +1,38 @@
1
+ module NexusAPI
2
+ class Script < ::Thor
3
+ attr_accessor :api
4
+
5
+ include NexusAPI::CLIUtils
6
+
7
+ desc 'delete', 'Delete the specified script from Nexus'
8
+ option :name, :aliases => '-n', :desc => 'Name of script to delete', :required => true
9
+ def delete
10
+ setup
11
+ @api.delete_script(name: options[:name])
12
+ end
13
+
14
+ # `run` is a reserved keyword in Thor, so we're using execute here instead
15
+ desc 'execute', 'Run the specified script in Nexus'
16
+ option :name, :aliases => '-n', :desc => 'Name of script to execute', :required => true
17
+ def execute
18
+ setup
19
+ @api.run_script(name: options[:name])
20
+ end
21
+
22
+ desc 'list', 'Prints out a list of all scripts'
23
+ option :full, :aliases => '-f', :desc => 'Print full JSON output'
24
+ def list
25
+ print_set(action: :list_scripts, filter: 'name')
26
+ end
27
+
28
+ desc 'upload', 'Upload the specified script to Nexus'
29
+ option :filename, :aliases => '-f', :desc => 'Path of file', :required => true
30
+ def upload
31
+ setup
32
+ options[:repository] = 'scripts'
33
+ if_file_exists? do
34
+ @api.upload_script(filename: options[:filename])
35
+ end
36
+ end
37
+ end
38
+ end
@@ -0,0 +1,34 @@
1
+ module NexusAPI
2
+ class Search < ::Thor
3
+ attr_accessor :api
4
+
5
+ include NexusAPI::CLIUtils
6
+
7
+ desc 'asset', 'Print names of any assets that match the search'
8
+ option :name, :aliases => '-n', :desc => 'Name of asset to search for', :required => true
9
+ option :type, :aliases => '-t', :desc => 'Searches assets within all repositories of this type'
10
+ option :repository, :aliases => '-r', :desc => 'Searches assets within this repository'
11
+ option :sha1, :aliases => '-s', :desc => 'Searches assets for a matching SHA1'
12
+ option :version, :aliases => '-v', :desc => 'Searches assets for a matching version'
13
+ option :full, :aliases => '-f', :desc => 'Print full JSON output'
14
+ def asset
15
+ setup
16
+ results = Array.new.tap do |results|
17
+ loop do
18
+ results.concat(
19
+ @api.search_asset(
20
+ name: options[:name],
21
+ format: options[:type],
22
+ repository: options[:repository],
23
+ sha1: options[:sha1],
24
+ version: options[:version],
25
+ paginate: true,
26
+ )
27
+ )
28
+ break unless @api.paginate?
29
+ end
30
+ end
31
+ puts options[:full] ? results : results.map { |result| result['path'] }
32
+ end
33
+ end
34
+ end
@@ -0,0 +1,47 @@
1
+ module NexusAPI
2
+ class Tag < ::Thor
3
+ attr_accessor :api
4
+
5
+ include NexusAPI::CLIUtils
6
+
7
+ desc 'add', 'Adds an existing tag to an asset'
8
+ option :name, :aliases => '-n', :desc => 'Tag name', :required => true
9
+ option :sha1, :aliases => '-s', :desc => 'SHA1 of asset', :required => true
10
+ option :repository, :aliases => '-r', :desc => 'Repository containing asset; Overrides -e/--team-config; Required if -e not provided'
11
+ def add
12
+ return false unless repository_set?
13
+ setup
14
+ @api.associate_tag(name: options[:name], sha1: options[:sha1], repository: options[:repository])
15
+ end
16
+
17
+ desc 'create', 'Creates a new tag in Nexus'
18
+ option :name, :aliases => '-n', :desc => 'Tag name', :required => true
19
+ def create
20
+ setup
21
+ @api.create_tag(name: options[:name])
22
+ end
23
+
24
+ desc 'delete', 'Deletes a tag from Nexus'
25
+ option :name, :aliases => '-n', :desc => 'Tag name', :required => true
26
+ def delete
27
+ setup
28
+ @api.delete_tag(name: options[:name])
29
+ end
30
+
31
+ desc 'list', 'Prints out a list of all tags'
32
+ option :full, :aliases => '-f', :desc => 'Print full JSON output'
33
+ def list
34
+ print_set(action: :list_tags, filter: 'name')
35
+ end
36
+
37
+ desc 'remove', 'Removes a tag from an asset'
38
+ option :name, :aliases => '-n', :desc => 'Tag name', :required => true
39
+ option :sha1, :aliases => '-s', :desc => 'SHA1 of asset', :required => true
40
+ option :repository, :aliases => '-r', :desc => 'Repository containing asset; Overrides -e/--team-config; Required if -e not provided'
41
+ def remove
42
+ return false unless repository_set?
43
+ setup
44
+ @api.delete_associated_tag(name: options[:name], sha1: options[:sha1], repository: options[:repository])
45
+ end
46
+ end
47
+ end