Autonomy Software C++ 24.5.1
Welcome to the Autonomy Software repository of the Mars Rover Design Team (MRDT) at Missouri University of Science and Technology (Missouri S&T)! API reference contains the source code and other resources for the development of the autonomy software for our Mars rover. The Autonomy Software project aims to compete in the University Rover Challenge (URC) by demonstrating advanced autonomous capabilities and robust navigation algorithms.
Loading...
Searching...
No Matches
duckdb::SecretManager Class Reference

The Secret Manager for DuckDB. Can handle both temporary and persistent secrets. More...

Collaboration diagram for duckdb::SecretManager:

Public Member Functions

DUCKDB_API void Initialize (DatabaseInstance &db)
DUCKDB_API void LoadSecretStorage (unique_ptr< SecretStorage > storage)
 Load a secret storage.
DUCKDB_API unique_ptr< BaseSecret > DeserializeSecret (Deserializer &deserializer, const string &secret_path="")
DUCKDB_API void RegisterSecretType (SecretType &type)
 Register a new SecretType.
DUCKDB_API SecretType LookupType (const string &type)
 Lookup a SecretType.
DUCKDB_API void RegisterSecretFunction (CreateSecretFunction function, OnCreateConflict on_conflict)
 Register a Secret Function i.e. a secret provider for a secret type.
DUCKDB_API unique_ptr< SecretEntry > RegisterSecret (CatalogTransaction transaction, unique_ptr< const BaseSecret > secret, OnCreateConflict on_conflict, SecretPersistType persist_type, const string &storage="")
 Register a secret by providing a secret manually.
DUCKDB_API unique_ptr< SecretEntry > CreateSecret (ClientContext &context, const CreateSecretInput &info)
 Create a secret from a CreateSecretInfo.
DUCKDB_API BoundStatement BindCreateSecret (CatalogTransaction transaction, CreateSecretInput &info)
 The Bind for create secret is done by the secret manager.
DUCKDB_API SecretMatch LookupSecret (CatalogTransaction transaction, const string &path, const string &type)
 Lookup the best matching secret by matching the secret scopes to the path.
DUCKDB_API unique_ptr< SecretEntry > GetSecretByName (CatalogTransaction transaction, const string &name, const string &storage="")
 Get a secret by name, optionally from a specific storage.
DUCKDB_API void DropSecretByName (CatalogTransaction transaction, const string &name, OnEntryNotFound on_entry_not_found, SecretPersistType persist_type=SecretPersistType::DEFAULT, const string &storage="")
 Delete a secret by name, optionally by providing the storage to drop from.
DUCKDB_API vector< SecretEntry > AllSecrets (CatalogTransaction transaction)
 List all secrets from all secret storages.
DUCKDB_API vector< SecretType > AllSecretTypes ()
 List all secret types.
virtual DUCKDB_API void SetEnablePersistentSecrets (bool enabled)
 Secret Manager settings.
virtual DUCKDB_API void ResetEnablePersistentSecrets ()
virtual DUCKDB_API bool PersistentSecretsEnabled ()
virtual DUCKDB_API void SetDefaultStorage (const string &storage)
virtual DUCKDB_API void ResetDefaultStorage ()
virtual DUCKDB_API string DefaultStorage ()
virtual DUCKDB_API void SetPersistentSecretPath (const string &path)
virtual DUCKDB_API void ResetPersistentSecretPath ()
virtual DUCKDB_API string PersistentSecretPath ()
DUCKDB_API void DropSecretByName (ClientContext &context, const string &name, OnEntryNotFound on_entry_not_found, SecretPersistType persist_type=SecretPersistType::DEFAULT, const string &storage="")
 Utility functions.

Static Public Member Functions

static DUCKDB_API SecretManager & Get (ClientContext &context)
 Static Helper Functions.
static DUCKDB_API SecretManager & Get (DatabaseInstance &db)

Static Public Attributes

static constexpr const char * TEMPORARY_STORAGE_NAME = "memory"
 The default storage backends.
static constexpr const char * LOCAL_FILE_STORAGE_NAME = "local_file"

Private Member Functions

void RegisterSecretTypeInternal (SecretType &type)
 Register a secret type.
SecretType LookupTypeInternal (const string &type)
 Lookup a SecretType, throws if not found.
bool TryLookupTypeInternal (const string &type, SecretType &type_out)
 Try to lookup a SecretType.
void RegisterSecretFunctionInternal (CreateSecretFunction function, OnCreateConflict on_conflict)
 Register a secret provider.
optional_ptr< CreateSecretFunction > LookupFunctionInternal (const string &type, const string &provider)
 Lookup a CreateSecretFunction.
unique_ptr< SecretEntry > RegisterSecretInternal (CatalogTransaction transaction, unique_ptr< const BaseSecret > secret, OnCreateConflict on_conflict, SecretPersistType persist_type, const string &storage="")
 Register a new Secret.
void InitializeSecrets (CatalogTransaction transaction)
 Initialize the secret catalog_set and persistent secrets (lazily).
