Sha256: 07db54032f06f319ba41d34c1b2e8f7cc2ece3f98aab5ae7b906708290ae9f05
Contents?: true
Size: 864 Bytes
Versions: 39
Compression:
Stored size: 864 Bytes
Contents
module Shipit class EnvironmentVariables NotPermitted = Class.new(StandardError) class << self def with(env) EnvironmentVariables.new(env) end end def permit(variable_definitions) return {} unless @env raise "A whitelist is required to sanitize environment variables" unless variable_definitions sanitize_env_vars(variable_definitions) end private def initialize(env) @env = env end def sanitize_env_vars(variable_definitions) allowed_variables = variable_definitions.map(&:name) allowed, disallowed = @env.partition { |k, _| allowed_variables.include?(k) }.map(&:to_h) error_message = "Variables #{disallowed.keys.to_sentence} have not been whitelisted" raise NotPermitted.new(error_message) unless disallowed.empty? allowed end end end
Version data entries
39 entries across 39 versions & 1 rubygems