safedb 0.3.1011 → 0.4.1002

Sign up to get free protection for your applications and to get access to all the features.
Files changed (116) hide show
  1. checksums.yaml +4 -4
  2. data/CONTRIBUTING.md +56 -19
  3. data/README.md +15 -15
  4. data/Rakefile +7 -0
  5. data/bin/safe +2 -2
  6. data/lib/{interprete.rb → cli.rb} +168 -121
  7. data/lib/controller/admin/README.md +47 -0
  8. data/lib/controller/admin/access.rb +47 -0
  9. data/lib/controller/admin/checkin.rb +83 -0
  10. data/lib/controller/admin/checkout.rb +57 -0
  11. data/lib/controller/admin/diff.rb +75 -0
  12. data/lib/{usecase → controller/admin}/export.rb +15 -14
  13. data/lib/controller/admin/goto.rb +52 -0
  14. data/lib/controller/admin/import.rb +54 -0
  15. data/lib/controller/admin/init.rb +113 -0
  16. data/lib/controller/admin/login.rb +88 -0
  17. data/lib/{usecase → controller/admin}/logout.rb +0 -0
  18. data/lib/controller/admin/open.rb +39 -0
  19. data/lib/{usecase → controller/admin}/token.rb +2 -2
  20. data/lib/controller/admin/tree.md +54 -0
  21. data/lib/{usecase → controller/admin}/use.rb +0 -0
  22. data/lib/controller/admin/view.rb +61 -0
  23. data/lib/{usecase → controller/api}/docker/README.md +0 -0
  24. data/lib/{usecase → controller/api}/docker/docker.rb +1 -1
  25. data/lib/{usecase → controller/api}/jenkins/README.md +0 -0
  26. data/lib/{usecase → controller/api}/jenkins/jenkins.rb +1 -1
  27. data/lib/{usecase → controller/api}/terraform/README.md +1 -1
  28. data/lib/{usecase → controller/api}/terraform/terraform.rb +1 -1
  29. data/lib/{usecase → controller/api}/vpn/README.md +1 -1
  30. data/lib/{usecase → controller/api}/vpn/vpn.ini +0 -0
  31. data/lib/{usecase → controller/api}/vpn/vpn.rb +0 -0
  32. data/lib/{usecase → controller}/config/README.md +0 -0
  33. data/lib/{usecase → controller}/edit/README.md +0 -0
  34. data/lib/controller/edit/editverse.rb +48 -0
  35. data/lib/controller/edit/put.rb +35 -0
  36. data/lib/controller/edit/remove.rb +29 -0
  37. data/lib/{usecase/update/README.md → controller/edit/rename.md} +0 -0
  38. data/lib/{usecase → controller}/files/README.md +1 -1
  39. data/lib/controller/files/read.rb +36 -0
  40. data/lib/{usecase/files/eject.rb → controller/files/write.rb} +15 -20
  41. data/lib/{usecase → controller}/id.rb +0 -0
  42. data/lib/controller/query/print.rb +26 -0
  43. data/lib/controller/query/queryverse.rb +39 -0
  44. data/lib/controller/query/show.rb +50 -0
  45. data/lib/{session/require.gem.rb → controller/requirer.rb} +13 -9
  46. data/lib/{usecase → controller}/set.rb +4 -4
  47. data/lib/controller/usecase.rb +244 -0
  48. data/lib/{usecase → controller}/verse.rb +0 -0
  49. data/lib/{usecase → controller}/visit/README.md +0 -0
  50. data/lib/{usecase → controller}/visit/visit.rb +0 -0
  51. data/lib/factbase/facts.safedb.net.ini +7 -7
  52. data/lib/{keytools/key.docs.rb → model/README.md} +102 -66
  53. data/lib/model/book.rb +484 -0
  54. data/lib/model/branch.rb +48 -0
  55. data/lib/model/checkin.feature +33 -0
  56. data/lib/{configs/README.md → model/configs.md} +4 -4
  57. data/lib/model/content.rb +214 -0
  58. data/lib/model/indices.rb +132 -0
  59. data/lib/model/safe_tree.rb +51 -0
  60. data/lib/model/state.inspect.rb +221 -0
  61. data/lib/model/state.migrate.rb +334 -0
  62. data/lib/model/text_chunk.rb +68 -0
  63. data/lib/{extension → utils/extend}/array.rb +0 -0
  64. data/lib/{extension → utils/extend}/dir.rb +0 -0
  65. data/lib/{extension → utils/extend}/file.rb +0 -0
  66. data/lib/utils/extend/hash.rb +76 -0
  67. data/lib/{extension → utils/extend}/string.rb +6 -6
  68. data/lib/{session/fact.finder.rb → utils/facts/fact.rb} +0 -0
  69. data/lib/utils/identity/identifier.rb +356 -0
  70. data/lib/{keytools/key.ident.rb → utils/identity/machine.id.rb} +67 -4
  71. data/lib/utils/inspect/inspector.rb +81 -0
  72. data/lib/{keytools/kdf.bcrypt.rb → utils/kdfs/bcrypt.rb} +0 -0
  73. data/lib/{keytools → utils/kdfs}/kdf.api.rb +16 -16
  74. data/lib/{keytools/key.local.rb → utils/kdfs/kdfs.rb} +40 -40
  75. data/lib/{keytools/kdf.pbkdf2.rb → utils/kdfs/pbkdf2.rb} +0 -0
  76. data/lib/{keytools/kdf.scrypt.rb → utils/kdfs/scrypt.rb} +0 -0
  77. data/lib/{keytools → utils}/key.error.rb +2 -2
  78. data/lib/{keytools → utils}/key.pass.rb +2 -2
  79. data/lib/{keytools → utils/keys}/key.64.rb +0 -0
  80. data/lib/{keytools → utils/keys}/key.rb +6 -2
  81. data/lib/{keytools/key.iv.rb → utils/keys/random.iv.rb} +0 -0
  82. data/lib/{logging/gem.logging.rb → utils/logs/logger.rb} +6 -5
  83. data/lib/{keytools/key.pair.rb → utils/store/datamap.rb} +48 -30
  84. data/lib/{keytools/key.db.rb → utils/store/datastore.rb} +38 -104
  85. data/lib/utils/store/merge-boys-school.json +40 -0
  86. data/lib/utils/store/merge-girls-school.json +48 -0
  87. data/lib/utils/store/merge-merged-data.json +56 -0
  88. data/lib/utils/store/struct.rb +75 -0
  89. data/lib/utils/store/test-commands.sh +24 -0
  90. data/lib/{keytools/key.now.rb → utils/time/timestamp.rb} +32 -21
  91. data/lib/version.rb +1 -1
  92. metadata +86 -73
  93. data/lib/extension/hash.rb +0 -33
  94. data/lib/keytools/key.algo.rb +0 -109
  95. data/lib/keytools/key.api.rb +0 -1326
  96. data/lib/keytools/key.id.rb +0 -322
  97. data/lib/modules/cryptology/amalgam.rb +0 -70
  98. data/lib/modules/cryptology/engineer.rb +0 -99
  99. data/lib/modules/mappers/dictionary.rb +0 -288
  100. data/lib/session/time.stamp.rb +0 -340
  101. data/lib/session/user.home.rb +0 -49
  102. data/lib/usecase/cmd.rb +0 -471
  103. data/lib/usecase/edit/delete.rb +0 -46
  104. data/lib/usecase/files/file_me.rb +0 -78
  105. data/lib/usecase/files/read.rb +0 -169
  106. data/lib/usecase/files/write.rb +0 -89
  107. data/lib/usecase/goto.rb +0 -57
  108. data/lib/usecase/import.rb +0 -157
  109. data/lib/usecase/init.rb +0 -61
  110. data/lib/usecase/login.rb +0 -72
  111. data/lib/usecase/open.rb +0 -71
  112. data/lib/usecase/print.rb +0 -40
  113. data/lib/usecase/put.rb +0 -81
  114. data/lib/usecase/show.rb +0 -138
  115. data/lib/usecase/update/rename.rb +0 -180
  116. data/lib/usecase/view.rb +0 -71
