Move license creation via license key/file into a service class
What does this MR do and why?
Part of https://gitlab.com/gitlab-org/gitlab/-/issues/475016+
Prior to this change, the logic used to create a new License
when applying a license key or uploading a license file was handled directly in the LicensesController
. The logic is already too complex for a controller. With upcoming changes, the logic needs to be modified which increased the complexity more.
This change moves the logic to create a License
when a license key is applied or a license file is uploaded to a dedicated service. This simplifies the controller specs and makes extending the logic easier and better maintainable.
MR acceptance checklist
Please evaluate this MR against the MR acceptance checklist. It helps you analyze changes to reduce risks in quality, performance, reliability, security, and maintainability.
How to set up and validate locally
Verify that the license upload under /admin/application_settings/general
in the Add License
section is still working as before with the below scenarios.
If you don't have the needed licenses handy, you can manually create testing licenses for offline cloud, legacy and trial legacy via admin/license/new_license
of your CustomersDot instance. Or create subscriptions in Zuora and setting the Turn on Cloud Licensing
attribute to either Yes
for online cloud subscriptions, offline
for offline cloud subscriptions and no
for legacy license subscriptions. For online cloud, you have to create a Zuora subscription and activate via the activation code so you can retrieve the key of the created license.
Select Enter license key
and accept the terms of service:
- Submit an empty field => This should result in an error.
- Submit an invalid key (type anything into the field) => This should result in an error.
- Submit an expired key => This should result in an error.
- Submit an online cloud license key => This should result in an error.
- Submit an offline cloud license key => This should be successful.
- Submit an legacy license key => This should be successful.
- Submit an trial legacy license key => This should be successful.
- Submit a future dated legacy license => This should be successful.
To test the license file upload, you'll need to create a file (e.g. via touch license.gitlab_license
in the terminal) and copy a license key into it. Then select Upload .gitlab-license file
, upload the file and accept the terms of service before submitting the form.