forked from omniedgeio/omniedge-windows
-
Notifications
You must be signed in to change notification settings - Fork 0
/
proxy.h
114 lines (97 loc) · 2.27 KB
/
proxy.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
#ifndef PROXY_H
#define PROXY_H
#include <QObject>
#include <QtNetwork>
const QString LIST_VIRTUAL_NETWORKS_QUERY = " \
query { \
listVirtualNetworks(limit: 3000) { \
items { \
id \
ipPrefix \
communityName \
devices { \
items { \
id \
name \
virtualIP \
description \
} \
} \
} \
} \
}";
//struct Device {
// QString id;
// QString name;
// QString virtualIP;
// QString description;
// bool operator()(const Device & a, const Device & b) const
// {
// return a.virtualIP < b.virtualIP;
// }
//};
//struct VirtualNetwork {
// QString id;
// QString ipPrefix;
// QString communityName;
// QList<Device> devices;
//};
struct UserInfo {
QString name;
QString email;
QString username; // userID
};
enum class ResponseStatus {
UnknownError,
AccessDenied, // 400
Unauthorized, // 401
InternalFailure, // 500
InvalidToken, // 403
MalformedQueryString, // 404
ServiceUnavailable, // 503
Success, // 200
};
struct GraphqlRequest {
QString query;
QVariantMap variables;
};
struct GraphqlResponse {
ResponseStatus status;
QVariantMap data;
};
class Proxy : public QObject
{
Q_OBJECT
Q_ENUM(ResponseStatus)
public:
explicit Proxy(QObject *parent = nullptr);
public slots:
void getUserInfo();
bool refreshToken();
void getVirtualNetworks();
void joinVirtualNetwork(QString virtualNetworkID);
signals:
void userInfo(ResponseStatus status, UserInfo info);
//void superNodeInfo(ResponseStatus status, SuperNodeInfo info);
//void virtualNetworks(ResponseStatus status, QList<VirtualNetwork> virtualNetworks);
private:
// Local
QString instanceID;
QString deviceName;
QString description;
QString deviceLanIp;
QString deviceMacAddr;
// Fetch settings from oauth.json
QString idToken;
QString accessToken;
QString clientId;
QString cognitoUri;
QString clientSecret;
QString apiEndpoint;
QString graphqlEndpoint;
QNetworkAccessManager *networkManager;
QString getInternalIP();
GraphqlResponse graphqlQuery(GraphqlRequest request);
ResponseStatus getResponseStatus(QNetworkReply* reply);
};
#endif // PROXY_H