Homebrew 使用 curl 选项扩展 CurlDownloadStrategy
Homebrew extend CurlDownloadStrategy with curl option
有谁知道如何使用 header 从自制程序扩展 CurlDownloadStrategy
吗?我已经在这里和 github 问题中进行了研究,但找不到任何简单有效的答案。基本上它是用于 gitlab 的,我需要设置一个 header.
我在这里找到了一个 snippet,修正了一个拼写错误,但是当我 运行 brew install mytab/mytool --debug
它不使用给定的 --header
选项,而是使用官方 code
中描述的标准选项
这是我拥有的:
require "download_strategy"
class PrivateRepositoryDownloadStrategy < CurlDownloadStrategy
def initialize(url, name, version, **meta)
super
set_gitlab_token
end
private
def _fetch(url:, resolved_url:)
args = ["--header", "Private-Token: #{@gitlab_token}"]
curl_download(@url, *args, to: temporary_path)
end
def set_gitlab_token
@gitlab_token = ENV["HOMEBREW_GITLAB_ACCESS_TKN"]
unless @gitlab_token
raise CurlDownloadStrategyError, "Environment variable HOMEBREW_GITLAB_ACCESS_TKN is required."
end
end
end
有什么想法吗? :)
好的,我解决了这个问题。基本上我需要能够从存储库的 gitlab 上传中下载工件。问题是我们需要将自定义 header 传递给 curl
并且 CurlDownloadStrategy
已经可以选择传递自定义 header 和 cookies (-b
) 根据这个 snippet。我在途中学到了一些 ruby 并且不再需要 PrivateRepositoryDownloadStrategy
:)
所以我的最终公式如下所示:
# This file was generated by GoReleaser. DO NOT EDIT.
class MyTool < Formula
desc "mytool desc"
homepage "https://gitab.mycompany/group/tool"
version "0.0.1"
bottle :unneeded
if OS.mac?
url "https://gitab.mycompany/group/tool/uploads/d046fcf878e88dd02312f15da23c5e00/mytool_Darwin_x86_64.tar.gz", :cookies => [["_gitlab_session", "#{ENV['HOMEBREW_GITLAB_SESSION_ACCESS_TOKEN']}"]]
sha256 "8f3957fdf78fde15d900229b29cae81c490eb585ff220acd7f0d71b4244f8d02"
elsif OS.linux?
if Hardware::CPU.intel?
url "https://gitab.mycompany/group/tool/uploads/6082ce9fead78d6029c9ac091d4dacda/mytool_Linux_x86_64.tar.gz", :cookies => [["_gitlab_session", "#{ENV['HOMEBREW_GITLAB_SESSION_ACCESS_TOKEN']}"]]
sha256 "d9713c89f565f2981ef7bc7a63d87ab7f7d84a00c7b3ffbc585ff959097f3d64"
end
end
def install
bin.install "mytool"
end
test do
system "#{bin}/mytool --help"
end
end
更新:
我还设法修复了自定义公式
require "download_strategy"
class PrivateRepositoryDownloadStrategy < CurlDownloadStrategy
def initialize(url, name, version, **meta)
super
set_gitlab_session_token
end
private
def _curl_args
args = ["-b", "_gitlab_session=#{@gitlab_session_token}"]
args
end
def set_gitlab_session_token
@gitlab_session_token = ENV["HOMEBREW_GITLAB_SESSION_ACCESS_TOKEN"]
unless @gitlab_session_token
raise CurlDownloadStrategyError, "Environment variable HOMEBREW_GITLAB_SESSION_ACCESS_TOKEN is required."
end
end
end
和一个改编的公式
require_relative "./PrivateRepositoryDownloadStrategy"
class MyTool < Formula
desc "mytool desc"
homepage "https://gitab.mycompany/group/tool"
version "0.0.1"
bottle :unneeded
if OS.mac?
url "https://gitab.mycompany/group/tool/uploads/d046fcf878e88dd02312f15da23c5e00/mytool_Darwin_x86_64.tar.gz", :using => PrivateRepositoryDownloadStrategy
sha256 "8f3957fdf78fde15d900229b29cae81c490eb585ff220acd7f0d71b4244f8d02"
elsif OS.linux?
if Hardware::CPU.intel?
url "https://gitab.mycompany/group/tool/uploads/6082ce9fead78d6029c9ac091d4dacda/mytool_Linux_x86_64.tar.gz", :using => PrivateRepositoryDownloadStrategy
sha256 "d9713c89f565f2981ef7bc7a63d87ab7f7d84a00c7b3ffbc585ff959097f3d64"
end
end
def install
bin.install "mytool"
end
test do
system "#{bin}/mytool --help"
end
end
有谁知道如何使用 header 从自制程序扩展 CurlDownloadStrategy
吗?我已经在这里和 github 问题中进行了研究,但找不到任何简单有效的答案。基本上它是用于 gitlab 的,我需要设置一个 header.
我在这里找到了一个 snippet,修正了一个拼写错误,但是当我 运行 brew install mytab/mytool --debug
它不使用给定的 --header
选项,而是使用官方 code
这是我拥有的:
require "download_strategy"
class PrivateRepositoryDownloadStrategy < CurlDownloadStrategy
def initialize(url, name, version, **meta)
super
set_gitlab_token
end
private
def _fetch(url:, resolved_url:)
args = ["--header", "Private-Token: #{@gitlab_token}"]
curl_download(@url, *args, to: temporary_path)
end
def set_gitlab_token
@gitlab_token = ENV["HOMEBREW_GITLAB_ACCESS_TKN"]
unless @gitlab_token
raise CurlDownloadStrategyError, "Environment variable HOMEBREW_GITLAB_ACCESS_TKN is required."
end
end
end
有什么想法吗? :)
好的,我解决了这个问题。基本上我需要能够从存储库的 gitlab 上传中下载工件。问题是我们需要将自定义 header 传递给 curl
并且 CurlDownloadStrategy
已经可以选择传递自定义 header 和 cookies (-b
) 根据这个 snippet。我在途中学到了一些 ruby 并且不再需要 PrivateRepositoryDownloadStrategy
:)
所以我的最终公式如下所示:
# This file was generated by GoReleaser. DO NOT EDIT.
class MyTool < Formula
desc "mytool desc"
homepage "https://gitab.mycompany/group/tool"
version "0.0.1"
bottle :unneeded
if OS.mac?
url "https://gitab.mycompany/group/tool/uploads/d046fcf878e88dd02312f15da23c5e00/mytool_Darwin_x86_64.tar.gz", :cookies => [["_gitlab_session", "#{ENV['HOMEBREW_GITLAB_SESSION_ACCESS_TOKEN']}"]]
sha256 "8f3957fdf78fde15d900229b29cae81c490eb585ff220acd7f0d71b4244f8d02"
elsif OS.linux?
if Hardware::CPU.intel?
url "https://gitab.mycompany/group/tool/uploads/6082ce9fead78d6029c9ac091d4dacda/mytool_Linux_x86_64.tar.gz", :cookies => [["_gitlab_session", "#{ENV['HOMEBREW_GITLAB_SESSION_ACCESS_TOKEN']}"]]
sha256 "d9713c89f565f2981ef7bc7a63d87ab7f7d84a00c7b3ffbc585ff959097f3d64"
end
end
def install
bin.install "mytool"
end
test do
system "#{bin}/mytool --help"
end
end
更新: 我还设法修复了自定义公式
require "download_strategy"
class PrivateRepositoryDownloadStrategy < CurlDownloadStrategy
def initialize(url, name, version, **meta)
super
set_gitlab_session_token
end
private
def _curl_args
args = ["-b", "_gitlab_session=#{@gitlab_session_token}"]
args
end
def set_gitlab_session_token
@gitlab_session_token = ENV["HOMEBREW_GITLAB_SESSION_ACCESS_TOKEN"]
unless @gitlab_session_token
raise CurlDownloadStrategyError, "Environment variable HOMEBREW_GITLAB_SESSION_ACCESS_TOKEN is required."
end
end
end
和一个改编的公式
require_relative "./PrivateRepositoryDownloadStrategy"
class MyTool < Formula
desc "mytool desc"
homepage "https://gitab.mycompany/group/tool"
version "0.0.1"
bottle :unneeded
if OS.mac?
url "https://gitab.mycompany/group/tool/uploads/d046fcf878e88dd02312f15da23c5e00/mytool_Darwin_x86_64.tar.gz", :using => PrivateRepositoryDownloadStrategy
sha256 "8f3957fdf78fde15d900229b29cae81c490eb585ff220acd7f0d71b4244f8d02"
elsif OS.linux?
if Hardware::CPU.intel?
url "https://gitab.mycompany/group/tool/uploads/6082ce9fead78d6029c9ac091d4dacda/mytool_Linux_x86_64.tar.gz", :using => PrivateRepositoryDownloadStrategy
sha256 "d9713c89f565f2981ef7bc7a63d87ab7f7d84a00c7b3ffbc585ff959097f3d64"
end
end
def install
bin.install "mytool"
end
test do
system "#{bin}/mytool --help"
end
end