Skip to content

Commit

Permalink
C++ version
Browse files Browse the repository at this point in the history
  • Loading branch information
Y-- committed Nov 1, 2024
1 parent 2daf4ee commit ad0a63c
Showing 1 changed file with 11 additions and 13 deletions.
24 changes: 11 additions & 13 deletions src/pgduckdb_duckdb.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -132,38 +132,36 @@ DuckDBManager::LoadSecrets(duckdb::ClientContext &context) {

int secret_id = 0;
for (auto &secret : duckdb_secrets) {
StringInfo secret_key = makeStringInfo();
std::ostringstream query;
bool is_r2_cloud_secret = (secret.type.rfind("R2", 0) == 0);
appendStringInfo(secret_key, "CREATE SECRET pgduckb_secret_%d ", secret_id);
appendStringInfo(secret_key, "(TYPE %s, KEY_ID '%s', SECRET '%s'", secret.type.c_str(), secret.key_id.c_str(),
secret.secret.c_str());
query << "CREATE SECRET pgduckb_secret_" << secret_id << " ";
query << "(TYPE " << secret.type << ", KEY_ID '" << secret.key_id << "', SECRET '" << secret.secret << "'";
if (secret.region.length() && !is_r2_cloud_secret) {
appendStringInfo(secret_key, ", REGION '%s'", secret.region.c_str());
query << ", REGION '" << secret.region << "'";
}
if (secret.session_token.length() && !is_r2_cloud_secret) {
appendStringInfo(secret_key, ", SESSION_TOKEN '%s'", secret.session_token.c_str());
query << ", SESSION_TOKEN '" << secret.session_token << "'";
}
if (secret.endpoint.length() && !is_r2_cloud_secret) {
appendStringInfo(secret_key, ", ENDPOINT '%s'", secret.endpoint.c_str());
query << ", ENDPOINT '" << secret.endpoint << "'";
}
if (is_r2_cloud_secret) {
appendStringInfo(secret_key, ", ACCOUNT_ID '%s'", secret.endpoint.c_str());
query << ", ACCOUNT_ID '" << secret.endpoint << "'";
}
if (!secret.use_ssl) {
appendStringInfo(secret_key, ", USE_SSL 'FALSE'");
query << ", USE_SSL 'FALSE'";
}
appendStringInfo(secret_key, ");");
DuckDBQueryOrThrow(context, secret_key->data);
query << ");";

pfree(secret_key->data);
DuckDBQueryOrThrow(context, query.str());
secret_id++;
secret_table_num_rows = secret_id;
}
}

void
DuckDBManager::DropSecrets(duckdb::ClientContext &context) {
for (auto secret_id = 0; secret_id < secret_table_num_rows; secret_id++) {
for (auto secret_id = 0; secret_id < secret_table_num_rows; ++secret_id) {
auto drop_secret_cmd = duckdb::StringUtil::Format("DROP SECRET pgduckb_secret_%d;", secret_id);
pgduckdb::DuckDBQueryOrThrow(context, drop_secret_cmd);
}
Expand Down

0 comments on commit ad0a63c

Please sign in to comment.