|
| 1 | +# NOTE: As of 2022-06-01 the GitLab Enterprise Edition License has the following |
| 2 | +# section: |
| 3 | +# Notwithstanding the foregoing, you may copy and modify the Software for development |
| 4 | +# and testing purposes, without requiring a subscription. |
| 5 | +# |
| 6 | +# https://gitlab.com/gitlab-org/gitlab/-/blob/29503bc97b96af8d4876dc23fc8996e3dab7d211/ee/LICENSE |
| 7 | +# |
| 8 | +# This code is strictly intended for use in the testing framework of python-gitlab |
| 9 | + |
| 10 | +# Code inspired by MIT licensed code at: https://github.com/CONIGUERO/gitlab-license.git |
| 11 | + |
| 12 | +require 'openssl' |
| 13 | +require 'gitlab/license' |
| 14 | + |
| 15 | +# Generate a 2048 bit key pair. |
| 16 | +license_encryption_key = OpenSSL::PKey::RSA.generate(2048) |
| 17 | + |
| 18 | +# Save the private key |
| 19 | +File.open("/.license_encryption_key", "w") { |f| f.write(license_encryption_key.to_pem) } |
| 20 | +# Save the public key |
| 21 | +public_key = license_encryption_key.public_key |
| 22 | +File.open("/.license_encryption_key.pub", "w") { |f| f.write(public_key.to_pem) } |
| 23 | +File.open("/opt/gitlab/embedded/service/gitlab-rails/.license_encryption_key.pub", "w") { |f| f.write(public_key.to_pem) } |
| 24 | + |
| 25 | +Gitlab::License.encryption_key = license_encryption_key |
| 26 | + |
| 27 | +# Build a new license. |
| 28 | +license = Gitlab::License.new |
| 29 | + |
| 30 | +license.licensee = { |
| 31 | + "Name" => "python-gitlab-ci", |
| 32 | + "Company" => "python-gitlab-ci", |
| 33 | + "Email" => "python-gitlab-ci@example.com", |
| 34 | +} |
| 35 | + |
| 36 | +# The date the license starts. |
| 37 | +license.starts_at = Date.today |
| 38 | +# Want to make sure we get at least 1 day of usage. Do two days after because if CI |
| 39 | +# started at 23:59 we could be expired in one minute if we only did one next_day. |
| 40 | +license.expires_at = Date.today.next_day.next_day |
| 41 | + |
| 42 | +# Use 'ultimate' plan so that we can test all features in the CI |
| 43 | +license.restrictions = { |
| 44 | + :plan => "ultimate", |
| 45 | + :id => rand(1000..99999999) |
| 46 | +} |
| 47 | + |
| 48 | +# Export the license, which encrypts and encodes it. |
| 49 | +data = license.export |
| 50 | + |
| 51 | +File.open("/python-gitlab-ci.gitlab-license", 'w') { |file| file.write(data) } |
0 commit comments