Class: Aikido::Zen::APICache

Inherits:
Object
  • Object
show all
Defined in:
lib/aikido/zen/api_cache.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initializeAPICache

Returns a new instance of APICache.



10
11
12
13
# File 'lib/aikido/zen/api_cache.rb', line 10

def initialize
  @runtime_config_generation = 0
  @runtime_firewall_lists_generation = 0
end

Instance Attribute Details

#runtime_configObject

Returns the value of attribute runtime_config.



5
6
7
# File 'lib/aikido/zen/api_cache.rb', line 5

def runtime_config
  @runtime_config
end

#runtime_config_generationObject (readonly)

Returns the value of attribute runtime_config_generation.



7
8
9
# File 'lib/aikido/zen/api_cache.rb', line 7

def runtime_config_generation
  @runtime_config_generation
end

#runtime_firewall_listsObject

Returns the value of attribute runtime_firewall_lists.



6
7
8
# File 'lib/aikido/zen/api_cache.rb', line 6

def runtime_firewall_lists
  @runtime_firewall_lists
end

#runtime_firewall_lists_generationObject (readonly)

Returns the value of attribute runtime_firewall_lists_generation.



8
9
10
# File 'lib/aikido/zen/api_cache.rb', line 8

def runtime_firewall_lists_generation
  @runtime_firewall_lists_generation
end

Instance Method Details

#config_if_changed(known_generation) ⇒ Array(Object, Integer)?

Returns the current value and generation, or nil if the known generation is already current.

Parameters:

  • known_generation (Integer, nil)

Returns:

  • (Array(Object, Integer), nil)

    the current value and generation, or nil if the known generation is already current.



48
49
50
51
# File 'lib/aikido/zen/api_cache.rb', line 48

def config_if_changed(known_generation)
  return nil if known_generation == runtime_config_generation
  [runtime_config, runtime_config_generation]
end

#firewall_lists_if_changed(known_generation) ⇒ Array(Object, Integer)?

Returns the current value and generation, or nil if the known generation is already current.

Parameters:

  • known_generation (Integer, nil)

Returns:

  • (Array(Object, Integer), nil)

    the current value and generation, or nil if the known generation is already current.



56
57
58
59
# File 'lib/aikido/zen/api_cache.rb', line 56

def firewall_lists_if_changed(known_generation)
  return nil if known_generation == runtime_firewall_lists_generation
  [runtime_firewall_lists, runtime_firewall_lists_generation]
end

#update_runtime_config(value) ⇒ Boolean

Returns whether the value actually changed.

Parameters:

  • value (Hash, nil)

Returns:

  • (Boolean)

    whether the value actually changed



25
26
27
28
29
30
31
32
# File 'lib/aikido/zen/api_cache.rb', line 25

def update_runtime_config(value)
  return false if value == @runtime_config

  @runtime_config_generation += 1
  @runtime_config = value

  true
end

#update_runtime_firewall_lists(value) ⇒ Boolean

Returns whether the value actually changed.

Parameters:

  • value (Hash, nil)

Returns:

  • (Boolean)

    whether the value actually changed



36
37
38
39
40
41
42
43
# File 'lib/aikido/zen/api_cache.rb', line 36

def update_runtime_firewall_lists(value)
  return false if value == @runtime_firewall_lists

  @runtime_firewall_lists_generation += 1
  @runtime_firewall_lists = value

  true
end