Update ee/lib/tasks/gitlab/license.rake to check if a license exists rather than crashing with an error
What does this MR do?
When running the gitlab-rake gitlab:license:info
maintenance task on a GitLab instance which does not have an applied license, the license info method will crash with the following error:
Today's Date: 2020-08-10
Current User Count: 7
Max Historical Count:
Max Users in License:
License valid from: to
rake aborted!
NoMethodError: undefined method `[]' for nil:NilClass
/opt/gitlab/embedded/service/gitlab-rails/ee/lib/tasks/gitlab/license.rake:13:in `block (3 levels) in <top (required)>'
/opt/gitlab/embedded/bin/bundle:23:in `load'
/opt/gitlab/embedded/bin/bundle:23:in `<main>'
Tasks: TOP => gitlab:license:info
(See full trace by running task with --trace)
This happens because the method is trying to print the Email
attribute which does not exist in the license object in an unlicensed GitLab instance.
This MR changes that functionality by inserting a condition that checks for the presence of the license_plan
attribute before attempting any of the puts
which provide the output of this method. If no license_plan
attribute exists, then the conditional will print a No license has been applied.
message instead.
I selected the license_plan
attribute because it seemed to fit more with the intent of the check, despite the actual failure happening when the Email
attribute was being fetched.
Screenshots
Does this MR meet the acceptance criteria?
Conformity
-
Changelog entry -
Documentation (if required) -
Code review guidelines -
Merge request performance guidelines -
Style guides -
Database guides -
Separation of EE specific content
Availability and Testing
-
Review and add/update tests for this feature/bug. Consider all test levels. See the Test Planning Process. -
Tested in all supported browsers -
Informed Infrastructure department of a default or new setting change, if applicable per definition of done
Security
If this MR contains changes to processing or storing of credentials or tokens, authorization and authentication methods and other items described in the security review guidelines:
-
Label as security and @ mention @gitlab-com/gl-security/appsec
-
The MR includes necessary changes to maintain consistency between UI, API, email, or other methods -
Security reports checked/validated by a reviewer from the AppSec team