48 lines
1.2 KiB
C++
48 lines
1.2 KiB
C++
#include "clientaccess.h"
|
|
|
|
#include <fstream>
|
|
#include <iomanip>
|
|
#include <Log.h>
|
|
|
|
ClientAccess::ClientAccess() {}
|
|
|
|
ClientAccess::ClientAccess(const std::string& token, uint16_t port) : authcode(token), port(port) {}
|
|
|
|
std::shared_ptr<ClientAccess> createFromLockfile(std::istream& lockfile) {
|
|
std::vector<std::string> parts;
|
|
std::string content;
|
|
while(std::getline(lockfile, content, ':')) {
|
|
parts.push_back(content);
|
|
}
|
|
|
|
if(parts.size() != 5) {
|
|
Log::error << "lockfile contained " << parts.size() << " parts, expected 5";
|
|
return {};
|
|
}
|
|
|
|
const std::string portstr = parts.at(2);
|
|
const std::string token = parts.at(3);
|
|
|
|
// try to parse port
|
|
try {
|
|
uint16_t port = std::stoi(portstr);
|
|
|
|
return std::shared_ptr<ClientAccess>(new ClientAccess(token, port));
|
|
} catch(std::exception& e) {
|
|
Log::error << "could not parse port: " << std::quoted(portstr);
|
|
}
|
|
return nullptr;
|
|
}
|
|
|
|
std::string ClientAccess::getBasicAuth() const {
|
|
return "riot:" + authcode;
|
|
}
|
|
|
|
uint16_t ClientAccess::getPort() const {
|
|
return port;
|
|
}
|
|
|
|
std::string ClientAccess::getURL() const {
|
|
return "https://127.0.0.1:" + std::to_string(port) + "/";
|
|
}
|