diff --git a/src/include/utils/secret.hpp b/src/include/utils/secret.hpp index d8c7a1b..f374de1 100644 --- a/src/include/utils/secret.hpp +++ b/src/include/utils/secret.hpp @@ -1,14 +1,12 @@ #pragma once #include "duckdb/main/client_context.hpp" -#include "duckdb/main/secret/secret.hpp" #include "duckdb/main/secret/secret_manager.hpp" namespace duckdb { namespace sheets { const SecretMatch GetSecretMatch(ClientContext &ctx, const std::string &path, const std::string &type); -const KeyValueSecret *GetGSheetSecret(ClientContext &ctx); } // namespace sheets } // namespace duckdb diff --git a/src/sheets/auth_factory.cpp b/src/sheets/auth_factory.cpp index 1d97094..c765d18 100644 --- a/src/sheets/auth_factory.cpp +++ b/src/sheets/auth_factory.cpp @@ -8,28 +8,29 @@ namespace duckdb { namespace sheets { std::unique_ptr CreateAuthFromSecret(ClientContext &ctx, IHttpClient &http) { - auto *secret = GetGSheetSecret(ctx); - if (!secret) { - return nullptr; - } - - auto provider = secret->GetProvider(); - if (provider == "key_file") { - Value emailValue, keyValue; - if (!secret->TryGetValue("email", emailValue)) { - throw InvalidInputException("'email' not found in gsheet secret"); - } - if (!secret->TryGetValue("secret", keyValue)) { - throw InvalidInputException("'secret' not found in gsheet secret"); - } - return make_uniq(http, emailValue.ToString(), keyValue.ToString()); - } else { - Value tokenValue; - if (!secret->TryGetValue("token", tokenValue)) { - throw InvalidInputException("'token' not found in gsheet secret"); + auto match = GetSecretMatch(ctx, "gsheet", "gsheet"); + if (match.HasMatch()) { + auto &secret = match.GetSecret(); + auto gsheet_secret = dynamic_cast(&secret); + auto provider = gsheet_secret->GetProvider(); + if (provider == "key_file") { + Value emailValue, keyValue; + if (!gsheet_secret->TryGetValue("email", emailValue)) { + throw InvalidInputException("'email' not found in gsheet secret"); + } + if (!gsheet_secret->TryGetValue("secret", keyValue)) { + throw InvalidInputException("'secret' not found in gsheet secret"); + } + return make_uniq(http, emailValue.ToString(), keyValue.ToString()); + } else { + Value tokenValue; + if (!gsheet_secret->TryGetValue("token", tokenValue)) { + throw InvalidInputException("'token' not found in gsheet secret"); + } + return make_uniq(tokenValue.ToString()); } - return make_uniq(tokenValue.ToString()); } + return nullptr; } } // namespace sheets diff --git a/src/utils/secret.cpp b/src/utils/secret.cpp index 7f7fd57..f833b61 100644 --- a/src/utils/secret.cpp +++ b/src/utils/secret.cpp @@ -1,6 +1,5 @@ #include "utils/secret.hpp" -#include "duckdb/main/secret/secret.hpp" #include "duckdb/main/secret/secret_manager.hpp" #include "duckdb/catalog/catalog_transaction.hpp" @@ -13,14 +12,5 @@ const SecretMatch GetSecretMatch(ClientContext &ctx, const std::string &path, co return manager.LookupSecret(transaction, path, type); } -const KeyValueSecret *GetGSheetSecret(ClientContext &ctx) { - auto match = GetSecretMatch(ctx, "gsheet", "gsheet"); - if (!match.HasMatch()) { - return nullptr; - } - auto &secret = match.GetSecret(); - return dynamic_cast(&secret); -} - } // namespace sheets } // namespace duckdb