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.



16
17
18
19
# File 'lib/chef/utils/licensing_handler.rb', line 16

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

Instance Attribute Details

#license_keyObject (readonly)

Returns the value of attribute license_key.



14
15
16
# File 'lib/chef/utils/licensing_handler.rb', line 14

def license_key
  @license_key
end

#license_typeObject (readonly)

Returns the value of attribute license_type.



14
15
16
# File 'lib/chef/utils/licensing_handler.rb', line 14

def license_type
  @license_type
end

Class Method Details

.validate!Object



32
33
34
35
36
37
38
39
40
41
42
# File 'lib/chef/utils/licensing_handler.rb', line 32

def validate!
  license_keys = ChefLicensing::LicenseKeyFetcher.fetch

  return new(nil, nil) if license_keys.blank?

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

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

Instance Method Details

#install_sh_urlObject



27
28
29
# File 'lib/chef/utils/licensing_handler.rb', line 27

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

#omnitruck_urlObject



21
22
23
24
25
# File 'lib/chef/utils/licensing_handler.rb', line 21

def omnitruck_url
  url = OMNITRUCK_URLS[license_type] || LEGACY_OMNITRUCK_URL

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