From e341ed7aced9e6da3d4ee0ee2605f17564e01987 Mon Sep 17 00:00:00 2001 From: Motalleb Fallahnezhad Date: Tue, 29 Oct 2024 20:21:46 +0330 Subject: [PATCH 1/5] feat: added more parameters to cli --- src/generator.license.rb | 51 +++++++++++++++++++++++++++++++++------- 1 file changed, 43 insertions(+), 8 deletions(-) diff --git a/src/generator.license.rb b/src/generator.license.rb index eccc57b..db22961 100755 --- a/src/generator.license.rb +++ b/src/generator.license.rb @@ -6,6 +6,12 @@ public_key_path = nil private_key_path = nil features_json_path = nil +license_name="Tim Cook" +license_company="Apple Computer, Inc." +license_email="tcook@apple.com" +license_plan='ultimate' +license_user_count=2147483647 +license_expire_year=2500 require 'optparse' OptionParser.new do |opts| @@ -31,6 +37,30 @@ license_json_path = File.expand_path(v) end + opts.on("--license-name ", "Specify license name (optional) [#{license_name}]") do |v| + license_name = v + end + + opts.on("--license-company ", "Specify license company (optional) [#{license_company}]") do |v| + license_company = v + end + + opts.on("--license-email ", "Specify license email address (optional) [#{license_email}]") do |v| + license_email = v + end + + opts.on("--license-plan ", "Specify license plan (optional) [#{license_plan}(default),premium,starter]") do |v| + license_plan = v + end + + opts.on("--license-user-count ", "Specify license user count (optional) [#{license_user_count}(default)]") do |v| + license_user_count = v.to_i + end + + opts.on("--license-expire-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 @@ -44,6 +74,11 @@ exit 1 end +if license_plan != 'ultimate' && license_plan != 'premium' && license_plan != 'starter' && + puts "[!] license plan is set to #{license_plan} which is not one of [ultimate, premium, starter]" + puts "[!] use -h for help" + exit 1 +end # ========== puts "[*] loading keys..." @@ -74,29 +109,29 @@ # don't use gitlab inc, search `gl_team_license` in lib for details license.licensee = { - "Name" => "Tim Cook", - "Company" => "Apple Computer, Inc.", - "Email" => "tcook@apple.com" + "Name" => license_name, + "Company" => license_company, + "Email" => license_email } # required of course license.starts_at = Date.new(1976, 4, 1) # required since gem gitlab-license v2.2.1 -license.expires_at = Date.new(2500, 4, 1) +license.expires_at = Date.new(license_expire_year, 4, 1) # prevent gitlab crash at # notification_start_date = trial? ? expires_at - NOTIFICATION_DAYS_BEFORE_TRIAL_EXPIRY : block_changes_at -license.block_changes_at = Date.new(2500, 4, 1) +license.block_changes_at = Date.new(license_expire_year, 4, 1) # required license.restrictions = { - plan: 'ultimate', + plan: license_plan, # STARTER_PLAN = 'starter' # PREMIUM_PLAN = 'premium' # ULTIMATE_PLAN = 'ultimate' - active_user_count: 2147483647, + active_user_count: license_user_count, # required, just dont overflow } @@ -105,7 +140,7 @@ # so here by we inject all features into restrictions # see scan.rb for a list of features that we are going to inject for feature in FEATURE_LIST - license.restrictions[feature] = 2147483647 + license.restrictions[feature] = license_user_count end puts "[*] validating license..." From 52bf6ed5ad9e9a312b8ff764218c5057bb150ee8 Mon Sep 17 00:00:00 2001 From: Motalleb Fallahnezhad Date: Tue, 29 Oct 2024 20:35:22 +0330 Subject: [PATCH 2/5] fix: license_plan condition --- src/generator.license.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/generator.license.rb b/src/generator.license.rb index db22961..6002263 100755 --- a/src/generator.license.rb +++ b/src/generator.license.rb @@ -74,7 +74,7 @@ exit 1 end -if license_plan != 'ultimate' && license_plan != 'premium' && license_plan != 'starter' && +if license_plan != 'ultimate' && license_plan != 'premium' && license_plan != 'starter' puts "[!] license plan is set to #{license_plan} which is not one of [ultimate, premium, starter]" puts "[!] use -h for help" exit 1 From e1306d3eefaf01ffa2e27d35019abfa191dcde13 Mon Sep 17 00:00:00 2001 From: Motalleb Fallahnezhad Date: Tue, 29 Oct 2024 20:37:53 +0330 Subject: [PATCH 3/5] Update generator.license.rb --- src/generator.license.rb | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/src/generator.license.rb b/src/generator.license.rb index 6002263..e1012fb 100755 --- a/src/generator.license.rb +++ b/src/generator.license.rb @@ -37,27 +37,27 @@ license_json_path = File.expand_path(v) end - opts.on("--license-name ", "Specify license name (optional) [#{license_name}]") do |v| + opts.on("--license-name NAME", "Specify license name (optional) [#{license_name}]") do |v| license_name = v end - opts.on("--license-company ", "Specify license company (optional) [#{license_company}]") do |v| + opts.on("--license-company COMPANY", "Specify license company (optional) [#{license_company}]") do |v| license_company = v end - opts.on("--license-email ", "Specify license email address (optional) [#{license_email}]") do |v| + opts.on("--license-email EMAIL-ADDRESS", "Specify license email address (optional) [#{license_email}]") do |v| license_email = v end - opts.on("--license-plan ", "Specify license plan (optional) [#{license_plan}(default),premium,starter]") do |v| + 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 ", "Specify license user count (optional) [#{license_user_count}(default)]") do |v| + 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 ", "Specify license expire year (optional) [#{license_expire_year}(default)]") do |v| + opts.on("--license-expire-year YEAR", "Specify license expire year (optional) [#{license_expire_year}(default)]") do |v| license_expire_year = v.to_i end From 17001b659fe1a8f0d768d73cf51cbe015e04d25d Mon Sep 17 00:00:00 2001 From: Motalleb Fallahnezhad Date: Tue, 29 Oct 2024 20:40:04 +0330 Subject: [PATCH 4/5] minor: optimized arg help messages --- src/generator.license.rb | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/generator.license.rb b/src/generator.license.rb index e1012fb..1ea589a 100755 --- a/src/generator.license.rb +++ b/src/generator.license.rb @@ -49,15 +49,15 @@ license_email = v end - opts.on("--license-plan PLAN", "Specify license plan (optional) [#{license_plan}(default),premium,starter]") do |v| + 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| + 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| + opts.on("--license-expire-year YEAR", "Specify license expire year (optional) [#{license_expire_year} (default)]") do |v| license_expire_year = v.to_i end From facf458bf2465b2d27ef9eac2f45f657b30c354a Mon Sep 17 00:00:00 2001 From: Motalleb Fallahnezhad Date: Tue, 29 Oct 2024 21:08:26 +0330 Subject: [PATCH 5/5] 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 @@ 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 @@ 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 @@ 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 @@ # 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)