Skip to content

Commit

Permalink
Extract methods for constants and ensure loads of secrets happen once
Browse files Browse the repository at this point in the history
  • Loading branch information
jrafanie committed Dec 10, 2024
1 parent a284128 commit 69cd2d0
Showing 1 changed file with 11 additions and 4 deletions.
15 changes: 11 additions & 4 deletions spec/shared/cassette_secrets_helper.rb
Original file line number Diff line number Diff line change
@@ -1,8 +1,15 @@
module Spec
module Shared
module CassetteSecretsHelper
DEFAULT_VCR_SECRETS_PATH = Pathname.new(Dir.pwd).join("config/secrets.defaults.yml")
VCR_SECRETS_PATH = Pathname.new(Dir.pwd).join("config/secrets.yml")
def default_vcr_secrets_path
Pathname.new(Dir.pwd).join("config/secrets.defaults.yml").tap do |path|
raise "Default vcr cassette secrets not found: #{path}! Create this file with placeholder secrets to be used in cassettes to avoid leaking actual secrets." unless path.exist?
end
end

def vcr_secrets_path
Pathname.new(Dir.pwd).join("config/secrets.yml")
end

def load_vcr_secrets(pathname)
if pathname.exist?
Expand All @@ -13,11 +20,11 @@ def load_vcr_secrets(pathname)
end

def default_vcr_secrets
@default_vcr_secrets ||= load_vcr_secrets(DEFAULT_VCR_SECRETS_PATH)
@@default_vcr_secrets ||= load_vcr_secrets(default_vcr_secrets_path)
end

def vcr_secrets
@vcr_secrets ||= load_vcr_secrets(VCR_SECRETS_PATH)
@@vcr_secrets ||= load_vcr_secrets(vcr_secrets_path)
end

def default_vcr_secret_by_key_path(*args)
Expand Down

0 comments on commit 69cd2d0

Please sign in to comment.