class SafeDb::Init

This idempotent init use case promises that a password-protected book with the given name will exist within the safe's directory tree, along with key derivation salts, ciphertext and other paraphernalia.

After successful execution, the following state is observable

Within the master index file in the [<BOOK_ID>] section will be

init use case pre-conditions

Warning or error messages must result unless these pre-conditions are met

Public Instance Methods

execute() click to toggle source
# File lib/controller/access/init.rb, line 34
def execute

  @book_id = Identifier.derive_ergonomic_identifier( @book_name, Indices::SAFE_BOOK_ID_LENGTH )

  if is_book_initialized?()
    print_already_initialized
    return
  end

  EvolveState.create_book( @book_id )

  book_secret = KeyPass.password_from_shell( true ) if @password.nil?
  book_secret = @password unless @password.nil?

  master_keys = DataMap.new( Indices::MASTER_INDICES_FILEPATH )
  master_keys.use( @book_id )

  EvolveState.recycle_both_keys(
    @book_id,
    book_secret,
    master_keys,
    virginal_book()
  )

  commit_msg = "safe init artifacts for newly created (#{@book_name}) book on #{TimeStamp.readable()}."

  GitFlow.init( Indices::MASTER_CRYPTS_FOLDER_PATH )
  GitFlow.config( Indices::MASTER_CRYPTS_FOLDER_PATH, "#{ENV[ "USER" ]}@#{Socket.gethostname()}", "SafeDb User" )
  GitFlow.stage( Indices::MASTER_CRYPTS_FOLDER_PATH )
  GitFlow.list( Indices::MASTER_CRYPTS_FOLDER_PATH )
  GitFlow.list( Indices::MASTER_CRYPTS_FOLDER_PATH, true )
  GitFlow.commit( Indices::MASTER_CRYPTS_FOLDER_PATH, commit_msg )

  print_success_initializing

end

Private Instance Methods

print_already_initialized() click to toggle source
print_success_initializing() click to toggle source
virginal_book() click to toggle source
# File lib/controller/access/init.rb, line 75
def virginal_book()

  initial_db = DataStore.new()
  initial_db.store( Indices::SAFE_BOOK_INITIALIZE_TIME, TimeStamp.readable() )
  initial_db.store( Indices::SAFE_BOOK_NAME, @book_name )
  initial_db.store( Indices::SAFE_BOOK_INIT_VERSION, "#{Indices::SAFE_PRE_VERSION_STRING}#{SafeDb::VERSION}" )
  initial_db.store( Indices::SAFE_BOOK_CHAPTER_KEYS, {} )

  return initial_db.to_json

end