Merge pull request #11766 from yahavi/private-registry

Add support for private registry
This commit is contained in:
Mike McQuaid 2021-07-27 13:52:38 +01:00 committed by GitHub
commit 250233acdf
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 14 additions and 5 deletions

View File

@ -388,7 +388,10 @@ class CurlDownloadStrategy < AbstractFileDownloadStrategy
ohai "Downloading #{url}"
resolved_url, _, url_time, = resolve_url_basename_time_file_size(url, timeout: end_time&.remaining!)
resolved_url, _, url_time, _, is_redirection =
resolve_url_basename_time_file_size(url, timeout: end_time&.remaining!)
# Authorization is no longer valid after redirects
meta[:headers].delete_if { |header| header.first&.start_with?("Authorization") } if is_redirection
fresh = if cached_location.exist? && url_time
url_time <= cached_location.mtime
@ -449,7 +452,7 @@ class CurlDownloadStrategy < AbstractFileDownloadStrategy
return @resolved_info_cache[url] if @resolved_info_cache.include?(url)
if (domain = Homebrew::EnvConfig.artifact_domain)
url = url.sub(%r{^((ht|f)tps?://)?}, "#{domain.chomp("/")}/")
url = url.sub(%r{^(https?://#{GitHubPackages::URL_DOMAIN}/)?}o, "#{domain.chomp("/")}/")
end
out, _, status= curl_output("--location", "--silent", "--head", "--request", "GET", url.to_s, timeout: timeout)
@ -507,8 +510,9 @@ class CurlDownloadStrategy < AbstractFileDownloadStrategy
.last
basename = filenames.last || parse_basename(redirect_url)
is_redirection = url != redirect_url
@resolved_info_cache[url] = [redirect_url, basename, time, file_size]
@resolved_info_cache[url] = [redirect_url, basename, time, file_size, is_redirection]
end
def _fetch(url:, resolved_url:, timeout:)
@ -564,7 +568,9 @@ class CurlGitHubPackagesDownloadStrategy < CurlDownloadStrategy
def initialize(url, name, version, **meta)
meta ||= {}
meta[:headers] ||= []
meta[:headers] << ["Authorization: Bearer QQ=="]
token = Homebrew::EnvConfig.docker_registry_token
token ||= "QQ=="
meta[:headers] << ["Authorization: Bearer #{token}"] if token.present?
super(url, name, version, meta)
end

View File

@ -170,6 +170,9 @@ module Homebrew
description: "Use this GitHub personal access token when accessing the GitHub Packages Registry "\
"(where bottles may be stored).",
},
HOMEBREW_DOCKER_REGISTRY_TOKEN: {
description: "Use this bearer token for authenticating with a Docker registry proxying GitHub Packages.",
},
HOMEBREW_GITHUB_PACKAGES_USER: {
description: "Use this username when accessing the GitHub Packages Registry (where bottles may be stored).",
},

View File

@ -15,7 +15,7 @@ class GitHubPackages
URL_DOMAIN = "ghcr.io"
URL_PREFIX = "https://#{URL_DOMAIN}/v2/"
DOCKER_PREFIX = "docker://#{URL_DOMAIN}/"
private_constant :URL_DOMAIN
public_constant :URL_DOMAIN
private_constant :URL_PREFIX
private_constant :DOCKER_PREFIX