mirror of
https://gitlab.com/spaceti-app/integrations/acs/colnod-connector.git
synced 2026-07-12 16:50:48 +02:00
Migration to mysql and update request auth
This commit is contained in:
parent
9d7f967843
commit
9a73a46f61
@ -1 +1 @@
|
|||||||
Subproject commit d4c4d75b49fe7e0399a6c4e57a7bb32f82bee59d
|
Subproject commit 8aa786fa51dbbd9c82ec20f10892295c93c4054c
|
||||||
@ -1,14 +1,13 @@
|
|||||||
#include <QCoreApplication>
|
#include <QCoreApplication>
|
||||||
|
|
||||||
#include "syncmanager.h"
|
|
||||||
#include <QCommandLineParser>
|
#include <QCommandLineParser>
|
||||||
#include "serversdk/requestmanager.h"
|
|
||||||
#include "serversdk/request.h"
|
|
||||||
|
|
||||||
#include "serversdk/logger.h"
|
#include <serversdk/requestmanager.h>
|
||||||
#include "serversdk/core.h"
|
#include <serversdk/request.h>
|
||||||
|
#include <serversdk/logger.h>
|
||||||
|
#include <serversdk/core.h>
|
||||||
|
|
||||||
#include "colnodapi.h"
|
#include "../colnod/colnodapi.h"
|
||||||
|
#include "../colnod/syncmanager.h"
|
||||||
|
|
||||||
int main(int argc, char *argv[])
|
int main(int argc, char *argv[])
|
||||||
{
|
{
|
||||||
@ -20,7 +19,7 @@ int main(int argc, char *argv[])
|
|||||||
// Command line parsing
|
// Command line parsing
|
||||||
QCommandLineParser parser;
|
QCommandLineParser parser;
|
||||||
parser.setApplicationDescription("Colnod sync");
|
parser.setApplicationDescription("Colnod sync");
|
||||||
QCommandLineOption dryModeOption("dryMode", "ColnodAPI", "Read-only mode, prints changes which would normally be made");
|
QCommandLineOption dryModeOption("dryMode", "Read-only mode, prints changes which would normally be made");
|
||||||
QCommandLineOption dropTablesOption("dropTables", "ColnodAPI", "Delete tables with datas from Colnod");
|
QCommandLineOption dropTablesOption("dropTables", "ColnodAPI", "Delete tables with datas from Colnod");
|
||||||
QCommandLineOption createTablesOption("createTables", "ColnodAPI", "Create tables for saving data from Colnod");
|
QCommandLineOption createTablesOption("createTables", "ColnodAPI", "Create tables for saving data from Colnod");
|
||||||
parser.addOption(dryModeOption);
|
parser.addOption(dryModeOption);
|
||||||
@ -34,8 +33,8 @@ int main(int argc, char *argv[])
|
|||||||
|
|
||||||
// Log messge Filtering
|
// Log messge Filtering
|
||||||
QStringList filters;
|
QStringList filters;
|
||||||
filters << "qt.*=false";
|
// filters << "qt.*=false";
|
||||||
filters << "sdk*=false";
|
// filters << "sdk*=false";
|
||||||
//filters << "*=false";
|
//filters << "*=false";
|
||||||
QLoggingCategory::setFilterRules(filters.join(QStringLiteral("\n")));
|
QLoggingCategory::setFilterRules(filters.join(QStringLiteral("\n")));
|
||||||
|
|
||||||
|
|||||||
@ -37,6 +37,8 @@ bool ColnodAPI::downloadData(const qint64 &time)
|
|||||||
}
|
}
|
||||||
AuthToken token;
|
AuthToken token;
|
||||||
|
|
||||||
|
qDebug(colnod) << "Data:" << login->responseData();
|
||||||
|
|
||||||
if (checkResponse(login->responseData())) {
|
if (checkResponse(login->responseData())) {
|
||||||
qCWarning(colnod) << "empty response data when logging in";
|
qCWarning(colnod) << "empty response data when logging in";
|
||||||
emit downloadDataFinished(nullptr);
|
emit downloadDataFinished(nullptr);
|
||||||
@ -231,12 +233,15 @@ std::shared_ptr<serversdk::Request> ColnodAPI::requestLogin()
|
|||||||
QString encodedPassword = QCryptographicHash::hash(
|
QString encodedPassword = QCryptographicHash::hash(
|
||||||
password().toLocal8Bit(), // -> bytearray
|
password().toLocal8Bit(), // -> bytearray
|
||||||
QCryptographicHash::Sha512 // SHA 512
|
QCryptographicHash::Sha512 // SHA 512
|
||||||
).toHex().toUpper();
|
).toHex();
|
||||||
login.setPassword(encodedPassword);
|
login.setPassword(encodedPassword);
|
||||||
|
|
||||||
auto loginRequest = composeRequest("/AaaManager/authSession", login.jsonData());
|
auto loginRequest = composeRequest("/AaaManager/authSession", login.jsonData());
|
||||||
loginRequest->setUserName(login.username());
|
// loginRequest->setUserName(login.username());
|
||||||
loginRequest->setPassword(login.password());
|
// loginRequest->setPassword(login.password());
|
||||||
|
QMap<QString, QString> header;
|
||||||
|
// loginRequest->addHeader("client-id", mClientId);
|
||||||
|
// loginRequest->addHeader("x-api-key", mApiKey);
|
||||||
mReqMan->processRequest(loginRequest);
|
mReqMan->processRequest(loginRequest);
|
||||||
|
|
||||||
return loginRequest;
|
return loginRequest;
|
||||||
@ -293,7 +298,12 @@ std::shared_ptr<serversdk::Request> ColnodAPI::deleteTokens(const QList<QString>
|
|||||||
std::shared_ptr<serversdk::Request> ColnodAPI::composeRequest(const QString &endpoint, const QByteArray &data)
|
std::shared_ptr<serversdk::Request> ColnodAPI::composeRequest(const QString &endpoint, const QByteArray &data)
|
||||||
{
|
{
|
||||||
QString url = mHost + endpoint;
|
QString url = mHost + endpoint;
|
||||||
return std::make_shared<serversdk::Request>("POST", url, data);
|
auto request = std::make_shared<serversdk::Request>("POST", url, data);
|
||||||
|
|
||||||
|
request->addHeader("client-id", mClientId);
|
||||||
|
request->addHeader("x-api-key", mApiKey);
|
||||||
|
|
||||||
|
return request;
|
||||||
}
|
}
|
||||||
|
|
||||||
bool ColnodAPI::checkRequest(const std::shared_ptr<serversdk::Request> &request)
|
bool ColnodAPI::checkRequest(const std::shared_ptr<serversdk::Request> &request)
|
||||||
|
|||||||
@ -1,9 +1,10 @@
|
|||||||
#pragma once
|
#pragma once
|
||||||
|
|
||||||
#include "serversdk/requestmanager.h"
|
#include <serversdk/requestmanager.h>
|
||||||
#include "serversdk/request.h"
|
#include <serversdk/request.h>
|
||||||
#include "serversdk/databasetable.h"
|
#include <serversdk/databasetable.h>
|
||||||
#include "serversdk/logger.h"
|
#include <serversdk/logger.h>
|
||||||
|
|
||||||
#include "data.h"
|
#include "data.h"
|
||||||
|
|
||||||
Q_DECLARE_LOGGING_CATEGORY(colnod)
|
Q_DECLARE_LOGGING_CATEGORY(colnod)
|
||||||
@ -57,7 +58,7 @@ class ColnodAPI: public QObject
|
|||||||
friend class ColnodTest;
|
friend class ColnodTest;
|
||||||
public:
|
public:
|
||||||
ColnodAPI() = default;
|
ColnodAPI() = default;
|
||||||
ColnodAPI(serversdk::RequestManager* reqManconst, const bool &dryMode = false, QString userName = "spaceti", QString password = "spaceti1");
|
ColnodAPI(serversdk::RequestManager* reqManconst, const bool &dryMode = false, QString userName = "spaceti", QString password = "Churchill.2020");
|
||||||
/**
|
/**
|
||||||
* @brief Downloading changed data from Colnod since last Synchronization
|
* @brief Downloading changed data from Colnod since last Synchronization
|
||||||
*
|
*
|
||||||
@ -125,13 +126,17 @@ signals:
|
|||||||
|
|
||||||
private:
|
private:
|
||||||
serversdk::RequestManager* mReqMan = nullptr;
|
serversdk::RequestManager* mReqMan = nullptr;
|
||||||
QString mHost = "https://192.168.1.3:8443";
|
// QString mHost = "https://192.168.254.11:8443";
|
||||||
|
QString mHost = "https://127.0.0.1:8443";
|
||||||
QString mUserName;
|
QString mUserName;
|
||||||
QString mPassword;
|
QString mPassword;
|
||||||
bool mDryMode = false;
|
bool mDryMode = false;
|
||||||
bool mValid = true;
|
bool mValid = true;
|
||||||
bool mSuccess = true;
|
bool mSuccess = true;
|
||||||
|
|
||||||
|
QString mClientId = "CND5EXTMAN";
|
||||||
|
QString mApiKey = "8ef1a4dd-2cea-4398-a174-fe1d95aec7ad";
|
||||||
|
|
||||||
QString authToken;
|
QString authToken;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|||||||
@ -14,7 +14,7 @@ DatabaseAPI::DatabaseAPI(serversdk::DatabaseManager *dbMan, bool dryMode)
|
|||||||
|
|
||||||
bool DatabaseAPI::open(const QString& host, const QString& name, const QString& user, const QString& password)
|
bool DatabaseAPI::open(const QString& host, const QString& name, const QString& user, const QString& password)
|
||||||
{
|
{
|
||||||
return mDbMan->openPostgres(host, name, user, password);
|
return mDbMan->openMysql(host, name, user, password);
|
||||||
}
|
}
|
||||||
|
|
||||||
bool DatabaseAPI::executeQuery(QSqlQuery &query, const QString &statement)
|
bool DatabaseAPI::executeQuery(QSqlQuery &query, const QString &statement)
|
||||||
@ -167,7 +167,7 @@ void DatabaseAPI::reupdateDeleted(const QList<QString>& ids)
|
|||||||
qint64 DatabaseAPI::getNow()
|
qint64 DatabaseAPI::getNow()
|
||||||
{
|
{
|
||||||
auto query = mDbMan->createQuery();
|
auto query = mDbMan->createQuery();
|
||||||
if (!executeQuery(query, "SELECT EXTRACT(EPOCH FROM NOW())*1000")) {
|
if (!executeQuery(query, "SELECT UNIX_TIMESTAMP()*1000")) {
|
||||||
qCritical(database) << "ERROR during getting acctual time from db";
|
qCritical(database) << "ERROR during getting acctual time from db";
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
@ -261,9 +261,11 @@ std::shared_ptr<Token> DatabaseAPI::getToken(const QString &id)
|
|||||||
{
|
{
|
||||||
auto query = mDbMan->createQuery();
|
auto query = mDbMan->createQuery();
|
||||||
query.prepare("SELECT * FROM colnod_token WHERE id = :id");
|
query.prepare("SELECT * FROM colnod_token WHERE id = :id");
|
||||||
query.bindValue(":id", id);
|
QString tempId = "'" + id + "'";
|
||||||
|
query.bindValue(":id", tempId);
|
||||||
if (!executeQuery(query)) {
|
if (!executeQuery(query)) {
|
||||||
qCritical(database) << "ERROR during accessing existing tokens. EXIT";
|
qCritical(database) << "ERROR during accessing existing tokens. EXIT";
|
||||||
|
qInfo(database) << "Query error:" << query.lastError().text();
|
||||||
return nullptr;
|
return nullptr;
|
||||||
}
|
}
|
||||||
auto list = utils->tableFromQuery<Token>(query);
|
auto list = utils->tableFromQuery<Token>(query);
|
||||||
|
|||||||
@ -1,15 +1,15 @@
|
|||||||
#pragma once
|
#pragma once
|
||||||
|
|
||||||
#include <QSql>
|
#include <QSql>
|
||||||
|
#include <QCoreApplication>
|
||||||
|
|
||||||
|
#include <serversdk/databasemanager.h>
|
||||||
|
#include <serversdk/databasetable.h>
|
||||||
|
#include <serversdk/databaseutils.h>
|
||||||
|
#include <serversdk/logger.h>
|
||||||
|
|
||||||
#include "data.h"
|
#include "data.h"
|
||||||
|
|
||||||
#include "serversdk/databasemanager.h"
|
|
||||||
#include "serversdk/databasetable.h"
|
|
||||||
#include "serversdk/databaseutils.h"
|
|
||||||
#include "serversdk/logger.h"
|
|
||||||
#include <QCoreApplication>
|
|
||||||
|
|
||||||
Q_DECLARE_LOGGING_CATEGORY(database)
|
Q_DECLARE_LOGGING_CATEGORY(database)
|
||||||
|
|
||||||
|
|
||||||
@ -28,10 +28,11 @@ public:
|
|||||||
* @param password
|
* @param password
|
||||||
* @return True if success False otherwise
|
* @return True if success False otherwise
|
||||||
*/
|
*/
|
||||||
bool open(const QString& host = "192.168.1.94",
|
bool open(//const QString& host = "penta",
|
||||||
const QString& name = "deloitte",
|
const QString& host = "127.0.0.1",
|
||||||
const QString& user = "postgres",
|
const QString& name = "spaceti",
|
||||||
const QString& password = "34rjkciea12");
|
const QString& user = "spaceti",
|
||||||
|
const QString& password = "27dML4aKJr");
|
||||||
|
|
||||||
|
|
||||||
std::shared_ptr<Data> downloadData();
|
std::shared_ptr<Data> downloadData();
|
||||||
|
|||||||
@ -1,10 +1,11 @@
|
|||||||
#pragma once
|
#pragma once
|
||||||
|
|
||||||
#include <QDateTime>
|
#include <QDateTime>
|
||||||
#include "serversdk/databasetable.h"
|
|
||||||
#include <qjsondocument.h>
|
#include <qjsondocument.h>
|
||||||
#include <QJsonObject>
|
#include <QJsonObject>
|
||||||
|
|
||||||
|
#include <serversdk/databasetable.h>
|
||||||
|
|
||||||
class SubjectAttribute : public serversdk::DatabaseTable {
|
class SubjectAttribute : public serversdk::DatabaseTable {
|
||||||
Q_OBJECT
|
Q_OBJECT
|
||||||
TABLE_PROPERTY(QString, id, setId, "")
|
TABLE_PROPERTY(QString, id, setId, "")
|
||||||
|
|||||||
@ -1,12 +1,13 @@
|
|||||||
#pragma once
|
#pragma once
|
||||||
|
|
||||||
#include <QDateTime>
|
#include <QDateTime>
|
||||||
#include "serversdk/databasetable.h"
|
|
||||||
#include <QSqlQuery>
|
#include <QSqlQuery>
|
||||||
#include <QJsonDocument>
|
#include <QJsonDocument>
|
||||||
#include <QJsonObject>
|
#include <QJsonObject>
|
||||||
#include <QJsonArray>
|
#include <QJsonArray>
|
||||||
|
|
||||||
|
#include <serversdk/databasetable.h>
|
||||||
|
|
||||||
class Token : public serversdk::DatabaseTable {
|
class Token : public serversdk::DatabaseTable {
|
||||||
Q_OBJECT
|
Q_OBJECT
|
||||||
TABLE_PROPERTY(QString, id, setId, QString())
|
TABLE_PROPERTY(QString, id, setId, QString())
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user