1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143
| require 'openssl' require 'gitlab/license'
key_pair = OpenSSL::PKey::RSA.generate(2048)
File.open("license_key", "w") { |f| f.write(key_pair.to_pem) }
public_key = key_pair.public_key
File.open("license_key.pub", "w") { |f| f.write(public_key.to_pem) }
private_key = OpenSSL::PKey::RSA.new File.read("license_key") Gitlab::License.encryption_key = private_key
license = Gitlab::License.new
license.licensee = { "Name" => "SkyHive", "Company" => "SkyHive", "Email" => "skyhive@163.com" }
license.starts_at = Date.new(2021, 4, 25)
license.expires_at = Date.new(2049, 4, 25)
license.notify_admins_at = Date.new(2099, 4, 25)
license.notify_users_at = Date.new(2099, 4, 25)
license.block_changes_at = Date.new(2049, 5, 7)
license.restrictions = { active_user_count: 10000 } puts "License:" puts license
data = license.export puts "Exported license:" puts data
File.open("GitLabBV.gitlab-license", "w") { |f| f.write(data) }
public_key = OpenSSL::PKey::RSA.new File.read("license_key.pub") Gitlab::License.encryption_key = public_key
data = File.read("GitLabBV.gitlab-license")
$license = Gitlab::License.import(data) puts "Imported license:" puts $license
unless $license raise "The license is invalid." end
if $license.restricted?(:active_user_count) active_user_count = 1000 if active_user_count > $license.restrictions[:active_user_count] raise "The active user count exceeds the allowed amount!" end end
if $license.notify_admins? puts "The license is due to expire on #{$license.expires_at}." end
if $license.notify_users? puts "The license is due to expire on #{$license.expires_at}." end
module Gitlab class GitAccess def check(cmd, changes = nil) if $license.block_changes? return build_status_object(false, "License expired") end end end end
puts "This instance of GitLab Enterprise Edition is licensed to:" $license.licensee.each do |key, value| puts "#{key}: #{value}" end if $license.expired? puts "The license expired on #{$license.expires_at}" elsif $license.will_expire? puts "The license will expire on #{$license.expires_at}" else puts "The license will never expire." end
|