Class: Google::Auth::Stores::AwsParameterStore

Inherits:
TokenStore
  • Object
show all
Defined in:
lib/google/auth/stores/aws_parameter_store.rb

Constant Summary collapse

VERSION =
"0.1.0"
DEFAULT_KEY_PREFIX =
"Google::Auth::Stores::AwsParameterStore::"

Instance Method Summary collapse

Constructor Details

#initialize(options = {}) ⇒ AwsParameterStore

Returns a new instance of AwsParameterStore.



10
11
12
13
14
15
16
17
# File 'lib/google/auth/stores/aws_parameter_store.rb', line 10

def initialize(options = {})
  super()

  @client = options.delete (:client)

  prefix = options.delete :prefix
  @prefix = prefix || DEFAULT_KEY_PREFIX
end

Instance Method Details

#delete(id) ⇒ Object



31
32
33
34
# File 'lib/google/auth/stores/aws_parameter_store.rb', line 31

def delete(id)
  key = key_for(id)
  @client.delete_parameter(name: key)
end

#key_for(id) ⇒ Object



36
37
38
# File 'lib/google/auth/stores/aws_parameter_store.rb', line 36

def key_for(id)
  @prefix + id
end

#load(id) ⇒ Object



19
20
21
22
23
24
# File 'lib/google/auth/stores/aws_parameter_store.rb', line 19

def load(id)
  key = key_for(id)
  @client.get_parameter(name: key, with_decryption: true)&.parameter&.value
rescue
  nil
end

#store(id, token) ⇒ Object



26
27
28
29
# File 'lib/google/auth/stores/aws_parameter_store.rb', line 26

def store(id, token)
  key = key_for(id)
  @client.put_parameter(name: key, value: token, type: 'SecureString', overwrite: true)
end