• Home
  • Features
  • Pricing
  • Docs
  • Announcements
  • Sign In

GothenburgBitFactory / taskwarrior / 12364338505

17 Dec 2024 01:08AM UTC coverage: 84.789% (-0.1%) from 84.898%
12364338505

push

github

web-flow
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.

1 of 30 new or added lines in 1 file covered. (3.33%)

2 existing lines in 2 files now uncovered.

19276 of 22734 relevant lines covered (84.79%)

23254.19 hits per line

Source File
Press 'n' to go to next uncovered line, 'b' for previous

46.91
/src/commands/CmdSync.cpp
1
////////////////////////////////////////////////////////////////////////////////
2
//
3
// Copyright 2006 - 2021, Tomas Babej, Paul Beckingham, Federico Hernandez.
4
//
5
// Permission is hereby granted, free of charge, to any person obtaining a copy
6
// of this software and associated documentation files (the "Software"), to deal
7
// in the Software without restriction, including without limitation the rights
8
// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
// copies of the Software, and to permit persons to whom the Software is
10
// furnished to do so, subject to the following conditions:
11
//
12
// The above copyright notice and this permission notice shall be included
13
// in all copies or substantial portions of the Software.
14
//
15
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
16
// OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
18
// THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
// SOFTWARE.
22
//
23
// https://www.opensource.org/licenses/mit-license.php
24
//
25
////////////////////////////////////////////////////////////////////////////////
26

27
#include <cmake.h>
28
// cmake.h include header must come first
29

30
#include <CmdSync.h>
31
#include <Color.h>
32
#include <Context.h>
33
#include <Filter.h>
34
#include <format.h>
35
#include <inttypes.h>
36
#include <shared.h>
37
#include <signal.h>
38
#include <taskchampion-cpp/lib.h>
39
#include <util.h>
40

41
#include <iostream>
42
#include <sstream>
43

44
////////////////////////////////////////////////////////////////////////////////
45
CmdSync::CmdSync() {
4,495✔
46
  _keyword = "synchronize";
4,495✔
47
  _usage = "task          synchronize [initialize]";
4,495✔
48
  _description = "Synchronizes data with the Taskserver";
4,495✔
49
  _read_only = false;
4,495✔
50
  _displays_id = false;
4,495✔
51
  _needs_gc = false;
4,495✔
52
  _uses_context = false;
4,495✔
53
  _accepts_filter = false;
4,495✔
54
  _accepts_modifications = false;
4,495✔
55
  _accepts_miscellaneous = true;
4,495✔
56
  _category = Command::Category::migration;
4,495✔
57
}
4,495✔
58

