98 lines
2.4 KiB
C++
98 lines
2.4 KiB
C++
#pragma once
|
|
|
|
#include <memory_resource>
|
|
#include <rapidjson/document.h>
|
|
#include <rublon/bits.hpp>
|
|
#include <rublon/configuration.hpp>
|
|
#include <rublon/json.hpp>
|
|
#include <rublon/utils.hpp>
|
|
#include <string>
|
|
#include <string_view>
|
|
|
|
namespace rublon {
|
|
|
|
class Session {
|
|
std::pmr::memory_resource * mr;
|
|
const Pam_t & _pam;
|
|
Configuration _config;
|
|
|
|
std::pmr::string _tid;
|
|
std::pmr::string _accessToken;
|
|
|
|
CoreHandler_t _coreHandler;
|
|
/// TODO log
|
|
public:
|
|
Session(const Pam_t & pam)
|
|
: mr{memory::default_resource()}, _pam{pam}, _config{mr}, _coreHandler{_config} {
|
|
details::initLog();
|
|
}
|
|
|
|
Session(Session &&) noexcept = delete;
|
|
Session(const Session &) = delete;
|
|
|
|
Session & operator=(Session &&) noexcept = delete;
|
|
Session & operator=(const Session &) = delete;
|
|
|
|
const auto & coreHandler() const {
|
|
return _coreHandler;
|
|
}
|
|
const auto & pam() const {
|
|
return _pam;
|
|
}
|
|
auto & config() {
|
|
return _config;
|
|
}
|
|
const auto & config() const {
|
|
return _config;
|
|
}
|
|
|
|
std::string_view systemToken() const {
|
|
return _config.systemToken;
|
|
}
|
|
const char * csystemToken() const {
|
|
return systemToken().data();
|
|
}
|
|
|
|
bool inInteractiveMode() const {
|
|
return _config.nonInteractiveMode == false;
|
|
}
|
|
|
|
void updateTransactionId(const Value * tid) {
|
|
log(LogLevel::Debug, "Set transaction ID %s", tid->GetString());
|
|
_tid = tid->GetString();
|
|
}
|
|
|
|
void updateAccessToken(const Value * accessToken) {
|
|
log(LogLevel::Debug, "AccessToken %s", accessToken->GetString());
|
|
_accessToken = accessToken->GetString();
|
|
}
|
|
bool hasAccessToken() const {
|
|
return not _accessToken.empty();
|
|
}
|
|
std::string_view accessToken() const {
|
|
return _accessToken;
|
|
}
|
|
const char * caccessToken() const {
|
|
return _accessToken.c_str();
|
|
}
|
|
|
|
std::string_view transactionID() const {
|
|
if(_tid.empty()) {
|
|
log(LogLevel::Warning, "Transaction ID is not defined, but requested");
|
|
return "";
|
|
} else {
|
|
return _tid;
|
|
}
|
|
}
|
|
const char * ctransactionID() const {
|
|
if(_tid.empty()) {
|
|
log(LogLevel::Warning, "Transaction ID is not defined, but requested");
|
|
return "";
|
|
} else {
|
|
return _tid.data();
|
|
}
|
|
}
|
|
};
|
|
|
|
} // namespace rublon
|