Class: Kustomize::Transform::FingerprintSuffixTransform

Inherits:
Kustomize::Transform show all
Includes:
Accessory, Singleton
Defined in:
lib/kustomize/transform/fingerprint_suffix_transform.rb

Constant Summary collapse

SUFFIX_JOINER =
"-"
APPLICABLE_KINDS =
Set[
  'Secret',
  'SealedSecret',
  'ConfigMap'
]
NAME_LENS =
Lens["metadata", "name"]
CONTENT_LENS_BY_KIND =
{
  "Secret" => Lens["data"],
  "ConfigMap" => Lens["data"],
  "SealedSecret" => Lens["spec", "encryptedData"]
}
FINGERPRINT_LENS =
Lens['metadata', 'annotations', 'kustomizer.covalenthq.com/effective-fingerprint']

Instance Method Summary collapse

Methods inherited from Kustomize::Transform

create, #inspect, #rewrite_all

Instance Method Details

#rewrite(rc) ⇒ Object



33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
# File 'lib/kustomize/transform/fingerprint_suffix_transform.rb', line 33

def rewrite(rc)
  rc_kind = rc['kind']
  return rc unless APPLICABLE_KINDS.member?(rc_kind)

  FINGERPRINT_LENS.update_in(rc) do |orig_value|
    next(:keep) if orig_value

    content_part = CONTENT_LENS_BY_KIND[rc_kind].get_in(rc)
    content_ser = content_part.to_json
    fingerprint = Digest::SHA256.base32digest(content_ser, :zbase32)[0, 6]

    [:set, fingerprint]
  end

  base_name = NAME_LENS.get_in(rc)
  fingerprint = FINGERPRINT_LENS.get_in(rc)

  NAME_LENS.update_in(rc) do |base_name|
    suffixed_name = [base_name, fingerprint].join(SUFFIX_JOINER)
    [:set, suffixed_name]
  end

  rc
end