]> git.ipfire.org Git - thirdparty/ccache.git/commitdiff
feat: Add option to use Bearer token with HTTP backend (#1001)
authorDelgan <4193924+Delgan@users.noreply.github.com>
Fri, 28 Jan 2022 18:28:15 +0000 (19:28 +0100)
committerGitHub <noreply@github.com>
Fri, 28 Jan 2022 18:28:15 +0000 (19:28 +0100)
doc/MANUAL.adoc
src/storage/secondary/HttpStorage.cpp

index ae386fb1415e9882260776e8580d7a62c88c6aee..1f238ed5681288417a0f9db93be6df1f788dbc8f 100644 (file)
@@ -1103,6 +1103,7 @@ Examples:
 
 Optional attributes:
 
+* *bearer-token*: Bearer token used to authorize the HTTP requests.
 * *connect-timeout*: Timeout (in ms) for network connection. The default is 100.
 * *keep-alive*: If *true*, keep the HTTP connection to the storage server open
   to avoid reconnects. The default is *true*.
index b7b79e8dfede288945f972d62766cd87b9579d29..57d906f6325524f74590277f5adc94afe3862f45 100644 (file)
@@ -116,7 +116,9 @@ HttpStorageBackend::HttpStorageBackend(const Params& params)
   auto operation_timeout = k_default_operation_timeout;
 
   for (const auto& attr : params.attributes) {
-    if (attr.key == "connect-timeout") {
+    if (attr.key == "bearer-token") {
+      m_http_client.set_bearer_token_auth(attr.value.c_str());
+    } else if (attr.key == "connect-timeout") {
       connect_timeout = parse_timeout_attribute(attr.value);
     } else if (attr.key == "keep-alive") {
       m_http_client.set_keep_alive(attr.value == "true");
@@ -281,6 +283,15 @@ HttpStorage::redact_secrets(Backend::Params& params) const
   if (user_info.second) {
     url.user_info(FMT("{}:{}", user_info.first, k_redacted_password));
   }
+
+  auto bearer_token_attribute =
+    std::find_if(params.attributes.begin(),
+                 params.attributes.end(),
+                 [&](const auto& attr) { return attr.key == "bearer-token"; });
+  if (bearer_token_attribute != params.attributes.end()) {
+    bearer_token_attribute->value = k_redacted_password;
+    bearer_token_attribute->raw_value = k_redacted_password;
+  }
 }
 
 } // namespace secondary