From 438114e353dca6eaee1ac522b8f9f6c3e31b8e9d Mon Sep 17 00:00:00 2001 From: Rudkovskiy Date: Tue, 22 Nov 2022 13:47:46 +0200 Subject: [PATCH] NLIC-2395: Allow custom properties for auto-created licensee * allow custom properties for auto-created licensee * allow custom properties for auto-created licensee * requested changes * cleanup * requested changes --- client_demo/netlicensing_client_demo.cc | 1 + include/netlicensing/validation_parameters.h | 39 ++++++++++++++---- src/netlicensing.cc | 42 ++++++-------------- 3 files changed, 45 insertions(+), 37 deletions(-) diff --git a/client_demo/netlicensing_client_demo.cc b/client_demo/netlicensing_client_demo.cc index 1a7ff04..a2ad7ce 100644 --- a/client_demo/netlicensing_client_demo.cc +++ b/client_demo/netlicensing_client_demo.cc @@ -372,6 +372,7 @@ int main(int argc, char* argv[]) { vParams.setProductModuleValidationParameters(productModuleNumber, "paramKey", "paramValue"); vParams.setLicenseeName(licenseeName); vParams.setProductNumber(productNumber); + vParams.setLicenseeProperty("some-licensee-property-key","some-licensee-property-value"); ValidationResult vres = LicenseeService::validate(ctx, licenseeNumber, vParams); std::cout << "Validation result for created licensee:\n" << vres.toString() << std::endl; diff --git a/include/netlicensing/validation_parameters.h b/include/netlicensing/validation_parameters.h index 5afea8d..19ec274 100644 --- a/include/netlicensing/validation_parameters.h +++ b/include/netlicensing/validation_parameters.h @@ -13,8 +13,7 @@ namespace netlicensing { private: String_t productNumber_i; - String_t licenseeName_i; - String_t licenseeSecret_i; + std::map licenseeParameters_i; std::map> parameters_i; public: @@ -32,6 +31,14 @@ namespace netlicensing { return productNumber_i; } + const std::map& getLicenseeProperties() const { + return licenseeParameters_i; + } + + void setLicenseeProperty(const String_t& key, const String_t& value) { + licenseeParameters_i[key] = value; + } + /** * Sets the name for the new licensee * @@ -41,11 +48,19 @@ namespace netlicensing { * 1000 characters. */ void setLicenseeName(const String_t& licenseeName) { - licenseeName_i = licenseeName; + licenseeParameters_i[PROP_LICENSEE_NAME] = licenseeName.toString(); } - const String_t& getLicenseeName() const { - return licenseeName_i; + const String_t getLicenseeName() const { + String_t licenseeName; + + auto it = licenseeParameters_i.find(PROP_LICENSEE_NAME); + + if (it != licenseeParameters_i.end()) { + licenseeName = (String_t)it->second; + } + + return licenseeName; } /** @@ -56,12 +71,20 @@ namespace netlicensing { */ [[deprecated("use NodeLocked licensing model instead")]] void setLicenseeSecret(const String_t& licenseeSecret) { - licenseeSecret_i = licenseeSecret; + licenseeParameters_i[PROP_LICENSEE_SECRET] = licenseeSecret.toString(); } [[deprecated("use NodeLocked licensing model instead")]] - const String_t& getLicenseeSecret() const { - return licenseeSecret_i; + const String_t getLicenseeSecret() const { + String_t licenseeSecret; + + auto it = licenseeParameters_i.find(PROP_LICENSEE_SECRET); + + if (it != licenseeParameters_i.end()) { + licenseeSecret = (String_t)it->second; + } + + return licenseeSecret; } const std::map>& getParameters() const { diff --git a/src/netlicensing.cc b/src/netlicensing.cc index 961cfdc..f80d23e 100644 --- a/src/netlicensing.cc +++ b/src/netlicensing.cc @@ -221,34 +221,25 @@ namespace netlicensing { * Validates active licenses of the licensee. See NetLicensingAPI for details: * https://netlicensing.io/wiki/licensee-services#validate-licensee */ + [[deprecated("Use LicenseeService::validate(Context, std::string, ValidationParameters) instead")]] ValidationResult LicenseeService::validate(Context& ctx, const std::string& licenseeNumber, const std::string& productNumber/* = std::string()*/, const std::string& licenseeName/* = std::string()*/, const parameters_type& validationParameters) { - std::string endpoint = std::string(LICENSEE_ENDPOINT_PATH) + "/" + escape_string(licenseeNumber) + "/" + ENDPOINT_PATH_VALIDATE; - parameters_type params; - if (!productNumber.empty()) params.push_back(std::make_pair(PRODUCT_NUMBER, escape_string(productNumber))); - if (!licenseeName.empty()) params.push_back(std::make_pair(PROP_LICENSEE_NAME, escape_string(licenseeName))); + ValidationParameters vp; + + vp.setProductNumber(productNumber); + vp.setLicenseeName(licenseeName); // Add licensing model specific validation parameters for (parameters_type::const_iterator paramIt = validationParameters.begin(); - paramIt != validationParameters.end(); ++paramIt) { - params.push_back(std::make_pair(escape_string(paramIt->first), escape_string(paramIt->second))); - } - - long http_code; - std::string res = ctx.post(endpoint, params, http_code); - ValidationResult validationResult; - ValidationResultMapper vrm(validationResult); - traverse(vrm, res); - - if (http_code != 200) { - throw RestException(vrm.getInfos(), http_code); + paramIt != validationParameters.end(); ++paramIt) { + vp.setLicenseeProperty(escape_string(paramIt->first), escape_string(paramIt->second)); } - return validationResult; + return LicenseeService::validate(ctx, licenseeNumber, vp); } /** @@ -265,19 +256,12 @@ namespace netlicensing { if (!escape_string(validationParameters.getProductNumber()).empty()) { params.push_back(std::make_pair(PRODUCT_NUMBER, escape_string(validationParameters.getProductNumber()))); } - if (!escape_string(validationParameters.getLicenseeName()).empty()) { - params.push_back(std::make_pair(PROP_LICENSEE_NAME, escape_string(validationParameters.getLicenseeName()))); - } -#ifdef __clang__ -#pragma clang diagnostic push -#pragma clang diagnostic ignored "-Wdeprecated-declarations" -#endif - if (!escape_string(validationParameters.getLicenseeSecret()).empty()) { - params.push_back(std::make_pair(PROP_LICENSEE_SECRET, escape_string(validationParameters.getLicenseeSecret()))); + + for (auto const& ent1 : validationParameters.getLicenseeProperties()) { + auto const &key = ent1.first; + auto const& value = ent1.second; + params.push_back(std::make_pair(key, escape_string(value))); } -#ifdef __clang__ -#pragma clang diagnostic pop -#endif int paramIt = 0; for(auto const &ent1 : validationParameters.getParameters()) {