2024-07-10 07:39:31 +08:00
|
|
|
# frozen_string_literal: true
|
|
|
|
|
|
|
|
module Onebox
|
|
|
|
module Mixins
|
|
|
|
module GithubAuthHeader
|
2024-07-15 11:07:36 +08:00
|
|
|
def github_auth_header(github_org)
|
|
|
|
return {} if SiteSetting.github_onebox_access_tokens.blank?
|
|
|
|
org_tokens =
|
|
|
|
SiteSetting.github_onebox_access_tokens.split("\n").map { |line| line.split("|") }.to_h
|
|
|
|
|
|
|
|
# Use the default token if no token is found for the org,
|
|
|
|
# this will be the token that used to be stored in the old
|
|
|
|
# github_onebox_access_token site setting if it was configured.
|
|
|
|
token = org_tokens[github_org] || org_tokens["default"]
|
|
|
|
return {} if token.blank?
|
|
|
|
|
|
|
|
{ "Authorization" => "Bearer #{token}" }
|
2024-07-10 07:39:31 +08:00
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|