Class: Bindings::ConfigTreeBinding

Inherits:
Object
  • Object
show all
Includes:
Binding
Defined in:
lib/binding.rb

Overview

An implementation of Bindings::Binding that reads files from a volume mounted Kubernetes Secret: kubernetes.io/docs/concepts/configuration/secret/#using-secrets

Instance Method Summary collapse

Methods included from Binding

#get, #provider, #type

Constructor Details

#initialize(root) ⇒ ConfigTreeBinding

Creates a new instance.

Parameters:

  • root (String)

    the root of the volume mounted Kubernetes Secret



123
124
125
# File 'lib/binding.rb', line 123

def initialize(root)
  @root = root
end

Instance Method Details

#get_as_bytes(key) ⇒ Array<Integer>?

Returns the contents of a binding entry in its raw bytes form.

Parameters:

  • key (String)

    the key of the entry to retrieve

Returns:

  • (Array<Integer>)

    the contents of a binding entry if it exists

  • (nil)


132
133
134
135
136
137
138
139
140
# File 'lib/binding.rb', line 132

def get_as_bytes(key)
  return nil unless Bindings.valid_secret_key?(key)

  p = File.join(@root, key)

  return nil unless File.exist?(p) && File.file?(p)

  File.read(p, mode: "rb").bytes
end

#nameString

Returns the name of the binding

Returns:

  • (String)

    the name of the binding



145
146
147
# File 'lib/binding.rb', line 145

def name
  File.basename(@root)
end