<commit_before>require 'ejson_wrapper'

module StackMaster
  module ParameterResolvers
    class Ejson < Resolver
      SecretNotFound = Class.new(StandardError)

      def initialize(config, stack_definition)
        @config = config
        @stack_definition = stack_definition
      end

      def resolve(secret_key)
        validate_ejson_file_specified
        secrets = decrypt_ejson_file
        secrets.fetch(secret_key.to_sym) do
          raise SecretNotFound, "Unable to find key #{secret_key} in file #{ejson_file}"
        end
      end

      private

      def validate_ejson_file_specified
        if @stack_definition.ejson_file.nil?
          raise ArgumentError, "No ejson_file defined for stack definition #{@stack_definition.stack_name} in #{@stack_definition.region}"
        end
      end

      def decrypt_ejson_file
        @decrypt_ejson_file ||= EJSONWrapper.decrypt(ejson_file_path,
                                                     use_kms: @stack_definition.ejson_file_kms,
                                                     region: ejson_file_region)
      end
<commit_msg>Use secrets file relative path in error message<commit_after>require 'ejson_wrapper'

module StackMaster
  module ParameterResolvers
    class Ejson < Resolver
      SecretNotFound = Class.new(StandardError)

      def initialize(config, stack_definition)
        @config = config
        @stack_definition = stack_definition
      end

      def resolve(secret_key)
        validate_ejson_file_specified
        secrets = decrypt_ejson_file
        secrets.fetch(secret_key.to_sym) do
          raise SecretNotFound, "Unable to find key #{secret_key} in file #{@stack_definition.ejson_file}"
        end
      end

      private

      def validate_ejson_file_specified
        if @stack_definition.ejson_file.nil?
          raise ArgumentError, "No ejson_file defined for stack definition #{@stack_definition.stack_name} in #{@stack_definition.region}"
        end
      end

      def decrypt_ejson_file
        @decrypt_ejson_file ||= EJSONWrapper.decrypt(ejson_file_path,
                                                     use_kms: @stack_definition.ejson_file_kms,
                                                     region: ejson_file_region)
      end

{'fraction_non_alphanumeric': 0.056288478452066845, 'fraction_numerical': 0.0, 'mean_word_length': 2.208744710860367, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 8, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '244224', 'n_tokens_mistral': 609, 'n_tokens_neox': 598, 'n_words': 137}