Skip to content

Commit

Permalink
Lazy load SSM client (#8)
Browse files Browse the repository at this point in the history
  • Loading branch information
dwilkie authored Oct 11, 2024
1 parent 683c046 commit da18ca8
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 9 deletions.
10 changes: 5 additions & 5 deletions Gemfile.lock
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,8 @@ GEM
tzinfo (~> 2.0, >= 2.0.5)
ast (2.4.2)
aws-eventstream (1.3.0)
aws-partitions (1.978.0)
aws-sdk-core (3.209.0)
aws-partitions (1.989.0)
aws-sdk-core (3.209.1)
aws-eventstream (~> 1, >= 1.3.0)
aws-partitions (~> 1, >= 1.651.0)
aws-sigv4 (~> 1.9)
Expand Down Expand Up @@ -65,7 +65,7 @@ GEM
rspec-expectations (3.13.3)
diff-lcs (>= 1.2.0, < 2.0)
rspec-support (~> 3.13.0)
rspec-mocks (3.13.1)
rspec-mocks (3.13.2)
diff-lcs (>= 1.2.0, < 2.0)
rspec-support (~> 3.13.0)
rspec-support (3.13.1)
Expand All @@ -87,7 +87,7 @@ GEM
rubocop-performance (1.22.1)
rubocop (>= 1.48.1, < 2.0)
rubocop-ast (>= 1.31.1, < 2.0)
rubocop-rails (2.26.1)
rubocop-rails (2.26.2)
activesupport (>= 4.2.0)
rack (>= 1.1)
rubocop (>= 1.52.0, < 2.0)
Expand All @@ -97,7 +97,7 @@ GEM
rubocop-minitest
rubocop-performance
rubocop-rails
rubocop-rspec (3.0.5)
rubocop-rspec (3.1.0)
rubocop (~> 1.61)
ruby-progressbar (1.13.0)
securerandom (0.3.1)
Expand Down
12 changes: 8 additions & 4 deletions lib/encrypted_credentials/encrypted_environment_variables.rb
Original file line number Diff line number Diff line change
Expand Up @@ -4,13 +4,17 @@

module EncryptedCredentials
class EncryptedEnvironmentVariables
attr_reader :ssm_client, :environment
attr_reader :environment

SSM_PARAMETER_NAME_PATTERN = "_SSM_PARAMETER_NAME"

def initialize(ssm_client: Aws::SSM::Client.new, environment: ENV)
@ssm_client = ssm_client
@environment = environment
def initialize(**options)
@ssm_client = options.fetch(:ssm_client) { -> { Aws::SSM::Client.new } }
@environment = options.fetch(:environment) { ENV }
end

def ssm_client
@ssm_client.respond_to?(:call) ? @ssm_client.call : @ssm_client
end

def decrypt
Expand Down

0 comments on commit da18ca8

Please sign in to comment.