Merge pull request #12673 from zachauten/basic-auth

Add basic auth to curl download strategy, HOMEBREW_DOCKER_REGISTRY_TO…
This commit is contained in:
Mike McQuaid 2022-01-06 15:30:06 +00:00 committed by GitHub
commit d880fcc92a
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 88 additions and 75 deletions

View File

@ -595,8 +595,14 @@ class CurlGitHubPackagesDownloadStrategy < CurlDownloadStrategy
def initialize(url, name, version, **meta) def initialize(url, name, version, **meta)
meta ||= {} meta ||= {}
meta[:headers] ||= [] meta[:headers] ||= []
token = Homebrew::EnvConfig.artifact_domain ? Homebrew::EnvConfig.docker_registry_token : "QQ==" meta[:headers] << if Homebrew::EnvConfig.artifact_domain && Homebrew::EnvConfig.docker_registry_token
meta[:headers] << "Authorization: Bearer #{token}" if token.present? "Authorization: Bearer #{Homebrew::EnvConfig.docker_registry_token}"
elsif Homebrew::EnvConfig.artifact_domain && Homebrew::EnvConfig.docker_registry_basic_auth_token
"Authorization: Basic #{Homebrew::EnvConfig.docker_registry_basic_auth_token}"
else
# This QQ== is needed for the no-auth GitHub Packages default.
"Authorization: Bearer QQ=="
end
super(url, name, version, meta) super(url, name, version, meta)
end end

View File

@ -174,8 +174,13 @@ 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_BASIC_AUTH_TOKEN: {
description: "Use this base64 encoded username and password for authenticating with a Docker registry " \
"proxying GitHub Packages. If HOMEBREW_DOCKER_REGISTRY_TOKEN is set, it will be used instead.",
},
HOMEBREW_DOCKER_REGISTRY_TOKEN: { HOMEBREW_DOCKER_REGISTRY_TOKEN: {
description: "Use this bearer token for authenticating with a Docker registry proxying GitHub Packages.", description: "Use this bearer token for authenticating with a Docker registry proxying GitHub Packages. " \
"Preferred over HOMEBREW_DOCKER_REGISTRY_TOKEN_BASIC.",
}, },
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).",

View File

@ -2622,6 +2622,8 @@ module Homebrew::EnvConfig
def self.docker_registry_token(); end def self.docker_registry_token(); end
def self.docker_registry_basic_auth_token(); end
def self.editor(); end def self.editor(); end
def self.fail_log_lines(); end def self.fail_log_lines(); end