Class: HelmWrapper::Shared::Chart

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

Constant Summary collapse

@@chart_metadata_file =
"Chart.yaml"

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods included from Logging

configure_logger_for, logger_for

Constructor Details

#initialize(options:) ⇒ Chart

Returns a new instance of Chart.



31
32
33
34
35
36
37
38
39
40
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
# File 'lib/helm-wrapper/shared/chart.rb', line 31

def initialize(options:)
  if options["path"].nil? then
    @path = options["path"]

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

    logger.fatal("Chart version must be a string!") unless options["version"].kind_of?(String)
    @version = options["version"]
  else
    logger.fatal("Chart path must be a string!") unless options["path"].kind_of?(String)
    logger.fatal("Chart path must not be blank!") if options["path"].strip.empty?
    logger.fatal("Chart path must exist!") unless File.directory?(options["path"])

    @path = options["path"]

    
  end

  logger.fatal("Chart repos must be a list of hashes!") unless options["repos"].kind_of?(Array)

  repos = options["repos"]

  @oci      = Array.new
  @artefact = Array.new

  repos.each do |repo|
    logger.fatal("All elements of chart repos must be hashes!") unless repo.kind_of?(Hash)

    logger.fatal("Chart repo: #{hash["name"]} must have a type attribute!") unless repo.key?("type")
    logger.fatal("Chart repo: #{hash["name"]} type must be a string!") unless repo["type"].kind_of?(String)
    logger.fatal("Chart repo: #{hash["name"]} type must either be 'artefact' or 'oci'.") unless [ "artefact", "oci" ].include?(repo["type"])

    is_artefact = repo["type"] == "artefact" ? true : false
    is_oci      = repo["type"] == "oci"      ? true : false

    hash = Hash.new

    logger.fatal("Chart repos must have a name attribute!") unless repo.key?("name")
    logger.fatal("Chart repo name must be a string!") unless repo["name"].kind_of?(String)
    logger.fatal("Chart repo name must not be blank!") if repo["name"].strip.empty?

    hash["name"] = repo["name"].strip

    logger.fatal("Chart repo: #{hash["name"]} must have a url attribute!") unless repo.key?("url")
    logger.fatal("Chart repo: #{hash["name"]} url must be a string!") unless repo["url"].kind_of?(String)
    logger.fatal("Chart repo: #{hash["name"]} url must not be blank!") if repo["url"].strip.empty?

    hash["url"] = repo["url"].strip

    if repo.key?("username") then
      logger.fatal("Chart repo: #{hash["name"]} username must be a string!") unless repo["username"].kind_of?(String)
      logger.fatal("Chart repo: #{hash["name"]} username must not be blank!") if repo["username"].strip.empty?

      hash["username"] = repo["username"].strip

      logger.fatal("Chart repo: #{hash["name"]} must have a password attribute if 'username' is set!") unless repo.key?("password")
      logger.fatal("Chart repo: #{hash["name"]} password must be a string!") unless repo["password"].kind_of?(String)
      logger.fatal("Chart repo: #{hash["name"]} password must not be blank!") if repo["password"].strip.empty?

      hash["password"] = repo["password"].strip
    else
      fatal("Chart repo: #{hash["name"]} is an OCI repository therefore must have a username attribute! Public OCI repositories do not need to be declared.") if is_oci
      hash["username"] = nil
      hash["password"] = nil
    end

    hash["active"] = false

    artefact.append(hash) if is_artefact
    oci.append(hash)      if is_oci
  end
end

Instance Attribute Details

#artefactObject (readonly)

Returns the value of attribute artefact.



23
24
25
# File 'lib/helm-wrapper/shared/chart.rb', line 23

def artefact
  @artefact
end

#nameObject (readonly)

Returns the value of attribute name.



24
25
26
# File 'lib/helm-wrapper/shared/chart.rb', line 24

def name
  @name
end

#ociObject (readonly)

Returns the value of attribute oci.



26
27
28
# File 'lib/helm-wrapper/shared/chart.rb', line 26

def oci
  @oci
end

#pathObject (readonly)

Returns the value of attribute path.



25
26
27
# File 'lib/helm-wrapper/shared/chart.rb', line 25

def path
  @path
end

#versionObject (readonly)

Returns the value of attribute version.



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

def version
  @version
end

Instance Method Details

#artefact_active(active:, index:) ⇒ Object



108
109
110
# File 'lib/helm-wrapper/shared/chart.rb', line 108

def artefact_active(active:, index:)
  artefact[index]["active"] = active
end

#oci_active(active:, index:) ⇒ Object



114
115
116
# File 'lib/helm-wrapper/shared/chart.rb', line 114

def oci_active(active:, index:)
  oci[index]["active"] = active
end