Class: Carioca::Services::SecureStore

Inherits:
Object
  • Object
show all
Extended by:
Injector
Defined in:
lib/carioca/services/securestore.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods included from Injector

active_services, add, create_methods, extended, inject, services

Constructor Details

#initialize(storefile: Carioca::Registry.config.secure_store_file, keyfile: Carioca::Registry.config.master_key_file) ⇒ SecureStore

Returns a new instance of SecureStore.



13
14
15
16
17
18
19
20
21
# File 'lib/carioca/services/securestore.rb', line 13

def initialize(storefile: Carioca::Registry.config.secure_store_file, keyfile: Carioca::Registry.config.master_key_file)
  [storefile, keyfile].map { |file| File.dirname(file) }.each do |path|
    setup.make_folder path: File.expand_path(path), mode: '400' unless sanitycheck.verify_folder name: path
  end
  @storefile = File.expand_path(storefile)
  @keyfile = File.expand_path(keyfile)
  init! unless initialized?
  @data = decrypt
end

Instance Attribute Details

#dataObject

Returns the value of attribute data.



6
7
8
# File 'lib/carioca/services/securestore.rb', line 6

def data
  @data
end

Instance Method Details

#init!Object



31
32
33
34
35
36
37
38
# File 'lib/carioca/services/securestore.rb', line 31

def init!
  path = File.dirname(@storefile)
  FileUtils.mkdir_p path
  generate_key
  init_data = {}
  encrypt(init_data)
  logger.warn(to_s) { 'Secure Store initialized' }
end

#initialized?Boolean

Returns:

  • (Boolean)


23
24
25
# File 'lib/carioca/services/securestore.rb', line 23

def initialized?
  File.exist?(@storefile) && File.exist?(@keyfile)
end

#save!Object



27
28
29
# File 'lib/carioca/services/securestore.rb', line 27

def save!
  encrypt(@data)
end