Page MenuHomePhabricator

D3951.id12411.diff
No OneTemporary

D3951.id12411.diff

diff --git a/services/backup/src/Constants.h b/services/backup/src/Constants.h
--- a/services/backup/src/Constants.h
+++ b/services/backup/src/Constants.h
@@ -1,5 +1,6 @@
#pragma once
+#include "GlobalTools.h"
#include "Tools.h"
#include <string>
diff --git a/services/backup/src/DatabaseManager.cpp b/services/backup/src/DatabaseManager.cpp
--- a/services/backup/src/DatabaseManager.cpp
+++ b/services/backup/src/DatabaseManager.cpp
@@ -1,5 +1,6 @@
#include "DatabaseManager.h"
#include "Constants.h"
+#include "GlobalTools.h"
#include "Tools.h"
#include <aws/core/utils/Outcome.h>
diff --git a/services/backup/src/Reactors/server/CreateNewBackupReactor.cpp b/services/backup/src/Reactors/server/CreateNewBackupReactor.cpp
--- a/services/backup/src/Reactors/server/CreateNewBackupReactor.cpp
+++ b/services/backup/src/Reactors/server/CreateNewBackupReactor.cpp
@@ -1,6 +1,7 @@
#include "CreateNewBackupReactor.h"
#include "DatabaseManager.h"
+#include "GlobalTools.h"
#include "Tools.h"
namespace comm {
diff --git a/services/backup/src/Tools.h b/services/backup/src/Tools.h
--- a/services/backup/src/Tools.h
+++ b/services/backup/src/Tools.h
@@ -1,15 +1,11 @@
#pragma once
-#include <cstdint>
#include <string>
namespace comm {
namespace network {
std::string generateRandomString(std::size_t length = 20);
-uint64_t getCurrentTimestamp();
-std::string decorateTableName(const std::string &baseName);
-bool isDevMode();
} // namespace network
} // namespace comm
diff --git a/services/backup/src/Tools.cpp b/services/backup/src/Tools.cpp
--- a/services/backup/src/Tools.cpp
+++ b/services/backup/src/Tools.cpp
@@ -19,27 +19,5 @@
return random_string;
}
-uint64_t getCurrentTimestamp() {
- using namespace std::chrono;
- return duration_cast<milliseconds>(system_clock::now().time_since_epoch())
- .count();
-}
-
-std::string decorateTableName(const std::string &baseName) {
- std::string suffix = "";
- if (std::getenv("COMM_TEST_SERVICES") != nullptr &&
- std::string(std::getenv("COMM_TEST_SERVICES")) == "1") {
- suffix = "-test";
- }
- return baseName + suffix;
-}
-
-bool isDevMode() {
- if (std::getenv("COMM_SERVICES_DEV_MODE") == nullptr) {
- return false;
- }
- return std::string(std::getenv("COMM_SERVICES_DEV_MODE")) == "1";
-}
-
} // namespace network
} // namespace comm
diff --git a/services/backup/test/DatabaseManagerTest.cpp b/services/backup/test/DatabaseManagerTest.cpp
--- a/services/backup/test/DatabaseManagerTest.cpp
+++ b/services/backup/test/DatabaseManagerTest.cpp
@@ -1,6 +1,7 @@
#include <gtest/gtest.h>
#include "DatabaseManager.h"
+#include "GlobalTools.h"
#include "Tools.h"
#include <iostream>
diff --git a/services/blob/src/Constants.h b/services/blob/src/Constants.h
--- a/services/blob/src/Constants.h
+++ b/services/blob/src/Constants.h
@@ -1,5 +1,6 @@
#pragma once
+#include "GlobalTools.h"
#include "Tools.h"
#include <string>
diff --git a/services/blob/src/DatabaseManager.cpp b/services/blob/src/DatabaseManager.cpp
--- a/services/blob/src/DatabaseManager.cpp
+++ b/services/blob/src/DatabaseManager.cpp
@@ -1,4 +1,5 @@
#include "DatabaseManager.h"
+#include "GlobalTools.h"
#include "Tools.h"
#include <aws/core/utils/Outcome.h>
diff --git a/services/blob/src/S3Tools.cpp b/services/blob/src/S3Tools.cpp
--- a/services/blob/src/S3Tools.cpp
+++ b/services/blob/src/S3Tools.cpp
@@ -1,6 +1,7 @@
#include "S3Tools.h"
#include "Constants.h"
#include "GlobalConstants.h"
+#include "GlobalTools.h"
#include "Tools.h"
#include <aws/s3/model/Bucket.h>
diff --git a/services/blob/src/Tools.h b/services/blob/src/Tools.h
--- a/services/blob/src/Tools.h
+++ b/services/blob/src/Tools.h
@@ -15,12 +15,6 @@
database::S3Path findS3Path(const database::ReverseIndexItem &reverseIndexItem);
-uint64_t getCurrentTimestamp();
-
-std::string decorateTableName(const std::string &baseName);
-
-bool isDevMode();
-
class invalid_argument_error : public std::runtime_error {
public:
invalid_argument_error(std::string errorMessage)
diff --git a/services/blob/src/Tools.cpp b/services/blob/src/Tools.cpp
--- a/services/blob/src/Tools.cpp
+++ b/services/blob/src/Tools.cpp
@@ -69,27 +69,5 @@
return result;
}
-uint64_t getCurrentTimestamp() {
- using namespace std::chrono;
- return duration_cast<milliseconds>(system_clock::now().time_since_epoch())
- .count();
-}
-
-std::string decorateTableName(const std::string &baseName) {
- std::string suffix = "";
- if (std::getenv("COMM_TEST_SERVICES") != nullptr &&
- std::string(std::getenv("COMM_TEST_SERVICES")) == "1") {
- suffix = "-test";
- }
- return baseName + suffix;
-}
-
-bool isDevMode() {
- if (std::getenv("COMM_SERVICES_DEV_MODE") == nullptr) {
- return false;
- }
- return std::string(std::getenv("COMM_SERVICES_DEV_MODE")) == "1";
-}
-
} // namespace network
} // namespace comm
diff --git a/services/lib/src/DynamoDBTools.cpp b/services/lib/src/DynamoDBTools.cpp
--- a/services/lib/src/DynamoDBTools.cpp
+++ b/services/lib/src/DynamoDBTools.cpp
@@ -1,6 +1,7 @@
#include "DynamoDBTools.h"
#include "Constants.h"
#include "GlobalConstants.h"
+#include "GlobalTools.h"
namespace comm {
namespace network {
diff --git a/services/backup/src/Tools.h b/services/lib/src/GlobalTools.h
copy from services/backup/src/Tools.h
copy to services/lib/src/GlobalTools.h
--- a/services/backup/src/Tools.h
+++ b/services/lib/src/GlobalTools.h
@@ -6,9 +6,10 @@
namespace comm {
namespace network {
-std::string generateRandomString(std::size_t length = 20);
uint64_t getCurrentTimestamp();
+
std::string decorateTableName(const std::string &baseName);
+
bool isDevMode();
} // namespace network
diff --git a/services/backup/src/Tools.cpp b/services/lib/src/GlobalTools.cpp
copy from services/backup/src/Tools.cpp
copy to services/lib/src/GlobalTools.cpp
--- a/services/backup/src/Tools.cpp
+++ b/services/lib/src/GlobalTools.cpp
@@ -1,24 +1,14 @@
-#include "Tools.h"
+#include "GlobalTools.h"
+
+#include <openssl/sha.h>
#include <chrono>
-#include <cstdlib>
-#include <random>
+#include <iomanip>
+#include <string>
namespace comm {
namespace network {
-std::string generateRandomString(std::size_t length) {
- const std::string CHARACTERS =
- "0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz";
- thread_local std::random_device generator;
- std::uniform_int_distribution<> distribution(0, CHARACTERS.size() - 1);
- std::string random_string;
- for (std::size_t i = 0; i < length; ++i) {
- random_string += CHARACTERS[distribution(generator)];
- }
- return random_string;
-}
-
uint64_t getCurrentTimestamp() {
using namespace std::chrono;
return duration_cast<milliseconds>(system_clock::now().time_since_epoch())

File Metadata

Mime Type
text/plain
Expires
Thu, Dec 26, 5:33 PM (11 h, 53 m)
Storage Engine
blob
Storage Format
Raw Data
Storage Handle
2704044
Default Alt Text
D3951.id12411.diff (6 KB)

Event Timeline