2021-09-30 23:02:18 +05:30
|
|
|
# frozen_string_literal: true
|
|
|
|
|
|
|
|
module Packages
|
|
|
|
module Helm
|
|
|
|
class IndexPresenter
|
|
|
|
include API::Helpers::RelatedResourcesHelpers
|
|
|
|
|
|
|
|
API_VERSION = 'v1'
|
|
|
|
CHANNEL = 'channel'
|
|
|
|
INDEX_YAML_SUFFIX = "/#{CHANNEL}/index.yaml"
|
2021-11-11 11:23:49 +05:30
|
|
|
EMPTY_HASH = {}.freeze
|
2021-09-30 23:02:18 +05:30
|
|
|
|
2021-11-11 11:23:49 +05:30
|
|
|
def initialize(project_id_param, channel, packages)
|
2021-09-30 23:02:18 +05:30
|
|
|
@project_id_param = project_id_param
|
2021-11-11 11:23:49 +05:30
|
|
|
@channel = channel
|
|
|
|
@packages = packages
|
2021-09-30 23:02:18 +05:30
|
|
|
end
|
|
|
|
|
|
|
|
def api_version
|
|
|
|
API_VERSION
|
|
|
|
end
|
|
|
|
|
|
|
|
def entries
|
2021-11-11 11:23:49 +05:30
|
|
|
return EMPTY_HASH unless @channel.present?
|
|
|
|
|
2021-09-30 23:02:18 +05:30
|
|
|
result = Hash.new { |h, k| h[k] = [] }
|
|
|
|
|
2021-11-11 11:23:49 +05:30
|
|
|
# this .each is safe as we have max 300 objects
|
|
|
|
most_recent_package_files.each do |package_file|
|
2021-09-30 23:02:18 +05:30
|
|
|
name = package_file.helm_metadata['name']
|
|
|
|
result[name] << package_file.helm_metadata.merge({
|
|
|
|
'created' => package_file.created_at.utc.strftime('%Y-%m-%dT%H:%M:%S.%NZ'),
|
|
|
|
'digest' => package_file.file_sha256,
|
|
|
|
'urls' => ["charts/#{package_file.file_name}"]
|
|
|
|
})
|
|
|
|
end
|
|
|
|
|
|
|
|
result
|
|
|
|
end
|
|
|
|
|
|
|
|
def generated
|
|
|
|
Time.zone.now.utc.strftime('%Y-%m-%dT%H:%M:%S.%NZ')
|
|
|
|
end
|
|
|
|
|
|
|
|
def server_info
|
|
|
|
path = api_v4_projects_packages_helm_index_yaml_path(
|
|
|
|
id: ERB::Util.url_encode(@project_id_param),
|
|
|
|
channel: CHANNEL
|
|
|
|
)
|
|
|
|
{
|
|
|
|
'contextPath' => path.delete_suffix(INDEX_YAML_SUFFIX)
|
|
|
|
}
|
|
|
|
end
|
2021-11-11 11:23:49 +05:30
|
|
|
|
|
|
|
private
|
|
|
|
|
|
|
|
def most_recent_package_files
|
|
|
|
::Packages::PackageFile.most_recent_for(
|
|
|
|
@packages,
|
|
|
|
extra_join: :helm_file_metadatum,
|
|
|
|
extra_where: { packages_helm_file_metadata: { channel: @channel } }
|
|
|
|
).preload_helm_file_metadata
|
|
|
|
end
|
2021-09-30 23:02:18 +05:30
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|