module Bindings
A library to access Service Binding
Specification for Kubernetes conformant Service Binding
Workload Projections.
@see k8s-service-bindings.github.io/spec
A library to access Service Binding
Specification for Kubernetes conformant Service Binding
Workload Projections.
@see k8s-service-bindings.github.io/spec
A library to access Service Binding
Specification for Kubernetes conformant Service Binding
Workload Projections.
Constants
- PROVIDER
The key for the provider of a binding
- SERVICE_BINDING_ROOT
The name of the environment variable read to determine the bindings filesystem root. Specified by the Kubernetes Service
Binding
Specification: github.com/k8s-service-bindings/spec#workload-projection- TYPE
The key for the type of a binding
Public Class Methods
Wraps each Bindings::Binding
in a Bindings::CacheBinding
.
@param [Array<Bindings::Binding>] bindings the bindings to wrap @return [Array<Bindings::Binding>] the wrapped bindings
# File lib/bindings.rb, line 31 def self.cached(bindings) bindings.map { |v| Bindings::CacheBinding.new(v) } end
Returns zero or more Bindings
with a given type and provider. If type or provider are None, the result is not filter on that argument. Comparisons are case-insensitive.
@param [Array<Bindings::Binding>] bindings the bindings to filter @param [String] type the type of the binding to find @param [nil] type @param [String] provider the provider of the binding to find @param [nil] provider @return [Array<Bindings::Binding>] the collection of bindings ith a given type and provider
# File lib/bindings.rb, line 82 def self.filter(bindings, type = nil, provider = nil) match = [] bindings.each do |b| next unless type.nil? || type_matches?(b, type) next unless provider.nil? || provider_matches?(b, provider) match.append(b) end match end
Returns a Bindings::Binding
with a given name. Comparison is case-insensitive.
@param [Array<Bindings::Binding>] bindings the bindings to find in @param [String] name the name of the binding to find @return [Bindings::Binding] the binding with a given name if it exists @return [nil]
# File lib/bindings.rb, line 65 def self.find(bindings, name) bindings.each do |b| return b if b.name.casecmp?(name) end nil end
Creates a new collection of Bindings::Binding's using the specified root. If the directory does not exist, an empty collection is returned.
@param [String] root the root to populate the bindings from @return [Array<Bindings::Binding>] the bindings found in the root
# File lib/bindings.rb, line 40 def self.from_path(root) return [] unless File.exist?(root) && File.directory?(root) Pathname.new(root).children.each_with_object([]) do |c, b| b.append(ConfigTreeBinding.new(c.to_s)) if File.directory?(c) end end
Creates a new collection of Bindings::Binding's using the +$SERVICE_BINDING_ROOT+ environment variable to determine system root. If the +$SERVICE_BINDING_ROOT+ environment variable is not set, an empty collection is returned. If the directory does not exist, an empty collection is returned.
@return [Array<Bindings::Binding>] the bindings found in $SERVICE_BINDING_ROOT
# File lib/bindings.rb, line 53 def self.from_service_binding_root return [] unless ENV.key?(SERVICE_BINDING_ROOT) from_path(ENV[SERVICE_BINDING_ROOT]) end
Tests whether a String is a valid Kubernetes Secret key: kubernetes.io/docs/concepts/configuration/secret/#overview-of-secrets
@param [String] key the key to check @return [boolean] true if the String is a valid Kubernetes Secret key, false otherwise
# File lib/secret.rb, line 26 def self.valid_secret_key?(key) /^[A-Za-z0-9\-_.]+$/.match(key) end
Private Class Methods
# File lib/bindings.rb, line 95 def self.provider_matches?(binding, provider) p = binding.provider !p.nil? && p.casecmp?(provider) end
# File lib/bindings.rb, line 100 def self.type_matches?(binding, type) t = binding.type !t.nil? && t.casecmp?(type) end