Class: Metatron::Templates::Secret

Inherits:
Metatron::Template show all
Includes:
Concerns::Annotated, Concerns::Namespaced
Defined in:
lib/metatron/templates/secret.rb

Overview

The Secret Kubernetes resource

Instance Attribute Summary collapse

Attributes inherited from Metatron::Template

#api_version, #base_labels, #kind, #name

Instance Method Summary collapse

Methods included from Concerns::Namespaced

#formatted_namespace, included, #namespaced_initialize

Methods included from Concerns::Annotated

#annotated_initialize, #formatted_annotations, included

Methods inherited from Metatron::Template

initializer, initializers, metatron_template_class?, nearest_metatron_ancestor

Constructor Details

#initialize(name, provided_string_data = nil, string_data: nil, data: nil) ⇒ Secret

Returns a new instance of Secret.



14
15
16
17
18
19
20
# File 'lib/metatron/templates/secret.rb', line 14

def initialize(name, provided_string_data = nil, string_data: nil, data: nil)
  super(name)
  @string_data = string_data || provided_string_data
  @data = data
  @additional_labels = {}
  @type = "Opaque"
end

Instance Attribute Details

#additional_labelsObject

Returns the value of attribute additional_labels.



10
11
12
# File 'lib/metatron/templates/secret.rb', line 10

def additional_labels
  @additional_labels
end

#dataObject

Returns the value of attribute data.



10
11
12
# File 'lib/metatron/templates/secret.rb', line 10

def data
  @data
end

#string_dataObject Also known as: stringData

Returns the value of attribute string_data.



10
11
12
# File 'lib/metatron/templates/secret.rb', line 10

def string_data
  @string_data
end

#typeObject

Returns the value of attribute type.



10
11
12
# File 'lib/metatron/templates/secret.rb', line 10

def type
  @type
end

Instance Method Details

#formatted_dataObject



22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
# File 'lib/metatron/templates/secret.rb', line 22

def formatted_data
  data_hash = {}

  # Only include one of data or string_data, preferring data if both are present
  return data_hash unless data || string_data

  # If string_data is provided, it should be a hash of string values
  # and will be base64 encoded
  if string_data
    data_hash[:data] = string_data.transform_values do |value|
      Base64.strict_encode64(value.to_s).gsub("\n", "")
    end
  end

  # If data is provided, it should be a hash of base64 encoded values
  data_hash[:data] = data if data

  data_hash
end

#renderObject



42
43
44
45
46
47
48
49
50
51
52
# File 'lib/metatron/templates/secret.rb', line 42

def render
  {
    apiVersion:,
    kind:,
    metadata: {
      name:,
      labels: base_labels.merge(additional_labels)
    }.merge(formatted_annotations).merge(formatted_namespace).compact,
    type:
  }.compact.merge(formatted_data).compact
end