void LoadSecretStorageInternal (unique_ptr< SecretStorage > storage)
 Load a secret storage.
void AutoloadExtensionForType (const string &type)
 Autoload extension for specific secret type.
void AutoloadExtensionForFunction (const string &type, const string &provider)
 Autoload extension for specific secret function.
void ThrowTypeNotFoundError (const string &type, const string &secret_path="")
 Will throw appropriate error message when type not found.
void ThrowProviderNotFoundError (const string &type, const string &provider, bool was_default=false)
vector< reference< SecretStorage > > GetSecretStorages ()
 Thread-safe accessors for secret_storages.
optional_ptr< SecretStorage > GetSecretStorage (const string &name)
void ThrowOnSettingChangeIfInitialized ()
 Throw an exception if the secret manager is initialized.

Private Attributes

mutex manager_lock
 Lock for types, functions, settings and storages.
case_insensitive_map_t< CreateSecretFunctionSet > secret_functions
 Secret functions;.
case_insensitive_map_t< SecretType > secret_types
 Secret types;.
case_insensitive_map_t< unique_ptr< SecretStorage > > secret_storages
 Map of all registered SecretStorages.
atomic< bool > initialized {false}
 While false, secret manager settings can still be changed.
SecretManagerConfig config
 Configuration for secret manager.
optional_ptr< DatabaseInstance > db
 Pointer to current db instance.

Friends

struct SecretEntry

Detailed Description

The Secret Manager for DuckDB. Can handle both temporary and persistent secrets.

Member Function Documentation

◆ Get() [1/2]

SecretManager & duckdb::SecretManager::Get ( ClientContext & context)
static

Static Helper Functions.

300872 {
300873 return *DBConfig::GetConfig(context).secret_manager;
300874}

◆ Get() [2/2]

SecretManager & duckdb::SecretManager::Get ( DatabaseInstance & db)
static
300875 {
300876 return *DBConfig::GetConfig(db).secret_manager;
300877}
optional_ptr< DatabaseInstance > db
Pointer to current db instance.
Definition duckdb.cpp:177984

◆ Initialize()

void duckdb::SecretManager::Initialize ( DatabaseInstance & db)
300180 {
300181 lock_guard<mutex> lck(manager_lock);
300182
300183 // Construct default path
300184 LocalFileSystem fs;
300185 config.default_secret_path = fs.GetHomeDirectory();
300186 vector<string> path_components = {".duckdb", "stored_secrets"};
300187 for (auto &path_ele : path_components) {
300188 config.default_secret_path = fs.JoinPath(config.default_secret_path, path_ele);
300189 }
300190 // Use default path if none has been specified by the user configuration
300191 if (config.secret_path.empty()) {
300192 config.secret_path = config.default_secret_path;
300193 }
300194
300195 // Set the defaults for persistent storage
300196 config.default_persistent_storage = LOCAL_FILE_STORAGE_NAME;
300197
300198 // Store the current db for enabling autoloading
300199 this->db = &db;
300200
300201 // Register default types
300204 }
300205
300206 // Register default functions
300208 RegisterSecretFunctionInternal(function, OnCreateConflict::ERROR_ON_CONFLICT);
300209 }
300210}
void RegisterSecretFunctionInternal(CreateSecretFunction function, OnCreateConflict on_conflict)
Register a secret provider.
Definition duckdb.cpp:300607
SecretManagerConfig config
Configuration for secret manager.
Definition duckdb.cpp:177982
mutex manager_lock
Lock for types, functions, settings and storages.
Definition duckdb.cpp:177972
void RegisterSecretTypeInternal(SecretType &type)
Register a secret type.
Definition duckdb.cpp:300569
static vector< CreateSecretFunction > GetDefaultSecretFunctions()
Get the default secret functions.
Definition duckdb.cpp:299762
static vector< SecretType > GetDefaultSecretTypes()
Get the default secret types.
Definition duckdb.cpp:299748

◆ LoadSecretStorage()

void duckdb::SecretManager::LoadSecretStorage ( unique_ptr< SecretStorage > storage)

Load a secret storage.

300212 {
300213 lock_guard<mutex> lck(manager_lock);
300214 return LoadSecretStorageInternal(std::move(storage));
300215}
void LoadSecretStorageInternal(unique_ptr< SecretStorage > storage)
Load a secret storage.
Definition duckdb.cpp:300217
Here is the call graph for this function:

◆ DeserializeSecret()

unique_ptr< BaseSecret > duckdb::SecretManager::DeserializeSecret ( Deserializer & deserializer,
const string & secret_path = "" )

Deserialize a secret by automatically selecting the correct deserializer, secret_path can be set to improve error hints