@@ -1,46 +0,0 @@
1
- #!/usr/bin/ruby
2
-
3
- module SafeDb
4
-
5
- # The <b>delete use case</b> delete's one or more of the safe's entities.
6
- #
7
- # - at <tt>verse</tt> level - it can delete one or more lines
8
- # - at <tt>chapter</tt> level - it can delete one or more verses
9
- # - at <tt>book</tt> level - it can delete one or more chapters
10
- # - at <tt>safe</tt> level - it can delete one book
11
- #
12
- class DeleteMe < UseCase
13
-
14
- attr_writer :entity_id
15
-
16
- # Deletion that currently expects an open chapter and verse and always
17
- # wants to delete only one line (key/value pair).
18
- def execute
19
-
20
- return unless ops_key_exists?
21
- master_db = KeyApi.read_master_db()
22
- return if unopened_envelope?( master_db )
23
-
24
- chapter_id = ENVELOPE_KEY_PREFIX + master_db[ ENV_PATH ]
25
- chapter_exists = KeyApi.db_envelope_exists?( master_db[ chapter_id ] )
26
- chapter_data = KeyDb.from_json( KeyApi.content_unlock( master_db[ chapter_id ] ) ) if chapter_exists
27
- chapter_data = KeyDb.new() unless chapter_exists
28
-
29
- content_hdr = create_header()
30
- master_db[ chapter_id ] = {} unless chapter_exists
31
- verse_id = master_db[ KEY_PATH ]
32
-
33
- chapter_data.delete_entry( verse_id, @entity_id )
34
- chapter_data.delete_entry( verse_id, "#{FILE_KEY_PREFIX}#{@entity_id}" )
35
-
36
- KeyApi.content_lock( master_db[ chapter_id ], chapter_data.to_json, content_hdr )
37
- KeyApi.write_master_db( content_hdr, master_db )
38
- Show.new.flow_of_events
39
-
40
- end
41
-
42
-
43
- end
44
-
45
-
46
- end
@@ -1,78 +0,0 @@
1
- #!/usr/bin/ruby
2
-
3
- module SafeDb
4
-
5
- # The <b>file use case</b> pulls a file in from either an accessible filesystem
6
- # or from a remote http, https, git, S3, GoogleDrive and/or ssh source.
7
- #
8
- # The @file_url is the most common parameter given to this use case.
9
- class FileMe < UseCase
10
-
11
- attr_writer :file_key, :file_url
12
-
13
- # There are 3 maps involved in the implementation and they are all (or in part) retrieved and/or
14
- # created as necessary. They are
15
- #
16
- # - the current chapter as a map
17
- # - the current verse as a map
18
- # - the file's keyname as a map
19
- #
20
- # Once the maps have been found and/or created if necessary the file's keyname map is either
21
- # populated or amended with the following data.
22
- #
23
- # - filename | {UseCase::FILE_NAME_KEY} | the file's simple name
24
- # - content64 | {UseCase::FILE_CONTENT_KEY} | the file's base64 content
25
- def execute
26
-
27
- return unless ops_key_exists?
28
- master_db = KeyApi.read_master_db()
29
- return if unopened_envelope?( master_db )
30
-
31
- chapter_id = ENVELOPE_KEY_PREFIX + master_db[ ENV_PATH ]
32
- chapter_exists = KeyApi.db_envelope_exists?( master_db[ chapter_id ] )
33
- chapter_data = KeyDb.from_json( KeyApi.content_unlock( master_db[ chapter_id ] ) ) if chapter_exists
34
- chapter_data = KeyDb.new() unless chapter_exists
35
-
36
- content_hdr = create_header()
37
- master_db[ chapter_id ] = {} unless chapter_exists
38
- verse_id = master_db[ KEY_PATH ]
39
-
40
- file_full_path = ::File.absolute_path( @file_url )
41
- file_base_name = ::File.basename( file_full_path )
42
- file_content64 = Base64.urlsafe_encode64( ::File.read( file_full_path ) )
43
-
44
- log.info(x) { "Key name of the file to ingest => #{@file_key}" }
45
- log.info(x) { "Ingesting file at path => #{file_full_path}" }
46
- log.info(x) { "The name of the file to ingest is => #{file_base_name}" }
47
- log.info(x) { "Size of base64 file content => [#{file_content64.length}]" }
48
-
49
- chapter_data.create_map_entry( verse_id, "#{FILE_KEY_PREFIX}#{@file_key}", FILE_NAME_KEY, file_base_name )
50
- chapter_data.create_map_entry( verse_id, "#{FILE_KEY_PREFIX}#{@file_key}", FILE_CONTENT_KEY, file_content64 )
51
-
52
- KeyApi.content_lock( master_db[ chapter_id ], chapter_data.to_json, content_hdr )
53
- KeyApi.write_master_db( content_hdr, master_db )
54
-
55
- Show.new.flow_of_events
56
-
57
- end
58
-
59
-
60
- private
61
-
62
-
63
- # Perform pre-conditional validations in preparation to executing the main flow
64
- # of events for this use case. This method may throw the below exceptions.
65
- #
66
- # @raise [SafeDirNotConfigured] if the safe's url has not been configured
67
- # @raise [EmailAddrNotConfigured] if the email address has not been configured
68
- # @raise [StoreUrlNotConfigured] if the crypt store url is not configured
69
- def pre_validation
70
-
71
-
72
- end
73
-
74
-
75
- end
76
-
77
-
78
- end
@@ -1,169 +0,0 @@
1
- #!/usr/bin/ruby
2
-
3
- module SafeDb
4
-
5
- # The <b>read use case</b> pulls a file in from either an accessible filesystem
6
- # or from a remote http, https, git, S3, GoogleDrive and/or ssh source.
7
- #
8
- # This use case expects a @file_url parameter. The actions it takes are to
9
- #
10
- # - register @in.url to mirror @file_url
11
- # - register @out.url to mirror @file_url
12
- # - check the location of @file_url
13
- # - if no file exists it humbly finishes up
14
- #
15
- # If a file does exist at the @in.url this use case
16
- #
17
- # - handles HOME directory enabling portability
18
- # - creates an encryption key and random iv
19
- # - creates a file (name) id
20
- # - stores the file byte and human readable size
21
- # - stores the extension if it has one
22
- # - stores the last created date
23
- # - stores the last modified date
24
- # - stores the (now) in date
25
- #
26
- # Once done it displays <b><em>key facts about the file</em></b>.
27
- class Read < UseCase
28
-
29
- # -- ---------------------- --#
30
- # -- ---------------------- --#
31
- # -- [SAFE] Name Changes --#
32
- # -- ---------------------- --#
33
- # -- Change env.path ~> open.chapter
34
- # -- Change key.path ~> open.verse
35
- # -- Change envelope@xxxx ~> chapter@xxxx
36
- # --
37
- # -- Change filenames to ~~~~~> book.db.breadcrumbs
38
- # -- Change filenames to ~~~~~> chapter.cipher.file
39
- # -- Change filenames to ~~~~~> safe.db.abc123xyzpq
40
- # -- ---------------------- --#
41
- # -- {
42
- # -- "db.create.date": "Sat Aug 11 11:20:16 2018 ( 18223.1120.07.511467675 )",
43
- # -- "db.domain.name": "ab.com",
44
- # -- "db.domain.id": "uhow-ku9l",
45
- # -- "env.path": "aa",
46
- # -- "key.path": "aa",
47
- # -- "envelope@aa": {
48
- # -- "content.xid": "3uzk12dxity",
49
- # -- "content.iv": "XTVe%qIGKVvWw@EKcgSa153nfVPaMVJH",
50
- # -- "content.key": "1u3b2o6KLiAUmt11yYEDThJw1E5Mh4%1iHYOpJQjWiYLthUGgl8IZ5szus8Fz2Jt"
51
- # -- }
52
- # -- }
53
- # -- ---------------------- --#
54
- # -- ---------------------- --#
55
-
56
- attr_writer :file_url
57
-
58
- # The <b>read use case</b> pulls a file in from either an accessible filesystem
59
- # or from a remote http, https, git, S3, GoogleDrive and/or ssh source.
60
- def execute
61
-
62
- return unless ops_key_exists?
63
- master_db = KeyApi.read_master_db()
64
- return if unopened_envelope?( master_db )
65
-
66
- # -- Get the open chapter identifier (id).
67
- # -- Decide whether chapter already exists.
68
- # -- Then get (or instantiate) the chapter's hash data structure
69
- # --
70
- chapter_id = ENVELOPE_KEY_PREFIX + master_db[ ENV_PATH ]
71
- chapter_exists = KeyApi.db_envelope_exists?( master_db[ chapter_id ] )
72
- chapter_data = KeyDb.from_json( KeyApi.content_unlock( master_db[ chapter_id ] ) ) if chapter_exists
73
- chapter_data = KeyDb.new() unless chapter_exists
74
-
75
- content_hdr = create_header()
76
-
77
- # -- If no content envelope exists we need to place
78
- # -- an empty one inside the appdb content database.
79
- # --
80
- master_db[ chapter_id ] = {} unless chapter_exists
81
-
82
- # -- We populate (PUT) file instance attributes into
83
- # -- the mini-dictionary at the [VERSE] location.
84
- # --
85
- verse_id = master_db[ KEY_PATH ]
86
- file_absolute_path = ::File.absolute_path( @file_url )
87
- chapter_data.create_entry( verse_id, "@in.url", file_absolute_path )
88
- chapter_data.create_entry( verse_id, "@out.url", file_absolute_path )
89
-
90
- # -- Lock No.1
91
- # --
92
- # -- Lock the file content and leave the 3 breadcrumbs
93
- # -- (content id, content iv and content key) inside
94
- # -- the file attributes mini dictionary to facilitate
95
- # -- decrypting and writing out the file again.
96
- # --
97
- KeyApi.content_lock( chapter_data[ verse_id ], ::File.read( @file_url ), content_hdr )
98
-
99
- # -- Lock No.2
100
- # --
101
- # -- Lock the chapter's data which includes the new or
102
- # -- updated mini-dictionary that holds the breadcrumbs
103
- # -- (content id, content iv and content key) that will
104
- # -- be used to decrypt and write out the file content.
105
- # --
106
- # -- Leave another set of breadcrumbs inside the master
107
- # -- database (content id, content iv and content key)
108
- # -- to facilitate decrypting the chapter's data.
109
- # --
110
- KeyApi.content_lock( master_db[ chapter_id ], chapter_data.to_json, content_hdr )
111
-
112
- # -- Lock No.3
113
- # --
114
- # -- Re-lock the master database including the breadcrumbs
115
- # -- (content id, content iv and content key) that will
116
- # -- (in the future) decrypt this chapter's data.
117
- # --
118
- KeyApi.write_master_db( content_hdr, master_db )
119
-
120
-
121
- # -- Communicate that the indicated file has just been
122
- # -- successfully ingested into the safe.
123
- # --
124
- print_file_success master_db[ ENV_PATH ], verse_id, file_absolute_path
125
-
126
- end
127
-
128
-
129
- private
130
-
131
-
132
- def print_file_success chapter_id, verse_id, file_url
133
-
134
- puts ""
135
- puts "|-"
136
- puts "|- Chapter ~> #{chapter_id}"
137
- puts "|- + Verse ~> #{verse_id}"
138
- puts "|-"
139
- puts "|- In File ~> #{file_url}"
140
- puts "|-"
141
- puts "|- File cocooned inside your safe."
142
- puts "|-"
143
- puts "|-Command Options"
144
- puts "|-"
145
- puts "|- #{COMMANDMENT} put out.dir ~/this/folder"
146
- puts "|- #{COMMANDMENT} put out.name new-filename.txt"
147
- puts "|- #{COMMANDMENT} write"
148
- puts "|-"
149
- puts ""
150
-
151
- end
152
-
153
-
154
- # Perform pre-conditional validations in preparation to executing the main flow
155
- # of events for this use case. This method may throw the below exceptions.
156
- #
157
- # @raise [SafeDirNotConfigured] if the safe's url has not been configured
158
- # @raise [EmailAddrNotConfigured] if the email address has not been configured
159
- # @raise [StoreUrlNotConfigured] if the crypt store url is not configured
160
- def pre_validation
161
-
162
-
163
- end
164
-
165
-
166
- end
167
-
168
-
169
- end
@@ -1,89 +0,0 @@
1
- #!/usr/bin/ruby
2
-
3
- module SafeDb
4
-
5
- # The <b>write use case</b> writes (or overwrites) a file at the
6
- # out url destination.
7
- class Write < UseCase
8
-
9
- attr_writer :file_url
10
-
11
- # The <b>read use case</b> pulls a file in from either an accessible filesystem
12
- # or from a remote http, https, git, S3, GoogleDrive and/or ssh source.
13
- def execute
14
-
15
- return unless ops_key_exists?
16
- master_db = get_master_database()
17
- return if unopened_envelope?( master_db )
18
-
19
- # Get the open chapter identifier (id).
20
- # Decide whether chapter already exists.
21
- # Then get (or instantiate) the chapter's hash data structure
22
- chapter_id = ENVELOPE_KEY_PREFIX + master_db[ ENV_PATH ]
23
- verse_id = master_db[ KEY_PATH ]
24
- chapter_exists = KeyApi.db_envelope_exists?( master_db[ chapter_id ] )
25
-
26
-
27
- # @todo begin
28
- # Throw an exception (error) if the chapter
29
- # either exists and is empty or does not exist.
30
- # @todo end
31
-
32
-
33
- # Unlock the chapter data structure by supplying
34
- # key/value mini-dictionary breadcrumbs sitting
35
- # within the master database at the section labelled
36
- # envelope@<<actual_chapter_id>>.
37
- chapter_data = KeyDb.from_json( KeyApi.content_unlock( master_db[ chapter_id ] ) )
38
-
39
-
40
- # Unlock the file content by supplying the
41
- # key/value mini-dictionary breadcrumbs sitting
42
- # within the chapter's data structure in the
43
- # section labelled <<verse_id>>.
44
- file_content = KeyApi.content_unlock( chapter_data[ verse_id ] )
45
-
46
-
47
- # We read the location url we plan to eject the
48
- # file out into.
49
- file_path = @file_url ? @file_url : chapter_data[ verse_id ][ "@out.url" ]
50
- file_name = ::File.basename( file_path)
51
-
52
- # If the directory the file will be exported to does
53
- # not exist we promptly create it.
54
- FileUtils.mkdir_p( File.dirname( file_path ) )
55
-
56
- # Create a backup file if we can detect that a
57
- # file occupies the eject (write) filepath.
58
- backup_file_path = ::File.join( ::File.dirname( file_path ), KeyNow.yyjjj_hhmm_sst() + "-" + file_name )
59
- ::File.write( backup_file_path, ::File.read( file_path ) ) if ::File.file?( file_path )
60
-
61
-
62
- # Now write (and if necessary overwrite) the eject
63
- # file url path with the previously ingested content.
64
- ::File.write( file_path, file_content )
65
-
66
-
67
- # Communicate that the indicated file has just been
68
- # successfully written out from the safe.
69
- print_file_success( master_db[ ENV_PATH ], verse_id, file_path )
70
-
71
- end
72
-
73
-
74
- private
75
-
76
-
77
- # Document a successful write of a file cocooned in the safe.
78
- # @param chapter_id the chapter of the file written out
79
- # @param verse_id the verse of the file written out
80
- # @param file_url the filepath the file was written to
81
- def print_file_success chapter_id, verse_id, file_url
82
- puts "File [#{file_url}] written out of safe at chapter [#{chapter_id}] and verse [#{verse_id}]."
83
- end
84
-
85
-
86
- end
87
-
88
-
89
- end
data/lib/usecase/goto.rb DELETED
@@ -1,57 +0,0 @@
1
- #!/usr/bin/ruby
2
-
3
- module SafeDb
4
-
5
- # Goto is a shortcut (or alias even) for the open command that takes an integer
6
- # index that effectively specifies which <envelope> and <key> to open.
7
- #
8
- # Use <b>view</b> to list the valid integer indices for each envelope and key
9
- # combination.
10
- #
11
- # View maps out and numbers each envelope/key combination.
12
- # Goto with the number effectively shortcuts the open pin pointer command.
13
- # Show prints the dictionary at the opened path masking any secrets.
14
- #
15
- # Once goto is enacted all path CRUD commands come into play as if you had
16
- # opened the path. These include put, copy, paste, show, tell and delete.
17
- class Goto < UseCase
18
-
19
- # The index (number) starting with 1 of the envelope and key-path
20
- # combination that should be opened.
21
- attr_writer :index
22
-
23
- def execute
24
-
25
- return unless ops_key_exists?
26
- master_db = KeyApi.read_master_db()
27
-
28
- goto_location = 0
29
- envelope_dictionaries = KeyApi.to_matching_dictionary( master_db, ENVELOPE_KEY_PREFIX )
30
- envelope_dictionaries.each_pair do | envelope_name, crumb_dictionary |
31
-
32
- envelope_content = KeyDb.from_json( KeyApi.content_unlock( crumb_dictionary ) )
33
- envelope_content.each_key do | envelope_key |
34
-
35
- goto_location += 1
36
- next unless @index.to_i == goto_location
37
-
38
- open_uc = Open.new
39
- open_uc.env_path = envelope_name
40
- open_uc.key_path = envelope_key
41
- open_uc.flow_of_events
42
-
43
- return
44
-
45
- end
46
-
47
-
48
- end
49
-
50
-
51
- end
52
-
53
-
54
- end
55
-
56
-
57
- end
@@ -1,157 +0,0 @@
1
- #!/usr/bin/ruby
2
-
3
- module SafeDb
4
-
5
- # The <b>import use case</b> follows <b>open</b> and it pulls a file into an
6
- # <em>(encrypted at rest)</em> <b>envelope</b> while writing metadata about
7
- # the file into the opened tree dictionary position.
8
- #
9
- # == import and reimport commands
10
- #
11
- # - the import command expects a path parameter and errors if not recvd
12
- # - the reimport command is happy with either one or zero parameters
13
- #
14
- # If the reimport command has no parameters it expects that the opened path
15
- # already contains an imported file. It uses the import.path key to locate
16
- # the file.
17
- #
18
- # If the path parameter is given to reimport it uses it and also resets the
19
- # import.path key to reflect the path it was given.
20
- #
21
- # == garbage collect dangling files
22
- #
23
- # Like dangling envelopes - dangling files will pop up when re-imported.
24
- # These are handled by the garbage collection policy which can be to
25
- # remove immediately - remove on next login - remove after a time period
26
- # or to never remove (manual garbage collection).
27
- #
28
- class Import < UseCase
29
-
30
- attr_writer :secret_id, :secret_value
31
-
32
- # The <b>put use case</b> follows <b>open</b> and it adds secrets into an
33
- # <em>(encrypted at rest)</em> envelope. Put can be called many times to
34
- # add secrets. Finally the <b>lock use case</b> commits all opened secrets
35
- # into the configured storage engines.
36
- #
37
- # Calling <em>put</em> <b>before</b> calling open or <b>after</b> calling lock
38
- # is not allowed and will result in an error.
39
- #
40
- # == Put Pre-Conditions
41
- #
42
- # When the put use case is called - the below conditions ring true.
43
- #
44
- # - the <b>folder path</b> ending in ../../my must exist
45
- # - a session id, filename and encryption key ( in workstation config )
46
- #
47
- # == Observable Value
48
- #
49
- # The observable value delivered by +put+ boils down to
50
- #
51
- # - a new <b>friends.xyz123abc.os.txt</b> file if this is the first put.
52
- # - a new group_name/key_name (like monica/surname) entry is added if required
53
- # - a secret value is added against the key or updated if it already exists
54
- # - a new session id and encryption key is generated and used to re-encrypt
55
- def execute
56
-
57
- return unless ops_key_exists?
58
- master_db = KeyApi.read_master_db()
59
-
60
- puts "---\n"
61
- puts "--- The Master Database (Before)\n"
62
- puts "---\n"
63
- puts JSON.pretty_generate( master_db )
64
- puts "---\n"
65
-
66
- return if unopened_envelope?( master_db )
67
-
68
- envelope_id = ENVELOPE_KEY_PREFIX + master_db[ ENV_PATH ]
69
- has_content = KeyApi.db_envelope_exists?( master_db[ envelope_id ] )
70
-
71
- # --
72
- # -- To get hold of the content we must either
73
- # --
74
- # -- a) unlock it using the breadcrumbs or
75
- # -- b) start afresh with a new content db
76
- # --
77
- content_box = KeyDb.from_json( KeyApi.content_unlock( master_db[ envelope_id ] ) ) if has_content
78
- content_box = KeyDb.new() unless has_content
79
- content_hdr = create_header()
80
-
81
- # --
82
- # -- If no content envelope exists we need to place
83
- # -- an empty one inside the appdb content database.
84
- # --
85
- master_db[ envelope_id ] = {} unless has_content
86
-
87
- # --
88
- # -- This is the PUT use case so we append a
89
- # --
90
- # -- a) key for the new dictionary entry
91
- # -- b) value for the new dictionary entry
92
- # --
93
- # -- into the current content envelope and write
94
- # -- the envelope to the content filepath.
95
- # --
96
- crumbs_dict = master_db[ envelope_id ]
97
- content_box.create_entry( master_db[ KEY_PATH ], @secret_id, @secret_value )
98
- KeyApi.content_lock( crumbs_dict, content_box.to_json, content_hdr )
99
-
100
- puts "---\n"
101
- puts "--- The Master Database (After)\n"
102
- puts "---\n"
103
- puts JSON.pretty_generate( master_db )
104
- puts "---\n"
105
-
106
- # --
107
- # -- Three envelope crumbs namely the external ID, the
108
- # -- random iv and the crypt key are written afreshinto
109
- # -- the master database.
110
- # --
111
- KeyApi.write_master_db( content_hdr, master_db )
112
- print_put_success
113
-
114
- return
115
-
116
-
117
- # ---> secret_ids = @secret_id.split("/")
118
- # ---> if ( envelope.has_key? secret_ids.first )
119
- # ---> envelope[secret_ids.first][secret_ids.last] = @secret_value
120
- # ---> else
121
- # ---> envelope[secret_ids.first] = { secret_ids.last => @secret_value }
122
- # ---> end
123
-
124
- end
125
-
126
-
127
- private
128
-
129
-
130
- def print_put_success
131
-
132
- puts ""
133
- puts "Success putting a key/value pair into the open envelope."
134
- puts "You can put more in and then close the envelope."
135
- puts ""
136
- puts " #{COMMANDMENT} close"
137
- puts ""
138
-
139
- end
140
-
141
-
142
- # Perform pre-conditional validations in preparation to executing the main flow
143
- # of events for this use case. This method may throw the below exceptions.
144
- #
145
- # @raise [SafeDirNotConfigured] if the safe's url has not been configured
146
- # @raise [EmailAddrNotConfigured] if the email address has not been configured
147
- # @raise [StoreUrlNotConfigured] if the crypt store url is not configured
148
- def pre_validation
149
-
150
-
151
- end
152
-
153
-
154
- end
155
-
156
-
157
- end