Class: ChefLicensing::ListLicenseKeys

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

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(opts = {}) ⇒ ListLicenseKeys

Returns a new instance of ListLicenseKeys.



17
18
19
20
21
22
23
# File 'lib/chef-licensing/list_license_keys.rb', line 17

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



9
10
11
# File 'lib/chef-licensing/list_license_keys.rb', line 9

def self.display(opts = {})
  new(opts).display
end

.display_overview(opts = {}) ⇒ Object



13
14
15
# File 'lib/chef-licensing/list_license_keys.rb', line 13

def self.display_overview(opts = {})
  new(opts).display_overview
end

Instance Method Details

#displayObject



25
26
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
# File 'lib/chef-licensing/list_license_keys.rb', line 25

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_overviewObject



60
61
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
# File 'lib/chef-licensing/list_license_keys.rb', line 60

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 ? days : 0} #{"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