diff --git a/services/tunnelbroker/src/Database/DeviceSessionItem.cpp b/services/tunnelbroker/src/Database/DeviceSessionItem.cpp index eaa743355..97573f8da 100644 --- a/services/tunnelbroker/src/Database/DeviceSessionItem.cpp +++ b/services/tunnelbroker/src/Database/DeviceSessionItem.cpp @@ -1,124 +1,124 @@ #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_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); } std::string DeviceSessionItem::getPrimaryKey() const { return DeviceSessionItem::FIELD_SESSION_ID; } 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/PublicKeyItem.cpp b/services/tunnelbroker/src/Database/PublicKeyItem.cpp index e6947f25a..ee7be912a 100644 --- a/services/tunnelbroker/src/Database/PublicKeyItem.cpp +++ b/services/tunnelbroker/src/Database/PublicKeyItem.cpp @@ -1,60 +1,60 @@ #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_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); } std::string PublicKeyItem::getPrimaryKey() const { return PublicKeyItem::FIELD_DEVICE_ID; } 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/SessionSignItem.cpp b/services/tunnelbroker/src/Database/SessionSignItem.cpp index d3bc25515..8cb61a27e 100644 --- a/services/tunnelbroker/src/Database/SessionSignItem.cpp +++ b/services/tunnelbroker/src/Database/SessionSignItem.cpp @@ -1,64 +1,64 @@ #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_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); } std::string SessionSignItem::getPrimaryKey() const { return SessionSignItem::FIELD_DEVICE_ID; } std::string SessionSignItem::getSign() const { return this->sign; } std::string SessionSignItem::getDeviceID() const { return this->deviceID; } } // namespace database } // namespace network } // namespace comm