require 'picsolve_docker_builder/base' require 'securerandom' module PicsolveDockerBuilder module Composer module Requirements # Base class for requirements class Base include PicsolveDockerBuilder::Base attr_reader :name, :config def initialize(name, config, context) @name = name @config = config @context = context end def environment(_kubernetes) [] end def stage @context.kubernetes.stage end def kubernetes @context.kubernetes end def namespace @context.namespace end def container @context.container end def gen_password(length = 16) SecureRandom.urlsafe_base64(length) end def create_secret(name, obj) secret = Kubeclient::Secret.new secret.metadata = { name: name, namespace: namespace } secret.data = {} obj.each do |key, value| secret.data[key.to_sym] = Base64.encode64(value).delete("\n") end kubernetes.client.create_secret secret end def get_secret(name) obj = kubernetes.client.get_secret(name, namespace) hash = {} obj.data.to_hash.each do |key, value| hash[key.to_s] = Base64.decode64(value) end hash end end end end end