Module: ChefLicensing
- Defined in:
- lib/chef-licensing/license.rb,
lib/chef-licensing.rb,
lib/chef-licensing/log.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/pstore_adapter.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/string_refinements.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, StringRefinements
Classes: ArgFetcher, ClientError, Config, Context, DescribeError, EnvFetcher, Error, FeatureNotEntitled, InvalidFileFormatVersion, InvalidLicense, License, LicenseFileCorrupted, LicenseKeyFetcher, LicenseKeyValidator, LicensingService, ListLicenseKeys, ListLicensesError, Log, MissingAPICredentialsError, PStoreAdapter, RestfulClientConnectionError, RestfulClientError, SoftwareNotEntitled, TUIEngine, UnsupportedContentType
Constant Summary
collapse
- VERSION =
"1.4.0".freeze
Class Method Summary
collapse
Class Method Details
.add_license ⇒ Object
103
104
105
|
# File 'lib/chef-licensing.rb', line 103
def add_license
ChefLicensing::LicenseKeyFetcher.add_license
end
|
.check_feature_entitlement!(feature_name: nil, feature_id: nil) ⇒ Object
26
27
28
29
30
31
32
33
34
35
36
37
38
|
# File 'lib/chef-licensing.rb', line 26
def check_feature_entitlement!(feature_name: nil, feature_id: nil)
return true if ChefLicensing::Config.make_licensing_optional
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
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
|
# File 'lib/chef-licensing.rb', line 40
def check_software_entitlement!
unless ChefLicensing::Config.make_licensing_optional
if license_keys.empty?
raise ChefLicensing::LicenseKeyFetcher::LicenseKeyNotFetchedError,
"Unable to obtain a License Key."
end
client(license_keys: license_keys)
end
true
rescue ChefLicensing::ClientError => e
if e.message.match?(/not entitled/)
raise(ChefLicensing::SoftwareNotEntitled)
else
raise
end
end
|
.client(opts = {}) ⇒ Object
99
100
101
|
# File 'lib/chef-licensing.rb', line 99
def client(opts = {})
ChefLicensing::Api::Client.info(opts)
end
|
22
23
24
|
# File 'lib/chef-licensing.rb', line 22
def configure(&block)
yield(ChefLicensing::Config)
end
|
.fetch_and_persist ⇒ Object
Note:
fetch_and_persist is invoked by chef-products to fetch and persist the license keys
66
67
68
69
70
71
72
73
74
75
76
77
78
|
# File 'lib/chef-licensing.rb', line 66
def fetch_and_persist
return true if ChefLicensing::Config.make_licensing_optional
ChefLicensing::LicenseKeyFetcher.fetch_and_persist
rescue ChefLicensing::ClientError => e
if e.message.match?(/not entitled/)
raise(ChefLicensing::SoftwareNotEntitled, "Software is not entitled.")
else
raise
end
end
|
.fetch_only ⇒ Object
Note:
fetch_only is invoked to fetch license keys without persisting them to a config file
81
82
83
84
85
86
87
88
89
90
91
92
93
|
# File 'lib/chef-licensing.rb', line 81
def fetch_only
return true if ChefLicensing::Config.make_licensing_optional
ChefLicensing::LicenseKeyFetcher.fetch_and_validate
rescue ChefLicensing::ClientError => e
if e.message.match?(/not entitled/)
raise(ChefLicensing::SoftwareNotEntitled, "Software is not entitled.")
else
raise
end
end
|
.license_context ⇒ Object
107
108
109
|
# File 'lib/chef-licensing.rb', line 107
def license_context
ChefLicensing::Context.license
end
|
.license_keys ⇒ Object
Note:
no in-memory caching of the licenses so that it fetches updated licenses always
61
62
63
|
# File 'lib/chef-licensing.rb', line 61
def license_keys
ChefLicensing::LicenseKeyFetcher.fetch
end
|
.list_license_keys_info(opts = {}) ⇒ Object
95
96
97
|
# File 'lib/chef-licensing.rb', line 95
def list_license_keys_info(opts = {})
ChefLicensing::ListLicenseKeys.display(opts)
end
|