diff --git a/services/backup/src/DatabaseEntities/BackupItem.cpp b/services/backup/src/DatabaseEntities/BackupItem.cpp index 5fc222e23..4380eeef4 100644 --- a/services/backup/src/DatabaseEntities/BackupItem.cpp +++ b/services/backup/src/DatabaseEntities/BackupItem.cpp @@ -1,115 +1,116 @@ #include "BackupItem.h" #include "Constants.h" namespace comm { namespace network { namespace database { const std::string BackupItem::FIELD_USER_ID = "userID"; const std::string BackupItem::FIELD_BACKUP_ID = "backupID"; const std::string BackupItem::FIELD_CREATED = "created"; const std::string BackupItem::FIELD_RECOVERY_DATA = "recoveryData"; const std::string BackupItem::FIELD_COMPACTION_HOLDER = "compactionHolder"; const std::string BackupItem::FIELD_ATTACHMENT_HOLDERS = "attachmentHolders"; std::string BackupItem::tableName = BACKUP_TABLE_NAME; BackupItem::BackupItem( std::string userID, std::string backupID, uint64_t created, std::string recoveryData, std::string compactionHolder, std::vector attachmentHolders) : userID(userID), backupID(backupID), created(created), recoveryData(recoveryData), compactionHolder(compactionHolder), attachmentHolders(attachmentHolders) { this->validate(); } BackupItem::BackupItem(const AttributeValues &itemFromDB) { this->assignItemFromDatabase(itemFromDB); } void BackupItem::validate() const { if (!this->userID.size()) { throw std::runtime_error("userID empty"); } if (!this->backupID.size()) { throw std::runtime_error("backupID empty"); } if (!this->created) { throw std::runtime_error("created not provided"); } if (!this->recoveryData.size()) { throw std::runtime_error("recoveryData empty"); } } void BackupItem::assignItemFromDatabase(const AttributeValues &itemFromDB) { try { this->userID = itemFromDB.at(BackupItem::FIELD_USER_ID).GetS(); this->backupID = itemFromDB.at(BackupItem::FIELD_BACKUP_ID).GetS(); this->created = std::stoll( std::string(itemFromDB.at(BackupItem::FIELD_CREATED).GetS()).c_str()); this->recoveryData = itemFromDB.at(BackupItem::FIELD_RECOVERY_DATA).GetS(); auto compactionHolder = itemFromDB.find(BackupItem::FIELD_COMPACTION_HOLDER); if (compactionHolder != itemFromDB.end()) { this->compactionHolder = compactionHolder->second.GetS(); } auto attachmentsHolders = itemFromDB.find(BackupItem::FIELD_ATTACHMENT_HOLDERS); if (attachmentsHolders != itemFromDB.end()) { this->attachmentHolders = attachmentsHolders->second.GetSS(); } } catch (std::logic_error &e) { throw std::runtime_error( "invalid backup item provided, " + std::string(e.what())); } this->validate(); } std::string BackupItem::getTableName() const { return BackupItem::tableName; } -PrimaryKey BackupItem::getPrimaryKey() const { - return PrimaryKey(BackupItem::FIELD_USER_ID, BackupItem::FIELD_BACKUP_ID); +PrimaryKeyDescriptor BackupItem::getPrimaryKeyDescriptor() const { + return PrimaryKeyDescriptor( + BackupItem::FIELD_USER_ID, BackupItem::FIELD_BACKUP_ID); } PrimaryKeyValue BackupItem::getPrimaryKeyValue() const { return PrimaryKeyValue(this->userID, this->backupID); } std::string BackupItem::getUserID() const { return this->userID; } std::string BackupItem::getBackupID() const { return this->backupID; } uint64_t BackupItem::getCreated() const { return this->created; } std::string BackupItem::getRecoveryData() const { return this->recoveryData; } std::string BackupItem::getCompactionHolder() const { return this->compactionHolder; } std::vector BackupItem::getAttachmentHolders() const { return this->attachmentHolders; } } // namespace database } // namespace network } // namespace comm diff --git a/services/backup/src/DatabaseEntities/BackupItem.h b/services/backup/src/DatabaseEntities/BackupItem.h index 92f0b9e87..73cb484d0 100644 --- a/services/backup/src/DatabaseEntities/BackupItem.h +++ b/services/backup/src/DatabaseEntities/BackupItem.h @@ -1,80 +1,80 @@ #pragma once #include "Item.h" #include #include namespace comm { namespace network { namespace database { /** * backup - backups assigned to users along with the data necessary to * decrypt * `created` - when the backup was created. This is a search key because * we want to be able to perform effective queries based on this info * (for example get me the latest backup, get me backup from some day) * `attachmentHolders` - this is a list of attachment references * `recoveryData` - data serialized with protobuf which is described by * one of the following structures: * { authType: 'password', pakePasswordCiphertext: string, nonce: string } * { authType: 'wallet', walletAddress: string, rawMessage: string } * * this class is used for representing two things: the rows in the main table, * and also the rows in the secondary index * * Needs userID(pk)-created(sk)-index that projects: * userID * backupID * created * recoveryData */ class BackupItem : public Item { std::string userID; std::string backupID; uint64_t created; std::string recoveryData; std::string compactionHolder; std::vector attachmentHolders; void validate() const override; public: static std::string tableName; static const std::string FIELD_USER_ID; static const std::string FIELD_BACKUP_ID; static const std::string FIELD_CREATED; static const std::string FIELD_RECOVERY_DATA; static const std::string FIELD_COMPACTION_HOLDER; static const std::string FIELD_ATTACHMENT_HOLDERS; BackupItem() { } BackupItem( std::string userID, std::string backupID, uint64_t created, std::string recoveryData, std::string compactionHolder, std::vector attachmentHolders); BackupItem(const AttributeValues &itemFromDB); void assignItemFromDatabase(const AttributeValues &itemFromDB) override; std::string getTableName() const override; - PrimaryKey getPrimaryKey() const override; + PrimaryKeyDescriptor getPrimaryKeyDescriptor() const override; PrimaryKeyValue getPrimaryKeyValue() const override; std::string getUserID() const; std::string getBackupID() const; uint64_t getCreated() const; std::string getRecoveryData() const; std::string getCompactionHolder() const; std::vector getAttachmentHolders() const; }; } // namespace database } // namespace network } // namespace comm diff --git a/services/backup/src/DatabaseEntities/LogItem.cpp b/services/backup/src/DatabaseEntities/LogItem.cpp index 861d619b5..eee3e5654 100644 --- a/services/backup/src/DatabaseEntities/LogItem.cpp +++ b/services/backup/src/DatabaseEntities/LogItem.cpp @@ -1,109 +1,109 @@ #include "LogItem.h" #include "Constants.h" #include namespace comm { namespace network { namespace database { const std::string LogItem::FIELD_BACKUP_ID = "backupID"; const std::string LogItem::FIELD_LOG_ID = "logID"; const std::string LogItem::FIELD_PERSISTED_IN_BLOB = "persistedInBlob"; const std::string LogItem::FIELD_VALUE = "value"; const std::string LogItem::FIELD_ATTACHMENT_HOLDERS = "attachmentHolders"; std::string LogItem::tableName = LOG_TABLE_NAME; LogItem::LogItem( const std::string backupID, const std::string logID, const bool persistedInBlob, const std::string value, std::vector attachmentHolders) : backupID(backupID), logID(logID), persistedInBlob(persistedInBlob), value(value), attachmentHolders(attachmentHolders) { this->validate(); } LogItem::LogItem(const AttributeValues &itemFromDB) { this->assignItemFromDatabase(itemFromDB); } void LogItem::validate() const { if (!this->backupID.size()) { throw std::runtime_error("backupID empty"); } if (!this->logID.size()) { throw std::runtime_error("logID empty"); } if (!this->value.size()) { throw std::runtime_error("value empty"); } if (!this->persistedInBlob && this->value.size() > LOG_DATA_SIZE_DATABASE_LIMIT) { throw std::runtime_error( "the value of this log is too big to be stored in the database, it " "should be stored in the blob instead"); } } void LogItem::assignItemFromDatabase(const AttributeValues &itemFromDB) { try { this->backupID = itemFromDB.at(LogItem::FIELD_BACKUP_ID).GetS(); this->logID = itemFromDB.at(LogItem::FIELD_LOG_ID).GetS(); this->persistedInBlob = std::stoi( std::string(itemFromDB.at(LogItem::FIELD_PERSISTED_IN_BLOB).GetS()) .c_str()); this->value = itemFromDB.at(LogItem::FIELD_VALUE).GetS(); auto attachmentsHolders = itemFromDB.find(LogItem::FIELD_ATTACHMENT_HOLDERS); if (attachmentsHolders != itemFromDB.end()) { this->attachmentHolders = attachmentsHolders->second.GetSS(); } } catch (std::logic_error &e) { throw std::runtime_error( "invalid log item provided, " + std::string(e.what())); } this->validate(); } std::string LogItem::getTableName() const { return LogItem::tableName; } -PrimaryKey LogItem::getPrimaryKey() const { - return PrimaryKey(LogItem::FIELD_BACKUP_ID, LogItem::FIELD_LOG_ID); +PrimaryKeyDescriptor LogItem::getPrimaryKeyDescriptor() const { + return PrimaryKeyDescriptor(LogItem::FIELD_BACKUP_ID, LogItem::FIELD_LOG_ID); } PrimaryKeyValue LogItem::getPrimaryKeyValue() const { return PrimaryKeyValue(this->backupID, this->logID); } std::string LogItem::getBackupID() const { return this->backupID; } std::string LogItem::getLogID() const { return this->logID; } bool LogItem::getPersistedInBlob() const { return this->persistedInBlob; } std::string LogItem::getValue() const { return this->value; } std::vector LogItem::getAttachmentHolders() const { return this->attachmentHolders; } } // namespace database } // namespace network } // namespace comm diff --git a/services/backup/src/DatabaseEntities/LogItem.h b/services/backup/src/DatabaseEntities/LogItem.h index cbc47efeb..cf24c3abd 100644 --- a/services/backup/src/DatabaseEntities/LogItem.h +++ b/services/backup/src/DatabaseEntities/LogItem.h @@ -1,63 +1,63 @@ #pragma once #include "Item.h" #include #include namespace comm { namespace network { namespace database { /* * log - a single log record * `backupID` - id of the backup that this log is assigned to * `value` - either the value itself which is a dump of a single operation (if * `persistedInBlob` is false) or the holder to blob (if `persistedInBlob` is * true) * `attachmentHolders` - this is a list of attachment references */ class LogItem : public Item { std::string backupID; std::string logID; bool persistedInBlob; std::string value; std::vector attachmentHolders; void validate() const override; public: static std::string tableName; static const std::string FIELD_BACKUP_ID; static const std::string FIELD_LOG_ID; static const std::string FIELD_PERSISTED_IN_BLOB; static const std::string FIELD_VALUE; static const std::string FIELD_ATTACHMENT_HOLDERS; LogItem() { } LogItem( const std::string backupID, const std::string logID, const bool persistedInBlob, const std::string value, std::vector attachmentHolders); LogItem(const AttributeValues &itemFromDB); void assignItemFromDatabase(const AttributeValues &itemFromDB) override; std::string getTableName() const override; - PrimaryKey getPrimaryKey() const override; + PrimaryKeyDescriptor getPrimaryKeyDescriptor() const override; PrimaryKeyValue getPrimaryKeyValue() const override; std::string getBackupID() const; std::string getLogID() const; bool getPersistedInBlob() const; std::string getValue() const; std::vector getAttachmentHolders() const; }; } // namespace database } // namespace network } // namespace comm diff --git a/services/blob/src/DatabaseEntities/BlobItem.cpp b/services/blob/src/DatabaseEntities/BlobItem.cpp index a709bb884..849cbadac 100644 --- a/services/blob/src/DatabaseEntities/BlobItem.cpp +++ b/services/blob/src/DatabaseEntities/BlobItem.cpp @@ -1,73 +1,73 @@ #include "BlobItem.h" #include "Constants.h" namespace comm { namespace network { namespace database { const std::string BlobItem::FIELD_BLOB_HASH = "blobHash"; const std::string BlobItem::FIELD_S3_PATH = "s3Path"; const std::string BlobItem::FIELD_CREATED = "created"; std::string BlobItem::tableName = BLOB_TABLE_NAME; BlobItem::BlobItem( const std::string blobHash, const S3Path s3Path, uint64_t created) : blobHash(blobHash), s3Path(s3Path), created(created) { this->validate(); } BlobItem::BlobItem(const AttributeValues &itemFromDB) { this->assignItemFromDatabase(itemFromDB); } void BlobItem::validate() const { if (!this->blobHash.size()) { throw std::runtime_error("blobHash empty"); } this->s3Path.validate(); } void BlobItem::assignItemFromDatabase(const AttributeValues &itemFromDB) { try { this->blobHash = itemFromDB.at(BlobItem::FIELD_BLOB_HASH).GetS(); this->s3Path = S3Path(itemFromDB.at(BlobItem::FIELD_S3_PATH).GetS()); this->created = std::stoll( std::string(itemFromDB.at(BlobItem::FIELD_CREATED).GetS()).c_str()); } catch (std::logic_error &e) { throw std::runtime_error( "invalid blob item provided, " + std::string(e.what())); } this->validate(); } std::string BlobItem::getTableName() const { return BlobItem::tableName; } -PrimaryKey BlobItem::getPrimaryKey() const { - return PrimaryKey(BlobItem::FIELD_BLOB_HASH); +PrimaryKeyDescriptor BlobItem::getPrimaryKeyDescriptor() const { + return PrimaryKeyDescriptor(BlobItem::FIELD_BLOB_HASH); } PrimaryKeyValue BlobItem::getPrimaryKeyValue() const { return PrimaryKeyValue(this->blobHash); } std::string BlobItem::getBlobHash() const { return this->blobHash; } S3Path BlobItem::getS3Path() const { return this->s3Path; } uint64_t BlobItem::getCreated() const { return this->created; } } // namespace database } // namespace network } // namespace comm diff --git a/services/blob/src/DatabaseEntities/BlobItem.h b/services/blob/src/DatabaseEntities/BlobItem.h index d70a83f50..74fe713f6 100644 --- a/services/blob/src/DatabaseEntities/BlobItem.h +++ b/services/blob/src/DatabaseEntities/BlobItem.h @@ -1,47 +1,47 @@ #pragma once #include "Item.h" #include "S3Path.h" #include namespace comm { namespace network { namespace database { class BlobItem : public Item { std::string blobHash; S3Path s3Path; uint64_t created = 0; void validate() const override; public: static std::string tableName; static const std::string FIELD_BLOB_HASH; static const std::string FIELD_S3_PATH; static const std::string FIELD_CREATED; BlobItem() { } BlobItem( const std::string blobHash, const S3Path s3Path, uint64_t created = 0); BlobItem(const AttributeValues &itemFromDB); void assignItemFromDatabase(const AttributeValues &itemFromDB) override; std::string getTableName() const override; - PrimaryKey getPrimaryKey() const override; + PrimaryKeyDescriptor getPrimaryKeyDescriptor() const override; PrimaryKeyValue getPrimaryKeyValue() const override; std::string getBlobHash() const; S3Path getS3Path() const; uint64_t getCreated() const; }; } // namespace database } // namespace network } // namespace comm diff --git a/services/blob/src/DatabaseEntities/ReverseIndexItem.cpp b/services/blob/src/DatabaseEntities/ReverseIndexItem.cpp index 4d0080a70..265c3aaab 100644 --- a/services/blob/src/DatabaseEntities/ReverseIndexItem.cpp +++ b/services/blob/src/DatabaseEntities/ReverseIndexItem.cpp @@ -1,62 +1,62 @@ #include "ReverseIndexItem.h" #include "Constants.h" namespace comm { namespace network { namespace database { const std::string ReverseIndexItem::FIELD_HOLDER = "holder"; const std::string ReverseIndexItem::FIELD_BLOB_HASH = "blobHash"; std::string ReverseIndexItem::tableName = REVERSE_INDEX_TABLE_NAME; ReverseIndexItem::ReverseIndexItem( const std::string holder, const std::string blobHash) : holder(holder), blobHash(blobHash) { this->validate(); } ReverseIndexItem::ReverseIndexItem(const AttributeValues &itemFromDB) { this->assignItemFromDatabase(itemFromDB); } void ReverseIndexItem::validate() const { if (!this->holder.size()) { throw std::runtime_error("reverse index empty"); } if (!this->blobHash.size()) { throw std::runtime_error("blobHash empty"); } } void ReverseIndexItem::assignItemFromDatabase( const AttributeValues &itemFromDB) { this->holder = itemFromDB.at(ReverseIndexItem::FIELD_HOLDER).GetS(); this->blobHash = itemFromDB.at(ReverseIndexItem::FIELD_BLOB_HASH).GetS(); this->validate(); } std::string ReverseIndexItem::getTableName() const { return ReverseIndexItem::tableName; } -PrimaryKey ReverseIndexItem::getPrimaryKey() const { - return PrimaryKey(ReverseIndexItem::FIELD_HOLDER); +PrimaryKeyDescriptor ReverseIndexItem::getPrimaryKeyDescriptor() const { + return PrimaryKeyDescriptor(ReverseIndexItem::FIELD_HOLDER); } PrimaryKeyValue ReverseIndexItem::getPrimaryKeyValue() const { return PrimaryKeyValue(this->holder); } std::string ReverseIndexItem::getHolder() const { return this->holder; } std::string ReverseIndexItem::getBlobHash() const { return this->blobHash; } } // namespace database } // namespace network } // namespace comm diff --git a/services/blob/src/DatabaseEntities/ReverseIndexItem.h b/services/blob/src/DatabaseEntities/ReverseIndexItem.h index 3a7727b8e..d7888c3c7 100644 --- a/services/blob/src/DatabaseEntities/ReverseIndexItem.h +++ b/services/blob/src/DatabaseEntities/ReverseIndexItem.h @@ -1,45 +1,45 @@ #pragma once #include "Item.h" #include namespace comm { namespace network { namespace database { /** * Needs blobHash(pk)-index that projects: * blobHash * holder */ class ReverseIndexItem : public Item { std::string holder; std::string blobHash; void validate() const override; public: static std::string tableName; static const std::string FIELD_HOLDER; static const std::string FIELD_BLOB_HASH; ReverseIndexItem() { } ReverseIndexItem(const std::string holder, const std::string blobHash); ReverseIndexItem(const AttributeValues &itemFromDB); void assignItemFromDatabase(const AttributeValues &itemFromDB) override; std::string getTableName() const override; - PrimaryKey getPrimaryKey() const override; + PrimaryKeyDescriptor getPrimaryKeyDescriptor() const override; PrimaryKeyValue getPrimaryKeyValue() const override; std::string getHolder() const; std::string getBlobHash() const; }; } // namespace database } // namespace network } // namespace comm diff --git a/services/lib/src/DatabaseManagerBase.cpp b/services/lib/src/DatabaseManagerBase.cpp index 891710e8d..76faa9789 100644 --- a/services/lib/src/DatabaseManagerBase.cpp +++ b/services/lib/src/DatabaseManagerBase.cpp @@ -1,47 +1,47 @@ #include "DatabaseManagerBase.h" #include "Item.h" #include #include #include namespace comm { namespace network { namespace database { void DatabaseManagerBase::innerPutItem( std::shared_ptr item, const Aws::DynamoDB::Model::PutItemRequest &request) { const Aws::DynamoDB::Model::PutItemOutcome outcome = getDynamoDBClient()->PutItem(request); if (!outcome.IsSuccess()) { throw std::runtime_error(outcome.GetError().GetMessage()); } } void DatabaseManagerBase::innerRemoveItem(const Item &item) { Aws::DynamoDB::Model::DeleteItemRequest request; request.SetTableName(item.getTableName()); - PrimaryKey pk = item.getPrimaryKey(); + PrimaryKeyDescriptor pk = item.getPrimaryKeyDescriptor(); PrimaryKeyValue primaryKeyValue = item.getPrimaryKeyValue(); request.AddKey( pk.partitionKey, Aws::DynamoDB::Model::AttributeValue(primaryKeyValue.partitionKey)); if (pk.sortKey != nullptr && primaryKeyValue.sortKey != nullptr) { request.AddKey( *pk.sortKey, Aws::DynamoDB::Model::AttributeValue(*primaryKeyValue.sortKey)); } const Aws::DynamoDB::Model::DeleteItemOutcome &outcome = getDynamoDBClient()->DeleteItem(request); if (!outcome.IsSuccess()) { throw std::runtime_error(outcome.GetError().GetMessage()); } } } // namespace database } // namespace network } // namespace comm diff --git a/services/lib/src/Item.h b/services/lib/src/Item.h index ecc24a1d5..906372342 100644 --- a/services/lib/src/Item.h +++ b/services/lib/src/Item.h @@ -1,49 +1,49 @@ #pragma once #include #include #include #include namespace comm { namespace network { namespace database { typedef Aws::Map AttributeValues; struct PrimaryKeyBase { PrimaryKeyBase(const std::string partitionKey) : partitionKey(partitionKey), sortKey(nullptr) { } PrimaryKeyBase(const std::string partitionKey, const std::string sortKey) : partitionKey(partitionKey), sortKey(std::make_unique(sortKey)) { } const std::string partitionKey; std::unique_ptr sortKey; }; -struct PrimaryKey : PrimaryKeyBase { +struct PrimaryKeyDescriptor : PrimaryKeyBase { using PrimaryKeyBase::PrimaryKeyBase; }; struct PrimaryKeyValue : PrimaryKeyBase { using PrimaryKeyBase::PrimaryKeyBase; }; class Item { virtual void validate() const = 0; public: virtual std::string getTableName() const = 0; - virtual PrimaryKey getPrimaryKey() const = 0; + virtual PrimaryKeyDescriptor getPrimaryKeyDescriptor() const = 0; virtual PrimaryKeyValue getPrimaryKeyValue() const = 0; virtual void assignItemFromDatabase(const AttributeValues &itemFromDB) = 0; }; } // namespace database } // namespace network } // namespace comm diff --git a/services/tunnelbroker/src/Database/DeviceSessionItem.cpp b/services/tunnelbroker/src/Database/DeviceSessionItem.cpp index 227b2ca59..7142a37f1 100644 --- a/services/tunnelbroker/src/Database/DeviceSessionItem.cpp +++ b/services/tunnelbroker/src/Database/DeviceSessionItem.cpp @@ -1,128 +1,128 @@ #include "DeviceSessionItem.h" #include "ConfigManager.h" #include "Tools.h" #include namespace comm { namespace network { namespace database { const std::string DeviceSessionItem::FIELD_SESSION_ID = "SessionID"; const std::string DeviceSessionItem::FIELD_DEVICE_ID = "DeviceID"; const std::string DeviceSessionItem::FIELD_PUBKEY = "PubKey"; const std::string DeviceSessionItem::FIELD_NOTIFY_TOKEN = "NotifyToken"; const std::string DeviceSessionItem::FIELD_DEVICE_TYPE = "DeviceType"; const std::string DeviceSessionItem::FIELD_APP_VERSION = "AppVersion"; const std::string DeviceSessionItem::FIELD_DEVICE_OS = "DeviceOS"; const std::string DeviceSessionItem::FIELD_CHECKPOINT_TIME = "CheckpointTime"; const std::string DeviceSessionItem::FIELD_EXPIRE = "Expire"; DeviceSessionItem::DeviceSessionItem( const std::string sessionID, const std::string deviceID, const std::string pubKey, const std::string notifyToken, const std::string deviceType, const std::string appVersion, const std::string deviceOs) : sessionID(sessionID), deviceID(deviceID), pubKey(pubKey), notifyToken(notifyToken), deviceType(deviceType), appVersion(appVersion), deviceOs(deviceOs) { this->validate(); } DeviceSessionItem::DeviceSessionItem(const AttributeValues &itemFromDB) { this->assignItemFromDatabase(itemFromDB); } void DeviceSessionItem::validate() const { if (!tools::validateSessionID(this->sessionID)) { throw std::runtime_error("Error: SessionID format is wrong."); } if (!tools::validateDeviceID(this->deviceID)) { throw std::runtime_error("Error: DeviceID format is wrong."); } tools::checkIfNotEmpty("pubKey", this->pubKey); tools::checkIfNotEmpty("notifyToken", this->notifyToken); tools::checkIfNotEmpty("deviceType", this->deviceType); tools::checkIfNotEmpty("appVersion", this->appVersion); tools::checkIfNotEmpty("deviceOs", this->deviceOs); } void DeviceSessionItem::assignItemFromDatabase( const AttributeValues &itemFromDB) { try { this->sessionID = itemFromDB.at(DeviceSessionItem::FIELD_SESSION_ID).GetS(); this->deviceID = itemFromDB.at(DeviceSessionItem::FIELD_DEVICE_ID).GetS(); this->pubKey = itemFromDB.at(DeviceSessionItem::FIELD_PUBKEY).GetS(); this->notifyToken = itemFromDB.at(DeviceSessionItem::FIELD_NOTIFY_TOKEN).GetS(); this->deviceType = itemFromDB.at(DeviceSessionItem::FIELD_DEVICE_TYPE).GetS(); this->appVersion = itemFromDB.at(DeviceSessionItem::FIELD_APP_VERSION).GetS(); this->deviceOs = itemFromDB.at(DeviceSessionItem::FIELD_DEVICE_OS).GetS(); this->checkpointTime = std::stoll( std::string( itemFromDB.at(DeviceSessionItem::FIELD_CHECKPOINT_TIME).GetS()) .c_str()); } catch (std::logic_error &e) { throw std::runtime_error( "Invalid device session database value " + std::string(e.what())); } this->validate(); } std::string DeviceSessionItem::getTableName() const { return config::ConfigManager::getInstance().getParameter( config::ConfigManager::OPTION_DYNAMODB_SESSIONS_TABLE); } -PrimaryKey DeviceSessionItem::getPrimaryKey() const { - return PrimaryKey(DeviceSessionItem::FIELD_SESSION_ID); +PrimaryKeyDescriptor DeviceSessionItem::getPrimaryKeyDescriptor() const { + return PrimaryKeyDescriptor(DeviceSessionItem::FIELD_SESSION_ID); } PrimaryKeyValue DeviceSessionItem::getPrimaryKeyValue() const { return PrimaryKeyValue(this->sessionID); } std::string DeviceSessionItem::getSessionID() const { return this->sessionID; } std::string DeviceSessionItem::getDeviceID() const { return this->deviceID; } std::string DeviceSessionItem::getPubKey() const { return this->pubKey; } std::string DeviceSessionItem::getNotifyToken() const { return this->notifyToken; } std::string DeviceSessionItem::getDeviceType() const { return this->deviceType; } std::string DeviceSessionItem::getAppVersion() const { return this->appVersion; } std::string DeviceSessionItem::getDeviceOs() const { return this->deviceOs; } int64_t DeviceSessionItem::getCheckpointTime() const { return this->checkpointTime; } } // namespace database } // namespace network } // namespace comm diff --git a/services/tunnelbroker/src/Database/DeviceSessionItem.h b/services/tunnelbroker/src/Database/DeviceSessionItem.h index d3f1c081d..2d9073099 100644 --- a/services/tunnelbroker/src/Database/DeviceSessionItem.h +++ b/services/tunnelbroker/src/Database/DeviceSessionItem.h @@ -1,62 +1,62 @@ #pragma once #include "Item.h" #include namespace comm { namespace network { namespace database { class DeviceSessionItem : public Item { std::string sessionID; std::string deviceID; std::string pubKey; std::string notifyToken; std::string deviceType; std::string appVersion; std::string deviceOs; int64_t checkpointTime = 0; void validate() const override; public: static const std::string FIELD_SESSION_ID; static const std::string FIELD_DEVICE_ID; static const std::string FIELD_PUBKEY; static const std::string FIELD_NOTIFY_TOKEN; static const std::string FIELD_DEVICE_TYPE; static const std::string FIELD_APP_VERSION; static const std::string FIELD_DEVICE_OS; static const std::string FIELD_CHECKPOINT_TIME; static const std::string FIELD_EXPIRE; - PrimaryKey getPrimaryKey() const override; + PrimaryKeyDescriptor getPrimaryKeyDescriptor() const override; PrimaryKeyValue getPrimaryKeyValue() const override; std::string getTableName() const override; std::string getSessionID() const; std::string getDeviceID() const; std::string getPubKey() const; std::string getNotifyToken() const; std::string getDeviceType() const; std::string getAppVersion() const; std::string getDeviceOs() const; int64_t getCheckpointTime() const; DeviceSessionItem() { } DeviceSessionItem( const std::string sessionID, const std::string deviceID, const std::string pubKey, const std::string notifyToken, const std::string deviceType, const std::string appVersion, const std::string deviceOs); DeviceSessionItem(const AttributeValues &itemFromDB); void assignItemFromDatabase(const AttributeValues &itemFromDB) override; }; } // namespace database } // namespace network } // namespace comm diff --git a/services/tunnelbroker/src/Database/MessageItem.cpp b/services/tunnelbroker/src/Database/MessageItem.cpp index fee22634d..ca9c57c1e 100644 --- a/services/tunnelbroker/src/Database/MessageItem.cpp +++ b/services/tunnelbroker/src/Database/MessageItem.cpp @@ -1,109 +1,109 @@ #include "MessageItem.h" #include "ConfigManager.h" #include "Tools.h" #include namespace comm { namespace network { namespace database { const std::string MessageItem::FIELD_MESSAGE_ID = "MessageID"; const std::string MessageItem::FIELD_FROM_DEVICE_ID = "FromDeviceID"; const std::string MessageItem::FIELD_TO_DEVICE_ID = "ToDeviceID"; const std::string MessageItem::FIELD_PAYLOAD = "Payload"; const std::string MessageItem::FIELD_BLOB_HASHES = "BlobHashes"; const std::string MessageItem::FIELD_EXPIRE = "Expire"; const std::string MessageItem::FIELD_CREATED_AT = "CreatedAt"; const std::string MessageItem::INDEX_TO_DEVICE_ID = "ToDeviceID-index"; MessageItem::MessageItem( const std::string messageID, const std::string fromDeviceID, const std::string toDeviceID, const std::string payload, const std::string blobHashes) : messageID(messageID), fromDeviceID(fromDeviceID), toDeviceID(toDeviceID), payload(payload), blobHashes(blobHashes) { this->validate(); } MessageItem::MessageItem(const AttributeValues &itemFromDB) { this->assignItemFromDatabase(itemFromDB); } void MessageItem::validate() const { if (!tools::validateDeviceID(this->fromDeviceID)) { throw std::runtime_error("Error: FromDeviceID format is wrong."); } if (!tools::validateDeviceID(this->toDeviceID)) { throw std::runtime_error("Error: ToDeviceID format is wrong."); } tools::checkIfNotEmpty("messageID", this->messageID); } void MessageItem::assignItemFromDatabase(const AttributeValues &itemFromDB) { try { this->messageID = itemFromDB.at(MessageItem::FIELD_MESSAGE_ID).GetS(); this->fromDeviceID = itemFromDB.at(MessageItem::FIELD_FROM_DEVICE_ID).GetS(); this->toDeviceID = itemFromDB.at(MessageItem::FIELD_TO_DEVICE_ID).GetS(); this->payload = itemFromDB.at(MessageItem::FIELD_PAYLOAD).GetS(); this->blobHashes = itemFromDB.at(MessageItem::FIELD_BLOB_HASHES).GetS(); this->expire = std::stoull(itemFromDB.at(MessageItem::FIELD_EXPIRE).GetS()); this->createdAt = std::stoull(itemFromDB.at(MessageItem::FIELD_CREATED_AT).GetS()); } catch (const std::exception &e) { throw std::runtime_error( "Got an exception at MessageItem: " + std::string(e.what())); } this->validate(); } std::string MessageItem::getTableName() const { return config::ConfigManager::getInstance().getParameter( config::ConfigManager::OPTION_DYNAMODB_MESSAGES_TABLE); } -PrimaryKey MessageItem::getPrimaryKey() const { - return PrimaryKey(MessageItem::FIELD_MESSAGE_ID); +PrimaryKeyDescriptor MessageItem::getPrimaryKeyDescriptor() const { + return PrimaryKeyDescriptor(MessageItem::FIELD_MESSAGE_ID); } PrimaryKeyValue MessageItem::getPrimaryKeyValue() const { return PrimaryKeyValue(this->messageID); } std::string MessageItem::getMessageID() const { return this->messageID; } std::string MessageItem::getFromDeviceID() const { return this->fromDeviceID; } std::string MessageItem::getToDeviceID() const { return this->toDeviceID; } std::string MessageItem::getPayload() const { return this->payload; } std::string MessageItem::getBlobHashes() const { return this->blobHashes; } uint64_t MessageItem::getExpire() const { return this->expire; } uint64_t MessageItem::getCreatedAt() const { return this->createdAt; } } // namespace database } // namespace network } // namespace comm diff --git a/services/tunnelbroker/src/Database/MessageItem.h b/services/tunnelbroker/src/Database/MessageItem.h index 37d9e806e..7ad796b05 100644 --- a/services/tunnelbroker/src/Database/MessageItem.h +++ b/services/tunnelbroker/src/Database/MessageItem.h @@ -1,57 +1,57 @@ #pragma once #include "Item.h" #include namespace comm { namespace network { namespace database { class MessageItem : public Item { std::string messageID; std::string fromDeviceID; std::string toDeviceID; std::string payload; std::string blobHashes; uint64_t expire; uint64_t createdAt; void validate() const override; public: static const std::string FIELD_MESSAGE_ID; static const std::string FIELD_FROM_DEVICE_ID; static const std::string FIELD_TO_DEVICE_ID; static const std::string FIELD_PAYLOAD; static const std::string FIELD_BLOB_HASHES; static const std::string FIELD_EXPIRE; static const std::string FIELD_CREATED_AT; static const std::string INDEX_TO_DEVICE_ID; - PrimaryKey getPrimaryKey() const override; + PrimaryKeyDescriptor getPrimaryKeyDescriptor() const override; PrimaryKeyValue getPrimaryKeyValue() const override; std::string getTableName() const override; std::string getMessageID() const; std::string getFromDeviceID() const; std::string getToDeviceID() const; std::string getPayload() const; std::string getBlobHashes() const; uint64_t getExpire() const; uint64_t getCreatedAt() const; MessageItem() { } MessageItem( const std::string messageID, const std::string fromDeviceID, const std::string toDeviceID, const std::string payload, const std::string blobHashes); MessageItem(const AttributeValues &itemFromDB); void assignItemFromDatabase(const AttributeValues &itemFromDB) override; }; } // namespace database } // namespace network } // namespace comm diff --git a/services/tunnelbroker/src/Database/PublicKeyItem.cpp b/services/tunnelbroker/src/Database/PublicKeyItem.cpp index 36e491ca4..711d1ef3c 100644 --- a/services/tunnelbroker/src/Database/PublicKeyItem.cpp +++ b/services/tunnelbroker/src/Database/PublicKeyItem.cpp @@ -1,64 +1,64 @@ #include "PublicKeyItem.h" #include "ConfigManager.h" #include "Tools.h" namespace comm { namespace network { namespace database { const std::string PublicKeyItem::FIELD_DEVICE_ID = "DeviceID"; const std::string PublicKeyItem::FIELD_PUBLIC_KEY = "PublicKey"; PublicKeyItem::PublicKeyItem( const std::string deviceID, const std::string publicKey) : deviceID(deviceID), publicKey(publicKey) { this->validate(); } PublicKeyItem::PublicKeyItem(const AttributeValues &itemFromDB) { this->assignItemFromDatabase(itemFromDB); } void PublicKeyItem::validate() const { if (!tools::validateDeviceID(this->deviceID)) { throw std::runtime_error("Error: DeviceID format is wrong."); } tools::checkIfNotEmpty("publicKey", this->publicKey); } void PublicKeyItem::assignItemFromDatabase(const AttributeValues &itemFromDB) { try { this->publicKey = itemFromDB.at(PublicKeyItem::FIELD_PUBLIC_KEY).GetS(); this->deviceID = itemFromDB.at(PublicKeyItem::FIELD_DEVICE_ID).GetS(); } catch (const std::exception &e) { throw std::runtime_error( "Got an exception at PublicKeyItem: " + std::string(e.what())); } this->validate(); } std::string PublicKeyItem::getTableName() const { return config::ConfigManager::getInstance().getParameter( config::ConfigManager::OPTION_DYNAMODB_SESSIONS_PUBLIC_KEY_TABLE); } -PrimaryKey PublicKeyItem::getPrimaryKey() const { - return PrimaryKey(PublicKeyItem::FIELD_DEVICE_ID); +PrimaryKeyDescriptor PublicKeyItem::getPrimaryKeyDescriptor() const { + return PrimaryKeyDescriptor(PublicKeyItem::FIELD_DEVICE_ID); } PrimaryKeyValue PublicKeyItem::getPrimaryKeyValue() const { return PrimaryKeyValue(this->deviceID); } std::string PublicKeyItem::getDeviceID() const { return this->deviceID; } std::string PublicKeyItem::getPublicKey() const { return this->publicKey; } } // namespace database } // namespace network } // namespace comm diff --git a/services/tunnelbroker/src/Database/PublicKeyItem.h b/services/tunnelbroker/src/Database/PublicKeyItem.h index 744188f18..d689a203b 100644 --- a/services/tunnelbroker/src/Database/PublicKeyItem.h +++ b/services/tunnelbroker/src/Database/PublicKeyItem.h @@ -1,36 +1,36 @@ #pragma once #include "Item.h" #include namespace comm { namespace network { namespace database { class PublicKeyItem : public Item { std::string deviceID; std::string publicKey; void validate() const override; public: static const std::string FIELD_DEVICE_ID; static const std::string FIELD_PUBLIC_KEY; - PrimaryKey getPrimaryKey() const override; + PrimaryKeyDescriptor getPrimaryKeyDescriptor() const override; PrimaryKeyValue getPrimaryKeyValue() const override; std::string getTableName() const override; std::string getDeviceID() const; std::string getPublicKey() const; PublicKeyItem() { } PublicKeyItem(const std::string deviceID, const std::string publicKey); PublicKeyItem(const AttributeValues &itemFromDB); void assignItemFromDatabase(const AttributeValues &itemFromDB) override; }; } // namespace database } // namespace network } // namespace comm diff --git a/services/tunnelbroker/src/Database/SessionSignItem.cpp b/services/tunnelbroker/src/Database/SessionSignItem.cpp index f9a164cd4..3b9a6630e 100644 --- a/services/tunnelbroker/src/Database/SessionSignItem.cpp +++ b/services/tunnelbroker/src/Database/SessionSignItem.cpp @@ -1,68 +1,68 @@ #include "SessionSignItem.h" #include "ConfigManager.h" #include "Tools.h" namespace comm { namespace network { namespace database { const std::string SessionSignItem::FIELD_SESSION_VERIFICATION = "VerificationMessage"; const std::string SessionSignItem::FIELD_DEVICE_ID = "DeviceID"; const std::string SessionSignItem::FIELD_EXPIRE = "Expire"; SessionSignItem::SessionSignItem( const std::string sign, const std::string deviceID) : sign(sign), deviceID(deviceID) { this->validate(); } SessionSignItem::SessionSignItem(const AttributeValues &itemFromDB) { this->assignItemFromDatabase(itemFromDB); } void SessionSignItem::validate() const { if (!tools::validateDeviceID(this->deviceID)) { throw std::runtime_error("Error: DeviceID format is wrong."); } tools::checkIfNotEmpty("sign", this->sign); } void SessionSignItem::assignItemFromDatabase( const AttributeValues &itemFromDB) { try { this->sign = itemFromDB.at(SessionSignItem::FIELD_SESSION_VERIFICATION).GetS(); this->deviceID = itemFromDB.at(SessionSignItem::FIELD_DEVICE_ID).GetS(); } catch (const std::exception &e) { throw std::runtime_error( "Got an exception at SessionSignItem: " + std::string(e.what())); } this->validate(); } std::string SessionSignItem::getTableName() const { return config::ConfigManager::getInstance().getParameter( config::ConfigManager::OPTION_DYNAMODB_SESSIONS_VERIFICATION_TABLE); } -PrimaryKey SessionSignItem::getPrimaryKey() const { - return PrimaryKey(SessionSignItem::FIELD_DEVICE_ID); +PrimaryKeyDescriptor SessionSignItem::getPrimaryKeyDescriptor() const { + return PrimaryKeyDescriptor(SessionSignItem::FIELD_DEVICE_ID); } PrimaryKeyValue SessionSignItem::getPrimaryKeyValue() const { return PrimaryKeyValue(this->deviceID); } std::string SessionSignItem::getSign() const { return this->sign; } std::string SessionSignItem::getDeviceID() const { return this->deviceID; } } // namespace database } // namespace network } // namespace comm diff --git a/services/tunnelbroker/src/Database/SessionSignItem.h b/services/tunnelbroker/src/Database/SessionSignItem.h index 24426f794..3df6fbab0 100644 --- a/services/tunnelbroker/src/Database/SessionSignItem.h +++ b/services/tunnelbroker/src/Database/SessionSignItem.h @@ -1,37 +1,37 @@ #pragma once #include "Item.h" #include namespace comm { namespace network { namespace database { class SessionSignItem : public Item { std::string sign; std::string deviceID; void validate() const override; public: static const std::string FIELD_SESSION_VERIFICATION; static const std::string FIELD_DEVICE_ID; static const std::string FIELD_EXPIRE; - PrimaryKey getPrimaryKey() const override; + PrimaryKeyDescriptor getPrimaryKeyDescriptor() const override; PrimaryKeyValue getPrimaryKeyValue() const override; std::string getTableName() const override; std::string getSign() const; std::string getDeviceID() const; SessionSignItem() { } SessionSignItem(const std::string sign, const std::string deviceID); SessionSignItem(const AttributeValues &itemFromDB); void assignItemFromDatabase(const AttributeValues &itemFromDB) override; }; } // namespace database } // namespace network } // namespace comm