mirror of
https://gitlab.com/spaceti-app/integrations/acs/colnod-connector.git
synced 2026-07-12 17:00:39 +02:00
Merge branch 'diffrent-format-of-input' into 'master'
Diffrent format of input See merge request spaceti-app/integrations/acs/colnod-connector!18
This commit is contained in:
commit
3a231c24c5
@ -6,23 +6,28 @@ stages:
|
||||
# To clone also submodules
|
||||
variables:
|
||||
GIT_SUBMODULE_STRATEGY: recursive
|
||||
PRO_FILE: ../colnod-connector.pro
|
||||
SCRIPT_PATH: server-sdk/scripts
|
||||
|
||||
cache:
|
||||
paths:
|
||||
- build/
|
||||
|
||||
##########
|
||||
###########
|
||||
# Build
|
||||
##########
|
||||
build:
|
||||
stage: build
|
||||
tags:
|
||||
- shell
|
||||
- shell
|
||||
before_script:
|
||||
- git submodule sync --recursive
|
||||
- git submodule update --init --recursive
|
||||
script:
|
||||
- mkdir -p build
|
||||
- cd build
|
||||
- qmake ../colnod-connector.pro
|
||||
- qmake $PRO_FILE
|
||||
- make -j4
|
||||
artifacts:
|
||||
paths:
|
||||
- build/
|
||||
|
||||
##########
|
||||
# Test
|
||||
@ -32,7 +37,9 @@ test:
|
||||
tags:
|
||||
- shell
|
||||
script:
|
||||
- mkdir -p build
|
||||
- cd build
|
||||
- qmake $PRO_FILE
|
||||
- make check
|
||||
|
||||
# memory leak check for unittest
|
||||
@ -41,7 +48,9 @@ valgrind:
|
||||
tags:
|
||||
- shell
|
||||
script:
|
||||
- mkdir -p build
|
||||
- cd build
|
||||
- qmake $PRO_FILE
|
||||
- valgrind make check
|
||||
|
||||
# Quality of code
|
||||
@ -51,7 +60,7 @@ cppcheck:
|
||||
- shell
|
||||
#allow_failure: true # Probably needed to allow failure
|
||||
script:
|
||||
- server-sdk/scripts/cppcheck.sh
|
||||
- $SCRIPT_PATH/cppcheck.sh
|
||||
dependencies: []
|
||||
|
||||
# Common checks ( Line endings )
|
||||
@ -60,7 +69,7 @@ lineendings:
|
||||
tags:
|
||||
- shell
|
||||
script:
|
||||
- server-sdk/scripts/check.sh
|
||||
- $SCRIPT_PATH/check.sh
|
||||
dependencies: []
|
||||
|
||||
codecoverage:
|
||||
@ -68,7 +77,7 @@ codecoverage:
|
||||
tags:
|
||||
- shell
|
||||
script:
|
||||
- server-sdk/scripts/codecoverage.sh
|
||||
- $SCRIPT_PATH/codecoverage.sh
|
||||
coverage: '/^\s+functions..:\s+(\d+\.\d+%).+$/'
|
||||
dependencies: []
|
||||
|
||||
@ -77,5 +86,5 @@ doc:
|
||||
tags:
|
||||
- shell
|
||||
script:
|
||||
- server-sdk/scripts/doc.sh clean # 'clean' better clean before generating documentation
|
||||
- $SCRIPT_PATH/doc.sh clean # 'clean' better clean before generating documentation
|
||||
dependencies: []
|
||||
|
||||
@ -168,3 +168,6 @@ It is possible to chain requests: [see doc](https://support.insomnia.rest/articl
|
||||
#### Install snowboard
|
||||
|
||||
`npm install -g snowboard`
|
||||
|
||||
## Possible checks
|
||||
[here](https://gitlab.com/spaceti-app/integrations/acs/colnod-connector/blob/master/doc/possible-checks.md)
|
||||
|
||||
5
doc/possible-checks.md
Normal file
5
doc/possible-checks.md
Normal file
@ -0,0 +1,5 @@
|
||||
|
||||
# Possible checks
|
||||
|
||||
## Cases:
|
||||
- try to add new virtual token to subject who has no physical card
|
||||
@ -1 +1 @@
|
||||
Subproject commit ee507683c6faf69730451b16fbe3ef2b508a15fa
|
||||
Subproject commit d54da50d5ed3e0ce70b46bb13f8548a048c64120
|
||||
@ -13,9 +13,25 @@ int main(int argc, char *argv[])
|
||||
Logger *logger = Logger::getLogger();
|
||||
parser.setApplicationDescription("Colnod sync");
|
||||
QCommandLineOption dryModeOption("dryMode", "ColnodAPI", "Read-only mode, prints changes which would normally be made");
|
||||
QCommandLineOption dropTablesOption("dropTables", "ColnodAPI", "Delete tables with datas from Colnod");
|
||||
QCommandLineOption createTablesOption("createTables", "ColnodAPI", "Create tables to saving data from Colnod");
|
||||
parser.addOption(dryModeOption);
|
||||
parser.addOption(dropTablesOption);
|
||||
parser.addOption(createTablesOption);
|
||||
parser.process(app);
|
||||
SyncManager api(parser.isSet(dryModeOption));
|
||||
QObject::connect(&api, &SyncManager::error, &app, [](){
|
||||
qDebug() << "error";
|
||||
QCoreApplication::exit(1);
|
||||
}, Qt::QueuedConnection);
|
||||
if (parser.isSet(dropTablesOption)){
|
||||
api.dropTables();
|
||||
return 0;
|
||||
}
|
||||
if (parser.isSet(createTablesOption)){
|
||||
api.createTables();
|
||||
return 0;
|
||||
}
|
||||
api.loadDataFromDB();
|
||||
api.loadDataFromColnod();
|
||||
QObject::connect(&api, &SyncManager::dataDownloaded, [&](){
|
||||
@ -26,9 +42,5 @@ int main(int argc, char *argv[])
|
||||
api.syncDataFromColnodToDB();
|
||||
api.syncDataFromDBToColnod();
|
||||
});
|
||||
QObject::connect(&api, &SyncManager::error, &app, [](){
|
||||
qDebug() << "error";
|
||||
QCoreApplication::exit(1);
|
||||
}, Qt::QueuedConnection);
|
||||
return QCoreApplication::exec();
|
||||
}
|
||||
|
||||
@ -186,19 +186,19 @@ void DatabaseManager::createTables()
|
||||
"deleted BOOLEAN)");
|
||||
executeQuery(query, "CREATE TABLE colnod_token ("
|
||||
"id CHAR(36) primary key NOT NULL,"
|
||||
"auth_errors INTEGER NOT NULL,"
|
||||
"auth_errors INTEGER DEFAULT 255,"
|
||||
"description VARCHAR(255),"
|
||||
"enabled BOOLEAN NOT NULL,"
|
||||
"last_update timestamp NOT NULL,"
|
||||
"enabled BOOLEAN DEFAULT true,"
|
||||
"last_update timestamp DEFAULT '1970-01-01 00:00:00'::timestamp without time zone,"
|
||||
"name VARCHAR(255),"
|
||||
"no_validity BOOLEAN NOT NULL,"
|
||||
"time_to_live INTEGER NOT NULL,"
|
||||
"token_bits INTEGER,"
|
||||
"no_validity BOOLEAN DEFAULT true,"
|
||||
"time_to_live INTEGER DEFAULT 255,"
|
||||
"token_bits INTEGER DEFAULT 32,"
|
||||
"token_data VARCHAR(255),"
|
||||
"token_type VARCHAR(255),"
|
||||
"token_type VARCHAR(255) DEFAULT 'Token'::character varying,"
|
||||
"subject_id CHAR(36),"
|
||||
"last_modified timestamp,"
|
||||
"deleted BOOLEAN)");
|
||||
"last_modified timestamp NOT NULL,"
|
||||
"deleted BOOLEAN DEFAULT false)");
|
||||
executeQuery(query, "CREATE TABLE colnod_subject_attribute ("
|
||||
"id VARCHAR(255) primary key,"
|
||||
"attribute_key VARCHAR(255),"
|
||||
@ -307,6 +307,15 @@ bool DatabaseManager::checkDeletedToken(const QString &id)
|
||||
return query.value(0).toBool();
|
||||
}
|
||||
|
||||
qint16 DatabaseManager::getNumOfTokensOfSubject(const QString &id)
|
||||
{
|
||||
QSqlQuery query;
|
||||
query.prepare("SELECT 1 FROM colnod_token WHERE subject_id = :id AND deleted = false");
|
||||
query.bindValue(":id", id);
|
||||
executeQuery(query);
|
||||
return static_cast<qint16>(query.size());
|
||||
}
|
||||
|
||||
bool DatabaseManager::isOpen()
|
||||
{
|
||||
return opened;
|
||||
|
||||
@ -40,6 +40,8 @@ public:
|
||||
QString getSubjectNameById(const QString &id);
|
||||
bool checkDeletedToken(const QString &id);
|
||||
|
||||
qint16 getNumOfTokensOfSubject(const QString &id);
|
||||
|
||||
bool isOpen();
|
||||
|
||||
|
||||
|
||||
@ -9,7 +9,7 @@ DataManager::DataManager(const bool &dryMode) :
|
||||
nextLastSync = db->getNow();
|
||||
lastSync = db->getLastSync();
|
||||
}
|
||||
connect(db.get(), &DatabaseManager::error, this, &DataManager::error);
|
||||
connect(db.get(), &DatabaseManager::error, this, &DataManager::error, Qt::QueuedConnection);
|
||||
}
|
||||
|
||||
// load all tokens from colnod to comparing with working set from DB
|
||||
@ -84,6 +84,13 @@ void DataManager::fillTokensToChangeDB()
|
||||
{
|
||||
auto token = std::make_shared<Token>();
|
||||
token->fromSQLRecord(query);
|
||||
if (token->getName() == NULL){
|
||||
qint16 num = db->getNumOfTokensOfSubject(token->subjectIdToStringWithoutBraces());
|
||||
token->setName(db->getSubjectNameByTokenId(token->idToStringWithoutBraces()) + "_mobile_" + QString::number(num + 1));
|
||||
token->setDescription("mobile");
|
||||
token->setLastUpdate(token->getLastModified());
|
||||
db->saveToken(token, "colnod_token");
|
||||
}
|
||||
if (token->getDeleted()){ // sort to delete / to update
|
||||
tokensFromDBToDeleteFromColnod.append(token->idToStringWithoutBraces());
|
||||
}
|
||||
@ -252,10 +259,26 @@ void DataManager::setDeletedToTokensFromDB()
|
||||
}
|
||||
|
||||
// recreate working tables
|
||||
void DataManager::emptyDatabase()
|
||||
void DataManager::dropTables()
|
||||
{
|
||||
db->dropTables();
|
||||
db->createTables();
|
||||
if (db->isOpen()){
|
||||
db->dropTables();
|
||||
}
|
||||
else{
|
||||
emit error();
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
void DataManager::createTables()
|
||||
{
|
||||
if (db->isOpen()){
|
||||
db->createTables();
|
||||
db->updateLastSync(0);
|
||||
}
|
||||
else{
|
||||
emit error();
|
||||
}
|
||||
}
|
||||
|
||||
quint64 DataManager::getLastModifiedOfToken(const QString &id)
|
||||
|
||||
@ -38,7 +38,9 @@ public:
|
||||
|
||||
void updateLastSync();
|
||||
|
||||
void emptyDatabase();
|
||||
void dropTables();
|
||||
|
||||
void createTables();
|
||||
|
||||
quint64 getLastModifiedOfToken(const QString &id);
|
||||
|
||||
|
||||
@ -5,8 +5,8 @@ SyncManager::SyncManager(bool dryMode) :
|
||||
dataMan( std::make_unique<DataManager>(dryMode)),
|
||||
dryMode(dryMode)
|
||||
{
|
||||
connect(reqMan.get(), &RequestManager::error, this, &SyncManager::error);
|
||||
connect(dataMan.get(), &DataManager::error, this, &SyncManager::error);
|
||||
connect(reqMan.get(), &RequestManager::error, this, &SyncManager::error, Qt::QueuedConnection);
|
||||
connect(dataMan.get(), &DataManager::error, this, &SyncManager::error, Qt::QueuedConnection);
|
||||
}
|
||||
|
||||
void SyncManager::loadDataFromColnod()
|
||||
@ -180,9 +180,14 @@ void SyncManager::syncDeletedDataFromDBToColnod()
|
||||
}
|
||||
|
||||
// For full sync
|
||||
void SyncManager::prepareDatabase()
|
||||
void SyncManager::dropTables()
|
||||
{
|
||||
dataMan->emptyDatabase();
|
||||
dataMan->dropTables();
|
||||
}
|
||||
|
||||
void SyncManager::createTables()
|
||||
{
|
||||
dataMan->createTables();
|
||||
}
|
||||
|
||||
bool SyncManager::isValid()
|
||||
|
||||
@ -14,7 +14,8 @@ public:
|
||||
void syncDataFromColnodToDB();
|
||||
void syncDataFromDBToColnod();
|
||||
|
||||
void prepareDatabase();
|
||||
void dropTables();
|
||||
void createTables();
|
||||
|
||||
bool isValid();
|
||||
|
||||
|
||||
@ -3,18 +3,13 @@
|
||||
#include <QJsonArray>
|
||||
#include <utility>
|
||||
|
||||
|
||||
Token::Token(const QString& name, QString tokenData, const QString& decription)
|
||||
{
|
||||
this->setName(name);
|
||||
this->tokenData = std::move(tokenData);
|
||||
this->setDescription(decription);
|
||||
this->setId(QUuid::createUuid());
|
||||
this->tokenType = "Token";
|
||||
this->tokenBits = 32;
|
||||
this->timeToLive = 255;
|
||||
this->authErrors = 255;
|
||||
this->flags = {"Enabled", "NoValidity"};
|
||||
|
||||
}
|
||||
|
||||
Token::Token(const QString &name)
|
||||
@ -35,6 +30,7 @@ void Token::fromJSON(const QJsonObject &json) {
|
||||
timeToLive = json["timeToLive"].toInt();
|
||||
authErrors = json["authErrors"].toInt();
|
||||
const auto &flagsArray = json["flags"].toArray();
|
||||
flags.clear();
|
||||
for(const auto &flag : flagsArray){
|
||||
flags.insert(flag.toString());
|
||||
}
|
||||
|
||||
@ -11,6 +11,16 @@ class Token : public Entity {
|
||||
public:
|
||||
// using Entity::Entity;
|
||||
|
||||
/**
|
||||
* # Needed values to proper sync
|
||||
*
|
||||
* * id - primary key
|
||||
* * lastModified - when it was edited/modified
|
||||
* * tokenData - key to open doors
|
||||
* * subjectId - no way of make unassinged token (token without subject)
|
||||
*
|
||||
*/
|
||||
|
||||
Token() = default;
|
||||
Token(const QString& name, QString tokenData, const QString& decription = "mobile");
|
||||
explicit Token(const QString& name);
|
||||
@ -60,11 +70,11 @@ public:
|
||||
QJsonObject toJSON() const override;
|
||||
|
||||
private:
|
||||
QString tokenType;
|
||||
int tokenBits{};
|
||||
QString tokenType = "Token";
|
||||
int tokenBits = 32;
|
||||
QString tokenData;
|
||||
int timeToLive{};
|
||||
int authErrors{};
|
||||
QSet<QString> flags;
|
||||
int timeToLive = 255;
|
||||
int authErrors = 255;
|
||||
QSet<QString> flags = {"NoValidity", "Enabled"};
|
||||
QUuid subjectId;
|
||||
};
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user