mirror of
https://gitlab.com/spaceti-app/integrations/acs/colnod-connector.git
synced 2026-07-12 10:50:38 +02:00
101 lines
2.8 KiB
C++
101 lines
2.8 KiB
C++
#pragma once
|
|
|
|
#include <QObject>
|
|
#include <QNetworkReply>
|
|
#include <QNetworkAccessManager>
|
|
#include <QNetworkRequest>
|
|
#include <QJsonDocument>
|
|
#include <QJsonObject>
|
|
#include <qcoreapplication.h>
|
|
#include <qnetworkreply.h>
|
|
#include <QByteArray>
|
|
#include <QJsonDocument>
|
|
#include <QJsonObject>
|
|
#include <QJsonArray>
|
|
#include <QJsonParseError>
|
|
#include <QFile>
|
|
#include <QString>
|
|
#include <QMultiMap>
|
|
#include <QPointer>
|
|
#include <QDir>
|
|
#include <QSslError>
|
|
#include <QPair>
|
|
|
|
|
|
#include "token.h"
|
|
#include "response.h"
|
|
#include "logger.h"
|
|
|
|
class RequestManager : public QObject
|
|
{
|
|
Q_OBJECT
|
|
|
|
public:
|
|
friend class UnitTest;
|
|
friend class ComplexTest;
|
|
|
|
RequestManager();
|
|
|
|
// this should be in ColnodAPI class BEGIN
|
|
Response* getSubjects();
|
|
Response* getTokens();
|
|
Response* getTokenSubject();
|
|
|
|
Response* getSubjectsUpdated(uint64_t time);
|
|
Response* getSubjectsDeleted(uint64_t time);
|
|
|
|
Response* getTokensUpdated(uint64_t time);
|
|
Response* getTokensDeleted(uint64_t time);
|
|
|
|
Response* getAccessGroups();
|
|
Response* getAccessGroupsUpdated(uint64_t time);
|
|
Response* getAccessGroupsDeleted(uint64_t time);
|
|
Response* getAccessGroupMembership();
|
|
Response* getAccessGroupMembershipUpdated(uint64_t time);
|
|
Response* getAccessGroupMembershipDeleted(uint64_t time);
|
|
|
|
Response* setTokens(const QHash<QString, std::shared_ptr<Token>> &tokens);
|
|
Response* deleteTokens(const QList<QString> &ids);
|
|
// END
|
|
|
|
private:
|
|
// should be public
|
|
QNetworkReply* postRequest(const QString& endpoint, const QByteArray& json = QByteArray());
|
|
Response* postRequestReturnLogic(const QString& endpoint, const QByteArray& data = QByteArray());
|
|
|
|
std::shared_ptr<Response> login();
|
|
std::shared_ptr<Response> getLoginResponse();
|
|
QString getFromJson(const QString& json, const QString &member);
|
|
QString encryptedPassword(const QString& password);
|
|
QString getLoginHeader(const QString& username, const QString& hash);
|
|
|
|
// in colnod api as well
|
|
QByteArray makeTimestampJson(uint64_t time);
|
|
QByteArray makeTokensJson(const QHash<QString, std::shared_ptr<Token>> &tokens); // maybe better to be in Token class
|
|
QByteArray makeIdsJson(const QList<QString> &ids); // Entity class
|
|
|
|
private slots:
|
|
void onSSLError(QNetworkReply *reply, const QList<QSslError> &errors);
|
|
//void onReplyFinished(QNetworkReply *reply);
|
|
void prepareAuthHeader();
|
|
|
|
signals:
|
|
void successLogin();
|
|
void responseReady();
|
|
void error();
|
|
|
|
private:
|
|
std::unique_ptr<QNetworkAccessManager> manager;
|
|
std::shared_ptr<Response> loginResponse;
|
|
QJsonDocument config;
|
|
QString authHeader;
|
|
const QString host = "https://192.168.1.3:8443";
|
|
//QString host = "https://localhost:8080";
|
|
|
|
const QString password = "spaceti1";
|
|
const QString user = "spaceti";
|
|
QString jsonResponse;
|
|
bool loginStatus = false;
|
|
|
|
};
|