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

GothenburgBitFactory / taskwarrior / 9800779936

04 Jul 2024 11:17PM UTC coverage: 84.081% (-0.1%) from 84.211%
9800779936

push

github

web-flow
Relax sync.server.origin to allow paths (#3423)

0 of 13 new or added lines in 2 files covered. (0.0%)

28 existing lines in 2 files now uncovered.

19221 of 22860 relevant lines covered (84.08%)

20051.8 hits per line

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

0.0
/src/tc/Server.cpp
1
////////////////////////////////////////////////////////////////////////////////
2
//
3
// Copyright 2022, Dustin J. Mitchell
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
#include <format.h>
29
#include "tc/Server.h"
30
#include "tc/util.h"
31

32
using namespace tc::ffi;
33

34
////////////////////////////////////////////////////////////////////////////////
35
tc::Server
36
tc::Server::new_local (const std::string &server_dir)
×
37
{
38
  TCString tc_server_dir = tc_string_borrow (server_dir.c_str ());
×
39
  TCString error;
40
  auto tcserver = tc_server_new_local (tc_server_dir, &error);
×
41
  if (!tcserver) {
×
42
    std::string errmsg = format ("Could not configure local server at {1}: {2}",
43
        server_dir, tc_string_content (&error));
×
44
    tc_string_free (&error);
×
45
    throw errmsg;
×
46
  }
47
  return Server (unique_tcserver_ptr (
×
48
      tcserver,
49
      [](TCServer* rep) { tc_server_free (rep); }));
×
50
}
51

52
////////////////////////////////////////////////////////////////////////////////
53
tc::Server
NEW
54
tc::Server::new_sync (const std::string &url, const std::string &client_id, const std::string &encryption_secret)
×
55
{
NEW
56
  TCString tc_url = tc_string_borrow (url.c_str ());
×
57
  TCString tc_client_id = tc_string_borrow (client_id.c_str ());
×
58
  TCString tc_encryption_secret = tc_string_borrow (encryption_secret.c_str ());
×
59

60
  TCUuid tc_client_uuid;
61
  if (tc_uuid_from_str(tc_client_id, &tc_client_uuid) != TC_RESULT_OK) {
×
NEW
62
    tc_string_free(&tc_url);
×
63
    tc_string_free(&tc_encryption_secret);
×
64
    throw format ("client_id '{1}' is not a valid UUID", client_id);
×
65
  }
66

67
  TCString error;
NEW
68
  auto tcserver = tc_server_new_sync (tc_url, tc_client_uuid, tc_encryption_secret, &error);
×
69
  if (!tcserver) {
×
70
    std::string errmsg = format ("Could not configure connection to server at {1}: {2}",
NEW
71
        url, tc_string_content (&error));
×
72
    tc_string_free (&error);
×
73
    throw errmsg;
×
74
  }
75
  return Server (unique_tcserver_ptr (
×
76
      tcserver,
77
      [](TCServer* rep) { tc_server_free (rep); }));
×
78
}
79

80
////////////////////////////////////////////////////////////////////////////////
81
tc::Server
82
tc::Server::new_gcp (const std::string &bucket, const std::string &credential_path, const std::string &encryption_secret)
×
83
{
84
  TCString tc_bucket = tc_string_borrow (bucket.c_str ());
×
85
  TCString tc_encryption_secret = tc_string_borrow (encryption_secret.c_str ());
×
86
  TCString tc_credential_path = tc_string_borrow (credential_path.c_str ());
×
87

88
  TCString error;
89
  auto tcserver = tc_server_new_gcp (tc_bucket, tc_credential_path, tc_encryption_secret, &error);
×
90
  if (!tcserver) {
×
91
    std::string errmsg = format ("Could not configure connection to GCP bucket {1}: {2}",
92
        bucket, tc_string_content (&error));
×
93
    tc_string_free (&error);
×
94
    throw errmsg;
×
95
  }
96
  return Server (unique_tcserver_ptr (
×
97
      tcserver,
98
      [](TCServer* rep) { tc_server_free (rep); }));
×
99
}
100

101
////////////////////////////////////////////////////////////////////////////////
102
tc::Server::Server (tc::Server &&other) noexcept
×
103
{
104
  // move inner from other
105
  inner = unique_tcserver_ptr (
×
106
      other.inner.release (),
107
      [](TCServer* rep) { tc_server_free (rep); });
×
108
}
109

110
////////////////////////////////////////////////////////////////////////////////
111
tc::Server& tc::Server::operator= (tc::Server &&other) noexcept
×
112
{
113
  if (this != &other) {
×
114
    // move inner from other
115
    inner = unique_tcserver_ptr (
×
116
        other.inner.release (),
117
        [](TCServer* rep) { tc_server_free (rep); });
×
118
  }
119
  return *this;
×
120
}
121

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