<commit_before>require "google/api_client"
require "google/client_builder/construction_helper"

module Google
  class ClientBuilder
    extend ConstructionHelper

    PRIVATE_KEY = ENV.fetch("GOOGLE_API_PRIVATE_KEY").gsub("\\n", "\n")
    PRIVATE_KEY_SECRET = "notasecret" # static default for Google P12 auth
    SERVICE_ACCOUNT_EMAIL = ENV.fetch("GOOGLE_API_SERVICE_ACCOUNT")

    attr_accessor :user_email, :scopes, :authorize

    def self.key
      OpenSSL::PKey::RSA.new(PRIVATE_KEY, PRIVATE_KEY_SECRET)
    end

    def initialize
      yield(self) if block_given?
    end

    def authorize!
      @authorize = true
    end

    def build
      Google::APIClient.new(application_name: "google-wrapper", application_version: Google::Wrapper::VERSION).tap do |client|
        client.authorization = asserter.authorize(user_email) if authorize?
      end
    end

    private

    def asserter
      Google::APIClient::JWTAsserter.new(SERVICE_ACCOUNT_EMAIL, scopes, self.class.key)
    end

    def authorize?
      @authorize === true
    end
  end
end<commit_msg>Don't use constants for key generation in Google::ClientBuilder<commit_after>require "google/api_client"
require "google/client_builder/construction_helper"

module Google
  class ClientBuilder
    extend ConstructionHelper

    attr_accessor :user_email, :scopes, :authorize

    def self.key
      OpenSSL::PKey::RSA.new(ENV.fetch("GOOGLE_API_PRIVATE_KEY").gsub("\\n", "\n"),
                             "notasecret") # static default for Google P12 auth
    end

    def initialize
      yield(self) if block_given?
    end

    def authorize!
      @authorize = true
    end

    def build
      Google::APIClient.new(application_name: "google-wrapper", application_version: Google::Wrapper::VERSION).tap do |client|
        client.authorization = asserter.authorize(user_email) if authorize?
      end
    end

    private

    def asserter
      Google::APIClient::JWTAsserter.new(ENV.fetch("GOOGLE_API_SERVICE_ACCOUNT"), scopes, self.class.key)
    end

    def authorize?
      @authorize === true
    end
  end
end
{'fraction_non_alphanumeric': 0.09264565425023878, 'fraction_numerical': 0.0019102196752626551, 'mean_word_length': 3.373695198329854, 'pattern_counts': {'":': 0, '<': 3, '<?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': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '4598322', 'n_tokens_mistral': 677, 'n_tokens_neox': 648, 'n_words': 142}