10Duke Enterprise C++ Client
Loading...
Searching...
No Matches
AbstractLicenseTokenAuthzApiRequest.h
1#ifndef TENDUKE_EE_LICENSING_AUTZHAPI_ABSTRACTLICENSETOKENAUTHZAPIREQUEST_H
2#define TENDUKE_EE_LICENSING_AUTZHAPI_ABSTRACTLICENSETOKENAUTHZAPIREQUEST_H
3
4#include "./AbstractAuthzApiRequest.h"
5#include "../../LicenseTokenParser.h"
6
7#include "http/HTTPClient.h"
8#include "http/HTTPRequestAuthenticator.h"
9#include "http/HTTPResponseToException.h"
10
11#include <memory>
12#include <string>
13
14
15namespace tenduke { namespace ee { namespace licensing { namespace authzapi {
16
17
23template<class T>
25{
26public:
27 virtual ~AbstractLicenseTokenAuthzApiRequest() = default;
28
37 const std::shared_ptr<const ::tenduke::http::HTTPClient> &httpClient,
38 const std::shared_ptr<const ::tenduke::http::HTTPRequestAuthenticator> &httpRequestAuthenticator,
39 const std::shared_ptr<const ::tenduke::http::HTTPResponseToException> &throwException,
40 const std::shared_ptr<const ::tenduke::ee::licensing::impl::LicenseTokenParser> &licenseTokenParser,
41 const std::shared_ptr<::tenduke::log::Logger> logger
42 ) : ::tenduke::ee::licensing::authzapi::AbstractAuthzApiRequest<T>(httpClient, httpRequestAuthenticator, throwException, logger)
43 , parseLicenseToken(licenseTokenParser)
44 {}
45
46protected:
54 T parseResponsePayload(const std::string &payload) const override
55 {
56 std::map<std::string, ::tenduke::ee::licensing::Lease> items;
57 std::map<std::string, ::tenduke::ee::licensing::LicensingError> failedItems;
58 int startOfToken = 0;
59
60 // If the response contains multiple licensed items, each of them are
61 // encoded separately as JWT and the JWTs are concatenated together. This parses those out.
62 std::size_t payloadLength = payload.length();
63 for (int i = 0; i < payloadLength; i++) {
64 if (payload.at(i) == '&') {
65 handleParsedResult(
66 parseLicenseToken->from(payload.substr(startOfToken, i - startOfToken)),
67 items,
68 failedItems
69 );
70
71 startOfToken = i + 1;
72 }
73 }
74 // Handle last token:
75 if (startOfToken < payloadLength) {
76 handleParsedResult(
77 parseLicenseToken->from(payload.substr(startOfToken)),
78 items,
79 failedItems
80 );
81 }
82 return {items, failedItems};
83 }
84
85private:
86 void handleParsedResult(
87 const ::tenduke::ee::licensing::impl::LeaseOrError &leaseOrError,
88 std::map<std::string, ::tenduke::ee::licensing::Lease> &items,
89 std::map<std::string, ::tenduke::ee::licensing::LicensingError> &failedItems
90 ) const
91 {
92 if (leaseOrError.isLease()) {
93 items.emplace(leaseOrError.lease.name, leaseOrError.lease);
94 }
95 else {
96 failedItems.emplace(leaseOrError.error.getItemName(), leaseOrError.error);
97 }
98 }
99
100private:
101 const std::shared_ptr<const ::tenduke::ee::licensing::impl::LicenseTokenParser> parseLicenseToken;
102};
103
104
105}}}}
106
107#endif // TENDUKE_EE_LICENSING_AUTZHAPI_ABSTRACTLICENSETOKENAUTHZAPIREQUEST_H
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:36
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:54
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:36
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
Root for classes, functions and globals of 10Duke C++ Client.
Definition APIRequest.h:4