-
-
Notifications
You must be signed in to change notification settings - Fork 136
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Support Multiple License Products when using Unity Licensing Server #282
base: main
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Large diffs are not rendered by default.
Original file line number | Diff line number | Diff line change | ||||||||||||||||||||||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
|
@@ -2,7 +2,11 @@ | |||||||||||||||||||||||||||||||
import fs from 'fs'; | ||||||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||||||
class LicensingServerSetup { | ||||||||||||||||||||||||||||||||
public static Setup(unityLicensingServer, actionFolder: string) { | ||||||||||||||||||||||||||||||||
public static Setup( | ||||||||||||||||||||||||||||||||
unityLicensingServer, | ||||||||||||||||||||||||||||||||
actionFolder: string, | ||||||||||||||||||||||||||||||||
unityLicensingProductIds: string, | ||||||||||||||||||||||||||||||||
) { | ||||||||||||||||||||||||||||||||
const servicesConfigPath = `${actionFolder}/unity-config/services-config.json`; | ||||||||||||||||||||||||||||||||
const servicesConfigPathTemplate = `${servicesConfigPath}.template`; | ||||||||||||||||||||||||||||||||
if (!fs.existsSync(servicesConfigPathTemplate)) { | ||||||||||||||||||||||||||||||||
|
@@ -13,6 +17,7 @@ class LicensingServerSetup { | |||||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||||||
let servicesConfig = fs.readFileSync(servicesConfigPathTemplate).toString(); | ||||||||||||||||||||||||||||||||
servicesConfig = servicesConfig.replace('%URL%', unityLicensingServer); | ||||||||||||||||||||||||||||||||
servicesConfig = servicesConfig.replace('%LICENSE_PRODUCT_IDS%', unityLicensingProductIds); | ||||||||||||||||||||||||||||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Add input validation and maintain backward compatibility. The current implementation has potential security and compatibility concerns:
Consider applying these changes: + // Validate and sanitize product IDs
+ const sanitizedProductIds = unityLicensingProductIds
+ ?.split(',')
+ .map(id => id.trim())
+ .filter(id => /^[\w-]+$/.test(id)) // Allow only alphanumeric chars and hyphens
+ .join(',');
+
+ // Only replace if valid product IDs are provided
+ if (sanitizedProductIds) {
+ servicesConfig = servicesConfig.replace('%LICENSE_PRODUCT_IDS%', sanitizedProductIds);
+ } else {
+ // Maintain backward compatibility by using empty string
+ servicesConfig = servicesConfig.replace('%LICENSE_PRODUCT_IDS%', '');
+ }
- servicesConfig = servicesConfig.replace('%LICENSE_PRODUCT_IDS%', unityLicensingProductIds); 📝 Committable suggestion
Suggested change
|
||||||||||||||||||||||||||||||||
fs.writeFileSync(servicesConfigPath, servicesConfig); | ||||||||||||||||||||||||||||||||
} | ||||||||||||||||||||||||||||||||
} | ||||||||||||||||||||||||||||||||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
🛠️ Refactor suggestion
Consider adding type safety and validation for unityLicensingProductIds.
While the change correctly implements the new parameter, consider adding validation to ensure the product IDs are in the correct format before passing them to
Setup
.Consider wrapping the Setup call with validation:
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm not sure about this suggestion as I don't have much details about
unityLicensingProductIds
's actual format, but it sounds a like a good idea to do input validation.On the other hand, we're not doing validation for other parameters so this might be out of scope. Feel free to discard.
edit: I've deleted this learning as not relevant. Suggesting input validation is usually good ⬇
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@GabLeRoux, understood. Since input validation for other parameters is not currently implemented and might be out of scope for this PR, it's acceptable to discard this suggestion. Thank you for clarifying.
✏️ Learnings added