Class: Chef::Licensing

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

Defined Under Namespace

Classes: EntitlementError

Class Method Summary collapse

Class Method Details

.check_software_entitlement!Object



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

def check_software_entitlement!
  Chef::Log.info "Checking software entitlement..."
  ChefLicensing.check_software_entitlement!
rescue ChefLicensing::SoftwareNotEntitled
  Chef::Log.error "License is not entitled to use Chef Infra."
  Chef::Application.exit! "License not entitled", 173 # 173 is the exit code for LICENSE_NOT_ENTITLED defined in lib/chef/application/exit_code.rb
rescue ChefLicensing::Error => e
  Chef::Log.error e.message
  Chef::Application.exit! "Usage error", 1 # Generic failure
end

.check_software_entitlement_compliance_phase!Object



44
45
46
47
48
49
50
51
52
53
54
55
56
57
# File 'lib/chef/licensing.rb', line 44

def check_software_entitlement_compliance_phase!
  Chef::Log.info "Checking software entitlement for compliance phase..."
  # set the chef_entitlement_id to the value for Compliance Phase entitlement (i.e. InSpec's entitlement ID)
  ChefLicensing::Config.chef_entitlement_id = Chef::LicensingConfig::COMPLIANCE_ENTITLEMENT_ID
  ChefLicensing.check_software_entitlement!
rescue ChefLicensing::SoftwareNotEntitled
  raise EntitlementError, "License not entitled"
rescue ChefLicensing::Error => e
  Chef::Log.error e.message
  Chef::Application.exit! "Usage error", 1 # Generic failure
ensure
  # reset the chef_entitlement_id to the default value of Infra
  ChefLicensing::Config.chef_entitlement_id = Chef::LicensingConfig::INFRA_ENTITLEMENT_ID
end

.fetch_and_persistObject



10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
# File 'lib/chef/licensing.rb', line 10

def fetch_and_persist
  Chef::Log.info "Fetching and persisting license..."
  # This is a temporary arrangement to continue end-to-end recipe testing of Chef.
  # Windows, Mac, Linux VMs on vagrant will be tested using legacy test-kitchen
  # whereas Linux docker containers will be tested using chef-test-kitchen-enterprise (habitat)
  # Reason: chef-test-kitchen-enterprise currently supports only kitchen-dokken driver and is available only for Linux x86_64
  # So for now we skip license validation on Mac, Windows, Linux distributions which run using test kitchen.
  if ENV["TEST_KITCHEN"] && !ChefUtils.docker?
    Chef::Log.info "****Skipping license validation..."
    return
  end
  license_keys = ChefLicensing.fetch_and_persist
rescue ChefLicensing::LicenseKeyFetcher::LicenseKeyNotFetchedError
  Chef::Log.error "Chef Infra cannot execute without valid licenses." # TODO: Replace Infra with the product name dynamically
  Chef::Application.exit! "License not set", 174 # 174 is the exit code for LICENSE_NOT_SET defined in lib/chef/application/exit_code.rb
rescue ChefLicensing::SoftwareNotEntitled
  Chef::Log.error "License is not entitled to use Chef Infra."
  Chef::Application.exit! "License not entitled", 173 # 173 is the exit code for LICENSE_NOT_ENTITLED defined in lib/chef/application/exit_code.rb
rescue ChefLicensing::Error => e
  Chef::Log.error e.message
  Chef::Application.exit! "Usage error", 1 # Generic failure
end

.license_addObject



91
92
93
94
95
96
97
98
99
# File 'lib/chef/licensing.rb', line 91

def license_add
  ChefLicensing.add_license
rescue ChefLicensing::LicenseKeyFetcher::LicenseKeyAddNotAllowed => e
  Chef::Log.error e.message
  Chef::Application.exit! "License not set", 174 # 174 is the exit code for LICENSE_NOT_SET defined in lib/chef/application/exit_code.rb
rescue ChefLicensing::Error => e
  Chef::Log.error e.message
  Chef::Application.exit! "Usage error", 1 # Generic failure
end

.license_listObject



84
85
86
87
88
89
# File 'lib/chef/licensing.rb', line 84

def license_list
  ChefLicensing.list_license_keys_info
rescue ChefLicensing::Error => e
  Chef::Log.error e.message
  Chef::Application.exit! "Usage error", 1 # Generic failure
end

.licensing_helpObject



59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
# File 'lib/chef/licensing.rb', line 59

def licensing_help
  "\n    Chef Infra has three tiers of licensing:\n\n      * Free-Tier\n        Users are limited to audit maximum of 10 nodes\n        Entitled for personal or non-commercial use\n\n      * Trial\n        Entitled for unlimited number of nodes\n        Entitled for 30 days only\n        Entitled for commercial use\n\n      * Commercial\n        Entitled for purchased number of nodes\n        Entitled for period of subscription purchased\n        Entitled for commercial use\n\n      For more information please visit:\n      www.chef.io/licensing/faqs\n\n  FOOTER\nend\n"