Page Menu
Home
Phabricator
Search
Configure Global Search
Log In
Files
F3535586
D3872.id12033.diff
No One
Temporary
Actions
View File
Edit File
Delete File
View Transforms
Subscribe
Mute Notifications
Award Token
Flag For Later
Size
7 KB
Referenced Files
None
Subscribers
None
D3872.id12033.diff
View Options
diff --git a/services/backup/CMakeLists.txt b/services/backup/CMakeLists.txt
--- a/services/backup/CMakeLists.txt
+++ b/services/backup/CMakeLists.txt
@@ -23,14 +23,7 @@
# FIND FILES
file(GLOB DOUBLE_CONVERSION_SOURCES "./lib/double-conversion/double-conversion/*.cc")
-if ($ENV{COMM_TEST_SERVICES} MATCHES 1)
- add_compile_definitions(COMM_TEST_SERVICES)
-endif()
-
file(GLOB GENERATED_CODE "./_generated/*.cc")
-if ($ENV{COMM_SERVICES_DEV_MODE} MATCHES 1)
- add_compile_definitions(COMM_SERVICES_DEV_MODE)
-endif()
file(GLOB_RECURSE SOURCE_CODE "./src/*.cpp")
diff --git a/services/backup/src/AwsTools.cpp b/services/backup/src/AwsTools.cpp
--- a/services/backup/src/AwsTools.cpp
+++ b/services/backup/src/AwsTools.cpp
@@ -1,16 +1,21 @@
#include "AwsTools.h"
#include "Constants.h"
+#include <cstdlib>
+
namespace comm {
namespace network {
std::unique_ptr<Aws::DynamoDB::DynamoDBClient> getDynamoDBClient() {
Aws::Client::ClientConfiguration config;
config.region = AWS_REGION;
-#ifdef COMM_SERVICES_DEV_MODE
- config.endpointOverride = Aws::String("localstack:4566");
- config.scheme = Aws::Http::Scheme::HTTP;
-#endif
+ if (std::string(
+ std::getenv("COMM_SERVICES_DEV_MODE")
+ ? std::getenv("COMM_SERVICES_DEV_MODE")
+ : "") == "1") {
+ config.endpointOverride = Aws::String("localstack:4566");
+ config.scheme = Aws::Http::Scheme::HTTP;
+ }
return std::make_unique<Aws::DynamoDB::DynamoDBClient>(config);
}
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,7 @@
#pragma once
+#include "Tools.h"
+
#include <string>
namespace comm {
@@ -22,13 +24,9 @@
const std::string AWS_REGION = "us-east-2";
-#ifdef COMM_TEST_SERVICES
-const std::string LOG_TABLE_NAME = "backup-service-log-test";
-const std::string BACKUP_TABLE_NAME = "backup-service-backup-test";
-#else
-const std::string LOG_TABLE_NAME = "backup-service-log";
-const std::string BACKUP_TABLE_NAME = "backup-service-backup";
-#endif
+const std::string LOG_TABLE_NAME = decorateTableName("backup-service-log");
+const std::string BACKUP_TABLE_NAME =
+ decorateTableName("backup-service-backup");
// This has to be smaller than GRPC_CHUNK_SIZE_LIMIT because we need to
// recognize if we may receive multiple chunks or just one. If it was larger
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
@@ -8,6 +8,7 @@
std::string generateRandomString(std::size_t length = 20);
uint64_t getCurrentTimestamp();
+std::string decorateTableName(const std::string &baseName);
} // 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
@@ -1,6 +1,7 @@
#include "Tools.h"
#include <chrono>
+#include <cstdlib>
#include <random>
namespace comm {
@@ -24,5 +25,14 @@
.count();
}
+std::string decorateTableName(const std::string &baseName) {
+ if (std::string(
+ std::getenv("COMM_TEST_SERVICES") ? std::getenv("COMM_TEST_SERVICES")
+ : "") == "1") {
+ return baseName + "-test";
+ }
+ return baseName;
+}
+
} // namespace network
} // namespace comm
diff --git a/services/blob/CMakeLists.txt b/services/blob/CMakeLists.txt
--- a/services/blob/CMakeLists.txt
+++ b/services/blob/CMakeLists.txt
@@ -24,15 +24,7 @@
# FIND FILES
file(GLOB DOUBLE_CONVERSION_SOURCES "./lib/double-conversion/double-conversion/*.cc")
-
-if ($ENV{COMM_TEST_SERVICES} MATCHES 1)
- add_compile_definitions(COMM_TEST_SERVICES)
-endif()
-
file(GLOB GENERATED_CODE "./_generated/*.cc")
-if ($ENV{COMM_SERVICES_DEV_MODE} MATCHES 1)
- add_compile_definitions(COMM_SERVICES_DEV_MODE)
-endif()
file(GLOB SOURCE_CODE "./src/*.cpp" "./src/**/*.cpp")
diff --git a/services/blob/src/AwsTools.cpp b/services/blob/src/AwsTools.cpp
--- a/services/blob/src/AwsTools.cpp
+++ b/services/blob/src/AwsTools.cpp
@@ -4,6 +4,8 @@
#include <aws/s3/model/Bucket.h>
+#include <cstdlib>
+
namespace comm {
namespace network {
@@ -28,24 +30,31 @@
std::unique_ptr<Aws::DynamoDB::DynamoDBClient> getDynamoDBClient() {
Aws::Client::ClientConfiguration config;
config.region = AWS_REGION;
-#ifdef COMM_SERVICES_DEV_MODE
- config.endpointOverride = Aws::String("localstack:4566");
- config.scheme = Aws::Http::Scheme::HTTP;
-#endif
+ if (std::string(
+ std::getenv("COMM_SERVICES_DEV_MODE")
+ ? std::getenv("COMM_SERVICES_DEV_MODE")
+ : "") == "1") {
+ config.endpointOverride = Aws::String("localstack:4566");
+ config.scheme = Aws::Http::Scheme::HTTP;
+ }
return std::make_unique<Aws::DynamoDB::DynamoDBClient>(config);
}
std::unique_ptr<Aws::S3::S3Client> getS3Client() {
Aws::Client::ClientConfiguration config;
config.region = AWS_REGION;
-#ifdef COMM_SERVICES_DEV_MODE
- config.endpointOverride = Aws::String("localstack:4566");
- config.scheme = Aws::Http::Scheme::HTTP;
- return std::make_unique<Aws::S3::S3Client>(
- config, Aws::Client::AWSAuthV4Signer::PayloadSigningPolicy::Never, false);
-#else
+ if (std::string(
+ std::getenv("COMM_SERVICES_DEV_MODE")
+ ? std::getenv("COMM_SERVICES_DEV_MODE")
+ : "") == "1") {
+ config.endpointOverride = Aws::String("localstack:4566");
+ config.scheme = Aws::Http::Scheme::HTTP;
+ return std::make_unique<Aws::S3::S3Client>(
+ config,
+ Aws::Client::AWSAuthV4Signer::PayloadSigningPolicy::Never,
+ false);
+ }
return std::make_unique<Aws::S3::S3Client>(config);
-#endif
}
} // namespace network
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,7 @@
#pragma once
+#include "Tools.h"
+
#include <string>
namespace comm {
@@ -25,13 +27,9 @@
const std::string AWS_REGION = "us-east-2";
const std::string BLOB_BUCKET_NAME = "commapp-blob";
-#ifdef COMM_TEST_SERVICES
-const std::string BLOB_TABLE_NAME = "blob-service-blob-test";
-const std::string REVERSE_INDEX_TABLE_NAME = "blob-service-reverse-index-test";
-#else
-const std::string BLOB_TABLE_NAME = "blob-service-blob";
-const std::string REVERSE_INDEX_TABLE_NAME = "blob-service-reverse-index";
-#endif
+const std::string BLOB_TABLE_NAME = decorateTableName("blob-service-blob");
+const std::string REVERSE_INDEX_TABLE_NAME =
+ decorateTableName("blob-service-reverse-index");
} // namespace network
} // namespace comm
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
@@ -1,6 +1,5 @@
#pragma once
-#include "Constants.h"
#include "DatabaseEntitiesTools.h"
#include "S3Path.h"
@@ -18,6 +17,8 @@
uint64_t getCurrentTimestamp();
+std::string decorateTableName(const std::string &baseName);
+
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
@@ -1,12 +1,14 @@
#include "Tools.h"
#include "AwsTools.h"
+#include "Constants.h"
#include "DatabaseEntitiesTools.h"
#include "DatabaseManager.h"
#include <openssl/sha.h>
#include <chrono>
+#include <cstdlib>
#include <iomanip>
#include <string>
@@ -72,5 +74,14 @@
.count();
}
+std::string decorateTableName(const std::string &baseName) {
+ if (std::string(
+ std::getenv("COMM_TEST_SERVICES") ? std::getenv("COMM_TEST_SERVICES")
+ : "") == "1") {
+ return baseName + "-test";
+ }
+ return baseName;
+}
+
} // namespace network
} // namespace comm
File Metadata
Details
Attached
Mime Type
text/plain
Expires
Thu, Dec 26, 4:14 PM (10 h, 15 m)
Storage Engine
blob
Storage Format
Raw Data
Storage Handle
2707436
Default Alt Text
D3872.id12033.diff (7 KB)
Attached To
Mode
D3872: [services] Blob/Backup - Read env vars in runtime instead of compile-time flags
Attached
Detach File
Event Timeline
Log In to Comment