Class: ChefLicensing::ListLicenseKeys
- Inherits:
-
Object
- Object
- ChefLicensing::ListLicenseKeys
- Defined in:
- lib/chef-licensing/list_license_keys.rb
Class Method Summary collapse
Instance Method Summary collapse
- #display ⇒ Object
- #display_overview ⇒ Object
-
#initialize(opts = {}) ⇒ ListLicenseKeys
constructor
A new instance of ListLicenseKeys.
Constructor Details
#initialize(opts = {}) ⇒ ListLicenseKeys
Returns a new instance of ListLicenseKeys.
19 20 21 22 23 24 25 |
# File 'lib/chef-licensing/list_license_keys.rb', line 19 def initialize(opts = {}) @logger = ChefLicensing::Config.logger @output = ChefLicensing::Config.output @pastel = Pastel.new @license_keys = fetch_license_keys(opts) @licenses_metadata = end |
Class Method Details
.display(opts = {}) ⇒ Object
11 12 13 |
# File 'lib/chef-licensing/list_license_keys.rb', line 11 def self.display(opts = {}) new(opts).display end |
.display_overview(opts = {}) ⇒ Object
15 16 17 |
# File 'lib/chef-licensing/list_license_keys.rb', line 15 def self.display_overview(opts = {}) new(opts).display_overview end |
Instance Method Details
#display ⇒ Object
27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 |
# File 'lib/chef-licensing/list_license_keys.rb', line 27 def display output.puts "+------------ License Information ------------+" output.puts "Total Licenses found: #{.length}\n\n" .each do |license| puts_bold "License Key : #{license.id}" # Note: The license type is returned as "free" for Free Tier Licenses from the server. # This is capitalized to "Free Tier" for display purposes as recommended by the product team. license_type = license.license_type == "free" ? "Free Tier" : license.license_type.capitalize output.puts <<~LICENSE Type : #{license_type} Status : #{license.status} Expiration Date : #{license.expiration_date} LICENSE iterate_attributes(license.software_entitlements, "Software Entitlements") iterate_attributes(license.asset_entitlements, "Asset Entitlements") iterate_attributes(license.feature_entitlements, "Feature Entitlements") puts_bold "License Limits" license.limits.each do |limit| usage_limit = limit.usage_limit == -1 ? "Unlimited" : limit.usage_limit output.puts <<~LIMIT Usage Status : #{limit.usage_status} Usage Limit : #{usage_limit} Usage Measure : #{limit.usage_measure} Used : #{limit.used} Software : #{limit.software} LIMIT end output.puts "+----------------------------------------------+" end end |
#display_overview ⇒ Object
62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 |
# File 'lib/chef-licensing/list_license_keys.rb', line 62 def display_overview output.puts "------------------------------------------------------------" .each do |license| # Note: The license type is returned as "free" for Free Tier Licenses from the server. # This is capitalized to "Free Tier" for display purposes as recommended by the product team. license_type = license.license_type == "free" ? "Free Tier" : license.license_type.capitalize # Sets the validity text for a Free Tier License as "Unlimited" and displays the number of days for others. validity = if license.license_type == "free" "Unlimited" else # find the number of days left for the license to expire days = (Date.parse(license.expiration_date) - Date.today).to_i "#{[days, 0].max} #{"Day".pluralize(days)}" end num_of_units = license.limits&.first&.usage_limit || 0 num_of_units = num_of_units == -1 ? "Unlimited" : num_of_units unit_measure = license.limits&.first&.usage_measure || "unit" output.puts <<~LICENSE #{pastel.bold("License Details")} Asset Name : #{license.limits.first.software} License ID : #{license.id} Type : #{license_type} Status : #{license.status.capitalize} Validity : #{validity} No. Of Units : #{num_of_units} #{unit_measure.capitalize.pluralize(num_of_units)} ------------------------------------------------------------ LICENSE end end |