Class: Mixlib::Install::Backend::Artifactory

Inherits:
Base
  • Object
show all
Defined in:
lib/mixlib/install/backend/artifactory.rb

Defined Under Namespace

Classes: AuthenticationError, ConnectionError, NoArtifactsError

Constant Summary collapse

ENDPOINT =
"http://artifactory.chef.co".freeze
ARTIFACTORY_USERNAME =

These credentials are read-only credentials in Chef’s artifactory server which is only available in Chef’s internal network.

"mixlib-install".freeze
ARTIFACTORY_PASSWORD =
"%mKPtzbT1JH1wm333kjkkjs39oeuFLgZ8vNoOdLBPd)TZAJsURs9w0HloWR$l6h".freeze

Instance Attribute Summary

Attributes inherited from Base

#options

Instance Method Summary collapse

Methods inherited from Base

#filter_artifacts, #info, #initialize, #platform_filters_available?

Constructor Details

This class inherits a constructor from Mixlib::Install::Backend::Base

Instance Method Details

#artifactory_artifacts(version) ⇒ Array<ArtifactInfo>

Get artifacts for a given version, channel and product_name

Returns:



99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
# File 'lib/mixlib/install/backend/artifactory.rb', line 99

def artifactory_artifacts(version)
  results = artifactory_query(<<-QUERY
items.find(
  {"repo": "omnibus-#{options.channel}-local"},
  {"@omnibus.project": "#{package_name}"},
  {"@omnibus.version": "#{version}"},
  {"name": {"$nmatch": "*.metadata.json" }}
).include("repo", "path", "name", "property")
  QUERY
  )

  # Merge artifactory properties and downloadUri to a flat Hash
  results.collect! do |result|
    { "downloadUri" => generate_download_uri(result) }.merge(
      map_properties(result["properties"])
    )
  end

  # Convert results to build records
  results.map { |a| create_artifact(a) }
end

#artifactory_latestArray<ArtifactInfo>

Get artifacts for the latest version, channel and product_name

Returns:



57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
# File 'lib/mixlib/install/backend/artifactory.rb', line 57

def artifactory_latest
  # Get the list of builds from the REST api.
  # We do this because a user in the readers group does not have
  # permissions to run aql against builds.
  builds = client.get("/api/build/#{package_name}")

  if builds.nil?
    raise NoArtifactsError, <<-MSG
Can not find any builds for #{options.product_name} in #{::Artifactory.endpoint}.
    MSG
  end

  # Output we get is something like:
  # {
  #   "buildsNumbers": [
  #     {"uri"=>"/12.5.1+20151213083009", "started"=>"2015-12-13T08:40:19.238+0000"},
  #     {"uri"=>"/12.6.0+20160111212038", "started"=>"2016-01-12T00:25:35.762+0000"},
  #     ...
  #   ]
  # }
  # First we sort based on started
  builds["buildsNumbers"].sort_by! { |b| b["started"] }.reverse!

  # Now check if the build is in the requested channel or not
  # Note that if you do this for any channel other than :unstable
  # it will run a high number of queries but it is fine because we
  # are using artifactory only for :unstable channel
  builds["buildsNumbers"].each do |build|
    version = build["uri"].delete("/")
    artifacts = artifactory_artifacts(version)

    return artifacts unless artifacts.empty?
  end

  # we could not find any matching artifacts
  []
end

#artifactory_query(query) ⇒ Array<Hash>

Run an artifactory query for the given query.

Returns:

  • (Array<Hash>)

    Array of results returned from artifactory



125
126
127
128
129
130
131
# File 'lib/mixlib/install/backend/artifactory.rb', line 125

def artifactory_query(query)
  results = artifactory_request do
    client.post("/api/search/aql", query, "Content-Type" => "text/plain")
  end

  results["results"]
end

#available_artifactsArray<ArtifactInfo>

Create filtered list of artifacts

channel, product name, and product version.

Returns:



45
46
47
48
49
50
51
# File 'lib/mixlib/install/backend/artifactory.rb', line 45

def available_artifacts
  if options.latest_version?
    artifactory_latest
  else
    artifactory_artifacts(options.product_version)
  end
end

#create_artifact(artifact_map) ⇒ Object



133
134
135
136
137
138
139
140
141
142
143
# File 'lib/mixlib/install/backend/artifactory.rb', line 133

def create_artifact(artifact_map)
  ArtifactInfo.new(
    md5:              artifact_map["omnibus.md5"],
    sha256:           artifact_map["omnibus.sha256"],
    version:          artifact_map["omnibus.version"],
    platform:         artifact_map["omnibus.platform"],
    platform_version: artifact_map["omnibus.platform_version"],
    architecture:     artifact_map["omnibus.architecture"],
    url:              artifact_map["downloadUri"]
  )
end