Module: MovableInk::AWS::SSM
- Included in:
- MovableInk::AWS
- Defined in:
- lib/movable_ink/aws/ssm.rb
Instance Method Summary collapse
- #extract_parameters(parameters, path) ⇒ Object
- #get_role_secrets(environment: mi_env, role:) ⇒ Object
- #get_secret(environment: mi_env, role:, attribute:) ⇒ Object
- #run_with_backoff_and_client_fallback(&block) ⇒ Object
- #ssm_client ⇒ Object
- #ssm_client_failover ⇒ Object
Instance Method Details
#extract_parameters(parameters, path) ⇒ Object
50 51 52 53 54 |
# File 'lib/movable_ink/aws/ssm.rb', line 50 def extract_parameters(parameters, path) parameters.map do |param| [ param.name.gsub("#{path}/", ''), param.value ] end.to_h end |
#get_role_secrets(environment: mi_env, role:) ⇒ Object
38 39 40 41 42 43 44 45 46 47 48 |
# File 'lib/movable_ink/aws/ssm.rb', line 38 def get_role_secrets(environment: mi_env, role:) path = "/#{environment}/#{role}" run_with_backoff_and_client_fallback do |ssm| ssm.get_parameters_by_path( path: path, with_decryption: true ).inject({}) do |secrets, resp| secrets.merge!(extract_parameters(resp.parameters, path)) end end end |
#get_secret(environment: mi_env, role:, attribute:) ⇒ Object
24 25 26 27 28 29 30 31 32 33 34 35 36 |
# File 'lib/movable_ink/aws/ssm.rb', line 24 def get_secret(environment: mi_env, role:, attribute:) run_with_backoff_and_client_fallback do |ssm| begin resp = ssm.get_parameter( name: "/#{environment}/#{role}/#{attribute}", with_decryption: true ) resp.parameter.value rescue Aws::SSM::Errors::ParameterNotFound => e nil end end end |
#run_with_backoff_and_client_fallback(&block) ⇒ Object
14 15 16 17 18 19 20 21 22 |
# File 'lib/movable_ink/aws/ssm.rb', line 14 def run_with_backoff_and_client_fallback(&block) run_with_backoff do block.call(ssm_client) end rescue MovableInk::AWS::Errors::FailedWithBackoff => e run_with_backoff(tries: 3) do block.call(ssm_client_failover) end end |
#ssm_client ⇒ Object
6 7 8 |
# File 'lib/movable_ink/aws/ssm.rb', line 6 def ssm_client @ssm_client ||= Aws::SSM::Client.new(region: 'us-east-1') end |
#ssm_client_failover ⇒ Object
10 11 12 |
# File 'lib/movable_ink/aws/ssm.rb', line 10 def ssm_client_failover @ssm_client_failover ||= Aws::SSM::Client.new(region: 'us-west-2') end |