300235 {
300236 auto type = deserializer.ReadProperty<string>(100, "type");
300237 auto provider = deserializer.ReadProperty<string>(101, "provider");
300238 auto name = deserializer.ReadProperty<string>(102, "name");
300239 vector<string> scope;
300240 deserializer.ReadList(103, "scope",
300241 [&](Deserializer::List &list, idx_t i) { scope.push_back(list.ReadElement<string>()); });
300242 auto serialization_type = deserializer.ReadPropertyWithExplicitDefault(104, "serialization_type",
300244
300245 switch (serialization_type) {
300246 // This allows us to skip looking up the secret type for deserialization altogether
300248 return KeyValueSecret::Deserialize<KeyValueSecret>(deserializer, {scope, type, provider, name});
300249 // Continues below: we need to do a type lookup to find the secret deserialize method
300251 break;
300252 default:
300253 throw IOException("Unrecognized secret serialization type found in secret '%s': %s", secret_path,
300254 EnumUtil::ToString(serialization_type));
300255 }
300256
300257 SecretType deserialized_type;
300258 if (!TryLookupTypeInternal(type, deserialized_type)) {
300259 ThrowTypeNotFoundError(type, secret_path);
300260 }
300261
300262 if (!deserialized_type.deserializer) {
300263 throw InvalidConfigurationException(
300264 "Attempted to deserialize secret type '%s' which does not have a deserialization method", type);
300265 }
300266
300267 return deserialized_type.deserializer(deserializer, {scope, type, provider, name});
300268}
void ThrowTypeNotFoundError(const string &type, const string &secret_path="")
Will throw appropriate error message when type not found.
Definition duckdb.cpp:300717
bool TryLookupTypeInternal(const string &type, SecretType &type_out)
Try to lookup a SecretType.
Definition duckdb.cpp:300577
@ KEY_VALUE_SECRET
The secret has been serialized as a KeyValueSecret.
Definition duckdb.hpp:53205
@ CUSTOM
The secret is serialized with a custom serialization function.
Definition duckdb.hpp:53203
uint64_t idx_t
a saner size_t for loop indices etc
Definition duckdb.hpp:237
Here is the call graph for this function:

◆ RegisterSecretType()

void duckdb::SecretManager::RegisterSecretType ( SecretType & type)

Register a new SecretType.

300270 {
300271 lock_guard<mutex> lck(manager_lock);
300273}
Here is the call graph for this function:

◆ LookupType()

SecretType duckdb::SecretManager::LookupType ( const string & type)

Lookup a SecretType.

300565 {
300566 return LookupTypeInternal(type);
300567}
SecretType LookupTypeInternal(const string &type)
Lookup a SecretType, throws if not found.
Definition duckdb.cpp:300599
Here is the call graph for this function:

◆ RegisterSecretFunction()

void duckdb::SecretManager::RegisterSecretFunction ( CreateSecretFunction function,
OnCreateConflict on_conflict )

Register a Secret Function i.e. a secret provider for a secret type.

300275 {
300276 unique_lock<mutex> lck(manager_lock);
300277 RegisterSecretFunctionInternal(std::move(function), on_conflict);
300278}
Here is the call graph for this function:

◆ RegisterSecret()

unique_ptr< SecretEntry > duckdb::SecretManager::RegisterSecret ( CatalogTransaction transaction,
unique_ptr< const BaseSecret > secret,
OnCreateConflict on_conflict,
SecretPersistType persist_type,
const string & storage = "" )

Register a secret by providing a secret manually.

300282 {
300283 InitializeSecrets(transaction);
300284 return RegisterSecretInternal(transaction, std::move(secret), on_conflict, persist_type, storage);
300285}
void InitializeSecrets(CatalogTransaction transaction)
Initialize the secret catalog_set and persistent secrets (lazily).
Definition duckdb.cpp:300692
unique_ptr< SecretEntry > RegisterSecretInternal(CatalogTransaction transaction, unique_ptr< const BaseSecret > secret, OnCreateConflict on_conflict, SecretPersistType persist_type, const string &storage="")
Register a new Secret.
Definition duckdb.cpp:300287
Here is the call graph for this function:

◆ CreateSecret()

unique_ptr< SecretEntry > duckdb::SecretManager::CreateSecret ( ClientContext & context,
const CreateSecretInput & info )

Create a secret from a CreateSecretInfo.

300370 {
300371 // Note that a context is required for CreateSecret, as the CreateSecretFunction expects one
300372 auto transaction = CatalogTransaction::GetSystemCatalogTransaction(context);
300373 InitializeSecrets(transaction);
300374
300375 // Make a copy to set the provider to default if necessary
300376 auto function_input = input;
300377 if (function_input.provider.empty()) {
300378 auto secret_type = LookupTypeInternal(function_input.type);
300379 function_input.provider = secret_type.default_provider;
300380 }
300381
300382 // Lookup function
300383 auto function_lookup = LookupFunctionInternal(function_input.type, function_input.provider);
300384 if (!function_lookup) {
300385 ThrowProviderNotFoundError(input.type, input.provider);
300386 }
300387
300388 // Call the function
300389 auto secret = function_lookup->function(context, function_input);
300390
300391 if (!secret) {
300392 throw InternalException("CreateSecretFunction for type: '%s' and provider: '%s' did not return a secret!",
300393 input.type, input.provider);
300394 }
300395
300396 // Register the secret at the secret_manager
300397 return RegisterSecretInternal(transaction, std::move(secret), input.on_conflict, input.persist_type,
300398 input.storage_type);
300399}
optional_ptr< CreateSecretFunction > LookupFunctionInternal(const string &type, const string &provider)
Lookup a CreateSecretFunction.
Definition duckdb.cpp:300344
Here is the call graph for this function:

◆ BindCreateSecret()

BoundStatement duckdb::SecretManager::BindCreateSecret ( CatalogTransaction transaction,
CreateSecretInput & info )

The Bind for create secret is done by the secret manager.

300401 {
300402 InitializeSecrets(transaction);
300403
300404 auto type = info.type;
300405 auto provider = info.provider;
300406 bool default_provider = false;
300407
300408 if (provider.empty()) {
300409 default_provider = true;
300410 auto secret_type = LookupTypeInternal(type);
300411 provider = secret_type.default_provider;
300412 }
300413
300414 string default_string = default_provider ? "default " : "";
300415
300416 auto function = LookupFunctionInternal(type, provider);
300417
300418 if (!function) {
300419 ThrowProviderNotFoundError(info.type, info.provider, default_provider);
300420 }
300421
300422 auto bound_info = info;
300423 bound_info.options.clear();
300424
300425 // We cast the passed parameters
300426 for (const auto &param : info.options) {
300427 auto matched_param = function->named_parameters.find(param.first);
300428 if (matched_param == function->named_parameters.end()) {
300429 throw BinderException("Unknown parameter '%s' for secret type '%s' with %sprovider '%s'", param.first, type,
300430 default_string, provider);
300431 }
300432
300433 // Cast the provided value to the expected type
300434 string error_msg;
300435 Value cast_value;
300436 if (!param.second.DefaultTryCastAs(matched_param->second, cast_value, &error_msg)) {
300437 throw BinderException("Failed to cast option '%s' to type '%s': '%s'", matched_param->first,
300438 matched_param->second.ToString(), error_msg);
300439 }
300440
300441 bound_info.options[matched_param->first] = {cast_value};
300442 }
300443
300444 BoundStatement result;
300445 result.names = {"Success"};
300446 result.types = {LogicalType::BOOLEAN};
300447 result.plan = make_uniq<LogicalCreateSecret>(std::move(bound_info));
300448 return result;
300449}
Here is the call graph for this function:

◆ LookupSecret()

SecretMatch duckdb::SecretManager::LookupSecret ( CatalogTransaction transaction,
const string & path,
const string & type )

Lookup the best matching secret by matching the secret scopes to the path.

300451 {
300452 InitializeSecrets(transaction);
300453
300454 int64_t best_match_score = NumericLimits<int64_t>::Minimum();
300455 unique_ptr<SecretEntry> best_match = nullptr;
300456
300457 for (const auto &storage_ref : GetSecretStorages()) {
300458 if (!storage_ref.get().IncludeInLookups()) {
300459 continue;
300460 }
300461 auto match = storage_ref.get().LookupSecret(path, StringUtil::Lower(type), &transaction);
300462 if (match.HasMatch() && match.score > best_match_score) {
300463 best_match = std::move(match.secret_entry);
300464 best_match_score = match.score;
300465 }
300466 }
300467
300468 if (best_match) {
300469 return SecretMatch(*best_match, best_match_score);
300470 }
300471
300472 return SecretMatch();
300473}
vector< reference< SecretStorage > > GetSecretStorages()
Thread-safe accessors for secret_storages.
Definition duckdb.cpp:300773
static DUCKDB_API string Lower(const string &str)
Convert a string to lowercase.
Definition duckdb.cpp:109630
::int64_t int64_t
Here is the call graph for this function:

◆ GetSecretByName()

unique_ptr< SecretEntry > duckdb::SecretManager::GetSecretByName ( CatalogTransaction transaction,
const string & name,
const string & storage = "" )

Get a secret by name, optionally from a specific storage.

300476 {
300477 InitializeSecrets(transaction);
300478
300479 unique_ptr<SecretEntry> result = nullptr;
300480 bool found = false;
300481
300482 if (!storage.empty()) {
300483 auto storage_lookup = GetSecretStorage(storage);
300484
300485 if (!storage_lookup) {
300486 throw InvalidInputException("Unknown secret storage found: '%s'", storage);
300487 }
300488
300489 return storage_lookup->GetSecretByName(name, &transaction);
300490 }
300491
300492 for (const auto &storage_ref : GetSecretStorages()) {
300493 auto lookup = storage_ref.get().GetSecretByName(name, &transaction);
300494 if (lookup) {
300495 if (found) {
300496 throw InvalidConfigurationException(
300497 "Ambiguity detected for secret name '%s', secret occurs in multiple storage backends.", name);
300498 }
300499
300500 result = std::move(lookup);
300501 found = true;
300502 }
300503 }
300504
300505 return result;
300506}
Here is the call graph for this function:

◆ DropSecretByName() [1/2]

void duckdb::SecretManager::DropSecretByName ( CatalogTransaction transaction,
const string & name,
OnEntryNotFound on_entry_not_found,
SecretPersistType persist_type = SecretPersistType::DEFAULT,
const string & storage = "" )

Delete a secret by name, optionally by providing the storage to drop from.

300510 {
300511 InitializeSecrets(transaction);
300512
300513 vector<reference<SecretStorage>> matches;
300514
300515 // storage to drop from was specified directly
300516 if (!storage.empty()) {
300517 auto storage_lookup = GetSecretStorage(storage);
300518 if (!storage_lookup) {
300519 throw InvalidInputException("Unknown storage type found for drop secret: '%s'", storage);
300520 }
300521 matches.push_back(*storage_lookup.get());
300522 } else {
300523 for (const auto &storage_ref : GetSecretStorages()) {
300524 if (persist_type == SecretPersistType::PERSISTENT && !storage_ref.get().Persistent()) {
300525 continue;
300526 }
300527 if (persist_type == SecretPersistType::TEMPORARY && storage_ref.get().Persistent()) {
300528 continue;
300529 }
300530
300531 auto lookup = storage_ref.get().GetSecretByName(name, &transaction);
300532 if (lookup) {
300533 matches.push_back(storage_ref.get());
300534 }
300535 }
300536 }
300537
300538 if (matches.size() > 1) {
300539 string list_of_matches;
300540 for (const auto &match : matches) {
300541 list_of_matches += match.get().GetName() + ",";
300542 }
300543 list_of_matches.pop_back(); // trailing comma
300544
300545 throw InvalidInputException(
300546 "Ambiguity found for secret name '%s', secret occurs in multiple storages: [%s] Please specify which "
300547 "secret to drop using: 'DROP <PERSISTENT|TEMPORARY> SECRET [FROM <storage>]'.",
300548 name, list_of_matches);
300549 }
300550
300551 if (matches.empty()) {
300552 if (on_entry_not_found == OnEntryNotFound::THROW_EXCEPTION) {
300553 string storage_str;
300554 if (!storage.empty()) {
300555 storage_str = " for storage '" + storage + "'";
300556 }
300557 throw InvalidInputException("Failed to remove non-existent secret with name '%s'%s", name, storage_str);
300558 }
300559 // Do nothing on OnEntryNotFound::RETURN_NULL...
300560 } else {
300561 matches[0].get().DropSecretByName(name, on_entry_not_found, &transaction);
300562 }
300563}
Here is the call graph for this function:
Here is the caller graph for this function:

◆ AllSecrets()

vector< SecretEntry > duckdb::SecretManager::AllSecrets ( CatalogTransaction transaction)

List all secrets from all secret storages.

300618 {
300619 InitializeSecrets(transaction);
300620
300621 vector<SecretEntry> result;
300622
300623 // Add results from all backends to the result set
300624 for (const auto &backend : secret_storages) {
300625 auto backend_result = backend.second->AllSecrets(&transaction);
300626 for (const auto &it : backend_result) {
300627 result.push_back(it);
300628 }
300629 }
300630
300631 return result;
300632}
case_insensitive_map_t< unique_ptr< SecretStorage > > secret_storages
Map of all registered SecretStorages.
Definition duckdb.cpp:177978
cv::gapi::GBackend backend()
Here is the call graph for this function:

◆ AllSecretTypes()

vector< SecretType > duckdb::SecretManager::AllSecretTypes ( )

List all secret types.

300634 {
300635 unique_lock<mutex> lck(manager_lock);
300636 vector<SecretType> result;
300637
300638 for (const auto &secret : secret_types) {
300639 result.push_back(secret.second);
300640 }
300641
300642 return result;
300643}
case_insensitive_map_t< SecretType > secret_types
Secret types;.
Definition duckdb.cpp:177976

◆ SetEnablePersistentSecrets()

void duckdb::SecretManager::SetEnablePersistentSecrets ( bool enabled)
virtual

Secret Manager settings.

300652 {
300654 config.allow_persistent_secrets = enabled;
300655}
void ThrowOnSettingChangeIfInitialized()
Throw an exception if the secret manager is initialized.
Definition duckdb.cpp:300645
Here is the call graph for this function:

◆ ResetEnablePersistentSecrets()

void duckdb::SecretManager::ResetEnablePersistentSecrets ( )
virtual
300657 {
300659 config.allow_persistent_secrets = SecretManagerConfig::DEFAULT_ALLOW_PERSISTENT_SECRETS;
300660}

◆ PersistentSecretsEnabled()

bool duckdb::SecretManager::PersistentSecretsEnabled ( )
virtual
300662 {
300663 return config.allow_persistent_secrets;
300664}

◆ SetDefaultStorage()

void duckdb::SecretManager::SetDefaultStorage ( const string & storage)
virtual
300666 {
300667 config.default_persistent_storage = storage;
300668}

◆ ResetDefaultStorage()

void duckdb::SecretManager::ResetDefaultStorage ( )
virtual
300670 {
300671 config.default_persistent_storage = SecretManager::LOCAL_FILE_STORAGE_NAME;
300672}

◆ DefaultStorage()

string duckdb::SecretManager::DefaultStorage ( )
virtual
300674 {
300675 return config.default_persistent_storage;
300676}

◆ SetPersistentSecretPath()

void duckdb::SecretManager::SetPersistentSecretPath ( const string & path)
virtual
300678 {
300680 config.secret_path = path;
300681}

◆ ResetPersistentSecretPath()

void duckdb::SecretManager::ResetPersistentSecretPath ( )
virtual
300683 {
300685 config.secret_path = config.default_secret_path;
300686}

◆ PersistentSecretPath()

string duckdb::SecretManager::PersistentSecretPath ( )
virtual
300688 {
300689 return config.secret_path;
300690}

◆ DropSecretByName() [2/2]

void duckdb::SecretManager::DropSecretByName ( ClientContext & context,
const string & name,
OnEntryNotFound on_entry_not_found,
SecretPersistType persist_type = SecretPersistType::DEFAULT,
const string & storage = "" )

Utility functions.

300880 {
300881 auto transaction = CatalogTransaction::GetSystemCatalogTransaction(context);
300882 return DropSecretByName(transaction, name, on_entry_not_found, persist_type, storage);
300883}
DUCKDB_API void DropSecretByName(CatalogTransaction transaction, const string &name, OnEntryNotFound on_entry_not_found, SecretPersistType persist_type=SecretPersistType::DEFAULT, const string &storage="")
Delete a secret by name, optionally by providing the storage to drop from.
Definition duckdb.cpp:300508
Here is the call graph for this function:

◆ RegisterSecretTypeInternal()

void duckdb::SecretManager::RegisterSecretTypeInternal ( SecretType & type)
private

Register a secret type.

300569 {
300570 auto lookup = secret_types.find(type.name);
300571 if (lookup != secret_types.end()) {
300572 throw InternalException("Attempted to register an already registered secret type: '%s'", type.name);
300573 }
300574 secret_types[type.name] = type;
300575}
Here is the caller graph for this function:

◆ LookupTypeInternal()

SecretType duckdb::SecretManager::LookupTypeInternal ( const string & type)
private

Lookup a SecretType, throws if not found.

300599 {
300600 SecretType return_value;
300601 if (!TryLookupTypeInternal(type, return_value)) {
300603 }
300604 return return_value;
300605}
Here is the call graph for this function:
Here is the caller graph for this function:

◆ TryLookupTypeInternal()

bool duckdb::SecretManager::TryLookupTypeInternal ( const string & type,
SecretType & type_out )
private

Try to lookup a SecretType.

300577 {
300578 unique_lock<mutex> lck(manager_lock);
300579 auto lookup = secret_types.find(type);
300580 if (lookup != secret_types.end()) {
300581 type_out = lookup->second;
300582 return true;
300583 }
300584
300585 // Try autoloading
300586 lck.unlock();
300588 lck.lock();
300589
300590 lookup = secret_types.find(type);
300591 if (lookup != secret_types.end()) {
300592 type_out = lookup->second;
300593 return true;
300594 }
300595
300596 return false;
300597}
void AutoloadExtensionForType(const string &type)
Autoload extension for specific secret type.
Definition duckdb.cpp:300713
Here is the call graph for this function:
Here is the caller graph for this function:

◆ RegisterSecretFunctionInternal()

void duckdb::SecretManager::RegisterSecretFunctionInternal ( CreateSecretFunction function,
OnCreateConflict on_conflict )
private

Register a secret provider.

300607 {
300608 auto lookup = secret_functions.find(function.secret_type);
300609 if (lookup != secret_functions.end()) {
300610 lookup->second.AddFunction(function, on_conflict);
300611 return;
300612 }
300613 CreateSecretFunctionSet new_set(function.secret_type);
300614 new_set.AddFunction(function, OnCreateConflict::ERROR_ON_CONFLICT);
300615 secret_functions.insert({function.secret_type, new_set});
300616}
case_insensitive_map_t< CreateSecretFunctionSet > secret_functions
Secret functions;.
Definition duckdb.cpp:177974
Here is the caller graph for this function:

◆ LookupFunctionInternal()

optional_ptr< CreateSecretFunction > duckdb::SecretManager::LookupFunctionInternal ( const string & type,
const string & provider )
private

Lookup a CreateSecretFunction.

300344 {
300345 unique_lock<mutex> lck(manager_lock);
300346 auto lookup = secret_functions.find(type);
300347
300348 if (lookup != secret_functions.end()) {
300349 if (lookup->second.ProviderExists(provider)) {
300350 return &lookup->second.GetFunction(provider);
300351 }
300352 }
300353
300354 // Try autoloading
300355 lck.unlock();
300356 AutoloadExtensionForFunction(type, provider);
300357 lck.lock();
300358
300359 lookup = secret_functions.find(type);
300360
300361 if (lookup != secret_functions.end()) {
300362 if (lookup->second.ProviderExists(provider)) {
300363 return &lookup->second.GetFunction(provider);
300364 }
300365 }
300366
300367 return nullptr;
300368}
void AutoloadExtensionForFunction(const string &type, const string &provider)
Autoload extension for specific secret function.
Definition duckdb.cpp:300743
Here is the call graph for this function:
Here is the caller graph for this function:

◆ RegisterSecretInternal()

unique_ptr< SecretEntry > duckdb::SecretManager::RegisterSecretInternal ( CatalogTransaction transaction,
unique_ptr< const BaseSecret > secret,
OnCreateConflict on_conflict,
SecretPersistType persist_type,
const string & storage = "" )
private

Register a new Secret.

Ensure we only create secrets for known types;

Handle default for persist type

Resolve storage

Lookup which backend to store the secret in

300290 {
300292 LookupTypeInternal(secret->GetType());
300293
300295 if (persist_type == SecretPersistType::DEFAULT) {
300296 if (storage.empty()) {
300297 persist_type = config.default_persist_type;
300298 } else if (storage == TEMPORARY_STORAGE_NAME) {
300299 persist_type = SecretPersistType::TEMPORARY;
300300 } else {
300301 persist_type = SecretPersistType::PERSISTENT;
300302 }
300303 }
300304
300306 string resolved_storage;
300307 if (storage.empty()) {
300308 resolved_storage =
300309 persist_type == SecretPersistType::PERSISTENT ? config.default_persistent_storage : TEMPORARY_STORAGE_NAME;
300310 } else {
300311 resolved_storage = storage;
300312 }
300313
300315 auto backend = GetSecretStorage(resolved_storage);
300316 if (!backend) {
300317 if (!config.allow_persistent_secrets &&
300318 (persist_type == SecretPersistType::PERSISTENT || storage == LOCAL_FILE_STORAGE_NAME)) {
300319 throw InvalidInputException("Persistent secrets are disabled. Restart DuckDB and enable persistent secrets "
300320 "through 'SET allow_persistent_secrets=true'");
300321 }
300322 throw InvalidInputException("Secret storage '%s' not found!", resolved_storage);
300323 }
300324
300325 // Validation on both allow_persistent_secrets and storage backend's own persist type
300326 if (persist_type == SecretPersistType::PERSISTENT) {
300327 if (backend->persistent) {
300328 if (!config.allow_persistent_secrets) {
300329 throw InvalidInputException(
300330 "Persistent secrets are currently disabled. To enable them, restart duckdb and "
300331 "run 'SET allow_persistent_secrets=true'");
300332 }
300333 } else { // backend is temp
300334 throw InvalidInputException("Cannot create persistent secrets in a temporary secret storage!");
300335 }
300336 } else { // SecretPersistType::TEMPORARY
300337 if (backend->persistent) {
300338 throw InvalidInputException("Cannot create temporary secrets in a persistent secret storage!");
300339 }
300340 }
300341 return backend->StoreSecret(std::move(secret), on_conflict, &transaction);
300342}
static constexpr const char * TEMPORARY_STORAGE_NAME
The default storage backends.
Definition duckdb.cpp:177872
Here is the call graph for this function:
Here is the caller graph for this function:

◆ InitializeSecrets()

void duckdb::SecretManager::InitializeSecrets ( CatalogTransaction transaction)
private

Initialize the secret catalog_set and persistent secrets (lazily).

300692 {
300693 if (!initialized) {
300694 lock_guard<mutex> lck(manager_lock);
300695 if (initialized) {
300696 // some sneaky other thread beat us to it
300697 return;
300698 }
300699
300700 // load the tmp storage
300701 LoadSecretStorageInternal(make_uniq<TemporarySecretStorage>(TEMPORARY_STORAGE_NAME, *transaction.db));
300702
300703 if (config.allow_persistent_secrets) {
300704 // load the persistent storage if enabled
300706 make_uniq<LocalFileSecretStorage>(*this, *transaction.db, LOCAL_FILE_STORAGE_NAME, config.secret_path));
300707 }
300708
300709 initialized = true;
300710 }
300711}
atomic< bool > initialized
While false, secret manager settings can still be changed.
Definition duckdb.cpp:177980
Here is the call graph for this function:
Here is the caller graph for this function:

