1#ifndef TENDUKE_EE_LICENSING_AUTZHAPI_ABSTRACTLICENSETOKENAUTHZAPIREQUEST_H
2#define TENDUKE_EE_LICENSING_AUTZHAPI_ABSTRACTLICENSETOKENAUTHZAPIREQUEST_H
4#include "./AbstractAuthzApiRequest.h"
5#include "../../InvalidLicenseToken.h"
6#include "../../LicenseTokenParser.h"
8#include "http/HTTPClient.h"
9#include "http/HTTPRequestAuthenticator.h"
10#include "http/HTTPResponseToException.h"
39 const std::shared_ptr<const ::tenduke::http::HTTPClient> &httpClient,
40 const std::shared_ptr<const ::tenduke::http::HTTPRequestAuthenticator> &httpRequestAuthenticator,
41 const std::shared_ptr<const ::tenduke::http::HTTPResponseToException> &throwException,
42 const std::shared_ptr<const ::tenduke::ee::licensing::impl::LicenseTokenParser> &licenseTokenParser,
43 const std::shared_ptr<::tenduke::log::Logger> logger
45 , parseLicenseToken(licenseTokenParser)
61 std::map<std::string, ::tenduke::ee::licensing::Lease> items;
62 std::map<std::string, ::tenduke::ee::licensing::LicensingError> failedItems;
67 std::size_t payloadLength = payload.length();
68 for (
int i = 0; i < payloadLength; i++) {
69 if (payload.at(i) ==
'&') {
70 handleToken(payload.substr(startOfToken, i - startOfToken), items, failedItems);
76 if (startOfToken < payloadLength) {
77 handleToken(payload.substr(startOfToken), items, failedItems);
79 return {items, failedItems};
84 const std::string &token,
85 std::map<std::string, ::tenduke::ee::licensing::Lease> &items,
86 std::map<std::string, ::tenduke::ee::licensing::LicensingError> &failedItems
90 const auto leaseOrError = parseLicenseToken->from(token);
91 if (leaseOrError.isLease()) {
92 items.emplace(leaseOrError.lease.name, leaseOrError.lease);
95 failedItems.emplace(leaseOrError.error.getItemName(), leaseOrError.error);
98 catch (const ::tenduke::ee::licensing::InvalidLicenseToken &e) {
100 std::string(
"AbstractLicenseTokenAuthzApiRequest Invalid license token in the response: ") + e.what()
104 error.setErrorCode(
"invalidLicenseToken");
105 error.setErrorMessage(e.what());
106 failedItems.emplace(error.getItemName(), error);
111 const std::shared_ptr<const ::tenduke::ee::licensing::impl::LicenseTokenParser> parseLicenseToken;
AbstractLicenseTokenAuthzApiRequest(const std::shared_ptr< const ::tenduke::http::HTTPClient > &httpClient, const std::shared_ptr< const ::tenduke::http::HTTPRequestAuthenticator > &httpRequestAuthenticator, const std::shared_ptr< const ::tenduke::http::HTTPResponseToException > &throwException, const std::shared_ptr< const ::tenduke::ee::licensing::impl::LicenseTokenParser > &licenseTokenParser, const std::shared_ptr<::tenduke::log::Logger > logger)
Constructs new instance.g.
Definition AbstractLicenseTokenAuthzApiRequest.h:38
Describes an error returned from the API.
Definition LicensingError.h:18
void setItemName(const std::string &pItemName)
Sets the "item" name.
Definition LicensingError.h:80
Base class for authz-API HTTP requests.
Definition AbstractAuthzApiRequest.h:24
AbstractAuthzApiRequest(const std::shared_ptr< const ::tenduke::http::HTTPClient > &httpClient, const std::shared_ptr< const ::tenduke::http::HTTPRequestAuthenticator > &httpRequestAuthenticator, const std::shared_ptr< const ::tenduke::http::HTTPResponseToException > &throwException, const std::shared_ptr<::tenduke::log::Logger > &logger)
Constructs new instance.
Definition AbstractAuthzApiRequest.h:34
T parseResponsePayload(const std::string &payload) const override
Parses the response payload.
Definition AbstractLicenseTokenAuthzApiRequest.h:59
AbstractLicenseTokenAuthzApiRequest(const std::shared_ptr< const ::tenduke::http::HTTPClient > &httpClient, const std::shared_ptr< const ::tenduke::http::HTTPRequestAuthenticator > &httpRequestAuthenticator, const std::shared_ptr< const ::tenduke::http::HTTPResponseToException > &throwException, const std::shared_ptr< const ::tenduke::ee::licensing::impl::LicenseTokenParser > &licenseTokenParser, const std::shared_ptr<::tenduke::log::Logger > logger)
Constructs new instance.g.
Definition AbstractLicenseTokenAuthzApiRequest.h:38
Low-level client for licensing operations using 10Duke authz-API.
Definition AuthzLicensingClient.h:13
Classes, functions and globals related to 10Duke Enterprise licensing.
Definition AuthzLicensingClient.h:13
Classes, functions and globals of 10Duke Enterprise C++ Client.
Definition APIRequest.h:4
void warning(const char *message)
Write message to global logger at WARNING-level.
Definition log.cpp:106
Root for classes, functions and globals of 10Duke C++ Client.
Definition APIRequest.h:4