class OpenSecret::Store::ColdStore

Cold storage can sync repositories with a bias during conflicts either to the remote repository when pulling, and then conversely to the local reposiory when pushing.

In between the sync operations a ColdStore can create, read, update and delete to and from the local mirror.

ColdStore | Use Cases

Any self-respecting coldstore must, after initialization, provide some basic (and mandatory) behaviour.

These include

Cold Storage is borrowed from BitCoin and represents offline storage for keys and crypts. opensecret separates keys and crypts so that you can transfer and share secrets by moving keys (not the crypts).

Houses and Gold Bullion

You don't carry houses or gold bullion around to rent, share or transfer their ownership.

You copy keys to rent secrets and when the tenure is up (or you change your mind) you revoke access with a metaphorical lock change.

opensecret embodies concepts like an owner who rents as opposed to a change in ownership.

trade secrets | commoditizing secrets

opensecret is a conduit through which secrets can be bought and sold.

It commoditizes secrets so that they can be owned, traded, leased and auctioned. Options to acquire or relinquish them at set prices can easily be taken out.

Public Class Methods

new(local_path) click to toggle source

@param base_path [String]

path to the store's (mirror) base directory.
If the denoted directory does not exist an attempt will be made to
create it. If a file exists at this path an error will be thrown.

@param domain [String]

the domain is an identifier (and namespace) denoting which opensecret
"account" is being accessed. opensecret allows the creation and use of
multiple domains.
# File lib/modules/storage/coldstore.rb, line 60
def initialize local_path

  @store_path = local_path
  FileUtils.mkdir_p @store_path

end

Public Instance Methods

read(from_path) click to toggle source

Read the file frozen (in this store mirror) at this path and return its contents.

Coldstores are usually frozen offline (offmachine) so for this to work the {ColdStore.pull} behaviour must have executed to create a local store mirror. This method reads from that mirror.

@param from_path [String]

read the file frozen at this path and return its contents
so that the defreeze process can begin.

This path is relative to the base of the store defined in
the constructor.

@return [String]

return the text frozen in a file at the denoted local path

nil is reurned if no file can be found in the local mirror
at the configured path

@raise [RuntimeError]

unless the path exists in this coldstore and that path is
a directory (as opposed to a file).

@raise [ArgumentError]

if more than one file match is made at the path specified.
# File lib/modules/storage/coldstore.rb, line 94
def read from_path

  frozen_filepath = File.join @store_path, from_path
  frozen_dir_path = File.dirname(frozen_filepath)

  log.info(x) { "Coldstore will search in folder [#{frozen_dir_path.hr_path}]" }

  exists_msg = "Directory #{frozen_dir_path} does not exist in store."
  is_dir_msg = "Path #{frozen_dir_path} should be a directory (not a file)."
  raise RuntimeError, exists_msg unless File.exists? frozen_dir_path
  raise RuntimeError, is_dir_msg unless File.directory? frozen_dir_path

  full_filepath = ""
  file_matched = false

  Dir.glob("#{frozen_dir_path}/**/*.os.txt").each do |matched_path|

    log.info(x) { "Coldstore search with [#{from_path}] has matched [#{matched_path.hr_path}]" }
    log.info(x) { "Ignore directory at [#{matched_path.hr_path}]." } if File.directory? matched_path
    next if File.directory? matched_path

    two_match_msg = "More than one file matched. The second is #{matched_path}."
    raise ArgumentError, two_match_msg if file_matched
    file_matched = true

    full_filepath = matched_path

  end

  no_file_msg = "Coldstore could not find path [#{from_path}] from [#{@store_path}]."
  raise RuntimeError, no_file_msg unless file_matched

  log.info(x) { "Coldstore matched exactly one envelope at [#{full_filepath.hr_path}]." }
  return File.read full_filepath

end
write(this_text, to_path) click to toggle source

Write (freeze) the text into a file at the denoted path. The folder path will be created if need be.

Coldstores are usually frozen offline (offmachine) so after this method completes the {ColdStore.push} behaviour must be executed to synchronize the local coldstore freezer with the remote mirror.

@param this_text [String]

this is the text that needs to be frozen into the local and
subsequently the remote coldstore freezer.

@param to_path [String]

write the text (effectively freezing it) into the file at
this path. An attempt will be made to put down the necessary
directory structure.

This path is relative to the base of the store defined in
the constructor.
# File lib/modules/storage/coldstore.rb, line 151
def write this_text, to_path

  freeze_filepath = File.join @store_path, to_path

  log.info(x) { "ColdStore freezing #{this_text.length} characters of worthless text."}
  log.info(x) { "ColdStore freeze file path => #{freeze_filepath.hr_path}"}

  FileUtils.mkdir_p(File.dirname(freeze_filepath))
  File.write freeze_filepath, this_text

end

Private Instance Methods

pull() click to toggle source

@todo - write sync (with a rmote bias during conflicts)

The open up to the public (published) api.
# File lib/modules/storage/coldstore.rb, line 175
def pull

end
push() click to toggle source

@todo - write sync (with a local bias during conflicts)

The open up to the public (published) api.
# File lib/modules/storage/coldstore.rb, line 168
def push


end