◆ LoadSecretStorageInternal()

void duckdb::SecretManager::LoadSecretStorageInternal ( unique_ptr< SecretStorage > storage)
private

Load a secret storage.

300217 {
300218 if (secret_storages.find(storage->GetName()) != secret_storages.end()) {
300219 throw InvalidConfigurationException("Secret Storage with name '%s' already registered!", storage->GetName());
300220 }
300221
300222 // Check for tie-break offset collisions to ensure we can always tie-break cleanly
300223 for (const auto &storage_ptr : secret_storages) {
300224 if (storage_ptr.second->tie_break_offset == storage->tie_break_offset) {
300225 throw InvalidConfigurationException(
300226 "Failed to load secret storage '%s', tie break score collides with '%s'", storage->GetName(),
300227 storage_ptr.second->GetName());
300228 }
300229 }
300230
300231 secret_storages[storage->GetName()] = std::move(storage);
300232}
Here is the caller graph for this function:

◆ AutoloadExtensionForType()

void duckdb::SecretManager::AutoloadExtensionForType ( const string & type)
private

Autoload extension for specific secret type.

300713 {
300714 ExtensionHelper::TryAutoloadFromEntry(*db, StringUtil::Lower(type), EXTENSION_SECRET_TYPES);
300715}
static void TryAutoloadFromEntry(DatabaseInstance &db, const string &entry, const ExtensionEntry(&entries)[N])
Lookup a name in an extension entry and try to autoload it.
Definition duckdb.cpp:6390
Here is the call graph for this function:
Here is the caller graph for this function:

