-
Notifications
You must be signed in to change notification settings - Fork 5
/
OAILicensesApi.cpp
788 lines (675 loc) · 29.6 KB
/
OAILicensesApi.cpp
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
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
/**
* GAMS Engine
* With GAMS Engine you can register and solve GAMS models. It has a namespace management system, so you can restrict your users to certain models.
*
* The version of the OpenAPI document: latest
*
* NOTE: This class is auto generated by OpenAPI Generator (https://openapi-generator.tech).
* https://openapi-generator.tech
* Do not edit the class manually.
*/
#include "OAILicensesApi.h"
#include "OAIServerConfiguration.h"
#include <QJsonArray>
#include <QJsonDocument>
namespace OpenAPI {
OAILicensesApi::OAILicensesApi(const int timeOut)
: _timeOut(timeOut),
_manager(nullptr),
_isResponseCompressionEnabled(false),
_isRequestCompressionEnabled(false) {
initializeServerConfigs();
}
OAILicensesApi::~OAILicensesApi() {
}
void OAILicensesApi::initializeServerConfigs() {
//Default server
QList<OAIServerConfiguration> defaultConf = QList<OAIServerConfiguration>();
//varying endpoint server
defaultConf.append(OAIServerConfiguration(
QUrl("//localhost/"),
"No description provided",
QMap<QString, OAIServerVariable>()));
_serverConfigs.insert("deleteLicense", defaultConf);
_serverIndices.insert("deleteLicense", 0);
_serverConfigs.insert("deleteSystemWideGAMSLicense", defaultConf);
_serverIndices.insert("deleteSystemWideGAMSLicense", 0);
_serverConfigs.insert("getEngineLicense", defaultConf);
_serverIndices.insert("getEngineLicense", 0);
_serverConfigs.insert("getLicense", defaultConf);
_serverIndices.insert("getLicense", 0);
_serverConfigs.insert("getSystemWideGAMSLicense", defaultConf);
_serverIndices.insert("getSystemWideGAMSLicense", 0);
_serverConfigs.insert("updateEngineLicense", defaultConf);
_serverIndices.insert("updateEngineLicense", 0);
_serverConfigs.insert("updateLicense", defaultConf);
_serverIndices.insert("updateLicense", 0);
_serverConfigs.insert("updateSystemWideGAMSLicense", defaultConf);
_serverIndices.insert("updateSystemWideGAMSLicense", 0);
}
/**
* returns 0 on success and -1, -2 or -3 on failure.
* -1 when the variable does not exist and -2 if the value is not defined in the enum and -3 if the operation or server index is not found
*/
int OAILicensesApi::setDefaultServerValue(int serverIndex, const QString &operation, const QString &variable, const QString &value) {
auto it = _serverConfigs.find(operation);
if (it != _serverConfigs.end() && serverIndex < it.value().size()) {
return _serverConfigs[operation][serverIndex].setDefaultValue(variable,value);
}
return -3;
}
void OAILicensesApi::setServerIndex(const QString &operation, int serverIndex) {
if (_serverIndices.contains(operation) && serverIndex < _serverConfigs.find(operation).value().size()) {
_serverIndices[operation] = serverIndex;
}
}
void OAILicensesApi::setApiKey(const QString &apiKeyName, const QString &apiKey) {
_apiKeys.insert(apiKeyName, apiKey);
}
void OAILicensesApi::setBearerToken(const QString &token) {
_bearerToken = token;
}
void OAILicensesApi::setUsername(const QString &username) {
_username = username;
}
void OAILicensesApi::setPassword(const QString &password) {
_password = password;
}
void OAILicensesApi::setTimeOut(const int timeOut) {
_timeOut = timeOut;
}
void OAILicensesApi::setWorkingDirectory(const QString &path) {
_workingDirectory = path;
}
void OAILicensesApi::setNetworkAccessManager(QNetworkAccessManager* manager) {
_manager = manager;
}
/**
* Appends a new ServerConfiguration to the config map for a specific operation.
* @param operation The id to the target operation.
* @param url A string that contains the URL of the server
* @param description A String that describes the server
* @param variables A map between a variable name and its value. The value is used for substitution in the server's URL template.
* returns the index of the new server config on success and -1 if the operation is not found
*/
int OAILicensesApi::addServerConfiguration(const QString &operation, const QUrl &url, const QString &description, const QMap<QString, OAIServerVariable> &variables) {
if (_serverConfigs.contains(operation)) {
_serverConfigs[operation].append(OAIServerConfiguration(
url,
description,
variables));
return _serverConfigs[operation].size()-1;
} else {
return -1;
}
}
/**
* Appends a new ServerConfiguration to the config map for a all operations and sets the index to that server.
* @param url A string that contains the URL of the server
* @param description A String that describes the server
* @param variables A map between a variable name and its value. The value is used for substitution in the server's URL template.
*/
void OAILicensesApi::setNewServerForAllOperations(const QUrl &url, const QString &description, const QMap<QString, OAIServerVariable> &variables) {
#if QT_VERSION >= QT_VERSION_CHECK(5, 12, 0)
for (auto keyIt = _serverIndices.keyBegin(); keyIt != _serverIndices.keyEnd(); keyIt++) {
setServerIndex(*keyIt, addServerConfiguration(*keyIt, url, description, variables));
}
#else
for (auto &e : _serverIndices.keys()) {
setServerIndex(e, addServerConfiguration(e, url, description, variables));
}
#endif
}
/**
* Appends a new ServerConfiguration to the config map for an operations and sets the index to that server.
* @param URL A string that contains the URL of the server
* @param description A String that describes the server
* @param variables A map between a variable name and its value. The value is used for substitution in the server's URL template.
*/
void OAILicensesApi::setNewServer(const QString &operation, const QUrl &url, const QString &description, const QMap<QString, OAIServerVariable> &variables) {
setServerIndex(operation, addServerConfiguration(operation, url, description, variables));
}
void OAILicensesApi::addHeaders(const QString &key, const QString &value) {
_defaultHeaders.insert(key, value);
}
void OAILicensesApi::enableRequestCompression() {
_isRequestCompressionEnabled = true;
}
void OAILicensesApi::enableResponseCompression() {
_isResponseCompressionEnabled = true;
}
void OAILicensesApi::abortRequests() {
emit abortRequestsSignal();
}
QString OAILicensesApi::getParamStylePrefix(const QString &style) {
if (style == "matrix") {
return ";";
} else if (style == "label") {
return ".";
} else if (style == "form") {
return "&";
} else if (style == "simple") {
return "";
} else if (style == "spaceDelimited") {
return "&";
} else if (style == "pipeDelimited") {
return "&";
} else {
return "none";
}
}
QString OAILicensesApi::getParamStyleSuffix(const QString &style) {
if (style == "matrix") {
return "=";
} else if (style == "label") {
return "";
} else if (style == "form") {
return "=";
} else if (style == "simple") {
return "";
} else if (style == "spaceDelimited") {
return "=";
} else if (style == "pipeDelimited") {
return "=";
} else {
return "none";
}
}
QString OAILicensesApi::getParamStyleDelimiter(const QString &style, const QString &name, bool isExplode) {
if (style == "matrix") {
return (isExplode) ? ";" + name + "=" : ",";
} else if (style == "label") {
return (isExplode) ? "." : ",";
} else if (style == "form") {
return (isExplode) ? "&" + name + "=" : ",";
} else if (style == "simple") {
return ",";
} else if (style == "spaceDelimited") {
return (isExplode) ? "&" + name + "=" : " ";
} else if (style == "pipeDelimited") {
return (isExplode) ? "&" + name + "=" : "|";
} else if (style == "deepObject") {
return (isExplode) ? "&" : "none";
} else {
return "none";
}
}
void OAILicensesApi::deleteLicense(const QString &username) {
QString fullPath = QString(_serverConfigs["deleteLicense"][_serverIndices.value("deleteLicense")].URL()+"/licenses/");
if (!_username.isEmpty() && !_password.isEmpty()) {
QByteArray b64;
b64.append(_username.toUtf8() + ":" + _password.toUtf8());
addHeaders("Authorization","Basic " + b64.toBase64());
}
QString queryPrefix, querySuffix, queryDelimiter, queryStyle;
{
queryStyle = "";
if (queryStyle == "")
queryStyle = "form";
queryPrefix = getParamStylePrefix(queryStyle);
querySuffix = getParamStyleSuffix(queryStyle);
queryDelimiter = getParamStyleDelimiter(queryStyle, "username", false);
if (fullPath.indexOf("?") > 0)
fullPath.append(queryPrefix);
else
fullPath.append("?");
fullPath.append(QUrl::toPercentEncoding("username")).append(querySuffix).append(QUrl::toPercentEncoding(::OpenAPI::toStringValue(username)));
}
OAIHttpRequestWorker *worker = new OAIHttpRequestWorker(this, _manager);
worker->setTimeOut(_timeOut);
worker->setWorkingDirectory(_workingDirectory);
OAIHttpRequestInput input(fullPath, "DELETE");
#if QT_VERSION >= QT_VERSION_CHECK(5, 15, 0)
for (auto keyValueIt = _defaultHeaders.keyValueBegin(); keyValueIt != _defaultHeaders.keyValueEnd(); keyValueIt++) {
input.headers.insert(keyValueIt->first, keyValueIt->second);
}
#else
for (auto key : _defaultHeaders.keys()) {
input.headers.insert(key, _defaultHeaders[key]);
}
#endif
connect(worker, &OAIHttpRequestWorker::on_execution_finished, this, &OAILicensesApi::deleteLicenseCallback);
connect(this, &OAILicensesApi::abortRequestsSignal, worker, &QObject::deleteLater);
connect(worker, &QObject::destroyed, this, [this]() {
if (findChildren<OAIHttpRequestWorker*>().count() == 0) {
emit allPendingRequestsCompleted();
}
});
worker->execute(&input);
}
void OAILicensesApi::deleteLicenseCallback(OAIHttpRequestWorker *worker) {
QString error_str = worker->error_str;
QNetworkReply::NetworkError error_type = worker->error_type;
if (worker->error_type != QNetworkReply::NoError) {
error_str = QString("%1, %2").arg(worker->error_str, QString(worker->response));
}
OAIMessage output(QString(worker->response));
worker->deleteLater();
if (worker->error_type == QNetworkReply::NoError) {
emit deleteLicenseSignal(output);
emit deleteLicenseSignalFull(worker, output);
} else {
emit deleteLicenseSignalE(output, error_type, error_str);
emit deleteLicenseSignalEFull(worker, error_type, error_str);
}
}
void OAILicensesApi::deleteSystemWideGAMSLicense() {
QString fullPath = QString(_serverConfigs["deleteSystemWideGAMSLicense"][_serverIndices.value("deleteSystemWideGAMSLicense")].URL()+"/licenses/system-wide");
if (!_username.isEmpty() && !_password.isEmpty()) {
QByteArray b64;
b64.append(_username.toUtf8() + ":" + _password.toUtf8());
addHeaders("Authorization","Basic " + b64.toBase64());
}
OAIHttpRequestWorker *worker = new OAIHttpRequestWorker(this, _manager);
worker->setTimeOut(_timeOut);
worker->setWorkingDirectory(_workingDirectory);
OAIHttpRequestInput input(fullPath, "DELETE");
#if QT_VERSION >= QT_VERSION_CHECK(5, 15, 0)
for (auto keyValueIt = _defaultHeaders.keyValueBegin(); keyValueIt != _defaultHeaders.keyValueEnd(); keyValueIt++) {
input.headers.insert(keyValueIt->first, keyValueIt->second);
}
#else
for (auto key : _defaultHeaders.keys()) {
input.headers.insert(key, _defaultHeaders[key]);
}
#endif
connect(worker, &OAIHttpRequestWorker::on_execution_finished, this, &OAILicensesApi::deleteSystemWideGAMSLicenseCallback);
connect(this, &OAILicensesApi::abortRequestsSignal, worker, &QObject::deleteLater);
connect(worker, &QObject::destroyed, this, [this]() {
if (findChildren<OAIHttpRequestWorker*>().count() == 0) {
emit allPendingRequestsCompleted();
}
});
worker->execute(&input);
}
void OAILicensesApi::deleteSystemWideGAMSLicenseCallback(OAIHttpRequestWorker *worker) {
QString error_str = worker->error_str;
QNetworkReply::NetworkError error_type = worker->error_type;
if (worker->error_type != QNetworkReply::NoError) {
error_str = QString("%1, %2").arg(worker->error_str, QString(worker->response));
}
OAIMessage output(QString(worker->response));
worker->deleteLater();
if (worker->error_type == QNetworkReply::NoError) {
emit deleteSystemWideGAMSLicenseSignal(output);
emit deleteSystemWideGAMSLicenseSignalFull(worker, output);
} else {
emit deleteSystemWideGAMSLicenseSignalE(output, error_type, error_str);
emit deleteSystemWideGAMSLicenseSignalEFull(worker, error_type, error_str);
}
}
void OAILicensesApi::getEngineLicense() {
QString fullPath = QString(_serverConfigs["getEngineLicense"][_serverIndices.value("getEngineLicense")].URL()+"/licenses/engine");
if (!_username.isEmpty() && !_password.isEmpty()) {
QByteArray b64;
b64.append(_username.toUtf8() + ":" + _password.toUtf8());
addHeaders("Authorization","Basic " + b64.toBase64());
}
OAIHttpRequestWorker *worker = new OAIHttpRequestWorker(this, _manager);
worker->setTimeOut(_timeOut);
worker->setWorkingDirectory(_workingDirectory);
OAIHttpRequestInput input(fullPath, "GET");
#if QT_VERSION >= QT_VERSION_CHECK(5, 15, 0)
for (auto keyValueIt = _defaultHeaders.keyValueBegin(); keyValueIt != _defaultHeaders.keyValueEnd(); keyValueIt++) {
input.headers.insert(keyValueIt->first, keyValueIt->second);
}
#else
for (auto key : _defaultHeaders.keys()) {
input.headers.insert(key, _defaultHeaders[key]);
}
#endif
connect(worker, &OAIHttpRequestWorker::on_execution_finished, this, &OAILicensesApi::getEngineLicenseCallback);
connect(this, &OAILicensesApi::abortRequestsSignal, worker, &QObject::deleteLater);
connect(worker, &QObject::destroyed, this, [this]() {
if (findChildren<OAIHttpRequestWorker*>().count() == 0) {
emit allPendingRequestsCompleted();
}
});
worker->execute(&input);
}
void OAILicensesApi::getEngineLicenseCallback(OAIHttpRequestWorker *worker) {
QString error_str = worker->error_str;
QNetworkReply::NetworkError error_type = worker->error_type;
if (worker->error_type != QNetworkReply::NoError) {
error_str = QString("%1, %2").arg(worker->error_str, QString(worker->response));
}
OAIEngine_license output(QString(worker->response));
worker->deleteLater();
if (worker->error_type == QNetworkReply::NoError) {
emit getEngineLicenseSignal(output);
emit getEngineLicenseSignalFull(worker, output);
} else {
emit getEngineLicenseSignalE(output, error_type, error_str);
emit getEngineLicenseSignalEFull(worker, error_type, error_str);
}
}
void OAILicensesApi::getLicense(const ::OpenAPI::OptionalParam<QString> &username, const ::OpenAPI::OptionalParam<QString> &x_fields, const ::OpenAPI::OptionalParam<bool> &only_owners) {
QString fullPath = QString(_serverConfigs["getLicense"][_serverIndices.value("getLicense")].URL()+"/licenses/");
if (!_username.isEmpty() && !_password.isEmpty()) {
QByteArray b64;
b64.append(_username.toUtf8() + ":" + _password.toUtf8());
addHeaders("Authorization","Basic " + b64.toBase64());
}
QString queryPrefix, querySuffix, queryDelimiter, queryStyle;
if (username.hasValue())
{
queryStyle = "";
if (queryStyle == "")
queryStyle = "form";
queryPrefix = getParamStylePrefix(queryStyle);
querySuffix = getParamStyleSuffix(queryStyle);
queryDelimiter = getParamStyleDelimiter(queryStyle, "username", false);
if (fullPath.indexOf("?") > 0)
fullPath.append(queryPrefix);
else
fullPath.append("?");
fullPath.append(QUrl::toPercentEncoding("username")).append(querySuffix).append(QUrl::toPercentEncoding(::OpenAPI::toStringValue(username.value())));
}
if (only_owners.hasValue())
{
queryStyle = "";
if (queryStyle == "")
queryStyle = "form";
queryPrefix = getParamStylePrefix(queryStyle);
querySuffix = getParamStyleSuffix(queryStyle);
queryDelimiter = getParamStyleDelimiter(queryStyle, "only-owners", false);
if (fullPath.indexOf("?") > 0)
fullPath.append(queryPrefix);
else
fullPath.append("?");
fullPath.append(QUrl::toPercentEncoding("only-owners")).append(querySuffix).append(QUrl::toPercentEncoding(::OpenAPI::toStringValue(only_owners.value())));
}
OAIHttpRequestWorker *worker = new OAIHttpRequestWorker(this, _manager);
worker->setTimeOut(_timeOut);
worker->setWorkingDirectory(_workingDirectory);
OAIHttpRequestInput input(fullPath, "GET");
if (x_fields.hasValue())
{
if (!::OpenAPI::toStringValue(x_fields.value()).isEmpty()) {
input.headers.insert("X-Fields", ::OpenAPI::toStringValue(x_fields.value()));
}
}
#if QT_VERSION >= QT_VERSION_CHECK(5, 15, 0)
for (auto keyValueIt = _defaultHeaders.keyValueBegin(); keyValueIt != _defaultHeaders.keyValueEnd(); keyValueIt++) {
input.headers.insert(keyValueIt->first, keyValueIt->second);
}
#else
for (auto key : _defaultHeaders.keys()) {
input.headers.insert(key, _defaultHeaders[key]);
}
#endif
connect(worker, &OAIHttpRequestWorker::on_execution_finished, this, &OAILicensesApi::getLicenseCallback);
connect(this, &OAILicensesApi::abortRequestsSignal, worker, &QObject::deleteLater);
connect(worker, &QObject::destroyed, this, [this]() {
if (findChildren<OAIHttpRequestWorker*>().count() == 0) {
emit allPendingRequestsCompleted();
}
});
worker->execute(&input);
}
void OAILicensesApi::getLicenseCallback(OAIHttpRequestWorker *worker) {
QString error_str = worker->error_str;
QNetworkReply::NetworkError error_type = worker->error_type;
if (worker->error_type != QNetworkReply::NoError) {
error_str = QString("%1, %2").arg(worker->error_str, QString(worker->response));
}
QList<OAILicense> output;
QString json(worker->response);
QByteArray array(json.toStdString().c_str());
QJsonDocument doc = QJsonDocument::fromJson(array);
QJsonArray jsonArray = doc.array();
for (QJsonValue obj : jsonArray) {
OAILicense val;
::OpenAPI::fromJsonValue(val, obj);
output.append(val);
}
worker->deleteLater();
if (worker->error_type == QNetworkReply::NoError) {
emit getLicenseSignal(output);
emit getLicenseSignalFull(worker, output);
} else {
emit getLicenseSignalE(output, error_type, error_str);
emit getLicenseSignalEFull(worker, error_type, error_str);
}
}
void OAILicensesApi::getSystemWideGAMSLicense() {
QString fullPath = QString(_serverConfigs["getSystemWideGAMSLicense"][_serverIndices.value("getSystemWideGAMSLicense")].URL()+"/licenses/system-wide");
if (!_username.isEmpty() && !_password.isEmpty()) {
QByteArray b64;
b64.append(_username.toUtf8() + ":" + _password.toUtf8());
addHeaders("Authorization","Basic " + b64.toBase64());
}
OAIHttpRequestWorker *worker = new OAIHttpRequestWorker(this, _manager);
worker->setTimeOut(_timeOut);
worker->setWorkingDirectory(_workingDirectory);
OAIHttpRequestInput input(fullPath, "GET");
#if QT_VERSION >= QT_VERSION_CHECK(5, 15, 0)
for (auto keyValueIt = _defaultHeaders.keyValueBegin(); keyValueIt != _defaultHeaders.keyValueEnd(); keyValueIt++) {
input.headers.insert(keyValueIt->first, keyValueIt->second);
}
#else
for (auto key : _defaultHeaders.keys()) {
input.headers.insert(key, _defaultHeaders[key]);
}
#endif
connect(worker, &OAIHttpRequestWorker::on_execution_finished, this, &OAILicensesApi::getSystemWideGAMSLicenseCallback);
connect(this, &OAILicensesApi::abortRequestsSignal, worker, &QObject::deleteLater);
connect(worker, &QObject::destroyed, this, [this]() {
if (findChildren<OAIHttpRequestWorker*>().count() == 0) {
emit allPendingRequestsCompleted();
}
});
worker->execute(&input);
}
void OAILicensesApi::getSystemWideGAMSLicenseCallback(OAIHttpRequestWorker *worker) {
QString error_str = worker->error_str;
QNetworkReply::NetworkError error_type = worker->error_type;
if (worker->error_type != QNetworkReply::NoError) {
error_str = QString("%1, %2").arg(worker->error_str, QString(worker->response));
}
OAISystem_wide_license output(QString(worker->response));
worker->deleteLater();
if (worker->error_type == QNetworkReply::NoError) {
emit getSystemWideGAMSLicenseSignal(output);
emit getSystemWideGAMSLicenseSignalFull(worker, output);
} else {
emit getSystemWideGAMSLicenseSignalE(output, error_type, error_str);
emit getSystemWideGAMSLicenseSignalEFull(worker, error_type, error_str);
}
}
void OAILicensesApi::updateEngineLicense(const QString &license) {
QString fullPath = QString(_serverConfigs["updateEngineLicense"][_serverIndices.value("updateEngineLicense")].URL()+"/licenses/engine");
if (!_username.isEmpty() && !_password.isEmpty()) {
QByteArray b64;
b64.append(_username.toUtf8() + ":" + _password.toUtf8());
addHeaders("Authorization","Basic " + b64.toBase64());
}
OAIHttpRequestWorker *worker = new OAIHttpRequestWorker(this, _manager);
worker->setTimeOut(_timeOut);
worker->setWorkingDirectory(_workingDirectory);
OAIHttpRequestInput input(fullPath, "PUT");
{
input.add_var("license", ::OpenAPI::toStringValue(license));
}
#if QT_VERSION >= QT_VERSION_CHECK(5, 15, 0)
for (auto keyValueIt = _defaultHeaders.keyValueBegin(); keyValueIt != _defaultHeaders.keyValueEnd(); keyValueIt++) {
input.headers.insert(keyValueIt->first, keyValueIt->second);
}
#else
for (auto key : _defaultHeaders.keys()) {
input.headers.insert(key, _defaultHeaders[key]);
}
#endif
connect(worker, &OAIHttpRequestWorker::on_execution_finished, this, &OAILicensesApi::updateEngineLicenseCallback);
connect(this, &OAILicensesApi::abortRequestsSignal, worker, &QObject::deleteLater);
connect(worker, &QObject::destroyed, this, [this]() {
if (findChildren<OAIHttpRequestWorker*>().count() == 0) {
emit allPendingRequestsCompleted();
}
});
worker->execute(&input);
}
void OAILicensesApi::updateEngineLicenseCallback(OAIHttpRequestWorker *worker) {
QString error_str = worker->error_str;
QNetworkReply::NetworkError error_type = worker->error_type;
if (worker->error_type != QNetworkReply::NoError) {
error_str = QString("%1, %2").arg(worker->error_str, QString(worker->response));
}
OAIMessage output(QString(worker->response));
worker->deleteLater();
if (worker->error_type == QNetworkReply::NoError) {
emit updateEngineLicenseSignal(output);
emit updateEngineLicenseSignalFull(worker, output);
} else {
emit updateEngineLicenseSignalE(output, error_type, error_str);
emit updateEngineLicenseSignalEFull(worker, error_type, error_str);
}
}
void OAILicensesApi::updateLicense(const QString &username, const QString &license) {
QString fullPath = QString(_serverConfigs["updateLicense"][_serverIndices.value("updateLicense")].URL()+"/licenses/");
if (!_username.isEmpty() && !_password.isEmpty()) {
QByteArray b64;
b64.append(_username.toUtf8() + ":" + _password.toUtf8());
addHeaders("Authorization","Basic " + b64.toBase64());
}
OAIHttpRequestWorker *worker = new OAIHttpRequestWorker(this, _manager);
worker->setTimeOut(_timeOut);
worker->setWorkingDirectory(_workingDirectory);
OAIHttpRequestInput input(fullPath, "PUT");
{
input.add_var("username", ::OpenAPI::toStringValue(username));
}
{
input.add_var("license", ::OpenAPI::toStringValue(license));
}
#if QT_VERSION >= QT_VERSION_CHECK(5, 15, 0)
for (auto keyValueIt = _defaultHeaders.keyValueBegin(); keyValueIt != _defaultHeaders.keyValueEnd(); keyValueIt++) {
input.headers.insert(keyValueIt->first, keyValueIt->second);
}
#else
for (auto key : _defaultHeaders.keys()) {
input.headers.insert(key, _defaultHeaders[key]);
}
#endif
connect(worker, &OAIHttpRequestWorker::on_execution_finished, this, &OAILicensesApi::updateLicenseCallback);
connect(this, &OAILicensesApi::abortRequestsSignal, worker, &QObject::deleteLater);
connect(worker, &QObject::destroyed, this, [this]() {
if (findChildren<OAIHttpRequestWorker*>().count() == 0) {
emit allPendingRequestsCompleted();
}
});
worker->execute(&input);
}
void OAILicensesApi::updateLicenseCallback(OAIHttpRequestWorker *worker) {
QString error_str = worker->error_str;
QNetworkReply::NetworkError error_type = worker->error_type;
if (worker->error_type != QNetworkReply::NoError) {
error_str = QString("%1, %2").arg(worker->error_str, QString(worker->response));
}
OAIMessage output(QString(worker->response));
worker->deleteLater();
if (worker->error_type == QNetworkReply::NoError) {
emit updateLicenseSignal(output);
emit updateLicenseSignalFull(worker, output);
} else {
emit updateLicenseSignalE(output, error_type, error_str);
emit updateLicenseSignalEFull(worker, error_type, error_str);
}
}
void OAILicensesApi::updateSystemWideGAMSLicense(const QString &license) {
QString fullPath = QString(_serverConfigs["updateSystemWideGAMSLicense"][_serverIndices.value("updateSystemWideGAMSLicense")].URL()+"/licenses/system-wide");
if (!_username.isEmpty() && !_password.isEmpty()) {
QByteArray b64;
b64.append(_username.toUtf8() + ":" + _password.toUtf8());
addHeaders("Authorization","Basic " + b64.toBase64());
}
OAIHttpRequestWorker *worker = new OAIHttpRequestWorker(this, _manager);
worker->setTimeOut(_timeOut);
worker->setWorkingDirectory(_workingDirectory);
OAIHttpRequestInput input(fullPath, "PUT");
{
input.add_var("license", ::OpenAPI::toStringValue(license));
}
#if QT_VERSION >= QT_VERSION_CHECK(5, 15, 0)
for (auto keyValueIt = _defaultHeaders.keyValueBegin(); keyValueIt != _defaultHeaders.keyValueEnd(); keyValueIt++) {
input.headers.insert(keyValueIt->first, keyValueIt->second);
}
#else
for (auto key : _defaultHeaders.keys()) {
input.headers.insert(key, _defaultHeaders[key]);
}
#endif
connect(worker, &OAIHttpRequestWorker::on_execution_finished, this, &OAILicensesApi::updateSystemWideGAMSLicenseCallback);
connect(this, &OAILicensesApi::abortRequestsSignal, worker, &QObject::deleteLater);
connect(worker, &QObject::destroyed, this, [this]() {
if (findChildren<OAIHttpRequestWorker*>().count() == 0) {
emit allPendingRequestsCompleted();
}
});
worker->execute(&input);
}
void OAILicensesApi::updateSystemWideGAMSLicenseCallback(OAIHttpRequestWorker *worker) {
QString error_str = worker->error_str;
QNetworkReply::NetworkError error_type = worker->error_type;
if (worker->error_type != QNetworkReply::NoError) {
error_str = QString("%1, %2").arg(worker->error_str, QString(worker->response));
}
OAIMessage output(QString(worker->response));
worker->deleteLater();
if (worker->error_type == QNetworkReply::NoError) {
emit updateSystemWideGAMSLicenseSignal(output);
emit updateSystemWideGAMSLicenseSignalFull(worker, output);
} else {
emit updateSystemWideGAMSLicenseSignalE(output, error_type, error_str);
emit updateSystemWideGAMSLicenseSignalEFull(worker, error_type, error_str);
}
}
void OAILicensesApi::tokenAvailable(){
oauthToken token;
switch (_OauthMethod) {
case 1: //implicit flow
token = _implicitFlow.getToken(_latestScope.join(" "));
if(token.isValid()){
_latestInput.headers.insert("Authorization", "Bearer " + token.getToken());
_latestWorker->execute(&_latestInput);
}else{
_implicitFlow.removeToken(_latestScope.join(" "));
qDebug() << "Could not retrieve a valid token";
}
break;
case 2: //authorization flow
token = _authFlow.getToken(_latestScope.join(" "));
if(token.isValid()){
_latestInput.headers.insert("Authorization", "Bearer " + token.getToken());
_latestWorker->execute(&_latestInput);
}else{
_authFlow.removeToken(_latestScope.join(" "));
qDebug() << "Could not retrieve a valid token";
}
break;
case 3: //client credentials flow
token = _credentialFlow.getToken(_latestScope.join(" "));
if(token.isValid()){
_latestInput.headers.insert("Authorization", "Bearer " + token.getToken());
_latestWorker->execute(&_latestInput);
}else{
_credentialFlow.removeToken(_latestScope.join(" "));
qDebug() << "Could not retrieve a valid token";
}
break;
case 4: //resource owner password flow
token = _passwordFlow.getToken(_latestScope.join(" "));
if(token.isValid()){
_latestInput.headers.insert("Authorization", "Bearer " + token.getToken());
_latestWorker->execute(&_latestInput);
}else{
_credentialFlow.removeToken(_latestScope.join(" "));
qDebug() << "Could not retrieve a valid token";
}
break;
default:
qDebug() << "No Oauth method set!";
break;
}
}
} // namespace OpenAPI