Class: ChefLicensing::License

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

Defined Under Namespace

Classes: AssetEntitlement, FeatureEntitlement, Limit, SoftwareEntitlement

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(opts = {}) ⇒ License

Returns a new instance of License.



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

def initialize(opts = {})
  # API parser based on the API call
  @parser = opts[:api_parser].new(opts[:data])
  @product_name = ChefLicensing::Config.chef_product_name

  @id = @parser.parse_id
  @status = @parser.parse_status
  @license_type = @parser.parse_license_type

  # expiration details
  @expiration_date = @parser.parse_expiration_date
  @expiration_status = @parser.parse_license_expiration_status

  # usage details
  @limits = []

  # Entitlements
  @feature_entitlements = []
  @software_entitlements = []
  @asset_entitlements = []
end

Instance Attribute Details

#expiration_dateObject (readonly)

Returns the value of attribute expiration_date.



10
11
12
# File 'lib/chef-licensing/license.rb', line 10

def expiration_date
  @expiration_date
end

#expiration_statusObject (readonly)

Returns the value of attribute expiration_status.



10
11
12
# File 'lib/chef-licensing/license.rb', line 10

def expiration_status
  @expiration_status
end

#idObject (readonly)

Returns the value of attribute id.



10
11
12
# File 'lib/chef-licensing/license.rb', line 10

def id
  @id
end

#license_typeObject (readonly)

Returns the value of attribute license_type.



10
11
12
# File 'lib/chef-licensing/license.rb', line 10

def license_type
  @license_type
end

#number_of_days_in_expirationObject

Returns the value of attribute number_of_days_in_expiration.



11
12
13
# File 'lib/chef-licensing/license.rb', line 11

def number_of_days_in_expiration
  @number_of_days_in_expiration
end

#statusObject (readonly)

Returns the value of attribute status.



10
11
12
# File 'lib/chef-licensing/license.rb', line 10

def status
  @status
end

Instance Method Details

#about_to_expire?Boolean

Returns:

  • (Boolean)


148
149
150
151
152
153
# File 'lib/chef-licensing/license.rb', line 148

def about_to_expire?
  require "Date" unless defined?(Date)
  self.number_of_days_in_expiration = (Date.parse(expiration_date) - Date.today).to_i
  # starts to nag before a week when about to expire
  status.eql?("Active") && expiration_status.eql?("Expired") && ((1..7).include? number_of_days_in_expiration)
end

#active?Boolean

Returns:

  • (Boolean)


140
141
142
# File 'lib/chef-licensing/license.rb', line 140

def active?
  status.eql?("Active")
end

#asset_entitlementsObject



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

def asset_entitlements
  return @asset_entitlements unless @asset_entitlements.empty?

  asset_entitlements = []
  asset_entitlements_data = @parser.parse_asset_entitlements
  asset_entitlements_data.each do |data|
    asset_entitlements << AssetEntitlement.new(data)
  end
  @asset_entitlements = asset_entitlements
end

#exhausted?Boolean

Returns:

  • (Boolean)


136
137
138
# File 'lib/chef-licensing/license.rb', line 136

def exhausted?
  status.eql?("Exhausted")
end

#expired?Boolean

Returns:

  • (Boolean)


132
133
134
# File 'lib/chef-licensing/license.rb', line 132

def expired?
  status.eql?("Expired")
end

#expiring_or_expired?Boolean

Returns:

  • (Boolean)


144
145
146
# File 'lib/chef-licensing/license.rb', line 144

def expiring_or_expired?
  have_grace? || expired? || about_to_expire?
end

#feature_entitlementsObject



35
36
37
38
39
40
41
42
43
44
# File 'lib/chef-licensing/license.rb', line 35

def feature_entitlements
  return @feature_entitlements unless @feature_entitlements.empty?

  feat_entitlements = []
  feat_entitlements_data = @parser.parse_feature_entitlements
  feat_entitlements_data.each do |data|
    feat_entitlements << FeatureEntitlement.new(data)
  end
  @feature_entitlements = feat_entitlements
end

#have_grace?Boolean

Returns:

  • (Boolean)


128
129
130
# File 'lib/chef-licensing/license.rb', line 128

def have_grace?
  status.eql?("Grace")
end

#limitsObject



68
69
70
71
72
73
74
75
76
77
# File 'lib/chef-licensing/license.rb', line 68

def limits
  return @limits unless @limits.empty?

  limits = []
  limits_data = @parser.parse_limits
  limits_data.each do |data|
    limits << Limit.new(data, { product_name: @product_name })
  end
  @limits = limits
end

#software_entitlementsObject



46
47
48
49
50
51
52
53
54
55
# File 'lib/chef-licensing/license.rb', line 46

def software_entitlements
  return @software_entitlements unless @software_entitlements.empty?

  sw_entitlements = []
  sw_entitlements_data = @parser.parse_software_entitlements
  sw_entitlements_data.each do |data|
    sw_entitlements << SoftwareEntitlement.new(data)
  end
  @software_entitlements = sw_entitlements
end