59
////////////////////////////////////////////////////////////////////////////////
60
int CmdSync::execute(std::string& output) {
2✔
61
  int status = 0;
2✔
62

63
  Context& context = Context::getContext();
2✔
64
  auto& replica = context.tdb2.replica();
2✔
65
  std::stringstream out;
2✔
66
  bool avoid_snapshots = false;
2✔
67
  bool verbose = Context::getContext().verbose("sync");
4✔
68

69
  std::string origin = Context::getContext().config.get("sync.server.origin");
4✔
70
  std::string url = Context::getContext().config.get("sync.server.url");
4✔
71
  std::string server_dir = Context::getContext().config.get("sync.local.server_dir");
4✔
72
  std::string client_id = Context::getContext().config.get("sync.server.client_id");
4✔
73
  std::string aws_bucket = Context::getContext().config.get("sync.aws.bucket");
4✔
74
  std::string gcp_bucket = Context::getContext().config.get("sync.gcp.bucket");
4✔
75
  std::string encryption_secret = Context::getContext().config.get("sync.encryption_secret");
4✔
76

77
  // sync.server.origin is a deprecated synonym for sync.server.url
78
  std::string server_url = url == "" ? origin : url;
2✔
79
  if (origin != "") {
2✔
80
    out << "sync.server.origin is deprecated. Use sync.server.url instead.\n";
×
81
  }
82

83
  if (server_dir != "") {
2✔
84
    if (verbose) {
2✔
85
      out << format("Syncing with {1}", server_dir) << '\n';
6✔
86
    }
87
    replica->sync_to_local(server_dir, avoid_snapshots);
2✔
NEW
88
  } else if (aws_bucket != "") {
×
NEW
89
    std::string aws_region = Context::getContext().config.get("sync.aws.region");
×
NEW
90
    std::string aws_profile = Context::getContext().config.get("sync.aws.profile");
×
NEW
91
    std::string aws_access_key_id = Context::getContext().config.get("sync.aws.access_key_id");
×
92
    std::string aws_secret_access_key =
NEW
93
        Context::getContext().config.get("sync.aws.secret_access_key");
×
94
    std::string aws_default_credentials =
NEW
95
        Context::getContext().config.get("sync.aws.default_credentials");
×
NEW
96
    if (aws_region == "") {
×
NEW
97
      throw std::string("sync.aws.region is required");
×
98
    }
NEW
99
    if (encryption_secret == "") {
×
NEW
100
      throw std::string("sync.encryption_secret is required");
×
101
    }
102

NEW
103
    bool using_profile = false;
×
NEW
104
    bool using_creds = false;
×
NEW
105
    bool using_default = false;
×
NEW
106
    if (aws_profile != "") {
×
NEW
107
      using_profile = true;
×
108
    }
NEW
109
    if (aws_access_key_id != "" || aws_secret_access_key != "") {
×
NEW
110
      using_creds = true;
×
111
    }
NEW
112
    if (aws_default_credentials != "") {
×
NEW
113
      using_default = true;
×
114
    }
115

NEW
116
    if (using_profile + using_creds + using_default != 1) {
×
NEW
117
      throw std::string("exactly one method of specifying AWS credentials is required");
×
118
    }
119

NEW
120
    if (verbose) {
×
NEW
121
      out << format("Syncing with AWS bucket {1}", aws_bucket) << '\n';
×
122
    }
123

NEW
124
    if (using_profile) {
×
NEW
125
      replica->sync_to_aws_with_profile(aws_region, aws_bucket, aws_profile, encryption_secret,
×
126
                                        avoid_snapshots);
NEW
127
    } else if (using_creds) {
×
NEW
128
      replica->sync_to_aws_with_access_key(aws_region, aws_bucket, aws_access_key_id,
×
129
                                           aws_secret_access_key, encryption_secret,
130
                                           avoid_snapshots);
131
    } else {
NEW
132
      replica->sync_to_aws_with_default_creds(aws_region, aws_bucket, encryption_secret,
×
133
                                              avoid_snapshots);
134
    }
135
  } else if (gcp_bucket != "") {
×
NEW
136
    std::string gcp_credential_path = Context::getContext().config.get("sync.gcp.credential_path");
×
137
    if (encryption_secret == "") {
×
138
      throw std::string("sync.encryption_secret is required");
×
139
    }
140
    if (verbose) {
×
141
      out << format("Syncing with GCP bucket {1}", gcp_bucket) << '\n';
×
142
    }
143
    replica->sync_to_gcp(gcp_bucket, gcp_credential_path, encryption_secret, avoid_snapshots);
×
144
  } else if (server_url != "") {
×
145
    if (client_id == "" || encryption_secret == "") {
×
146
      throw std::string("sync.server.client_id and sync.encryption_secret are required");
×
147
    }
148
    if (verbose) {
×
149
      out << format("Syncing with sync server at {1}", server_url) << '\n';
×
150
    }
151
    replica->sync_to_remote(server_url, tc::uuid_from_string(client_id), encryption_secret,
×
152
                            avoid_snapshots);
153
  } else {
154
    throw std::string("No sync.* settings are configured. See task-sync(5).");
×
155
  }
156

157
  if (context.config.getBoolean("purge.on-sync")) {
6✔
158
    context.tdb2.expire_tasks();
1✔
159
  }
160

161
  output = out.str();
2✔
162
  return status;
2✔
163
}
2✔
164

165
////////////////////////////////////////////////////////////////////////////////
STATUS · Troubleshooting · Open an Issue · Sales · Support · CAREERS · ENTERPRISE · START FREE · SCHEDULE DEMO
ANNOUNCEMENTS · TWITTER · TOS & SLA · Supported CI Services · What's a CI service? · Automated Testing

© 2026 Coveralls, Inc