Last active
April 8, 2019 20:57
-
-
Save dennismclaugh/56ecc447f6d27ea9555279c900d30538 to your computer and use it in GitHub Desktop.
Demonstration of how to read secrets from AWS Parameter Store using Ruby. https://www.dennismclaughlin.tech/use-aws-parameter-store-to-guard-your-secrets/
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
require 'aws-sdk-ssm' | |
class AWSHelper | |
@@ssm_parameters = [] | |
@@test_environment = nil | |
# Reads and stores Parameter Store values for a particular path. | |
def self.load_ssm_parameters(test_environment) | |
@@test_environment = test_environment | |
Aws.config.update({ | |
region: 'us-east-1', | |
credentials: Aws::Credentials.new('AWS_ACCESS_KEY_GOES_HERE', 'AWS_SECRET_KEY_GOES_HERE') | |
}) | |
ssm = Aws::SSM::Client.new | |
next_token = nil | |
while true | |
params = { | |
path: "/WebDriver_Tests/#{test_environment}", | |
recursive: true, | |
with_decryption: true | |
} | |
params[:next_token] = next_token unless next_token.nil? | |
resp = ssm.get_parameters_by_path(params) | |
unless resp.parameters.empty? | |
(@@ssm_parameters << resp.parameters).flatten! | |
end | |
break if resp.next_token.nil? | |
next_token = resp.next_token | |
end | |
end | |
# Returns the value of a particular Parameter Store parameter. | |
def self.get_parameter_value(name) | |
param = @@ssm_parameters.each.select { |ssm_parameter| ssm_parameter.name == "/WebDriver_Tests/#{@@test_environment}/#{name}"} | |
param[0].value | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment