Class: SafeDb::Read
Overview
The read use case pulls a file in from either an accessible filesystem or from a remote http, https, git, S3, GoogleDrive and/or ssh source.
This use case expects a @file_url parameter. The actions it takes are to
-
register @in.url to mirror @file_url
-
register @out.url to mirror @file_url
-
check the location of @file_url
-
if no file exists it humbly finishes up
If a file does exist at the @in.url this use case
-
handles HOME directory enabling portability
-
creates an encryption key and random iv
-
creates a file (name) id
-
stores the file byte and human readable size
-
stores the extension if it has one
-
stores the last created date
-
stores the last modified date
-
stores the (now) in date
Once done it displays key facts about the file.
Constant Summary
Constants inherited from UseCase
UseCase::APP_DIR_NAME, UseCase::COMMANDMENT, UseCase::ENV_VAR_KEY_NAME, UseCase::ENV_VAR_PREFIX_A, UseCase::ENV_VAR_PREFIX_B, UseCase::FILE_CONTENT_KEY, UseCase::FILE_KEY_PREFIX, UseCase::FILE_NAME_KEY
Instance Attribute Summary collapse
-
#file_url ⇒ Object
writeonly
– ———————- –# – ———————- –# – [SAFE] Name Changes –# – ———————- –# – Change env.path ~> open.chapter – Change key.path ~> open.verse – Change envelope@xxxx ~> chapter@xxxx – – Change filenames to ~~~~~> book.db.breadcrumbs – Change filenames to ~~~~~> chapter.cipher.file – Change filenames to ~~~~~> safe.db.abc123xyzpq – ———————- –# – { – “db.create.date”: “Sat Aug 11 11:20:16 2018 ( 18223.1120.07.511467675 )”, – “db.domain.name”: “ab.com”, – “db.domain.id”: “uhow-ku9l”, – “env.path”: “aa”, – “key.path”: “aa”, – “envelope@aa”: { – “content.xid”: “3uzk12dxity”, – “content.iv”: “XTVe%qIGKVvWw@EKcgSa153nfVPaMVJH”, – “content.key”: “1u3b2o6KLiAUmt11yYEDThJw1E5Mh4%1iHYOpJQjWiYLthUGgl8IZ5szus8Fz2Jt” – } – } – ———————- –# – ———————- –#.
Attributes inherited from UseCase
Instance Method Summary collapse
-
#execute ⇒ Object
The read use case pulls a file in from either an accessible filesystem or from a remote http, https, git, S3, GoogleDrive and/or ssh source.
Methods inherited from UseCase
#check_post_conditions, #check_pre_conditions, #cleanup, #config_directory, #config_file, #flow_of_events, #get_master_database, #initialize, #post_validation
Constructor Details
This class inherits a constructor from SafeDb::UseCase
Instance Attribute Details
#file_url=(value) ⇒ Object (writeonly)
– ———————- –# – ———————- –# – [SAFE] Name Changes –# – ———————- –# – Change env.path ~> open.chapter – Change key.path ~> open.verse – Change envelope@xxxx ~> chapter@xxxx – – Change filenames to ~~~~~> book.db.breadcrumbs – Change filenames to ~~~~~> chapter.cipher.file – Change filenames to ~~~~~> safe.db.abc123xyzpq – ———————- –# – { – “db.create.date”: “Sat Aug 11 11:20:16 2018 ( 18223.1120.07.511467675 )”, – “db.domain.name”: “ab.com”, – “db.domain.id”: “uhow-ku9l”, – “env.path”: “aa”, – “key.path”: “aa”, – “envelope@aa”: { – “content.xid”: “3uzk12dxity”, – “content.iv”: “XTVe%qIGKVvWw@EKcgSa153nfVPaMVJH”, – “content.key”: “1u3b2o6KLiAUmt11yYEDThJw1E5Mh4%1iHYOpJQjWiYLthUGgl8IZ5szus8Fz2Jt” – } – } – ———————- –# – ———————- –#
56 57 58 |
# File 'lib/usecase/files/read.rb', line 56 def file_url=(value) @file_url = value end |
Instance Method Details
#execute ⇒ Object
The read use case pulls a file in from either an accessible filesystem or from a remote http, https, git, S3, GoogleDrive and/or ssh source.
60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 |
# File 'lib/usecase/files/read.rb', line 60 def execute return unless ops_key_exists? master_db = KeyApi.read_master_db() return if unopened_envelope?( master_db ) # -- Get the open chapter identifier (id). # -- Decide whether chapter already exists. # -- Then get (or instantiate) the chapter's hash data structure # -- chapter_id = ENVELOPE_KEY_PREFIX + master_db[ ENV_PATH ] chapter_exists = KeyApi.db_envelope_exists?( master_db[ chapter_id ] ) chapter_data = KeyDb.from_json( KeyApi.content_unlock( master_db[ chapter_id ] ) ) if chapter_exists chapter_data = KeyDb.new() unless chapter_exists content_hdr = create_header() # -- If no content envelope exists we need to place # -- an empty one inside the appdb content database. # -- master_db[ chapter_id ] = {} unless chapter_exists # -- We populate (PUT) file instance attributes into # -- the mini-dictionary at the [VERSE] location. # -- verse_id = master_db[ KEY_PATH ] file_absolute_path = ::File.absolute_path( @file_url ) chapter_data.create_entry( verse_id, "@in.url", file_absolute_path ) chapter_data.create_entry( verse_id, "@out.url", file_absolute_path ) # -- Lock No.1 # -- # -- Lock the file content and leave the 3 breadcrumbs # -- (content id, content iv and content key) inside # -- the file attributes mini dictionary to facilitate # -- decrypting and writing out the file again. # -- KeyApi.content_lock( chapter_data[ verse_id ], ::File.read( @file_url ), content_hdr ) # -- Lock No.2 # -- # -- Lock the chapter's data which includes the new or # -- updated mini-dictionary that holds the breadcrumbs # -- (content id, content iv and content key) that will # -- be used to decrypt and write out the file content. # -- # -- Leave another set of breadcrumbs inside the master # -- database (content id, content iv and content key) # -- to facilitate decrypting the chapter's data. # -- KeyApi.content_lock( master_db[ chapter_id ], chapter_data.to_json, content_hdr ) # -- Lock No.3 # -- # -- Re-lock the master database including the breadcrumbs # -- (content id, content iv and content key) that will # -- (in the future) decrypt this chapter's data. # -- KeyApi.write_master_db( content_hdr, master_db ) # -- Communicate that the indicated file has just been # -- successfully ingested into the safe. # -- print_file_success master_db[ ENV_PATH ], verse_id, file_absolute_path end |