Merge pull request #11766 from yahavi/private-registry
Add support for private registry
This commit is contained in:
commit
250233acdf
@ -388,7 +388,10 @@ class CurlDownloadStrategy < AbstractFileDownloadStrategy
|
|||||||
|
|
||||||
ohai "Downloading #{url}"
|
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
|
fresh = if cached_location.exist? && url_time
|
||||||
url_time <= cached_location.mtime
|
url_time <= cached_location.mtime
|
||||||
@ -449,7 +452,7 @@ class CurlDownloadStrategy < AbstractFileDownloadStrategy
|
|||||||
return @resolved_info_cache[url] if @resolved_info_cache.include?(url)
|
return @resolved_info_cache[url] if @resolved_info_cache.include?(url)
|
||||||
|
|
||||||
if (domain = Homebrew::EnvConfig.artifact_domain)
|
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
|
end
|
||||||
|
|
||||||
out, _, status= curl_output("--location", "--silent", "--head", "--request", "GET", url.to_s, timeout: timeout)
|
out, _, status= curl_output("--location", "--silent", "--head", "--request", "GET", url.to_s, timeout: timeout)
|
||||||
@ -507,8 +510,9 @@ class CurlDownloadStrategy < AbstractFileDownloadStrategy
|
|||||||
.last
|
.last
|
||||||
|
|
||||||
basename = filenames.last || parse_basename(redirect_url)
|
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
|
end
|
||||||
|
|
||||||
def _fetch(url:, resolved_url:, timeout:)
|
def _fetch(url:, resolved_url:, timeout:)
|
||||||
@ -564,7 +568,9 @@ class CurlGitHubPackagesDownloadStrategy < CurlDownloadStrategy
|
|||||||
def initialize(url, name, version, **meta)
|
def initialize(url, name, version, **meta)
|
||||||
meta ||= {}
|
meta ||= {}
|
||||||
meta[:headers] ||= []
|
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)
|
super(url, name, version, meta)
|
||||||
end
|
end
|
||||||
|
|
||||||
|
@ -170,6 +170,9 @@ module Homebrew
|
|||||||
description: "Use this GitHub personal access token when accessing the GitHub Packages Registry "\
|
description: "Use this GitHub personal access token when accessing the GitHub Packages Registry "\
|
||||||
"(where bottles may be stored).",
|
"(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: {
|
HOMEBREW_GITHUB_PACKAGES_USER: {
|
||||||
description: "Use this username when accessing the GitHub Packages Registry (where bottles may be stored).",
|
description: "Use this username when accessing the GitHub Packages Registry (where bottles may be stored).",
|
||||||
},
|
},
|
||||||
|
@ -15,7 +15,7 @@ class GitHubPackages
|
|||||||
URL_DOMAIN = "ghcr.io"
|
URL_DOMAIN = "ghcr.io"
|
||||||
URL_PREFIX = "https://#{URL_DOMAIN}/v2/"
|
URL_PREFIX = "https://#{URL_DOMAIN}/v2/"
|
||||||
DOCKER_PREFIX = "docker://#{URL_DOMAIN}/"
|
DOCKER_PREFIX = "docker://#{URL_DOMAIN}/"
|
||||||
private_constant :URL_DOMAIN
|
public_constant :URL_DOMAIN
|
||||||
private_constant :URL_PREFIX
|
private_constant :URL_PREFIX
|
||||||
private_constant :DOCKER_PREFIX
|
private_constant :DOCKER_PREFIX
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user