Class: Chef::Utils::LicensingHandler

Inherits:
Object
  • Object
show all
Defined in:
lib/chef/utils/licensing_handler.rb

Constant Summary collapse

LEGACY_OMNITRUCK_URL =
"https://omnitruck.chef.io".freeze
OMNITRUCK_URLS =
{
  "free"       => "https://chefdownload-trial.chef.io",
  "trial"      => "https://chefdownload-trial.chef.io",
  "commercial" => "https://chefdownload-commerical.chef.io",
}.freeze

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(key, type) ⇒ LicensingHandler

Returns a new instance of LicensingHandler.



33
34
35
36
# File 'lib/chef/utils/licensing_handler.rb', line 33

def initialize(key, type)
  @license_key = key
  @license_type = type
end

Instance Attribute Details

#license_keyObject (readonly)

Returns the value of attribute license_key.



31
32
33
# File 'lib/chef/utils/licensing_handler.rb', line 31

def license_key
  @license_key
end

#license_typeObject (readonly)

Returns the value of attribute license_type.



31
32
33
# File 'lib/chef/utils/licensing_handler.rb', line 31

def license_type
  @license_type
end

Class Method Details

.validate!Object



51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
# File 'lib/chef/utils/licensing_handler.rb', line 51

def validate!
  license_keys = begin
                   ChefLicensing::LicenseKeyFetcher.fetch
                 # If the env is airgapped or the local licensing service is unreachable,
                 # the licensing gem will raise ChefLicensing::RestfulClientConnectionError.
                 # In such cases, we are assuming the license is not available.
                 rescue ChefLicensing::RestfulClientConnectionError
                   []
                 end

  return new(nil, nil) if license_keys&.empty?

   = ChefLicensing::Api::Describe.list({
    license_keys: license_keys,
  })

  new(.last.id, .last.license_type)
end

Instance Method Details

#install_sh_urlObject



46
47
48
# File 'lib/chef/utils/licensing_handler.rb', line 46

def install_sh_url
  format(omnitruck_url, "install.sh")
end

#omnitruck_urlObject



38
39
40
41
42
43
44
# File 'lib/chef/utils/licensing_handler.rb', line 38

def omnitruck_url
  url = OMNITRUCK_URLS[license_type]
  is_legacy = url.nil?
  url ||= LEGACY_OMNITRUCK_URL

  "#{url}/%s#{is_legacy ? "" : "?license_id=#{license_key}"}"
end