Skip to content

Commit

Permalink
NLIC-2395: Allow custom properties for auto-created licensee
Browse files Browse the repository at this point in the history
* allow custom properties for auto-created licensee
* allow custom properties for auto-created licensee
* requested changes
* cleanup
* requested changes
  • Loading branch information
v-rudkovskiy authored Nov 22, 2022
1 parent e80617c commit 438114e
Show file tree
Hide file tree
Showing 3 changed files with 45 additions and 37 deletions.
1 change: 1 addition & 0 deletions client_demo/netlicensing_client_demo.cc
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand Down
39 changes: 31 additions & 8 deletions include/netlicensing/validation_parameters.h
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,7 @@ namespace netlicensing {

private:
String_t productNumber_i;
String_t licenseeName_i;
String_t licenseeSecret_i;
std::map<std::string, std::string> licenseeParameters_i;
std::map<std::string, std::map<std::string, std::string>> parameters_i;

public:
Expand All @@ -32,6 +31,14 @@ namespace netlicensing {
return productNumber_i;
}

const std::map<std::string, std::string>& 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
*
Expand All @@ -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;
}

/**
Expand All @@ -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<std::string, std::map<std::string, std::string>>& getParameters() const {
Expand Down
42 changes: 13 additions & 29 deletions src/netlicensing.cc
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}

/**
Expand All @@ -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()) {
Expand Down

0 comments on commit 438114e

Please sign in to comment.