Skip to content

Commit

Permalink
Merge pull request #17851 from Homebrew/misconfigured-nss-fix
Browse files Browse the repository at this point in the history
utils/github/api: handle systems with misconfigured NSS
  • Loading branch information
Bo98 committed Jul 25, 2024
2 parents a4b6564 + 40ca1de commit e6348b1
Showing 1 changed file with 11 additions and 3 deletions.
14 changes: 11 additions & 3 deletions Library/Homebrew/utils/github/api.rb
Original file line number Diff line number Diff line change
Expand Up @@ -137,15 +137,23 @@ def initialize(github_message, errors)
JSON::ParserError,
].freeze

sig { returns(T.nilable(String)) }
private_class_method def self.uid_home
Etc.getpwuid(Process.uid)&.dir
rescue ArgumentError
# Cover for misconfigured NSS setups
nil
end

# Gets the token from the GitHub CLI for github.com.
sig { returns(T.nilable(String)) }
def self.github_cli_token
Utils::UID.drop_euid do
# Avoid `Formula["gh"].opt_bin` so this method works even with `HOMEBREW_DISABLE_LOAD_FORMULA`.
env = {
"PATH" => PATH.new(HOMEBREW_PREFIX/"opt/gh/bin", ENV.fetch("PATH")),
"HOME" => Etc.getpwuid(Process.uid)&.dir,
}
"HOME" => uid_home,
}.compact
gh_out, _, result = system_command "gh",
args: ["auth", "token", "--hostname", "github.com"],
env:,
Expand All @@ -164,7 +172,7 @@ def self.keychain_username_password
git_credential_out, _, result = system_command "git",
args: ["credential-osxkeychain", "get"],
input: ["protocol=https\n", "host=github.com\n"],
env: { "HOME" => Etc.getpwuid(Process.uid)&.dir },
env: { "HOME" => uid_home }.compact,
print_stderr: false
return unless result.success?

Expand Down

0 comments on commit e6348b1

Please sign in to comment.