Class: ChefLicensing::LicenseKeyFetcher::Base

Inherits:
Object
  • Object
show all
Defined in:
lib/chef-licensing/license_key_fetcher/base.rb

Defined Under Namespace

Classes: InvalidLicenseKeyFormat

Constant Summary collapse

LICENSE_KEY_REGEX =

4[license type]-(8-4-4-4-12)-4

Examples:

LICENSE UUID: tmns-58555821-925e-4a27-8fdc-e79dae5a425b-9763

SERIAL NUMBER: A8BCD1XS2B4F6FYBWG8TE0N490

COMMERCIAL KEY: e0b8f309-6abd-4668-909b-ef2d5fc043a1

"([a-z]{4}-[0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12}-[0-9]{1,4})".freeze
LICENSE_KEY_PATTERN_DESC =
"Hexadecimal".freeze
SERIAL_KEY_REGEX =

Serial number is a 26 character alphanumeric string

"([A-Z0-9]{26})".freeze
SERIAL_KEY_PATTERN_DESC =
"26 character alphanumeric string".freeze
COMMERCIAL_KEY_REGEX =
"([0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12})".freeze
QUIT_KEY_REGEX =
"(q|Q)".freeze

Class Method Summary collapse

Class Method Details

.verify_and_extract_license(license_key) ⇒ Object



17
18
19
20
21
22
23
# File 'lib/chef-licensing/license_key_fetcher/base.rb', line 17

def self.verify_and_extract_license(license_key)
  if license_key && (match = license_key.match(/^#{LICENSE_KEY_REGEX}$/) || license_key.match(/^#{SERIAL_KEY_REGEX}$/) || license_key.match(/^#{COMMERCIAL_KEY_REGEX}$/))
    match[1]
  else
    raise InvalidLicenseKeyFormat, "Malformed License Key passed on command line - should be #{LICENSE_KEY_PATTERN_DESC} or #{SERIAL_KEY_PATTERN_DESC}"
  end
end