-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* secret manager * ENV support * cast unique_ptr to the correct type * cast unique_ptr to the correct type * resync * add tests * fix env, secrets handling * Update README.md
- Loading branch information
Showing
8 changed files
with
212 additions
and
15 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Submodule duckdb
updated
3121 files
Submodule extension-ci-tools
updated
16 files
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
#pragma once | ||
|
||
#include "duckdb/main/secret/secret.hpp" | ||
#include "duckdb/main/extension_util.hpp" | ||
|
||
namespace duckdb { | ||
|
||
struct CreateOpenPromptSecretFunctions { | ||
public: | ||
static void Register(DatabaseInstance &instance); | ||
}; | ||
|
||
} // namespace duckdb |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,60 @@ | ||
#include "open_prompt_secret.hpp" | ||
#include "duckdb/common/exception.hpp" | ||
#include "duckdb/main/secret/secret.hpp" | ||
#include "duckdb/main/extension_util.hpp" | ||
|
||
namespace duckdb { | ||
|
||
static void CopySecret(const std::string &key, const CreateSecretInput &input, KeyValueSecret &result) { | ||
auto val = input.options.find(key); | ||
if (val != input.options.end()) { | ||
result.secret_map[key] = val->second; | ||
} | ||
} | ||
|
||
static void RegisterCommonSecretParameters(CreateSecretFunction &function) { | ||
// Register open_prompt common parameters | ||
function.named_parameters["api_token"] = LogicalType::VARCHAR; | ||
function.named_parameters["api_url"] = LogicalType::VARCHAR; | ||
function.named_parameters["model_name"] = LogicalType::VARCHAR; | ||
function.named_parameters["api_timeout"] = LogicalType::VARCHAR; | ||
} | ||
|
||
static void RedactCommonKeys(KeyValueSecret &result) { | ||
// Redact sensitive information | ||
result.redact_keys.insert("api_token"); | ||
} | ||
|
||
static unique_ptr<BaseSecret> CreateOpenPromptSecretFromConfig(ClientContext &context, CreateSecretInput &input) { | ||
auto scope = input.scope; | ||
auto result = make_uniq<KeyValueSecret>(scope, input.type, input.provider, input.name); | ||
|
||
// Copy all relevant secrets | ||
CopySecret("api_token", input, *result); | ||
CopySecret("api_url", input, *result); | ||
CopySecret("model_name", input, *result); | ||
CopySecret("api_timeout", input, *result); | ||
|
||
// Redact sensitive keys | ||
RedactCommonKeys(*result); | ||
|
||
return std::move(result); | ||
} | ||
|
||
void CreateOpenPromptSecretFunctions::Register(DatabaseInstance &instance) { | ||
string type = "open_prompt"; | ||
|
||
// Register the new type | ||
SecretType secret_type; | ||
secret_type.name = type; | ||
secret_type.deserializer = KeyValueSecret::Deserialize<KeyValueSecret>; | ||
secret_type.default_provider = "config"; | ||
ExtensionUtil::RegisterSecretType(instance, secret_type); | ||
|
||
// Register the config secret provider | ||
CreateSecretFunction config_function = {type, "config", CreateOpenPromptSecretFromConfig}; | ||
RegisterCommonSecretParameters(config_function); | ||
ExtensionUtil::RegisterFunction(instance, config_function); | ||
} | ||
|
||
} // namespace duckdb |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
# name: test/sql/rusty_quack.test | ||
# description: test rusty_quack extension | ||
# group: [quack] | ||
|
||
# Before we load the extension, this will fail | ||
statement error | ||
SELECT open_prompt('error'); | ||
---- | ||
Catalog Error: Scalar Function with name open_prompt does not exist! | ||
|
||
# Require statement will ensure the extension is loaded from now on | ||
require open_prompt | ||
|
||
# Confirm the extension works by setting a secret | ||
query I | ||
CREATE SECRET IF NOT EXISTS open_prompt ( | ||
TYPE open_prompt, | ||
PROVIDER config, | ||
api_token 'xxxxx', | ||
api_url 'https://api.groq.com/openai/v1/chat/completions', | ||
model_name 'llama-3.3-70b-versatile', | ||
api_timeout '30' | ||
); | ||
---- | ||
true | ||
|
||
# Confirm the secret exists | ||
query I | ||
SELECT name FROM duckdb_secrets() WHERE name = 'open_prompt' ; | ||
---- | ||
open_prompt |