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

GothenburgBitFactory / taskwarrior / 14451514896

14 Apr 2025 05:08PM UTC coverage: 85.151% (-0.09%) from 85.237%
14451514896

push

github

web-flow
Redact HTTP credentials from "Syncing…" message (#3846) (#3847)

2 of 3 new or added lines in 1 file covered. (66.67%)

21 existing lines in 2 files now uncovered.

19538 of 22945 relevant lines covered (85.15%)

23386.95 hits per line

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

48.81
/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 <shared.h>
36
#include <taskchampion-cpp/lib.h>
37
#include <util.h>
38

39
#include <regex>
40
#include <sstream>
41

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

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

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

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

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

82
  // redact credentials from `server_url`, if present
83
  std::regex remove_creds_regex("^(https?://.+):(.+)@(.+)");
2✔
84
  std::string safe_server_url = std::regex_replace(server_url, remove_creds_regex, "$1:****@$3");
2✔
85

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

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

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

123
    if (verbose) {
×
124
      out << format("Syncing with AWS bucket {1}", aws_bucket) << '\n';
×
125
    }
126

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

160
  if (context.config.getBoolean("purge.on-sync")) {
6✔
161
    context.tdb2.expire_tasks();
1✔
162
  }
163

164
  output = out.str();
2✔
165
  return status;
2✔
166
}
2✔
167

168
////////////////////////////////////////////////////////////////////////////////
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