Class: Artifactory::Resource::Artifact
- Defined in:
- lib/artifactory/resources/artifact.rb
Class Method Summary collapse
-
.checksum_search(options = {}) ⇒ Array<Resource::Artifact>
Search for an artifact by its checksum.
-
.from_hash(hash, options = {}) ⇒ Resource::Artifact
Create a instance from the given Hash.
-
.from_url(url, options = {}) ⇒ Resource::Artifact
Construct an artifact from the given URL.
-
.gavc_search(options = {}) ⇒ Array<Resource::Artifact>
Search for an artifact by Maven coordinates: Group ID, Artifact ID,
Version
andClassifier
. -
.latest_version(options = {}) ⇒ String?
Get the latest version of an artifact.
-
.property_search(options = {}) ⇒ Array<Resource::Artifact>
Search for an artifact by the given properties.
-
.search(options = {}) ⇒ Array<Resource::Artifact>
Search for an artifact by the full or partial filename.
-
.versions(options = {}) ⇒ Object
Get all versions of an artifact.
Instance Method Summary collapse
-
#api_path ⇒ Object
Return this object’s
api_path
. -
#api_path=(value) ⇒ Object
Set this object’s
api_path
. -
#api_path? ⇒ Boolean
Determines if the
api_path
value exists and is truthy. -
#compliance ⇒ Hash<String, Array<Hash>>
Get compliance info for a given artifact path.
- #copy(destination, options = {}) ⇒ Object
-
#created ⇒ Object
Return this object’s
created
. -
#created=(value) ⇒ Object
Set this object’s
created
. -
#created? ⇒ Boolean
Determines if the
created
value exists and is truthy. -
#delete ⇒ Boolean
Delete this artifact from repository, suppressing any
ResourceNotFound
exceptions might occur. -
#download(target = Dir.mktmpdir, options = {}) ⇒ String
Download the artifact onto the local disk.
-
#download_path ⇒ Object
Return this object’s
download_path
. -
#download_path=(value) ⇒ Object
Set this object’s
download_path
. -
#download_path? ⇒ Boolean
Determines if the
download_path
value exists and is truthy. -
#last_modified ⇒ Object
Return this object’s
last_modified
. -
#last_modified=(value) ⇒ Object
Set this object’s
last_modified
. -
#last_modified? ⇒ Boolean
Determines if the
last_modified
value exists and is truthy. -
#last_updated ⇒ Object
Return this object’s
last_updated
. -
#last_updated=(value) ⇒ Object
Set this object’s
last_updated
. -
#last_updated? ⇒ Boolean
Determines if the
last_updated
value exists and is truthy. -
#local_path ⇒ Object
Return this object’s
local_path
. -
#local_path=(value) ⇒ Object
Set this object’s
local_path
. -
#local_path? ⇒ Boolean
Determines if the
local_path
value exists and is truthy. -
#md5 ⇒ Object
Return this object’s
md5
. -
#md5=(value) ⇒ Object
Set this object’s
md5
. -
#md5? ⇒ Boolean
Determines if the
md5
value exists and is truthy. -
#mime_type ⇒ Object
Return this object’s
mime_type
. -
#mime_type=(value) ⇒ Object
Set this object’s
mime_type
. -
#mime_type? ⇒ Boolean
Determines if the
mime_type
value exists and is truthy. - #move(destination, options = {}) ⇒ Object
-
#properties ⇒ Hash<String, Object>
The list of properties for this object.
-
#repo ⇒ Object
Return this object’s
repo
. -
#repo=(value) ⇒ Object
Set this object’s
repo
. -
#repo? ⇒ Boolean
Determines if the
repo
value exists and is truthy. -
#sha1 ⇒ Object
Return this object’s
sha1
. -
#sha1=(value) ⇒ Object
Set this object’s
sha1
. -
#sha1? ⇒ Boolean
Determines if the
sha1
value exists and is truthy. -
#size ⇒ Object
Return this object’s
size
. -
#size=(value) ⇒ Object
Set this object’s
size
. -
#size? ⇒ Boolean
Determines if the
size
value exists and is truthy.
Methods inherited from Base
attribute, #attributes, attributes, #client, #client=, #client?, extract_client!, #extract_client!, format_repos!, #format_repos!, #initialize, #inspect, #set, #to_s, #url_safe, url_safe
Constructor Details
This class inherits a constructor from Artifactory::Resource::Base
Class Method Details
.checksum_search(options = {}) ⇒ Array<Resource::Artifact>
Search for an artifact by its checksum
160 161 162 163 164 165 166 167 168 |
# File 'lib/artifactory/resources/artifact.rb', line 160 def checksum_search( = {}) client = extract_client!() params = Util.slice(, :md5, :sha1, :repos) format_repos!(params) client.get('/api/search/checksum', params)['results'].map do |artifact| from_url(artifact['uri'], client: client) end end |
.from_hash(hash, options = {}) ⇒ Resource::Artifact
Create a instance from the given Hash. This method extracts the “safe” information from the hash and adds them to the instance.
291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 |
# File 'lib/artifactory/resources/artifact.rb', line 291 def from_hash(hash, = {}) client = extract_client!() new.tap do |instance| instance.api_path = hash['uri'] instance.client = client instance.created = Time.parse(hash['created']) instance.download_path = hash['downloadUri'] instance.last_modified = Time.parse(hash['lastModified']) instance.last_updated = Time.parse(hash['lastUpdated']) instance.md5 = hash['checksums']['md5'] instance.mime_type = hash['mimeType'] instance.repo = hash['repo'] instance.sha1 = hash['checksums']['sha1'] instance.size = hash['size'].to_i end end |
.from_url(url, options = {}) ⇒ Resource::Artifact
Construct an artifact from the given URL.
272 273 274 275 |
# File 'lib/artifactory/resources/artifact.rb', line 272 def from_url(url, = {}) client = extract_client!() from_hash(client.get(url), client: client) end |
.gavc_search(options = {}) ⇒ Array<Resource::Artifact>
Search for an artifact by Maven coordinates: Group ID, Artifact ID, Version
and Classifier
.
76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 |
# File 'lib/artifactory/resources/artifact.rb', line 76 def gavc_search( = {}) client = extract_client!() = Util.rename_keys(, :group => :g, :name => :a, :version => :v, :classifier => :c, ) params = Util.slice(, :g, :a, :v, :c, :repos) format_repos!(params) client.get('/api/search/gavc', params)['results'].map do |artifact| from_url(artifact['uri'], client: client) end end |
.latest_version(options = {}) ⇒ String?
Get the latest version of an artifact.
240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 |
# File 'lib/artifactory/resources/artifact.rb', line 240 def latest_version( = {}) client = extract_client!() = Util.rename_keys(, :group => :g, :name => :a, :version => :v, ) params = Util.slice(, :g, :a, :v, :repos, :remote) format_repos!(params) # For whatever reason, Artifactory won't accept "true" - they want a # literal "1"... params[:remote] = 1 if [:remote] client.get('/api/search/latestVersion', params) rescue Error::NotFound nil end |
.property_search(options = {}) ⇒ Array<Resource::Artifact>
Search for an artifact by the given properties. These are arbitrary properties defined by the user on artifact, so the search uses a free- form schema.
121 122 123 124 125 126 127 128 129 |
# File 'lib/artifactory/resources/artifact.rb', line 121 def property_search( = {}) client = extract_client!() params = .dup format_repos!(params) client.get('/api/search/prop', params)['results'].map do |artifact| from_url(artifact['uri'], client: client) end end |
.search(options = {}) ⇒ Array<Resource::Artifact>
Search for an artifact by the full or partial filename.
26 27 28 29 30 31 32 33 34 |
# File 'lib/artifactory/resources/artifact.rb', line 26 def search( = {}) client = extract_client!() params = Util.slice(, :name, :repos) format_repos!(params) client.get('/api/search/artifact', params)['results'].map do |artifact| from_url(artifact['uri'], client: client) end end |
.versions(options = {}) ⇒ Object
Get all versions of an artifact.
190 191 192 193 194 195 196 197 198 199 200 201 202 203 |
# File 'lib/artifactory/resources/artifact.rb', line 190 def versions( = {}) client = extract_client!() = Util.rename_keys(, :group => :g, :name => :a, :version => :v, ) params = Util.slice(, :g, :a, :v, :repos) format_repos!(params) client.get('/api/search/versions', params)['results'] rescue Error::NotFound [] end |
Instance Method Details
#api_path ⇒ Object
Return this object’s api_path
310 |
# File 'lib/artifactory/resources/artifact.rb', line 310 attribute :api_path, ->{ raise 'API path missing!' } |
#api_path=(value) ⇒ Object
Set this object’s api_path
310 |
# File 'lib/artifactory/resources/artifact.rb', line 310 attribute :api_path, ->{ raise 'API path missing!' } |
#api_path? ⇒ Boolean
Determines if the api_path
value exists and is truthy
310 |
# File 'lib/artifactory/resources/artifact.rb', line 310 attribute :api_path, ->{ raise 'API path missing!' } |
#compliance ⇒ Hash<String, Array<Hash>>
Get compliance info for a given artifact path. The result includes license and vulnerabilities, if any.
**This requires the Black Duck addon to be enabled!**
373 374 375 |
# File 'lib/artifactory/resources/artifact.rb', line 373 def compliance @compliance ||= client.get(File.join('/api/compliance', relative_path)) end |
#copy(destination, options = {}) ⇒ Object
325 326 327 |
# File 'lib/artifactory/resources/artifact.rb', line 325 def copy(destination, = {}) copy_or_move(:copy, destination, ) end |
#created ⇒ Object
Return this object’s created
311 |
# File 'lib/artifactory/resources/artifact.rb', line 311 attribute :created |
#created=(value) ⇒ Object
Set this object’s created
311 |
# File 'lib/artifactory/resources/artifact.rb', line 311 attribute :created |
#created? ⇒ Boolean
Determines if the created
value exists and is truthy
311 |
# File 'lib/artifactory/resources/artifact.rb', line 311 attribute :created |
#delete ⇒ Boolean
Delete this artifact from repository, suppressing any ResourceNotFound
exceptions might occur.
336 337 338 339 340 |
# File 'lib/artifactory/resources/artifact.rb', line 336 def delete !!client.delete(download_path) rescue Error::NotFound false end |
#download(target = Dir.mktmpdir, options = {}) ⇒ String
Download the artifact onto the local disk.
398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 |
# File 'lib/artifactory/resources/artifact.rb', line 398 def download(target = Dir.mktmpdir, = {}) target = File.(target) # Make the directory if it doesn't yet exist FileUtils.mkdir_p(target) unless File.exists?(target) # Use the server artifact's filename if one wasn't given filename = [:filename] || File.basename(download_path) # Construct the full path for the file destination = File.join(targer, filename) File.open(File.join(destination, filename), 'wb') do |file| file.write(_get(download_path)) end destination end |
#download_path ⇒ Object
Return this object’s download_path
312 |
# File 'lib/artifactory/resources/artifact.rb', line 312 attribute :download_path, ->{ raise 'Download path missing!' } |
#download_path=(value) ⇒ Object
Set this object’s download_path
312 |
# File 'lib/artifactory/resources/artifact.rb', line 312 attribute :download_path, ->{ raise 'Download path missing!' } |
#download_path? ⇒ Boolean
Determines if the download_path
value exists and is truthy
312 |
# File 'lib/artifactory/resources/artifact.rb', line 312 attribute :download_path, ->{ raise 'Download path missing!' } |
#last_modified ⇒ Object
Return this object’s last_modified
313 |
# File 'lib/artifactory/resources/artifact.rb', line 313 attribute :last_modified |
#last_modified=(value) ⇒ Object
Set this object’s last_modified
313 |
# File 'lib/artifactory/resources/artifact.rb', line 313 attribute :last_modified |
#last_modified? ⇒ Boolean
Determines if the last_modified
value exists and is truthy
313 |
# File 'lib/artifactory/resources/artifact.rb', line 313 attribute :last_modified |
#last_updated ⇒ Object
Return this object’s last_updated
314 |
# File 'lib/artifactory/resources/artifact.rb', line 314 attribute :last_updated |
#last_updated=(value) ⇒ Object
Set this object’s last_updated
314 |
# File 'lib/artifactory/resources/artifact.rb', line 314 attribute :last_updated |
#last_updated? ⇒ Boolean
Determines if the last_updated
value exists and is truthy
314 |
# File 'lib/artifactory/resources/artifact.rb', line 314 attribute :last_updated |
#local_path ⇒ Object
Return this object’s local_path
315 |
# File 'lib/artifactory/resources/artifact.rb', line 315 attribute :local_path, ->{ raise 'Local destination missing!' } |
#local_path=(value) ⇒ Object
Set this object’s local_path
315 |
# File 'lib/artifactory/resources/artifact.rb', line 315 attribute :local_path, ->{ raise 'Local destination missing!' } |
#local_path? ⇒ Boolean
Determines if the local_path
value exists and is truthy
315 |
# File 'lib/artifactory/resources/artifact.rb', line 315 attribute :local_path, ->{ raise 'Local destination missing!' } |
#md5 ⇒ Object
Return this object’s md5
317 |
# File 'lib/artifactory/resources/artifact.rb', line 317 attribute :md5 |
#md5=(value) ⇒ Object
Set this object’s md5
317 |
# File 'lib/artifactory/resources/artifact.rb', line 317 attribute :md5 |
#md5? ⇒ Boolean
Determines if the md5
value exists and is truthy
317 |
# File 'lib/artifactory/resources/artifact.rb', line 317 attribute :md5 |
#mime_type ⇒ Object
Return this object’s mime_type
316 |
# File 'lib/artifactory/resources/artifact.rb', line 316 attribute :mime_type |
#mime_type=(value) ⇒ Object
Set this object’s mime_type
316 |
# File 'lib/artifactory/resources/artifact.rb', line 316 attribute :mime_type |
#mime_type? ⇒ Boolean
Determines if the mime_type
value exists and is truthy
316 |
# File 'lib/artifactory/resources/artifact.rb', line 316 attribute :mime_type |
#move(destination, options = {}) ⇒ Object
345 346 347 |
# File 'lib/artifactory/resources/artifact.rb', line 345 def move(destination, = {}) copy_or_move(:move, destination, ) end |
#properties ⇒ Hash<String, Object>
The list of properties for this object.
358 359 360 |
# File 'lib/artifactory/resources/artifact.rb', line 358 def properties @properties ||= client.get(api_path, properties: nil)['properties'] end |
#repo ⇒ Object
Return this object’s repo
318 |
# File 'lib/artifactory/resources/artifact.rb', line 318 attribute :repo |
#repo=(value) ⇒ Object
Set this object’s repo
318 |
# File 'lib/artifactory/resources/artifact.rb', line 318 attribute :repo |
#repo? ⇒ Boolean
Determines if the repo
value exists and is truthy
318 |
# File 'lib/artifactory/resources/artifact.rb', line 318 attribute :repo |
#sha1 ⇒ Object
Return this object’s sha1
319 |
# File 'lib/artifactory/resources/artifact.rb', line 319 attribute :sha1 |
#sha1=(value) ⇒ Object
Set this object’s sha1
319 |
# File 'lib/artifactory/resources/artifact.rb', line 319 attribute :sha1 |
#sha1? ⇒ Boolean
Determines if the sha1
value exists and is truthy
319 |
# File 'lib/artifactory/resources/artifact.rb', line 319 attribute :sha1 |
#size ⇒ Object
Return this object’s size
320 |
# File 'lib/artifactory/resources/artifact.rb', line 320 attribute :size |
#size=(value) ⇒ Object
Set this object’s size
320 |
# File 'lib/artifactory/resources/artifact.rb', line 320 attribute :size |
#size? ⇒ Boolean
Determines if the size
value exists and is truthy
320 |
# File 'lib/artifactory/resources/artifact.rb', line 320 attribute :size |