feat(package): authenticate private binary-variant downloads
This commit is contained in:
1 parent
40fef50a6f
commit
4e5bdab8cd
10 files changed
+140
-8
No files matched your search
+2
-1
@@ -1203,7 +1203,8 @@ int execute_binaries_command(std::string_view sub, const BinariesCmdOptions &opt
|
||||
Void::Encoding::Url::encode(*opts.version_arg) + "/binaries/" +
|
||||
Void::Encoding::Url::encode(match->variant_id) + "/download";
|
||||
auto downloaded = Package::download_binary_artifact(url, match->sha256,
|
||||
std::filesystem::path{*opts.output_arg});
|
||||
std::filesystem::path{*opts.output_arg},
|
||||
Package::RegistryAuth{auth.bearer_token});
|
||||
if (!downloaded) {
|
||||
std::cerr << "vbs binaries fetch: " << downloaded.error().message() << '\n';
|
||||
return 1;
|
||||
|
||||
@@ -191,8 +191,8 @@ materialize_binary_variant(const BinaryCompatibilityKey &key,
|
||||
}
|
||||
}
|
||||
std::filesystem::create_directories(destination.parent_path(), ec);
|
||||
auto downloaded =
|
||||
download_binary_artifact(selected->download_url, selected->sha256, destination);
|
||||
auto downloaded = download_binary_artifact(selected->download_url, selected->sha256,
|
||||
destination, RegistryAuth{options.bearer_token});
|
||||
if (!downloaded) {
|
||||
return std::unexpected{downloaded.error()};
|
||||
}
|
||||
|
||||
@@ -530,12 +530,16 @@ fetch_binary_variants(std::string_view registry_url, std::string_view package_na
|
||||
|
||||
Void::Result::Result<std::filesystem::path, Void::Result::Error>
|
||||
download_binary_artifact(std::string_view url, std::string_view expected_sha256,
|
||||
const std::filesystem::path &dest_file) {
|
||||
const std::filesystem::path &dest_file, const RegistryAuth &auth) {
|
||||
auto parsed_url = parse_registry_url(url);
|
||||
if (!parsed_url) {
|
||||
return std::unexpected{parsed_url.error()};
|
||||
}
|
||||
auto reply = send_http_request(*parsed_url, "GET", "", {}, {});
|
||||
std::map<std::string, std::string, std::less<>> headers;
|
||||
if (!auth.bearer_token.empty()) {
|
||||
headers["Authorization"] = "Bearer " + auth.bearer_token;
|
||||
}
|
||||
auto reply = send_http_request(*parsed_url, "GET", "", headers, {});
|
||||
if (!reply) {
|
||||
return std::unexpected{reply.error()};
|
||||
}
|
||||
|
||||
Reference in new issue
Block a user