class Kustomize::Transform::FingerprintSuffixTransform

Constants

APPLICABLE_KINDS
CONTENT_LENS_BY_KIND
FINGERPRINT_LENS
NAME_LENS
SUFFIX_JOINER

Public Instance Methods

rewrite(rc) click to toggle source
# 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|
    if orig_value
      if orig_value == ''
        next(:pop)
      else
        next(:keep)
      end
    end

    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)

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

  rc
end