22#include "grk_config_private.h"
26#ifdef GRK_ENABLE_LIBCURL
31class GSFetcher :
public CurlFetcher
34 void parse(
const std::string& path)
override
37 std::string mutable_path = path;
38 ParsedFetchPath parsed;
39 if(mutable_path.starts_with(
"/vsigs/"))
42 FetchPathParser::parseVsiPath(mutable_path, parsed,
"vsigs");
43 parsed.host =
"storage.googleapis.com";
46 else if(mutable_path.starts_with(
"https://"))
49 FetchPathParser::parseHttpsPath(mutable_path, parsed);
53 grklog.
error(
"Unsupported URL format for GS: %s", path.c_str());
54 throw std::runtime_error(
"Unsupported URL format for GS");
57 grklog.
debug(
"Parsed GS URL - Host: %s, Port: %d, Bucket: %s, Key: %s", parsed.host.c_str(),
58 parsed.port, parsed.bucket.c_str(), parsed.key.c_str());
61 url_ =
"https://" + parsed.host +
"/" + parsed.bucket +
"/" + parsed.key;
62 grklog.
debug(
"Parsed GSFetcher URL: %s", url_.c_str());
65 void auth(CURL* curl)
override
68 CurlFetcher::auth(curl);
71 std::string access_key = auth_.username_;
72 std::string secret_key = auth_.password_;
74 if(access_key.empty())
76 if(
const char* key = std::getenv(
"GS_ACCESS_KEY_ID"))
79 grklog.
debug(
"Set GS access key = %s", access_key.c_str());
82 if(secret_key.empty())
84 if(
const char* secret = std::getenv(
"GS_SECRET_ACCESS_KEY"))
87 grklog.
debug(
"Set GS secret key = %s", secret_key.c_str());
92 if(!access_key.empty() && !secret_key.empty())
94 curl_easy_setopt(curl, CURLOPT_USERNAME, access_key.c_str());
95 curl_easy_setopt(curl, CURLOPT_PASSWORD, secret_key.c_str());
96 std::string sigv4 =
"aws:amz:auto:s3";
97 curl_easy_setopt(curl, CURLOPT_AWS_SIGV4, sigv4.c_str());
98 grklog.
debug(
"Applied GCS HMAC interop authentication (SigV4) for access key: %s",
103 grklog.
debug(
"No GS authentication applied (public access or other auth)");
107 curl_slist* prepareAuthHeaders(curl_slist* headers)
override
112 strftime(date_buf,
sizeof(date_buf),
"%a, %d %b %Y %H:%M:%S GMT", gmtime(&now));
113 std::string date_header =
"Date: " + std::string(date_buf);
114 headers = curl_slist_append(headers, date_header.c_str());
ResWindow.
Definition CompressedChunkCache.h:36
ILogger & grklog
Definition Logger.cpp:24
virtual void error(const char *fmt,...)=0
virtual void debug(const char *fmt,...)=0