From 9a70dabcfb0b68ad43d26deb35c3d341badd7011 Mon Sep 17 00:00:00 2001 From: Motalleb Fallahnezhad Date: Tue, 29 Oct 2024 21:08:26 +0330 Subject: [PATCH] fix: added year and user count validations --- src/generator.license.rb | 25 +++++++++++++++++++------ 1 file changed, 19 insertions(+), 6 deletions(-) diff --git a/src/generator.license.rb b/src/generator.license.rb index 1ea589a..304b3cb 100755 --- a/src/generator.license.rb +++ b/src/generator.license.rb @@ -48,19 +48,19 @@ OptionParser.new do |opts| 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 @@ -79,6 +79,19 @@ if license_plan != 'ultimate' && license_plan != 'premium' && license_plan != 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..." @@ -94,7 +107,7 @@ if !features_json_path.nil? 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}" @@ -116,7 +129,7 @@ license.licensee = { # 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)