class OpenSecret::Put

The put use case follows open and it adds secrets into an (encrypted at rest) envelope. Put can be called many times and when done, the lock use case can be called to commit all opened secrets into the configured storage engines.

Calling put before calling open or after calling lock is not allowed and will result in an error.

Put Pre-Conditions

When the put use case is called - the below conditions ring true.

Observable Value

The observable value delivered by put boils down to

Attributes

secret_id[W]
secret_value[W]

Public Instance Methods

execute() click to toggle source

Execute the act of putting a string key and string value pair into a map at the chapter and verse location, overwriting if need be.

# File lib/usecase/put.rb, line 34
def execute

  return unless ops_key_exists?
  master_db = OpenKey::KeyApi.read_master_db()

  return if unopened_envelope?( master_db )

  envelope_id = ENVELOPE_KEY_PREFIX + master_db[ ENV_PATH ]
  has_content = OpenKey::KeyApi.db_envelope_exists?( master_db[ envelope_id ] )

  # To get hold of the content we must either
  #
  #   a) unlock it using the breadcrumbs or
  #   b) start afresh with a new content db
  content_box = OpenKey::KeyDb.from_json( OpenKey::KeyApi.content_unlock( master_db[ envelope_id ] ) ) if has_content
  content_box = OpenKey::KeyDb.new() unless has_content
  content_hdr = create_header()

  # If no content envelope exists we need to place
  # an empty one inside the appdb content database.
  master_db[ envelope_id ] = {} unless has_content

  # This is the PUT use case so we append a
  #
  #   a) key for the new dictionary entry
  #   b) value for the new dictionary entry
  #
  # into the current content envelope and write
  # the envelope to the content filepath.
  crumbs_dict = master_db[ envelope_id ]
  content_box.create_entry( master_db[ KEY_PATH ], @secret_id, @secret_value )
  OpenKey::KeyApi.content_lock( crumbs_dict, content_box.to_json, content_hdr )

  # Three envelope crumbs namely the external ID, the
  # random iv and the crypt key are written afresh into
  # the master database.
  OpenKey::KeyApi.write_master_db( content_hdr, master_db )

  # Show the mini dictionary at the opened chapter and verse location
  Show.new.flow_of_events

end