Skip to content

Commit

Permalink
fix: added year and user count validations
Browse files Browse the repository at this point in the history
  • Loading branch information
FMotalleb authored Oct 29, 2024
1 parent 17001b6 commit facf458
Showing 1 changed file with 19 additions and 6 deletions.
25 changes: 19 additions & 6 deletions src/generator.license.rb
Original file line number Diff line number Diff line change
Expand Up @@ -48,19 +48,19 @@
opts.on("--license-email EMAIL-ADDRESS", "Specify license email address (optional) [#{license_email}]") do |v|
license_email = v
end

opts.on("--license-plan PLAN", "Specify license plan (optional) [#{license_plan} (default), premium, starter]") do |v|
license_plan = v
end

opts.on("--license-user-count COUNT", "Specify license user count (optional) [#{license_user_count} (default)]") do |v|
license_user_count = v.to_i
end

opts.on("--license-expire-year YEAR", "Specify license expire year (optional) [#{license_expire_year} (default)]") do |v|
license_expire_year = v.to_i
end

opts.on("-h", "--help", "Prints this help") do
puts opts
exit
Expand All @@ -79,6 +79,19 @@
puts "[!] use -h for help"
exit 1
end

if Time.now.year > license_expire_year
puts "[!] license expiry year is set to #{license_expire_year} which is less than current year, this value must be greater than current year"
puts "[!] use -h for help"
exit 1
end

if license_user_count < 1
puts "[!] license user count is set to #{license_user_count} which is less minumum user count possible"
puts "[!] use -h for help"
exit 1
end

# ==========

puts "[*] loading keys..."
Expand All @@ -94,7 +107,7 @@
puts "[*] loading features from #{features_json_path}"
require 'json'
FEATURE_LIST = JSON.parse(File.read(features_json_path))
else
else
FEATURE_LIST = []
end
puts "[*] total features to inject: #{FEATURE_LIST.size}"
Expand All @@ -116,7 +129,7 @@

# required of course
license.starts_at = Date.new(1976, 4, 1)

puts Date.new()
# required since gem gitlab-license v2.2.1
license.expires_at = Date.new(license_expire_year, 4, 1)

Expand Down

0 comments on commit facf458

Please sign in to comment.