Class: Dotenv::SecretsManager::Reference

Inherits:
Object
  • Object
show all
Defined in:
lib/dotenv/secretsmanager/reference.rb

Overview

Parses a single .env value into its Secrets Manager components.

aws-sm:<secret-id>             => whole secret string
aws-sm:<secret-id>|<json-key>  => one key from a JSON secret

The remainder after the scheme is split on the LAST pipe, so neither a friendly name nor an ARN (which contain no pipe) is ever mis-split.

Constant Summary collapse

SCHEME =
"aws-sm:"

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(raw) ⇒ Reference

Returns a new instance of Reference.



25
26
27
28
29
30
31
32
33
34
35
36
37
# File 'lib/dotenv/secretsmanager/reference.rb', line 25

def initialize(raw)
  @raw = raw
  remainder = raw[SCHEME.length..] || ""

  if remainder.include?("|")
    before, _, after = remainder.rpartition("|")
    @secret_id = before
    @json_key = after
  else
    @secret_id = remainder
    @json_key = nil
  end
end

Instance Attribute Details

#json_keyObject (readonly)

Returns the value of attribute json_key.



15
16
17
# File 'lib/dotenv/secretsmanager/reference.rb', line 15

def json_key
  @json_key
end

#rawObject (readonly)

Returns the value of attribute raw.



15
16
17
# File 'lib/dotenv/secretsmanager/reference.rb', line 15

def raw
  @raw
end

#secret_idObject (readonly)

Returns the value of attribute secret_id.



15
16
17
# File 'lib/dotenv/secretsmanager/reference.rb', line 15

def secret_id
  @secret_id
end

Class Method Details

.parse(value) ⇒ Object



21
22
23
# File 'lib/dotenv/secretsmanager/reference.rb', line 21

def self.parse(value)
  new(value)
end

.reference?(value) ⇒ Boolean

Returns:

  • (Boolean)


17
18
19
# File 'lib/dotenv/secretsmanager/reference.rb', line 17

def self.reference?(value)
  value.is_a?(String) && value.start_with?(SCHEME)
end

Instance Method Details

#malformed?Boolean

Returns:

  • (Boolean)


39
40
41
42
43
44
# File 'lib/dotenv/secretsmanager/reference.rb', line 39

def malformed?
  return true if @secret_id.nil? || @secret_id.empty?
  return true if !@json_key.nil? && @json_key.empty?

  false
end