22#include "grk_config_private.h"
26#ifdef GRK_ENABLE_LIBCURL
31class ADLSFetcher :
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(
"/vsiadls/"))
43 if(!auth_.username_.empty())
45 account = auth_.username_;
46 grklog.
debug(
"Using auth-provided account for vsiadls: %s", account.c_str());
50 grklog.
error(
"No Azure account provided for /vsiadls/ path");
51 throw std::runtime_error(
"No Azure account provided for /vsiadls/ path");
53 FetchPathParser::parseVsiPath(mutable_path, parsed,
"vsiadls");
54 parsed.host = account +
".dfs.core.windows.net";
57 else if(mutable_path.starts_with(
"https://"))
60 FetchPathParser::parseHttpsPath(mutable_path, parsed);
61 if(!parsed.host.ends_with(
".dfs.core.windows.net"))
63 grklog.
error(
"Invalid ADLS HTTPS URL: host must end with .dfs.core.windows.net: %s",
65 throw std::runtime_error(
66 "Invalid ADLS HTTPS URL: host must end with .dfs.core.windows.net");
71 grklog.
error(
"Unsupported URL format for ADLS: %s", path.c_str());
72 throw std::runtime_error(
"Unsupported URL format for ADLS");
75 grklog.
debug(
"Parsed ADLS URL - Host: %s, Port: %d, Filesystem: %s, Path: %s",
76 parsed.host.c_str(), parsed.port, parsed.bucket.c_str(), parsed.key.c_str());
79 url_ =
"https://" + parsed.host +
"/" + parsed.bucket +
"/" + parsed.key;
80 grklog.
debug(
"Parsed ADLSFetcher URL: %s", url_.c_str());
83 void auth(CURL* curl)
override
86 CurlFetcher::auth(curl);
89 std::string final_url = url_;
90 std::string account = auth_.username_;
91 std::string secret = auth_.password_;
96 if(
const char* key = std::getenv(
"AZURE_STORAGE_ACCOUNT"))
99 grklog.
debug(
"Set ADLS account = %s", account.c_str());
104 if(
const char* key = std::getenv(
"AZURE_STORAGE_KEY"))
109 else if(
const char* sas = std::getenv(
"AZURE_STORAGE_SAS_TOKEN"))
112 grklog.
debug(
"Set ADLS SAS token = %s", secret.c_str());
117 if(!account.empty() && !secret.empty() && secret.find(
"?") != 0)
120 curl_easy_setopt(curl, CURLOPT_USERNAME, account.c_str());
121 curl_easy_setopt(curl, CURLOPT_PASSWORD, secret.c_str());
122 grklog.
debug(
"Applied ADLS account key authentication for account: %s", account.c_str());
124 else if(!secret.empty() && secret.find(
"?") == 0)
128 curl_easy_setopt(curl, CURLOPT_URL, final_url.c_str());
129 grklog.
debug(
"Applied ADLS SAS token authentication, final URL: %s", final_url.c_str());
133 grklog.
debug(
"No additional ADLS authentication applied (public access or other auth)");
137 curl_slist* prepareAuthHeaders(curl_slist* headers)
override
142 strftime(date_buf,
sizeof(date_buf),
"%a, %d %b %Y %H:%M:%S GMT", gmtime(&now));
143 std::string date_header =
"x-ms-date: " + std::string(date_buf);
144 headers = curl_slist_append(headers, date_header.c_str());
146 return curl_slist_append(headers,
"x-ms-version: 2020-04-08");
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