Class: Aspera::Secret::Bootstrap
- Inherits:
-
Object
- Object
- Aspera::Secret::Bootstrap
- Defined in:
- lib/aspera/secret/reference.rb
Overview
Bootstrap secret of a store in configuration (e.g. password of type file):
the value, or @file:<path> to read it from a file when used (e.g. a systemd credential), without final newline.
Syntax of extended values of ascli, only @file: is supported: other prefixes may be added.
In YAML, quote the value: @ cannot start a plain scalar.
Constant Summary collapse
- FILE_PREFIX =
'@file:'
Instance Method Summary collapse
-
#file? ⇒ Boolean
trueif read from a file. -
#initialize(name, text) ⇒ Bootstrap
constructor
A new instance of Bootstrap.
-
#inspect ⇒ Object
No value in logs and errors.
-
#mtime ⇒ Time?
Modification time of file,
nilfor a value. -
#value ⇒ String
Value, read from the file at each call.
Constructor Details
#initialize(name, text) ⇒ Bootstrap
Returns a new instance of Bootstrap.
48 49 50 51 52 53 54 55 56 57 |
# File 'lib/aspera/secret/reference.rb', line 48 def initialize(name, text) raise Error, "#{name}: expecting the value, or #{FILE_PREFIX}<path>" unless text.is_a?(String) && !text.empty? if text.start_with?(FILE_PREFIX) @path = text.delete_prefix(FILE_PREFIX) raise Error, "#{name}: expecting #{FILE_PREFIX}<path>" if @path.empty? else @value = text Secret::Hider.instance.add_secret_values(text) end end |
Instance Method Details
#file? ⇒ Boolean
Returns true if read from a file.
60 61 62 |
# File 'lib/aspera/secret/reference.rb', line 60 def file? !@path.nil? end |
#inspect ⇒ Object
No value in logs and errors
79 80 81 |
# File 'lib/aspera/secret/reference.rb', line 79 def inspect "#<#{self.class} #{@path.nil? ? 'value' : "#{FILE_PREFIX}#{@path}"}>" end |
#mtime ⇒ Time?
Returns Modification time of file, nil for a value.
66 67 68 69 70 |
# File 'lib/aspera/secret/reference.rb', line 66 def mtime File.mtime(@path) unless @path.nil? rescue SystemCallError => e raise Error, "secret file: #{e.}" end |