feat(clients): Part.thoughtSignature and file-backed access tokens; plan rules updated
Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
This commit is contained in:
@@ -2,14 +2,31 @@
|
||||
|
||||
#include <cstdlib>
|
||||
|
||||
#include "google/errors.h"
|
||||
#include "google/service_account.h"
|
||||
#include <fstream>
|
||||
#include <iterator>
|
||||
#include <sstream>
|
||||
|
||||
#include "clients/body/json.h"
|
||||
|
||||
namespace molo::google {
|
||||
|
||||
FileTokenAuth::FileTokenAuth(std::string path) : path_(std::move(path)) {}
|
||||
|
||||
void FileTokenAuth::apply(clients::ClientRequest& request) const {
|
||||
std::ifstream in(path_, std::ios::binary);
|
||||
std::string token((std::istreambuf_iterator<char>(in)), std::istreambuf_iterator<char>());
|
||||
if (token.size() > 8 * 1024) token.clear();
|
||||
while (!token.empty() && (token.back() == '\n' || token.back() == '\r' ||
|
||||
token.back() == ' '))
|
||||
token.pop_back();
|
||||
if (token.empty())
|
||||
throw GoogleError(401, "UNAUTHENTICATED",
|
||||
"access token file is missing, empty or over the size cap");
|
||||
request.bearer(token);
|
||||
}
|
||||
|
||||
std::shared_ptr<clients::Auth> Credentials::api_key(std::string key) {
|
||||
return std::make_shared<clients::ApiKeyAuth>(std::move(key), "x-goog-api-key");
|
||||
}
|
||||
@@ -62,6 +79,8 @@ std::shared_ptr<clients::Auth> Credentials::api_key_from_env(const char* name) {
|
||||
std::shared_ptr<clients::Auth> Credentials::oauth_from_env() {
|
||||
std::string token = env("GOOGLE_ACCESS_TOKEN");
|
||||
if (!token.empty()) return bearer(std::move(token));
|
||||
std::string file = env("GOOGLE_ACCESS_TOKEN_FILE");
|
||||
if (!file.empty()) return std::make_shared<FileTokenAuth>(std::move(file));
|
||||
return ServiceAccountAuth::from_env();
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user