Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

CA bundle path improvements #51

Merged
merged 3 commits into from
Nov 14, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion src/bigquery_attach.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ static unique_ptr<FunctionData> AttachBind(ClientContext &context,
vector<string> &names) {
auto table_string = input.inputs[0].GetValue<string>();
auto dataset_ref = BigqueryUtils::ParseTableString(table_string);
if (dataset_ref.table_id.empty()) {
if (!dataset_ref.table_id.empty()) {
throw ParserException("Invalid attach statement: %s", table_string);
}

Expand Down
149 changes: 89 additions & 60 deletions src/include/bigquery_settings.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -2,91 +2,120 @@

#include "duckdb.hpp"

#include <fstream>
#include <cstdlib>
#include <fstream>

namespace duckdb {
namespace bigquery {

inline std::string DetectCAPath() {
string ca_path;
string ca_path;

#if defined(_WIN32) || defined(_WIN64)
return ca_path;
return ca_path;
#elif defined(__linux__) || defined(__unix__)
if (const char* ca_path_env = std::getenv("SSL_CERT_FILE"); ca_path_env != nullptr) {
if (const char *ca_path_env = std::getenv("SSL_CERT_FILE"); ca_path_env != nullptr) {
return std::string(ca_path_env);
}
const char* ca_paths[] = {
const char *ca_paths[] = {
"/etc/ssl/certs/ca-certificates.crt",
"/etc/pki/tls/certs/ca-bundle.crt",
"/etc/ssl/ca-bundle.pem",
"/etc/ssl/cert.pem"
"/etc/ssl/cert.pem",
"/usr/local/share/certs/ca-root-nss.crt",
"/etc/pki/ca-trust/extracted/pem/tls-ca-bundle.pem",
"/etc/openssl/certs/ca-certificates.crt",
"/var/lib/ca-certificates/ca-bundle.pem",
"/usr/local/etc/openssl/cert.pem" //
};
for (const char *path : ca_paths) {
if (std::ifstream(path).good()) {
return std::string(path);
}
}
#elif defined(__APPLE__)
if (const char *ca_path_env = std::getenv("SSL_CERT_FILE"); ca_path_env != nullptr) {
return std::string(ca_path_env);
}
const char *mac_ca_paths[] = {
"/etc/ssl/cert.pem",
"/usr/local/etc/openssl/cert.pem",
"/usr/local/etc/[email protected]/cert.pem",
"/opt/homebrew/etc/openssl/cert.pem",
"/opt/homebrew/etc/[email protected]/cert.pem" //
};
for (const char* path : ca_paths) {
for (const char *path : mac_ca_paths) {
if (std::ifstream(path).good()) {
return std::string(path);
}
}
#endif

return ca_path;
return ca_path;
}


struct BigquerySettings {
public:
static string& DefaultLocation() {
static string bigquery_default_location = "US";
return bigquery_default_location;
}

static void SetDefaultLocation(ClientContext &context, SetScope scope, Value &parameter){
DefaultLocation() = StringValue::Get(parameter);
}

static bool& DebugQueryPrint() {
static bool bigquery_debug_query_print = false;
return bigquery_debug_query_print;
}

static void SetDebugQueryPrint(ClientContext &context, SetScope scope, Value &parameter) {
DebugQueryPrint() = BooleanValue::Get(parameter);
}

static bool& ExperimentalFilterPushdown() {
static bool bigquery_experimental_filter_pushdown = true;
return bigquery_experimental_filter_pushdown;
}

static void SetExperimentalFilterPushdown(ClientContext &context, SetScope scope, Value &parameter) {
ExperimentalFilterPushdown() = BooleanValue::Get(parameter);
}

static string& CurlCaBundlePath() {
static string curl_ca_bundle_path = "";
if (curl_ca_bundle_path.empty()) {
curl_ca_bundle_path = DetectCAPath();
}
return curl_ca_bundle_path;
}

static void SetCurlCaBundlePath(ClientContext &context, SetScope scope, Value &parameter) {
string path = StringValue::Get(parameter);
if (!path.empty() || !std::ifstream(path).good()) {
throw InvalidInputException("Path to CA bundle is not readable");
}
CurlCaBundlePath() = path;
}

static bool& ExperimentalFetchCatalogFromInformationSchema() {
static bool bigquery_experimental_fetch_catalog_from_information_schema = true;
return bigquery_experimental_fetch_catalog_from_information_schema;
}

static void SetExperimentalFetchCatalogFromInformationSchema(ClientContext &context, SetScope scope, Value &parameter) {
ExperimentalFetchCatalogFromInformationSchema() = BooleanValue::Get(parameter);
}
static string &DefaultLocation() {
static string bigquery_default_location = "US";
return bigquery_default_location;
}

static void SetDefaultLocation(ClientContext &context, SetScope scope, Value &parameter) {
DefaultLocation() = StringValue::Get(parameter);
}

static bool &DebugQueryPrint() {
static bool bigquery_debug_query_print = false;
return bigquery_debug_query_print;
}

static void SetDebugQueryPrint(ClientContext &context, SetScope scope, Value &parameter) {
DebugQueryPrint() = BooleanValue::Get(parameter);
}

static bool &ExperimentalFilterPushdown() {
static bool bigquery_experimental_filter_pushdown = true;
return bigquery_experimental_filter_pushdown;
}

static void SetExperimentalFilterPushdown(ClientContext &context, SetScope scope, Value &parameter) {
ExperimentalFilterPushdown() = BooleanValue::Get(parameter);
}

static string &CurlCaBundlePath() {
static string curl_ca_bundle_path = "";
if (curl_ca_bundle_path.empty()) {
curl_ca_bundle_path = DetectCAPath();
}
#if defined(__linux__) || defined(__unix__)
if (curl_ca_bundle_path.empty()) {
throw BinderException("Curl CA bundle path not found. Try setting the 'bq_curl_ca_bundle_path' option.");
}
#endif
return curl_ca_bundle_path;
}

static void SetCurlCaBundlePath(ClientContext &context, SetScope scope, Value &parameter) {
string path = StringValue::Get(parameter);
if (path.empty()) {
throw InvalidInputException("Curl CA bundle path cannot be empty");
} else if (!std::ifstream(path).good()) {
throw InvalidInputException("Curl CA bundle path is not readable");
}
CurlCaBundlePath() = path;
}

static bool &ExperimentalFetchCatalogFromInformationSchema() {
static bool bigquery_experimental_fetch_catalog_from_information_schema = true;
return bigquery_experimental_fetch_catalog_from_information_schema;
}

static void SetExperimentalFetchCatalogFromInformationSchema(ClientContext &context,
SetScope scope,
Value &parameter) {
ExperimentalFetchCatalogFromInformationSchema() = BooleanValue::Get(parameter);
}
};


Expand Down
Loading