Class: KeeperSecretsManager::Storage::InMemoryStorage

Inherits:
Object
  • Object
show all
Includes:
KeyValueStorage
Defined in:
lib/keeper_secrets_manager/storage.rb

Overview

In-memory storage implementation

Instance Method Summary collapse

Methods included from KeyValueStorage

#contains?, #get_bytes, #save_bytes

Constructor Details

#initialize(config_data = nil) ⇒ InMemoryStorage

Returns a new instance of InMemoryStorage.



55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
# File 'lib/keeper_secrets_manager/storage.rb', line 55

def initialize(config_data = nil)
  @data = {}

  # Initialize from JSON string, base64 string, or hash
  if config_data
    parsed = case config_data
             when String
               # Check if it's base64 encoded
               if is_base64?(config_data)
                 JSON.parse(Base64.decode64(config_data))
               else
                 JSON.parse(config_data)
               end
             when Hash
               config_data
             else
               {}
             end

    parsed.each { |k, v| @data[k.to_s] = v.to_s }
  end
end

Instance Method Details

#delete(key) ⇒ Object



86
87
88
# File 'lib/keeper_secrets_manager/storage.rb', line 86

def delete(key)
  @data.delete(key.to_s)
end

#get_string(key) ⇒ Object



78
79
80
# File 'lib/keeper_secrets_manager/storage.rb', line 78

def get_string(key)
  @data[key.to_s]
end

#save_string(key, value) ⇒ Object



82
83
84
# File 'lib/keeper_secrets_manager/storage.rb', line 82

def save_string(key, value)
  @data[key.to_s] = value.to_s
end

#to_hObject



90
91
92
# File 'lib/keeper_secrets_manager/storage.rb', line 90

def to_h
  @data.dup
end

#to_json(*args) ⇒ Object



94
95
96
# File 'lib/keeper_secrets_manager/storage.rb', line 94

def to_json(*args)
  @data.to_json(*args)
end