Module: ArtifactoryExtensions::ClassMethods
- Defined in:
- lib/packaging/artifactory/extensions.rb
Instance Method Summary collapse
-
#checksum_search(options = {}) ⇒ Object
This adds the ‘name` option to artifactory checksum search.
-
#pattern_search(options = {}) ⇒ Array<Resource::Artifact>
Search for an artifact in a repo using an Ant-like pattern.
-
#search(options = {}) ⇒ Object
This adds the ‘exact_match` option to artifactory search, and defaults it to true.
Instance Method Details
#checksum_search(options = {}) ⇒ Object
This adds the ‘name` option to artifactory checksum search. It defaults to unset. If set, the artifact is only returned if the download uri matches the passed name
73 74 75 76 77 78 79 |
# File 'lib/packaging/artifactory/extensions.rb', line 73 def checksum_search( = {}) artifacts = super if [:name] artifacts.select! { |artifact| File.basename(artifact.download_uri) == [:name] } end artifacts end |
#pattern_search(options = {}) ⇒ Array<Resource::Artifact>
Search for an artifact in a repo using an Ant-like pattern. Unlike many Artifactory searches, this one is restricted to a single repository.
29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 |
# File 'lib/packaging/artifactory/extensions.rb', line 29 def pattern_search( = {}) client = extract_client!() params = Artifactory::Util.slice(, :pattern, :repo) pattern_search_parameter = { :pattern => "#{params[:repo]}:#{params[:pattern]}" } response = client.get('/api/search/pattern', pattern_search_parameter) return [] if response['files'].nil? || response['files'].empty? # A typical response: # { # "repoUri"=>"https:<artifactory endpoint>/<repo>", # "sourcePattern"=>"<repo>:<provided search pattern>", # "files"=>[<filename that matched pattern>, ...] # } # # Inserting '/api/storage' before the repo makes the 'from_url' call work correctly. # repo_uri = response['repoUri'] unless repo_uri.include?('/api/storage/') # rubocop:disable Style/PercentLiteralDelimiters repo_uri.sub!(%r(/#{params[:repo]}$), "/api/storage/#{params[:repo]}") # rubocop:enable Style/PercentLiteralDelimiters end response['files'].map do |file_path| from_url("#{repo_uri}/#{file_path}", client: client) end end |
#search(options = {}) ⇒ Object
This adds the ‘exact_match` option to artifactory search, and defaults it to true. With `exact_match` set to `true` the artifact will only be returned if the name in the download uri matches the name we’re trying to download
60 61 62 63 64 65 66 67 68 |
# File 'lib/packaging/artifactory/extensions.rb', line 60 def search( = {}) exact_match = [:exact_match].nil? ? true : [:exact_match] artifacts = super if exact_match artifacts.select! { |artifact| File.basename(artifact.download_uri) == [:name] } end artifacts end |