◆ AutoloadExtensionForFunction()

void duckdb::SecretManager::AutoloadExtensionForFunction ( const string & type,
const string & provider )
private

Autoload extension for specific secret function.

300743 {
300745 EXTENSION_SECRET_PROVIDERS);
300746}
Here is the call graph for this function:
Here is the caller graph for this function:

◆ ThrowTypeNotFoundError()

void duckdb::SecretManager::ThrowTypeNotFoundError ( const string & type,
const string & secret_path = "" )
private

Will throw appropriate error message when type not found.

300717 {
300718 auto entry = ExtensionHelper::FindExtensionInEntries(StringUtil::Lower(type), EXTENSION_SECRET_TYPES);
300719 string error_message;
300720
300721 if (!entry.empty() && db) {
300722 error_message = "Secret type '" + type + "' does not exist, but it exists in the " + entry + " extension.";
300723 error_message = ExtensionHelper::AddExtensionInstallHintToErrorMsg(*db, error_message, entry);
300724
300725 if (!secret_path.empty()) {
300726 error_message += "\n\nAlternatively, ";
300727 }
300728 } else {
300729 error_message = StringUtil::Format("Secret type '%s' not found", type);
300730
300731 if (!secret_path.empty()) {
300732 error_message += ", ";
300733 }
300734 }
300735
300736 if (!secret_path.empty()) {
300737 error_message += StringUtil::Format("try removing the secret at path '%s'.", secret_path);
300738 }
300739
300740 throw InvalidInputException(error_message);
300741}
static string FindExtensionInEntries(const string &name, const ExtensionEntry(&entries)[N])
Lookup a name in an ExtensionEntry list.
Definition duckdb.cpp:6376
static string Format(const string fmt_str, ARGS... params)
Format a string using printf semantics.
Definition duckdb.hpp:4002
Here is the call graph for this function:
Here is the caller graph for this function:

