added BYOS (Bring Your Own SERVICE_ACCOUNT) for GCS authentication (#3262)

This commit is contained in:
Akash Shanmugaraj
2024-01-27 18:27:12 +05:30
committed by GitHub
parent 83bbe4ec37
commit aeb6acf640
10 changed files with 88 additions and 12 deletions

View File

@@ -283,6 +283,7 @@ std::string configurationDefaults =
"#sync.server.client_id # Client ID for sync to a server\n"
"#sync.server.origin # Origin of the sync server\n"
"#sync.local.server_dir # Directory for local sync\n"
"#sync.gcp.credential_path # Path to JSON file containing credentials to authenticate GCP Sync\n"
"#sync.gcp.bucket # Bucket for sync to GCP\n"
"\n"
"# Aliases - alternate names for commands\n"

View File

@@ -193,6 +193,7 @@ int CmdShow::execute (std::string& output)
" sugar"
" summary.all.projects"
" sync.local.server_dir"
" sync.gcp.credential_path"
" sync.gcp.bucket"
" sync.server.client_id"
" sync.encryption_secret"

View File

@@ -64,6 +64,7 @@ int CmdSync::execute (std::string& output)
// If no server is set up, quit.
std::string origin = Context::getContext ().config.get ("sync.server.origin");
std::string server_dir = Context::getContext ().config.get ("sync.local.server_dir");
std::string gcp_credential_path = Context::getContext ().config.get ("sync.gcp.credential_path");
std::string gcp_bucket = Context::getContext ().config.get ("sync.gcp.bucket");
std::string encryption_secret = Context::getContext ().config.get ("sync.encryption_secret");
if (server_dir != "") {
@@ -73,7 +74,7 @@ int CmdSync::execute (std::string& output)
if (encryption_secret == "") {
throw std::string ("sync.encryption_secret is required");
}
server = tc::Server::new_gcp (gcp_bucket, encryption_secret);
server = tc::Server::new_gcp (gcp_bucket, gcp_credential_path, encryption_secret);
std::ostringstream os;
os << "GCP bucket " << gcp_bucket;
server_ident = os.str();

View File

@@ -79,13 +79,14 @@ tc::Server::new_sync (const std::string &origin, const std::string &client_id, c
////////////////////////////////////////////////////////////////////////////////
tc::Server
tc::Server::new_gcp (const std::string &bucket, const std::string &encryption_secret)
tc::Server::new_gcp (const std::string &bucket, const std::string &credential_path, const std::string &encryption_secret)
{
TCString tc_bucket = tc_string_borrow (bucket.c_str ());
TCString tc_encryption_secret = tc_string_borrow (encryption_secret.c_str ());
TCString tc_credential_path = tc_string_borrow (credential_path.c_str ());
TCString error;
auto tcserver = tc_server_new_gcp (tc_bucket, tc_encryption_secret, &error);
auto tcserver = tc_server_new_gcp (tc_bucket, tc_credential_path, tc_encryption_secret, &error);
if (!tcserver) {
auto errmsg = format ("Could not configure connection to GCP bucket {1}: {2}",
bucket, tc_string_content (&error));

View File

@@ -57,7 +57,7 @@ namespace tc {
static Server new_sync (const std::string &origin, const std::string &client_id, const std::string &encryption_secret);
// Construct a GCP server (tc_server_new_gcp).
static Server new_gcp (const std::string &bucket, const std::string &encryption_secret);
static Server new_gcp (const std::string &bucket, const std::string &credential_path, const std::string &encryption_secret);
// This object "owns" inner, so copy is not allowed.
Server (const Server &) = delete;