Class: HelmWrapper::Shared::Config

Inherits:
Object
  • Object
show all
Includes:
Logging
Defined in:
lib/helm-wrapper/shared/config.rb

Constant Summary collapse

@@config_exts =
[ "", ".yaml", ".yml" ]

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods included from Logging

configure_logger_for, logger_for

Constructor Details

#initialize(chart:, options:) ⇒ Config

Returns a new instance of Config.



41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
# File 'lib/helm-wrapper/shared/config.rb', line 41

def initialize(chart:, options:)
  logger.fatal("Configuration atomic mode must be a boolean!") unless [ true, false ].include?(options["atomic"])

  @atomic = options["atomic"]

  logger.fatal("Configuration base path must be a string!") unless options["base"].kind_of?(String)
  logger.fatal("Configuration base path must not be blank!") if options["base"].strip.empty?

  @base = options["base"]

  logger.fatal("Configuration name must be a string!") unless options["name"].kind_of?(String)
  logger.fatal("Configuration name must not be blank!") if options["name"].strip.empty?

  @name = options["name"]

  logger.fatal("Configuration release name must be a string!") unless options["release"].kind_of?(String)
  logger.fatal("Configuration release name must not be blank!") if options["release"].strip.empty?

  @release = options["release"]

  logger.fatal("Configuration wait timeout must be a string!") unless options["timeout"].kind_of?(String)
  logger.fatal("Configuration wait timeout must not be blank!") if options["timeout"].strip.empty?

  @timeout = options["timeout"]

  logger.fatal("Configuration authenticator for Azure enabled must be a boolean!") unless [ true, false ].include?(options["auth-azure"])

  auth_azure = options["auth-azure"]

  logger.fatal("Configuration authenticator for Azure options must be a hash!") unless options["auth-azure-options"].kind_of?(Hash)

  auth_azure_options = options["auth-azure-options"]

  logger.fatal("Configuration destination namespace must be a string!") unless options["namespace"].kind_of?(String)
  logger.fatal("Configuration destination namespace must not be blank!") if options["namespace"].strip.empty?

  namespace = options["namespace"]

  logger.fatal("Configuration wait mode must be a boolean!") unless [ true, false ].include?(options["wait"])

  wait = options["wait"]

  @chart = chart
  @path  = ::HelmWrapper.find(base: @base, name: @name, exts: @@config_exts, description: "Configuration")
  @wait  = (not @atomic) and wait

  yaml = YAML.load(File.read(@path))
  logger.fatal("Invalid YAML in configuration file: #{@path}") unless yaml.kind_of?(Hash)

  identifers = yaml.key?("identifiers") ? yaml["identifiers"] : Hash.new
  @variables = HelmWrapper::Shared::Variables.new(chart: @chart.name, config: @name, namespace: namespace, release: @release, identifiers: identifers)
  @namespace = @variables.core[:namespace]

  if yaml.key?("globals") then
    logger.fatal("Key 'globals' is not a hash in configuration file: #{@path}") unless yaml["globals"].kind_of?(Hash)
    globals = yaml["globals"]

    @variables.add_variables(variables: globals["variables"]) if globals.key?("variables")
  end

  if yaml.key?("helm") then
    logger.fatal("Key 'helm' is not a hash in configuration file: #{@path}") unless yaml["helm"].kind_of?(Hash)
    helm = yaml["helm"]

    [ "globals", @release ].each do |extra|
      if helm.key?(extra) then
        logger.fatal("Key '#{extra}' under 'helm' is not a hash in configuration file: #{@path}") unless helm[extra].kind_of?(Hash)
        section = helm[extra]

        @variables.add_variables(variables: section["variables"]) if section.key?("variables")
        @variables.add_files(base: @base, files: section["files"]) if section.key?("files")
      end
    end
  end

  @auths = Array.new
  @auths.append(HelmWrapper::Shared::Auths::Azure.new(options: auth_azure_options, variables: @variables)) if auth_azure
end

Instance Attribute Details

#atomicObject (readonly)

Returns the value of attribute atomic.



27
28
29
# File 'lib/helm-wrapper/shared/config.rb', line 27

def atomic
  @atomic
end

#authsObject (readonly)

Returns the value of attribute auths.



28
29
30
# File 'lib/helm-wrapper/shared/config.rb', line 28

def auths
  @auths
end

#baseObject (readonly)

Returns the value of attribute base.



29
30
31
# File 'lib/helm-wrapper/shared/config.rb', line 29

def base
  @base
end

#chartObject (readonly)

Returns the value of attribute chart.



30
31
32
# File 'lib/helm-wrapper/shared/config.rb', line 30

def chart
  @chart
end

#nameObject (readonly)

Returns the value of attribute name.



31
32
33
# File 'lib/helm-wrapper/shared/config.rb', line 31

def name
  @name
end

#namespaceObject (readonly)

Returns the value of attribute namespace.



32
33
34
# File 'lib/helm-wrapper/shared/config.rb', line 32

def namespace
  @namespace
end

#pathObject (readonly)

Returns the value of attribute path.



34
35
36
# File 'lib/helm-wrapper/shared/config.rb', line 34

def path
  @path
end

#releaseObject (readonly)

Returns the value of attribute release.



33
34
35
# File 'lib/helm-wrapper/shared/config.rb', line 33

def release
  @release
end

#timeoutObject (readonly)

Returns the value of attribute timeout.



35
36
37
# File 'lib/helm-wrapper/shared/config.rb', line 35

def timeout
  @timeout
end

#variablesObject (readonly)

Returns the value of attribute variables.



36
37
38
# File 'lib/helm-wrapper/shared/config.rb', line 36

def variables
  @variables
end

#waitObject (readonly)

Returns the value of attribute wait.



37
38
39
# File 'lib/helm-wrapper/shared/config.rb', line 37

def wait
  @wait
end