◆ ThrowProviderNotFoundError()

void duckdb::SecretManager::ThrowProviderNotFoundError ( const string & type,
const string & provider,
bool was_default = false )
private
300748 {
300750 EXTENSION_SECRET_PROVIDERS);
300751 if (!entry.empty() && db) {
300752 string error_message = was_default ? "Default secret provider" : "Secret provider";
300753 error_message +=
300754 " '" + provider + "' for type '" + type + "' does not exist, but it exists in the " + entry + " extension.";
300755 error_message = ExtensionHelper::AddExtensionInstallHintToErrorMsg(*db, error_message, entry);
300756
300757 throw InvalidInputException(error_message);
300758 }
300759 throw InvalidInputException("Secret provider '%s' not found for type '%s'", provider, type);
300760}

◆ GetSecretStorages()

vector< reference< SecretStorage > > duckdb::SecretManager::GetSecretStorages ( )
private

Thread-safe accessors for secret_storages.

300773 {
300774 lock_guard<mutex> lock(manager_lock);
300775
300776 vector<reference<SecretStorage>> result;
300777
300778 for (const auto &storage : secret_storages) {
300779 result.push_back(*storage.second);
300780 }
300781
300782 return result;
300783}
Here is the caller graph for this function:

◆ GetSecretStorage()

optional_ptr< SecretStorage > duckdb::SecretManager::GetSecretStorage ( const string & name)
private
300762 {
300763 lock_guard<mutex> lock(manager_lock);
300764
300765 auto lookup = secret_storages.find(name);
300766 if (lookup != secret_storages.end()) {
300767 return lookup->second.get();
300768 }
300769
300770 return nullptr;
300771}

◆ ThrowOnSettingChangeIfInitialized()

void duckdb::SecretManager::ThrowOnSettingChangeIfInitialized ( )
private

Throw an exception if the secret manager is initialized.

300645 {
300646 if (initialized) {
300647 throw InvalidInputException(
300648 "Changing Secret Manager settings after the secret manager is used is not allowed!");
300649 }
300650}
Here is the caller graph for this function:

Member Data Documentation

◆ initialized

atomic<bool> duckdb::SecretManager::initialized {false}
private

While false, secret manager settings can still be changed.

177980{false};

The documentation for this class was generated from the following file: