Module: SecretServer::Commands::Cache

Included in:
SecretServer::Commands
Defined in:
lib/secret_server/commands/cache.rb

Overview

Command to control caching of Secret values

Constant Summary collapse

StrategyNever =

rubocop:disable Naming/ConstantName

0
StrategyServerThenCache =
1
StrategyCacheThenServer =
2
StrategyCacheThenServerAllowExpired =
3

Instance Method Summary collapse

Instance Method Details

#cache_ageObject



27
28
29
# File 'lib/secret_server/commands/cache.rb', line 27

def cache_age
  cache_strategy[1]
end

#cache_age=(age) ⇒ Object



31
32
33
34
35
36
# File 'lib/secret_server/commands/cache.rb', line 31

def cache_age=(age)
  unless age.is_a?(Integer) && age >= 0
    raise ArgumentError, 'age must be a nonnegative integer'
  end
  sdkclient_exec('cache', '-a', age.to_s)
end

#cache_clear!Object



38
39
40
# File 'lib/secret_server/commands/cache.rb', line 38

def cache_clear!
  sdkclient_exec('cache', '-b')
end

#cache_strategyObject

rubocop:enable Naming/ConstantName



12
13
14
15
16
17
# File 'lib/secret_server/commands/cache.rb', line 12

def cache_strategy
  stdout, * = sdkclient_exec('cache', '-c')
  result = /Strategy : (\w+)(?:, Max Age : (\d+) minutes)?/.match(stdout)
  strategy = SecretServer::SdkClient.const_get("Strategy#{result[1]}")
  [strategy, result[2].to_i]
end

#cache_strategy=(value) ⇒ Object



19
20
21
22
23
24
25
# File 'lib/secret_server/commands/cache.rb', line 19

def cache_strategy=(value)
  strategy, age = value.is_a?(Array) ? value : [value, nil]
  validate_cache_strategy_args(strategy, age)
  args = ['cache', '-s', strategy.to_s]
  args += ['-a', age.to_s] unless age.nil?
  sdkclient_exec(*args)
end