Class: Entitlement::Entry

Inherits:
Object
  • Object
show all
Defined in:
lib/entitlement/entry.rb

Overview

Base class for all entitlement entries

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(modules, from = nil, to = nil, filename_string = nil, &proc) ⇒ Entry

Returns a new instance of Entry.



13
14
15
16
17
18
19
20
21
22
# File 'lib/entitlement/entry.rb', line 13

def initialize(modules, from = nil, to = nil, filename_string = nil, &proc)
  # rubocop:disable Style/GlobalVars
  @file            = $entitlements_file
  @warning_period  = 30
  @modules         = modules.to_a
  @from            = from
  @to              = to
  @filename_string = filename_string
  @validator       = proc
end

Instance Attribute Details

#fileObject (readonly)

Returns the value of attribute file.



11
12
13
# File 'lib/entitlement/entry.rb', line 11

def file
  @file
end

Instance Method Details

#days_leftObject



62
63
64
# File 'lib/entitlement/entry.rb', line 62

def days_left
  @to - Date.today
end

#expiring?Boolean

Returns:

  • (Boolean)


58
59
60
# File 'lib/entitlement/entry.rb', line 58

def expiring?
  @to && @to <= (Date.today + @warning_period)
end

#inspectObject

rubocop: enable Metrics/CyclomaticComplexity



50
51
52
53
54
55
56
# File 'lib/entitlement/entry.rb', line 50

def inspect
  puts "Lic. File   : #{@file}"
  puts "modules     : #{@modules.join(',')}"
  puts "From date   : #{@from}" if @from
  puts "To date     : #{@to}" if @to
  puts "Purgable    : #{purgable? ? 'yes' : 'no'}"
end

#notify_if_expiring(module_name) ⇒ Object

rubocop:enable Style/GlobalVars



25
26
27
28
29
30
# File 'lib/entitlement/entry.rb', line 25

def notify_if_expiring(module_name)
  return unless expiring? && valid?(module_name) && !@expire_message_printed
  @expire_message_printed = true
  Puppet.alert "*WARNING* : Only #{days_left.round} days left until your entitlement for module #{module_name} on current node is expiring. Take appropriate action."
  # rubocop:enable Metrics/LineLength
end

#purgable?Boolean

Returns:

  • (Boolean)


32
33
34
# File 'lib/entitlement/entry.rb', line 32

def purgable?
  @to && @to <= Date.today
end

#valid?(module_name, resources = nil) ⇒ Boolean

rubocop: disable Metrics/CyclomaticComplexity

Returns:

  • (Boolean)


37
38
39
40
41
42
43
44
45
46
47
# File 'lib/entitlement/entry.rb', line 37

def valid?(module_name, resources = nil)
  # If the entitlement file is in the older version, do not perform check
  if @filename_string
    return false unless filename_match?
  end
  return false if @from && @from > Date.today
  return false if @to && @to <= Date.today
  return false unless matching_module(module_name)
  return true unless @validator
  @validator.call(resources)
end