|
1 | 1 | #include "redis_secret.hpp" |
2 | 2 | #include "duckdb/common/exception.hpp" |
3 | 3 | #include "duckdb/main/secret/secret.hpp" |
4 | | -#include "duckdb/main/extension_loader.hpp" |
| 4 | +#include "duckdb/main/extension/extension_loader.hpp" |
5 | 5 |
|
6 | 6 | namespace duckdb { |
7 | 7 |
|
8 | 8 | static void CopySecret(const std::string &key, const CreateSecretInput &input, KeyValueSecret &result) { |
9 | | - auto val = input.options.find(key); |
10 | | - if (val != input.options.end()) { |
11 | | - result.secret_map[key] = val->second; |
12 | | - } |
| 9 | + auto val = input.options.find(key); |
| 10 | + if (val != input.options.end()) { |
| 11 | + result.secret_map[key] = val->second; |
| 12 | + } |
13 | 13 | } |
14 | 14 |
|
15 | 15 | static void RegisterCommonSecretParameters(CreateSecretFunction &function) { |
16 | | - // Register redis connection parameters |
17 | | - function.named_parameters["host"] = LogicalType::VARCHAR; |
18 | | - function.named_parameters["port"] = LogicalType::VARCHAR; |
19 | | - function.named_parameters["password"] = LogicalType::VARCHAR; |
| 16 | + // Register redis connection parameters |
| 17 | + function.named_parameters["host"] = LogicalType::VARCHAR; |
| 18 | + function.named_parameters["port"] = LogicalType::VARCHAR; |
| 19 | + function.named_parameters["password"] = LogicalType::VARCHAR; |
20 | 20 | } |
21 | 21 |
|
22 | 22 | static void RedactCommonKeys(KeyValueSecret &result) { |
23 | | - // Redact sensitive information |
24 | | - result.redact_keys.insert("password"); |
| 23 | + // Redact sensitive information |
| 24 | + result.redact_keys.insert("password"); |
25 | 25 | } |
26 | 26 |
|
27 | 27 | static unique_ptr<BaseSecret> CreateRedisSecretFromConfig(ClientContext &context, CreateSecretInput &input) { |
28 | | - auto scope = input.scope; |
29 | | - auto result = make_uniq<KeyValueSecret>(scope, input.type, input.provider, input.name); |
| 28 | + auto scope = input.scope; |
| 29 | + auto result = make_uniq<KeyValueSecret>(scope, input.type, input.provider, input.name); |
30 | 30 |
|
31 | | - // Copy all relevant secrets |
32 | | - CopySecret("host", input, *result); |
33 | | - CopySecret("port", input, *result); |
34 | | - CopySecret("password", input, *result); |
| 31 | + // Copy all relevant secrets |
| 32 | + CopySecret("host", input, *result); |
| 33 | + CopySecret("port", input, *result); |
| 34 | + CopySecret("password", input, *result); |
35 | 35 |
|
36 | | - // Redact sensitive keys |
37 | | - RedactCommonKeys(*result); |
| 36 | + // Redact sensitive keys |
| 37 | + RedactCommonKeys(*result); |
38 | 38 |
|
39 | | - return result; |
| 39 | + return result; |
40 | 40 | } |
41 | 41 |
|
42 | 42 | static unique_ptr<BaseSecret> RedisSecretDeserialize(Deserializer &deserializer, BaseSecret base_secret) { |
43 | | - auto result = KeyValueSecret::Deserialize<KeyValueSecret>(deserializer, std::move(base_secret)); |
44 | | - auto kv_secret = dynamic_cast<KeyValueSecret*>(result.get()); |
45 | | - if (kv_secret) { |
46 | | - RedactCommonKeys(*kv_secret); |
47 | | - } |
48 | | - return result; |
| 43 | + auto result = KeyValueSecret::Deserialize<KeyValueSecret>(deserializer, std::move(base_secret)); |
| 44 | + auto kv_secret = dynamic_cast<KeyValueSecret *>(result.get()); |
| 45 | + if (kv_secret) { |
| 46 | + RedactCommonKeys(*kv_secret); |
| 47 | + } |
| 48 | + return result; |
49 | 49 | } |
50 | 50 |
|
51 | 51 | void CreateRedisSecretFunctions::Register(ExtensionLoader &loader) { |
52 | | - string type = "redis"; |
| 52 | + string type = "redis"; |
53 | 53 |
|
54 | | - // Register the new type |
55 | | - SecretType secret_type; |
56 | | - secret_type.name = type; |
57 | | - secret_type.deserializer = RedisSecretDeserialize; |
58 | | - secret_type.default_provider = "config"; |
59 | | - loader.RegisterSecretType(secret_type); |
| 54 | + // Register the new type |
| 55 | + SecretType secret_type; |
| 56 | + secret_type.name = type; |
| 57 | + secret_type.deserializer = RedisSecretDeserialize; |
| 58 | + secret_type.default_provider = "config"; |
| 59 | + loader.RegisterSecretType(secret_type); |
60 | 60 |
|
61 | | - // Register the config secret provider |
62 | | - CreateSecretFunction config_function = {type, "config", CreateRedisSecretFromConfig}; |
63 | | - RegisterCommonSecretParameters(config_function); |
64 | | - loader.RegisterFunction(config_function); |
| 61 | + // Register the config secret provider |
| 62 | + CreateSecretFunction config_function = {type, "config", CreateRedisSecretFromConfig}; |
| 63 | + RegisterCommonSecretParameters(config_function); |
| 64 | + loader.RegisterFunction(config_function); |
65 | 65 | } |
66 | 66 |
|
67 | | -} // namespace duckdb |
| 67 | +} // namespace duckdb |
0 commit comments