Add support for sync to AWS (#3723)

This is closely modeled on support for sync to GCP (#3223), but with
different authentication options to mirror typical usage of AWS.
This commit is contained in:
Dustin J. Mitchell 2024-12-16 20:08:50 -05:00 committed by GitHub
parent ff325bc19e
commit 758ac8f850
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
7 changed files with 506 additions and 150 deletions

View file

@ -194,9 +194,15 @@ int CmdShow::execute(std::string& output) {
" search.case.sensitive"
" sugar"
" summary.all.projects"
" sync.local.server_dir"
" sync.aws.access_key_id"
" sync.aws.bucket"
" sync.aws.default_credentials"
" sync.aws.profile"
" sync.aws.region"
" sync.aws.secret_access_key"
" sync.gcp.credential_path"
" sync.gcp.bucket"
" sync.local.server_dir"
" sync.server.client_id"
" sync.encryption_secret"
" sync.server.url"

View file

@ -38,6 +38,7 @@
#include <taskchampion-cpp/lib.h>
#include <util.h>
#include <iostream>
#include <sstream>
////////////////////////////////////////////////////////////////////////////////
@ -65,12 +66,11 @@ int CmdSync::execute(std::string& output) {
bool avoid_snapshots = false;
bool verbose = Context::getContext().verbose("sync");
// If no server is set up, quit.
std::string origin = Context::getContext().config.get("sync.server.origin");
std::string url = Context::getContext().config.get("sync.server.url");
std::string server_dir = Context::getContext().config.get("sync.local.server_dir");
std::string client_id = Context::getContext().config.get("sync.server.client_id");
std::string gcp_credential_path = Context::getContext().config.get("sync.gcp.credential_path");
std::string aws_bucket = Context::getContext().config.get("sync.aws.bucket");
std::string gcp_bucket = Context::getContext().config.get("sync.gcp.bucket");
std::string encryption_secret = Context::getContext().config.get("sync.encryption_secret");
@ -85,7 +85,55 @@ int CmdSync::execute(std::string& output) {
out << format("Syncing with {1}", server_dir) << '\n';
}
replica->sync_to_local(server_dir, avoid_snapshots);
} else if (aws_bucket != "") {
std::string aws_region = Context::getContext().config.get("sync.aws.region");
std::string aws_profile = Context::getContext().config.get("sync.aws.profile");
std::string aws_access_key_id = Context::getContext().config.get("sync.aws.access_key_id");
std::string aws_secret_access_key =
Context::getContext().config.get("sync.aws.secret_access_key");
std::string aws_default_credentials =
Context::getContext().config.get("sync.aws.default_credentials");
if (aws_region == "") {
throw std::string("sync.aws.region is required");
}
if (encryption_secret == "") {
throw std::string("sync.encryption_secret is required");
}
bool using_profile = false;
bool using_creds = false;
bool using_default = false;
if (aws_profile != "") {
using_profile = true;
}
if (aws_access_key_id != "" || aws_secret_access_key != "") {
using_creds = true;
}
if (aws_default_credentials != "") {
using_default = true;
}
if (using_profile + using_creds + using_default != 1) {
throw std::string("exactly one method of specifying AWS credentials is required");
}
if (verbose) {
out << format("Syncing with AWS bucket {1}", aws_bucket) << '\n';
}
if (using_profile) {
replica->sync_to_aws_with_profile(aws_region, aws_bucket, aws_profile, encryption_secret,
avoid_snapshots);
} else if (using_creds) {
replica->sync_to_aws_with_access_key(aws_region, aws_bucket, aws_access_key_id,
aws_secret_access_key, encryption_secret,
avoid_snapshots);
} else {
replica->sync_to_aws_with_default_creds(aws_region, aws_bucket, encryption_secret,
avoid_snapshots);
}
} else if (gcp_bucket != "") {
std::string gcp_credential_path = Context::getContext().config.get("sync.gcp.credential_path");
if (encryption_secret == "") {
throw std::string("sync.encryption_secret is required");
}