Class: OpenC3::Secrets

Inherits:
Object show all
Defined in:
lib/openc3/utilities/secrets.rb

Direct Known Subclasses

RedisSecrets

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initializeSecrets

Returns a new instance of Secrets.



23
24
25
# File 'lib/openc3/utilities/secrets.rb', line 23

def initialize
  @local_secrets = {}
end

Class Method Details

.getClientObject



27
28
29
30
31
32
# File 'lib/openc3/utilities/secrets.rb', line 27

def self.getClient
  raise 'OPENC3_SECRET_BACKEND environment variable is required' unless ENV['OPENC3_SECRET_BACKEND']
  secrets_class = ENV['OPENC3_SECRET_BACKEND'].capitalize + 'Secrets'
  klass = OpenC3.require_class('openc3/utilities/' + secrets_class.class_name_to_filename)
  klass.new
end

Instance Method Details

#delete(key, secret_store: nil, scope:) ⇒ Object

Raises:

  • (NotImplementedError)


46
47
48
# File 'lib/openc3/utilities/secrets.rb', line 46

def delete(key, secret_store: nil, scope:)
  raise NotImplementedError, "#{self.class} has not implemented method '#{__method__}'"
end

#get(key, secret_store: nil, scope:) ⇒ Object



38
39
40
# File 'lib/openc3/utilities/secrets.rb', line 38

def get(key, secret_store: nil, scope:)
  return @local_secrets[key]
end

#keys(secret_store: nil, scope:) ⇒ Object

Raises:

  • (NotImplementedError)


34
35
36
# File 'lib/openc3/utilities/secrets.rb', line 34

def keys(secret_store: nil, scope:)
  raise NotImplementedError, "#{self.class} has not implemented method '#{__method__}'"
end

#set(key, value, secret_store: nil, scope:) ⇒ Object

Raises:

  • (NotImplementedError)


42
43
44
# File 'lib/openc3/utilities/secrets.rb', line 42

def set(key, value, secret_store: nil, scope:)
  raise NotImplementedError, "#{self.class} has not implemented method '#{__method__}'"
end

#setup(secrets) ⇒ Object



50
51
52
53
54
55
56
57
58
59
60
61
# File 'lib/openc3/utilities/secrets.rb', line 50

def setup(secrets)
  secrets.each do |type, key, data, secret_store|
    case type
    when 'ENV'
      @local_secrets[key] = ENV[data]
    when 'FILE'
      @local_secrets[key] = File.read(data)
    else
      raise "Unknown secret type: #{type}"
    end
  end
end