Module: ChefLicensing

Defined in:
lib/chef-licensing/license.rb,
lib/chef-licensing.rb,
lib/chef-licensing/config.rb,
lib/chef-licensing/context.rb,
lib/chef-licensing/version.rb,
lib/chef-licensing/api/client.rb,
lib/chef-licensing/api/describe.rb,
lib/chef-licensing/cli_flags/thor.rb,
lib/chef-licensing/exceptions/error.rb,
lib/chef-licensing/api/list_licenses.rb,
lib/chef-licensing/api/parser/client.rb,
lib/chef-licensing/list_license_keys.rb,
lib/chef-licensing/restful_client/v1.rb,
lib/chef-licensing/api/parser/describe.rb,
lib/chef-licensing/license_key_fetcher.rb,
lib/chef-licensing/restful_client/base.rb,
lib/chef-licensing/cli_flags/mixlib_cli.rb,
lib/chef-licensing/license_key_validator.rb,
lib/chef-licensing/tui_engine/tui_engine.rb,
lib/chef-licensing/tui_engine/tui_prompt.rb,
lib/chef-licensing/tui_engine/tui_actions.rb,
lib/chef-licensing/exceptions/client_error.rb,
lib/chef-licensing/licensing_service/local.rb,
lib/chef-licensing/license_key_fetcher/base.rb,
lib/chef-licensing/license_key_fetcher/file.rb,
lib/chef-licensing/exceptions/describe_error.rb,
lib/chef-licensing/tui_engine/tui_exceptions.rb,
lib/chef-licensing/config_fetcher/arg_fetcher.rb,
lib/chef-licensing/config_fetcher/env_fetcher.rb,
lib/chef-licensing/exceptions/invalid_license.rb,
lib/chef-licensing/license_key_fetcher/prompt.rb,
lib/chef-licensing/tui_engine/tui_interaction.rb,
lib/chef-licensing/tui_engine/tui_engine_state.rb,
lib/chef-licensing/exceptions/list_licenses_error.rb,
lib/chef-licensing/api/license_feature_entitlement.rb,
lib/chef-licensing/exceptions/feature_not_entitled.rb,
lib/chef-licensing/exceptions/restful_client_error.rb,
lib/chef-licensing/api/license_software_entitlement.rb,
lib/chef-licensing/exceptions/software_not_entitled.rb,
lib/chef-licensing/exceptions/license_file_corrupted.rb,
lib/chef-licensing/exceptions/unsupported_content_type.rb,
lib/chef-licensing/license_key_fetcher/license_file/v3.rb,
lib/chef-licensing/license_key_fetcher/license_file/v4.rb,
lib/chef-licensing/license_key_fetcher/license_file/base.rb,
lib/chef-licensing/exceptions/invalid_file_format_version.rb,
lib/chef-licensing/exceptions/missing_api_credentials_error.rb,
lib/chef-licensing/exceptions/restful_client_connection_error.rb

Overview

LicenseKeyFetcher allows us to inspect obtain the license Key from the user in a variety of ways.

Defined Under Namespace

Modules: Api, CLIFlags, LicenseFile, RestfulClient Classes: ArgFetcher, ClientError, Config, Context, DescribeError, EnvFetcher, Error, FeatureNotEntitled, InvalidFileFormatVersion, InvalidLicense, License, LicenseFileCorrupted, LicenseKeyFetcher, LicenseKeyValidator, LicensingService, ListLicenseKeys, ListLicensesError, MissingAPICredentialsError, RestfulClientConnectionError, RestfulClientError, SoftwareNotEntitled, TUIEngine, UnsupportedContentType

Constant Summary collapse

VERSION =
"1.0.4".freeze

Class Method Summary collapse

Class Method Details

.add_licenseObject



76
77
78
# File 'lib/chef-licensing.rb', line 76

def add_license
  ChefLicensing::LicenseKeyFetcher.add_license
end

.check_feature_entitlement!(feature_name: nil, feature_id: nil) ⇒ Object



25
26
27
28
29
30
31
32
33
34
# File 'lib/chef-licensing.rb', line 25

def check_feature_entitlement!(feature_name: nil, feature_id: nil)
  # Checking for feature presence in license feature entitlements
  license = client(license_keys: license_keys)
  feature_entitlements = license.feature_entitlements.select { |feature| feature.id == feature_id || feature.name == feature_name }
  if feature_entitlements.empty?
    raise(ChefLicensing::FeatureNotEntitled)
  else
    true
  end
end

.check_software_entitlement!Object



36
37
38
39
40
41
42
43
44
45
46
47
48
49
# File 'lib/chef-licensing.rb', line 36

def check_software_entitlement!
  # If API call is not breaking that means license is entitled.
  raise ChefLicensing::LicenseKeyFetcher::LicenseKeyNotFetchedError.new("Unable to obtain a License Key.") if license_keys.empty?

  client(license_keys: license_keys)
  true
rescue ChefLicensing::ClientError => e
  # Checking specific text phrase for entitlement error
  if e.message.match?(/not entitled/)
    raise(ChefLicensing::SoftwareNotEntitled)
  else
    raise
  end
end

.client(opts = {}) ⇒ Object



72
73
74
# File 'lib/chef-licensing.rb', line 72

def client(opts = {})
  ChefLicensing::Api::Client.info(opts)
end

.configure {|ChefLicensing::Config| ... } ⇒ Object

Examples:

ChefLicensing.configure do |config|
  config.licensing_server_url  = 'LICENSE_SERVER'
  config.logger = Logger.new($stdout)
end

Yields:



21
22
23
# File 'lib/chef-licensing.rb', line 21

def configure(&block)
  yield(ChefLicensing::Config)
end

.fetch_and_persistObject

Note:

fetch_and_persist is invoked by chef-products to fetch and persist the license keys



57
58
59
60
61
62
63
64
65
66
# File 'lib/chef-licensing.rb', line 57

def fetch_and_persist
  ChefLicensing::LicenseKeyFetcher.fetch_and_persist
rescue ChefLicensing::ClientError => e
  # Checking specific text phrase for entitlement error
  if e.message.match?(/not entitled/)
    raise(ChefLicensing::SoftwareNotEntitled, "Software is not entitled.")
  else
    raise
  end
end

.license_contextObject



80
81
82
# File 'lib/chef-licensing.rb', line 80

def license_context
  ChefLicensing::Context.license
end

.license_keysObject

Note:

no in-memory caching of the licenses so that it fetches updated licenses always



52
53
54
# File 'lib/chef-licensing.rb', line 52

def license_keys
  ChefLicensing::LicenseKeyFetcher.fetch
end

.list_license_keys_info(opts = {}) ⇒ Object



68
69
70
# File 'lib/chef-licensing.rb', line 68

def list_license_keys_info(opts = {})
  ChefLicensing::ListLicenseKeys.display(opts)
end