Class: Kubert::Environment

Inherits:
Object
  • Object
show all
Defined in:
lib/kubert/environment.rb

Constant Summary collapse

PEEK_LENGTH =
4

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(key, value, raw_options) ⇒ Environment

Returns a new instance of Environment.



16
17
18
19
20
21
22
23
24
25
26
# File 'lib/kubert/environment.rb', line 16

def initialize(key, value, raw_options)
  @key      = key
  @value    = value
  @options  = raw_options.with_indifferent_access
  abort("ERROR: Cannot specify env set as both new_secret and new_config") if options[:new_config] && options[:new_secret]
  Kubert.ky_configuration(options) # memoizes and avoids passing to FileAccess
  @config_data = FileAccess.new(:config, yaml_key)
  @secret_data = FileAccess.new(:secret, yaml_key)
  return if print_all?
  @create_mode      = (options[:new_config] || options[:new_secret])&.to_sym
end

Class Method Details

.get(key, options) ⇒ Object



4
5
6
# File 'lib/kubert/environment.rb', line 4

def self.get(key, options)
  new(key, nil, options).get
end

.set(key, value, options) ⇒ Object



8
9
10
# File 'lib/kubert/environment.rb', line 8

def self.set(key, value, options)
  new(key, value, options).set
end

.unset(key, options) ⇒ Object



12
13
14
# File 'lib/kubert/environment.rb', line 12

def self.unset(key, options)
  new(key, nil, options).set
end

Instance Method Details

#getObject



38
39
40
41
42
43
44
45
46
47
48
# File 'lib/kubert/environment.rb', line 38

def get
  return get_all if print_all?
  case total_found
  when 0
    puts "#{yaml_key} not found in configmap or secrets"
  when 1
    puts existing_value
  else
    puts "ERROR! multiple entries found for key: config - #{config_data.found}, secret - #{secret_data.found}"
  end
end

#setObject



28
29
30
31
32
33
34
35
36
# File 'lib/kubert/environment.rb', line 28

def set
  if create_mode
    abort("ERROR: #{key} exists but #{create_mode} flag set! Call without flag to update existing value") unless total_found == 0
    create
  else
    report_unchanged if existing_value == value
    update
  end
end