Class: Dotenv::SecretsManager::Reference
- Inherits:
-
Object
- Object
- Dotenv::SecretsManager::Reference
- 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
-
#json_key ⇒ Object
readonly
Returns the value of attribute json_key.
-
#raw ⇒ Object
readonly
Returns the value of attribute raw.
-
#secret_id ⇒ Object
readonly
Returns the value of attribute secret_id.
Class Method Summary collapse
Instance Method Summary collapse
-
#initialize(raw) ⇒ Reference
constructor
A new instance of Reference.
- #malformed? ⇒ Boolean
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_key ⇒ Object (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 |
#raw ⇒ Object (readonly)
Returns the value of attribute raw.
15 16 17 |
# File 'lib/dotenv/secretsmanager/reference.rb', line 15 def raw @raw end |
#secret_id ⇒ Object (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
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
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 |