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.
-
.creation_search(options = {}) ⇒ Array<Resource::Artifact>
Search for an artifact by its creation date.
- .from_hash(hash, options = {}) ⇒ Object
-
.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.
-
.usage_search(options = {}) ⇒ Array<Resource::Artifact>
Search for an artifact by its usage.
-
.versions(options = {}) ⇒ Object
Get all versions of an artifact.
Instance Method Summary collapse
-
#checksums ⇒ Object
Return this object’s
checksums
. -
#checksums=(value) ⇒ Object
Set this object’s
checksums
. -
#checksums? ⇒ Boolean
Determines if the
checksums
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_uri ⇒ Object
Return this object’s
download_uri
. -
#download_uri=(value) ⇒ Object
Set this object’s
download_uri
. -
#download_uri? ⇒ Boolean
Determines if the
download_uri
value exists and is truthy. -
#key ⇒ Object
Return this object’s
key
. -
#key=(value) ⇒ Object
Set this object’s
key
. -
#key? ⇒ Boolean
Determines if the
key
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 ⇒ String
The MD5 of this artifact.
-
#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(props = nil) ⇒ Hash<String, Object>
Set 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 ⇒ String
The SHA of this artifact.
-
#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. -
#upload(repo, remote_path, properties = {}, headers = {}) ⇒ Resource::Artifact
Upload an artifact into the repository.
-
#upload_checksum(repo, remote_path, type, value) ⇒ true
Upload the checksum for this artifact.
-
#upload_from_archive(repo, remote_path, properties = {}) ⇒ Object
Upload an artifact with the given archive.
-
#upload_with_checksum(repo, remote_path, checksum, properties = {}) ⇒ Object
Upload an artifact with the given SHA checksum.
-
#uri ⇒ Object
Return this object’s
uri
. -
#uri=(value) ⇒ Object
Set this object’s
uri
. -
#uri? ⇒ Boolean
Determines if the
uri
value exists and is truthy.
Methods inherited from Base
attribute, attributes, #attributes, #client, #client=, #client?, #extract_client!, extract_client!, find_from_config, format_repos!, #format_repos!, from_url, has_attribute?, #initialize, #inspect, list_from_config, #set, #to_hash, #to_json, #to_matrix_properties, #to_query_string_parameters, #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
179 180 181 182 183 184 185 186 187 |
# File 'lib/artifactory/resources/artifact.rb', line 179 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 |
.creation_search(options = {}) ⇒ Array<Resource::Artifact>
Search for an artifact by its creation date
261 262 263 264 265 266 267 268 269 |
# File 'lib/artifactory/resources/artifact.rb', line 261 def creation_search( = {}) client = extract_client!() params = Util.slice(, :from, :to, :repos) format_repos!(params) client.get("/api/search/creation", params)["results"].map do |artifact| from_url(artifact["uri"], client: client) end end |
.from_hash(hash, options = {}) ⇒ Object
365 366 367 368 369 370 371 372 |
# File 'lib/artifactory/resources/artifact.rb', line 365 def from_hash(hash, = {}) super.tap do |instance| instance.created = Time.parse(instance.created) rescue nil instance.last_modified = Time.parse(instance.last_modified) rescue nil instance.last_updated = Time.parse(instance.last_updated) rescue nil instance.size = instance.size.to_i end end |
.gavc_search(options = {}) ⇒ Array<Resource::Artifact>
Search for an artifact by Maven coordinates: Group ID, Artifact ID, Version
and Classifier
.
95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 |
# File 'lib/artifactory/resources/artifact.rb', line 95 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.
342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 |
# File 'lib/artifactory/resources/artifact.rb', line 342 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::HTTPError => e raise unless e.code == 404 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.
140 141 142 143 144 145 146 147 148 |
# File 'lib/artifactory/resources/artifact.rb', line 140 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.
45 46 47 48 49 50 51 52 53 |
# File 'lib/artifactory/resources/artifact.rb', line 45 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 |
.usage_search(options = {}) ⇒ Array<Resource::Artifact>
Search for an artifact by its usage
220 221 222 223 224 225 226 227 228 |
# File 'lib/artifactory/resources/artifact.rb', line 220 def usage_search( = {}) client = extract_client!() params = Util.slice(, :notUsedSince, :createdBefore, :repos) format_repos!(params) client.get("/api/search/usage", params)["results"].map do |artifact| from_url(artifact["uri"], client: client) end end |
.versions(options = {}) ⇒ Object
Get all versions of an artifact.
291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 |
# File 'lib/artifactory/resources/artifact.rb', line 291 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::HTTPError => e raise unless e.code == 404 [] end |
Instance Method Details
#checksums ⇒ Object
Return this object’s checksums
376 |
# File 'lib/artifactory/resources/artifact.rb', line 376 attribute :checksums |
#checksums=(value) ⇒ Object
Set this object’s checksums
376 |
# File 'lib/artifactory/resources/artifact.rb', line 376 attribute :checksums |
#checksums? ⇒ Boolean
Determines if the checksums
value exists and is truthy
376 |
# File 'lib/artifactory/resources/artifact.rb', line 376 attribute :checksums |
#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!**
467 468 469 |
# File 'lib/artifactory/resources/artifact.rb', line 467 def compliance @compliance ||= client.get(File.join("/api/compliance", relative_path)) end |
#copy(destination, options = {}) ⇒ Object
408 409 410 |
# File 'lib/artifactory/resources/artifact.rb', line 408 def copy(destination, = {}) copy_or_move(:copy, destination, ) end |
#created ⇒ Object
Return this object’s created
377 |
# File 'lib/artifactory/resources/artifact.rb', line 377 attribute :created |
#created=(value) ⇒ Object
Set this object’s created
377 |
# File 'lib/artifactory/resources/artifact.rb', line 377 attribute :created |
#created? ⇒ Boolean
Determines if the created
value exists and is truthy
377 |
# File 'lib/artifactory/resources/artifact.rb', line 377 attribute :created |
#delete ⇒ Boolean
Delete this artifact from repository, suppressing any ResourceNotFound
exceptions might occur.
419 420 421 422 423 |
# File 'lib/artifactory/resources/artifact.rb', line 419 def delete !!client.delete(download_uri) rescue Error::HTTPError false end |
#download(target = Dir.mktmpdir, options = {}) ⇒ String
Download the artifact onto the local disk.
492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 |
# File 'lib/artifactory/resources/artifact.rb', line 492 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_uri) # Construct the full path for the file destination = File.join(target, filename) File.open(destination, "wb") do |file| client.get(download_uri) do |chunk| file.write chunk end end destination end |
#download_uri ⇒ Object
Return this object’s download_uri
378 |
# File 'lib/artifactory/resources/artifact.rb', line 378 attribute :download_uri, -> { raise "Download URI missing!" } |
#download_uri=(value) ⇒ Object
Set this object’s download_uri
378 |
# File 'lib/artifactory/resources/artifact.rb', line 378 attribute :download_uri, -> { raise "Download URI missing!" } |
#download_uri? ⇒ Boolean
Determines if the download_uri
value exists and is truthy
378 |
# File 'lib/artifactory/resources/artifact.rb', line 378 attribute :download_uri, -> { raise "Download URI missing!" } |
#key ⇒ Object
Return this object’s key
379 |
# File 'lib/artifactory/resources/artifact.rb', line 379 attribute :key |
#key=(value) ⇒ Object
Set this object’s key
379 |
# File 'lib/artifactory/resources/artifact.rb', line 379 attribute :key |
#key? ⇒ Boolean
Determines if the key
value exists and is truthy
379 |
# File 'lib/artifactory/resources/artifact.rb', line 379 attribute :key |
#last_modified ⇒ Object
Return this object’s last_modified
380 |
# File 'lib/artifactory/resources/artifact.rb', line 380 attribute :last_modified |
#last_modified=(value) ⇒ Object
Set this object’s last_modified
380 |
# File 'lib/artifactory/resources/artifact.rb', line 380 attribute :last_modified |
#last_modified? ⇒ Boolean
Determines if the last_modified
value exists and is truthy
380 |
# File 'lib/artifactory/resources/artifact.rb', line 380 attribute :last_modified |
#last_updated ⇒ Object
Return this object’s last_updated
381 |
# File 'lib/artifactory/resources/artifact.rb', line 381 attribute :last_updated |
#last_updated=(value) ⇒ Object
Set this object’s last_updated
381 |
# File 'lib/artifactory/resources/artifact.rb', line 381 attribute :last_updated |
#last_updated? ⇒ Boolean
Determines if the last_updated
value exists and is truthy
381 |
# File 'lib/artifactory/resources/artifact.rb', line 381 attribute :last_updated |
#local_path ⇒ Object
Return this object’s local_path
382 |
# File 'lib/artifactory/resources/artifact.rb', line 382 attribute :local_path, -> { raise "Local destination missing!" } |
#local_path=(value) ⇒ Object
Set this object’s local_path
382 |
# File 'lib/artifactory/resources/artifact.rb', line 382 attribute :local_path, -> { raise "Local destination missing!" } |
#local_path? ⇒ Boolean
Determines if the local_path
value exists and is truthy
382 |
# File 'lib/artifactory/resources/artifact.rb', line 382 attribute :local_path, -> { raise "Local destination missing!" } |
#md5 ⇒ String
The MD5 of this artifact.
401 402 403 |
# File 'lib/artifactory/resources/artifact.rb', line 401 def md5 checksums && checksums["md5"] end |
#mime_type ⇒ Object
Return this object’s mime_type
383 |
# File 'lib/artifactory/resources/artifact.rb', line 383 attribute :mime_type |
#mime_type=(value) ⇒ Object
Set this object’s mime_type
383 |
# File 'lib/artifactory/resources/artifact.rb', line 383 attribute :mime_type |
#mime_type? ⇒ Boolean
Determines if the mime_type
value exists and is truthy
383 |
# File 'lib/artifactory/resources/artifact.rb', line 383 attribute :mime_type |
#move(destination, options = {}) ⇒ Object
428 429 430 |
# File 'lib/artifactory/resources/artifact.rb', line 428 def move(destination, = {}) copy_or_move(:move, destination, ) end |
#properties(props = nil) ⇒ Hash<String, Object>
Set properties for this object. If no properties are given it lists the properties for this object.
447 448 449 450 451 452 453 454 |
# File 'lib/artifactory/resources/artifact.rb', line 447 def properties(props = nil) if props.nil? || props.empty? get_properties else set_properties(props) get_properties(true) end end |
#repo ⇒ Object
Return this object’s repo
384 |
# File 'lib/artifactory/resources/artifact.rb', line 384 attribute :repo |
#repo=(value) ⇒ Object
Set this object’s repo
384 |
# File 'lib/artifactory/resources/artifact.rb', line 384 attribute :repo |
#repo? ⇒ Boolean
Determines if the repo
value exists and is truthy
384 |
# File 'lib/artifactory/resources/artifact.rb', line 384 attribute :repo |
#sha1 ⇒ String
The SHA of this artifact.
392 393 394 |
# File 'lib/artifactory/resources/artifact.rb', line 392 def sha1 checksums && checksums["sha1"] end |
#size ⇒ Object
Return this object’s size
385 |
# File 'lib/artifactory/resources/artifact.rb', line 385 attribute :size |
#size=(value) ⇒ Object
Set this object’s size
385 |
# File 'lib/artifactory/resources/artifact.rb', line 385 attribute :size |
#size? ⇒ Boolean
Determines if the size
value exists and is truthy
385 |
# File 'lib/artifactory/resources/artifact.rb', line 385 attribute :size |
#upload(repo, remote_path, properties = {}, headers = {}) ⇒ Resource::Artifact
Upload an artifact into the repository. If the first parameter is a File object, that file descriptor is passed to the uploader. If the first parameter is a string, it is assumed to be the path to a local file on disk. This method will automatically construct the File object from the given path.
546 547 548 549 550 551 552 553 554 555 556 557 558 559 |
# File 'lib/artifactory/resources/artifact.rb', line 546 def upload(repo, remote_path, properties = {}, headers = {}) file = File.new(File.(local_path)) matrix = to_matrix_properties(properties) endpoint = File.join("#{url_safe(repo)}#{matrix}", remote_path) # Include checksums in headers if given. headers["X-Checksum-Md5"] = md5 if md5 headers["X-Checksum-Sha1"] = sha1 if sha1 response = client.put(endpoint, file, headers) return unless response.is_a?(Hash) self.class.from_hash(response) end |
#upload_checksum(repo, remote_path, type, value) ⇒ true
Upload the checksum for this artifact. **The artifact must already be uploaded or Artifactory will throw an exception!**.
577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 |
# File 'lib/artifactory/resources/artifact.rb', line 577 def upload_checksum(repo, remote_path, type, value) file = Tempfile.new("checksum.#{type}") file.write(value) file.rewind endpoint = File.join(url_safe(repo), "#{remote_path}.#{type}") client.put(endpoint, file) true ensure if file file.close file.unlink end end |
#upload_from_archive(repo, remote_path, properties = {}) ⇒ Object
Upload an artifact with the given archive. Consult the artifactory documentation for the format of the archive to upload.
627 628 629 630 631 |
# File 'lib/artifactory/resources/artifact.rb', line 627 def upload_from_archive(repo, remote_path, properties = {}) upload(repo, remote_path, properties, "X-Explode-Archive" => true ) end |
#upload_with_checksum(repo, remote_path, checksum, properties = {}) ⇒ Object
Upload an artifact with the given SHA checksum. Consult the artifactory documentation for the possible responses when the checksums fail to match.
608 609 610 611 612 613 |
# File 'lib/artifactory/resources/artifact.rb', line 608 def upload_with_checksum(repo, remote_path, checksum, properties = {}) upload(repo, remote_path, properties, "X-Checksum-Deploy" => true, "X-Checksum-Sha1" => checksum ) end |
#uri ⇒ Object
Return this object’s uri
375 |
# File 'lib/artifactory/resources/artifact.rb', line 375 attribute :uri, -> { raise "API path missing!" } |
#uri=(value) ⇒ Object
Set this object’s uri
375 |
# File 'lib/artifactory/resources/artifact.rb', line 375 attribute :uri, -> { raise "API path missing!" } |
#uri? ⇒ Boolean
Determines if the uri
value exists and is truthy
375 |
# File 'lib/artifactory/resources/artifact.rb', line 375 attribute :uri, -> { raise "API path missing!" } |