Skip to content

Commit 438114e

Browse files
authored
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
1 parent e80617c commit 438114e

File tree

3 files changed

+45
-37
lines changed

3 files changed

+45
-37
lines changed

client_demo/netlicensing_client_demo.cc

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -372,6 +372,7 @@ int main(int argc, char* argv[]) {
372372
vParams.setProductModuleValidationParameters(productModuleNumber, "paramKey", "paramValue");
373373
vParams.setLicenseeName(licenseeName);
374374
vParams.setProductNumber(productNumber);
375+
vParams.setLicenseeProperty("some-licensee-property-key","some-licensee-property-value");
375376
ValidationResult vres = LicenseeService::validate(ctx, licenseeNumber, vParams);
376377
std::cout << "Validation result for created licensee:\n" << vres.toString() << std::endl;
377378

include/netlicensing/validation_parameters.h

Lines changed: 31 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -13,8 +13,7 @@ namespace netlicensing {
1313

1414
private:
1515
String_t productNumber_i;
16-
String_t licenseeName_i;
17-
String_t licenseeSecret_i;
16+
std::map<std::string, std::string> licenseeParameters_i;
1817
std::map<std::string, std::map<std::string, std::string>> parameters_i;
1918

2019
public:
@@ -32,6 +31,14 @@ namespace netlicensing {
3231
return productNumber_i;
3332
}
3433

34+
const std::map<std::string, std::string>& getLicenseeProperties() const {
35+
return licenseeParameters_i;
36+
}
37+
38+
void setLicenseeProperty(const String_t& key, const String_t& value) {
39+
licenseeParameters_i[key] = value;
40+
}
41+
3542
/**
3643
* Sets the name for the new licensee
3744
*
@@ -41,11 +48,19 @@ namespace netlicensing {
4148
* 1000 characters.
4249
*/
4350
void setLicenseeName(const String_t& licenseeName) {
44-
licenseeName_i = licenseeName;
51+
licenseeParameters_i[PROP_LICENSEE_NAME] = licenseeName.toString();
4552
}
4653

47-
const String_t& getLicenseeName() const {
48-
return licenseeName_i;
54+
const String_t getLicenseeName() const {
55+
String_t licenseeName;
56+
57+
auto it = licenseeParameters_i.find(PROP_LICENSEE_NAME);
58+
59+
if (it != licenseeParameters_i.end()) {
60+
licenseeName = (String_t)it->second;
61+
}
62+
63+
return licenseeName;
4964
}
5065

5166
/**
@@ -56,12 +71,20 @@ namespace netlicensing {
5671
*/
5772
[[deprecated("use NodeLocked licensing model instead")]]
5873
void setLicenseeSecret(const String_t& licenseeSecret) {
59-
licenseeSecret_i = licenseeSecret;
74+
licenseeParameters_i[PROP_LICENSEE_SECRET] = licenseeSecret.toString();
6075
}
6176

6277
[[deprecated("use NodeLocked licensing model instead")]]
63-
const String_t& getLicenseeSecret() const {
64-
return licenseeSecret_i;
78+
const String_t getLicenseeSecret() const {
79+
String_t licenseeSecret;
80+
81+
auto it = licenseeParameters_i.find(PROP_LICENSEE_SECRET);
82+
83+
if (it != licenseeParameters_i.end()) {
84+
licenseeSecret = (String_t)it->second;
85+
}
86+
87+
return licenseeSecret;
6588
}
6689

6790
const std::map<std::string, std::map<std::string, std::string>>& getParameters() const {

src/netlicensing.cc

Lines changed: 13 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -221,34 +221,25 @@ namespace netlicensing {
221221
* Validates active licenses of the licensee. See NetLicensingAPI for details:
222222
* https://netlicensing.io/wiki/licensee-services#validate-licensee
223223
*/
224+
[[deprecated("Use LicenseeService::validate(Context, std::string, ValidationParameters) instead")]]
224225
ValidationResult LicenseeService::validate(Context& ctx,
225226
const std::string& licenseeNumber,
226227
const std::string& productNumber/* = std::string()*/,
227228
const std::string& licenseeName/* = std::string()*/,
228229
const parameters_type& validationParameters) {
229230

230-
std::string endpoint = std::string(LICENSEE_ENDPOINT_PATH) + "/" + escape_string(licenseeNumber) + "/" + ENDPOINT_PATH_VALIDATE;
231-
parameters_type params;
232-
if (!productNumber.empty()) params.push_back(std::make_pair(PRODUCT_NUMBER, escape_string(productNumber)));
233-
if (!licenseeName.empty()) params.push_back(std::make_pair(PROP_LICENSEE_NAME, escape_string(licenseeName)));
231+
ValidationParameters vp;
232+
233+
vp.setProductNumber(productNumber);
234+
vp.setLicenseeName(licenseeName);
234235

235236
// Add licensing model specific validation parameters
236237
for (parameters_type::const_iterator paramIt = validationParameters.begin();
237-
paramIt != validationParameters.end(); ++paramIt) {
238-
params.push_back(std::make_pair(escape_string(paramIt->first), escape_string(paramIt->second)));
239-
}
240-
241-
long http_code;
242-
std::string res = ctx.post(endpoint, params, http_code);
243-
ValidationResult validationResult;
244-
ValidationResultMapper vrm(validationResult);
245-
traverse(vrm, res);
246-
247-
if (http_code != 200) {
248-
throw RestException(vrm.getInfos(), http_code);
238+
paramIt != validationParameters.end(); ++paramIt) {
239+
vp.setLicenseeProperty(escape_string(paramIt->first), escape_string(paramIt->second));
249240
}
250241

251-
return validationResult;
242+
return LicenseeService::validate(ctx, licenseeNumber, vp);
252243
}
253244

254245
/**
@@ -265,19 +256,12 @@ namespace netlicensing {
265256
if (!escape_string(validationParameters.getProductNumber()).empty()) {
266257
params.push_back(std::make_pair(PRODUCT_NUMBER, escape_string(validationParameters.getProductNumber())));
267258
}
268-
if (!escape_string(validationParameters.getLicenseeName()).empty()) {
269-
params.push_back(std::make_pair(PROP_LICENSEE_NAME, escape_string(validationParameters.getLicenseeName())));
270-
}
271-
#ifdef __clang__
272-
#pragma clang diagnostic push
273-
#pragma clang diagnostic ignored "-Wdeprecated-declarations"
274-
#endif
275-
if (!escape_string(validationParameters.getLicenseeSecret()).empty()) {
276-
params.push_back(std::make_pair(PROP_LICENSEE_SECRET, escape_string(validationParameters.getLicenseeSecret())));
259+
260+
for (auto const& ent1 : validationParameters.getLicenseeProperties()) {
261+
auto const &key = ent1.first;
262+
auto const& value = ent1.second;
263+
params.push_back(std::make_pair(key, escape_string(value)));
277264
}
278-
#ifdef __clang__
279-
#pragma clang diagnostic pop
280-
#endif
281265

282266
int paramIt = 0;
283267
for(auto const &ent1 : validationParameters.getParameters()) {

0 commit comments

Comments
 (0)