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
@@ -3,10 +3,10 @@
3
3
  module SafeDb
4
4
 
5
5
 
6
- # This class is the parent to all opensession errors
6
+ # This class is the parent to all openbranch errors
7
7
  # that originate from the command line.
8
8
  #
9
- # All opensession cli originating errors are about
9
+ # All openbranch cli originating errors are about
10
10
  #
11
11
  # - a problem with the input or
12
12
  # - a problem with the current state or
@@ -43,14 +43,14 @@ module SafeDb
43
43
  assert_min_size MINIMUM_PASSWORD_SIZE
44
44
 
45
45
  sleep(1)
46
- puts "Password:"
46
+ puts "Enter Password:"
47
47
  first_secret = STDIN.noecho(&:gets).chomp
48
48
 
49
49
  assert_input_text_size first_secret.length, MINIMUM_PASSWORD_SIZE
50
50
  return first_secret unless prompt_twice
51
51
 
52
52
  sleep(1)
53
- puts "Re-enter the password:"
53
+ puts "Re-enter Password:"
54
54
  check_secret = STDIN.noecho(&:gets).chomp
55
55
 
56
56
  assert_same_size_text first_secret, check_secret
File without changes
@@ -143,12 +143,16 @@ module SafeDb
143
143
 
144
144
 
145
145
  def self.to_random_bits the_byte_length
146
+
147
+ require 'securerandom'
148
+
146
149
  random_bit_string = ""
147
150
  for n in 1 .. the_byte_length
148
151
  random_integer = SecureRandom.random_number( EIGHT_BIT_INTEGER_SIZE )
149
152
  random_bit_string += "%08d" % [ random_integer.to_s(2) ]
150
153
  end
151
154
  return random_bit_string
155
+
152
156
  end
153
157
 
154
158
 
@@ -271,7 +275,7 @@ module SafeDb
271
275
  # If the bit value string for this key is nil.
272
276
  # Or if the bit string length is not a multiple of six.
273
277
  # Or if it contains any character that is not a 1 or 0.
274
- def to_char64
278
+ def to_char64()
275
279
  assert_non_nil_bits
276
280
  return Key64.from_bits( @bit_string )
277
281
  end
@@ -288,7 +292,7 @@ module SafeDb
288
292
  # @return [Byte]
289
293
  # a non-printable binary string of eight (8) bit bytes which can be
290
294
  # used as input to both digest and symmetric cipher functions.
291
- def to_binary
295
+ def to_binary()
292
296
  return [ to_s ].pack("B*")
293
297
  end
294
298
 
File without changes
@@ -1,5 +1,5 @@
1
1
  require "logger"
2
- require "session/user.home"
2
+
3
3
 
4
4
  # [MIXIN] magic is deployed to hand out DevOps quality logging
5
5
  # features to any class that includes the logging module.
@@ -22,12 +22,12 @@ require "session/user.home"
22
22
  # Refer to the below link for excellent coverage of mixins.
23
23
  # @see http://ruby-doc.com/docs/ProgrammingRuby/html/tut_modules.html
24
24
  #
25
- module OpenLogger
25
+ module LogImpl
26
26
 
27
27
  @@gem_name = "safedb.net"
28
- @@gem_base = File.join OpenSession::Home.dir, ".#{@@gem_name}"
29
- FileUtils.mkdir_p @@gem_base unless File.exists? @@gem_base
30
- @@log_path = File.join @@gem_base, "safedb.net-cli.log"
28
+ @@gem_base = File.join( Dir.home(), ".#{@@gem_name}" )
29
+ FileUtils.mkdir_p( @@gem_base ) unless File.exists?( @@gem_base )
30
+ @@log_path = File.join( @@gem_base, "safedb-summary.log" )
31
31
 
32
32
 
33
33
  # Classes that include (MIXIN) this logging module will
@@ -88,6 +88,7 @@ module OpenLogger
88
88
  def get_logger
89
89
 
90
90
  file_logger = Logger.new @@log_path
91
+ file_logger.level = Logger::INFO
91
92
  original_formatter = Logger::Formatter.new
92
93
 
93
94
  file_logger.formatter = proc { |severity, datetime, progname, msg|
@@ -5,7 +5,7 @@ module SafeDb
5
5
 
6
6
  require 'inifile'
7
7
 
8
- # KeyPair is a <b>key-value</b> store backed by a plain-text file in
8
+ # DataMap is a <b>key-value</b> store backed by a plain-text file in
9
9
  # an <b>INI format</b> that sits on an accessible file-system.
10
10
  #
11
11
  #
@@ -13,11 +13,11 @@ module SafeDb
13
13
  #
14
14
  # Issue the below ruby calls and specify a /path/to/file
15
15
  #
16
- # keymap = KeyPair.new "/path/to/file"
16
+ # datamap = DataMap.new ( "/path/to/file" )
17
17
  #
18
- # keymap.use "phone_numbers"
19
- # keymap.set "joe", "0044 7500 123456"
20
- # keymap.set "amy", "0044 7678 123456"
18
+ # datamap.use ( "phone_numbers" )
19
+ # datamap.set ( "joe", "0044 7500 123456" )
20
+ # datamap.set ( "amy", "0044 7678 123456" )
21
21
  #
22
22
  # Now visit the file to see your exchanged data.
23
23
  #
@@ -35,7 +35,7 @@ module SafeDb
35
35
  # You do not need a new object to switch sections - just go ahead and
36
36
  # use another another one.
37
37
  #
38
- # Remember that KeyPair is <b>two-dimensional</b> data structure so all
38
+ # Remember that DataMap is <b>two-dimensional</b> data structure so all
39
39
  # key-value pairs are stored under the auspices of a section.
40
40
  #
41
41
  # == Key-Value Pair Exchanges
@@ -47,7 +47,7 @@ module SafeDb
47
47
  #
48
48
  # The name given to the default group can be specified to the constructor.
49
49
  # If none is provided the aptly named "default" is used.
50
- class KeyPair
50
+ class DataMap
51
51
 
52
52
  # Initialize the key value store and auto write a time stamp that
53
53
  # has nano-second accuracy with a key whose name is gleened from
@@ -64,9 +64,9 @@ module SafeDb
64
64
  # @param the_default_group [String]
65
65
  # the name of the default group. If none is presented this value
66
66
  # will default to the aptly named "default".
67
- def initialize backing_file_path
67
+ def initialize( backing_file_path )
68
68
  @file_path = backing_file_path
69
- create_dir_if_necessary
69
+ create_dir_unless_exists()
70
70
  end
71
71
 
72
72
 
@@ -76,7 +76,7 @@ module SafeDb
76
76
  # @param the_section_name [String]
77
77
  # the non-nil and non whitespace only section name that will lead a
78
78
  # set of key-value pairs in the INI formatted file.
79
- def use the_section_name
79
+ def use( the_section_name )
80
80
  raise ArgumentError, "Cannot use a Nil section name." if the_section_name.nil?
81
81
  @section_to_use = the_section_name
82
82
  end
@@ -86,7 +86,7 @@ module SafeDb
86
86
  #
87
87
  # @param key_name [String] the name of the key whose value is to be written
88
88
  # @param key_value [String] the data item value of the key specified
89
- def set key_name, key_value
89
+ def set( key_name, key_value )
90
90
  raise ArgumentError, "Cannot set a Nil section name." if @section_to_use.nil?
91
91
  write @section_to_use, key_name, key_value
92
92
  end
@@ -98,14 +98,25 @@ module SafeDb
98
98
  # @param key_name [String] the name of the key whose value is to be written
99
99
  # @return [String]
100
100
  # return the value of the configuration directive in the default group
101
- def get key_name
101
+ def get( key_name )
102
102
  raise ArgumentError, "Cannot get from a Nil section name." if @section_to_use.nil?
103
- read @section_to_use, key_name
103
+ read( @section_to_use, key_name )
104
+ end
105
+
106
+
107
+ # Return the name of the currently in-focus section that has been set using
108
+ # the {use} method.
109
+ #
110
+ # @return [String]
111
+ # return the name of the currently in-focus section
112
+ def section()
113
+ raise ArgumentError, "The use method has not specified a section." if @section_to_use.nil?
114
+ return @section_to_use
104
115
  end
105
116
 
106
117
 
107
118
  # Write the key/value pair in the parameter into this key/value store's
108
- # base file-system backing INI file.
119
+ # backing INI file.
109
120
  #
110
121
  # This method assumes the existence of the backing configuration file at
111
122
  # the @file_path instance variable that was set during initialization.
@@ -120,12 +131,12 @@ module SafeDb
120
131
  # @param key [String] the key name of config directive to be written into the file
121
132
  # @param value [String] value of the config directive to be written into the file
122
133
  #
123
- def write section_name, key, value
134
+ def write( section_name, key, value )
124
135
 
125
- config_map = IniFile.new( :filename => @file_path, :encoding => 'UTF-8' )
126
- config_map = IniFile.load( @file_path ) if File.file? @file_path
127
- config_map[section_name][key] = value
128
- config_map.write
136
+ data_map = IniFile.new( :filename => @file_path, :encoding => 'UTF-8' )
137
+ data_map = IniFile.load( @file_path ) if File.file? @file_path
138
+ data_map[section_name][key] = value
139
+ data_map.write
129
140
 
130
141
  end
131
142
 
@@ -142,7 +153,7 @@ module SafeDb
142
153
  # cause the key value to not be retrieved. This can range from
143
154
  # non-existent directories and files, non readable files, incorrect
144
155
  # configurations right down to missing keys or even missing values.
145
- def read section_name, key_name
156
+ def read( section_name, key_name )
146
157
 
147
158
  raise ArgumentError.new "No section given." if section_name.nil? || section_name.strip.empty?
148
159
  raise ArgumentError.new "No parameter key given." if key_name.nil? || key_name.strip.empty?
@@ -184,7 +195,7 @@ module SafeDb
184
195
  # raise [ArgumentError]
185
196
  # if the configuration file does not exist or is empty
186
197
  # if the paramter key_name is nil, empty or contains only whitespace
187
- def contains? key_name
198
+ def contains?( key_name )
188
199
 
189
200
  raise ArgumentError.new "No parameter key given." if key_name.nil? || key_name.strip.empty?
190
201
  raise ArgumentError.new "No file found at [ #{@file_path} ]" unless File.exists? @file_path
@@ -198,7 +209,6 @@ module SafeDb
198
209
  end
199
210
 
200
211
 
201
-
202
212
  # Return true if the settings configuration file contains the specified
203
213
  # section name. This method ignores whatever section that may or may not
204
214
  # have been pointed to by the use command.
@@ -208,7 +218,7 @@ module SafeDb
208
218
  #
209
219
  # @return [Boolean]
210
220
  # return true if a section exists with the specified name
211
- def has_section? section_name
221
+ def has_section?( section_name )
212
222
 
213
223
  KeyError.not_new( section_name, self )
214
224
 
@@ -222,7 +232,6 @@ module SafeDb
222
232
  end
223
233
 
224
234
 
225
-
226
235
  # Get the time stamp that was written to the key-value store at
227
236
  # the point it was first initialized and then subsequently written
228
237
  # out (serialized) onto the file-system.
@@ -234,21 +243,30 @@ module SafeDb
234
243
  # the string time stamp denoting the first time this key-value
235
244
  # store was first initialized and then subsequently written out
236
245
  # (serialized) onto the file-system.
237
- def time_stamp
246
+ def time_stamp()
238
247
  return get INIT_TIME_STAMP_NAME
239
248
  end
240
249
 
241
250
 
251
+ # Fetch this one-dimensional data store as a string in INI file format.
252
+ # @return [String] an INI formatted string representation of this data
253
+ def as_string()
254
+
255
+ data_map = IniFile.new( :filename => @file_path, :encoding => 'UTF-8' )
256
+ data_map = IniFile.load( @file_path ) if File.file? @file_path
257
+ return data_map.to_s
258
+
259
+ end
242
260
 
243
- private
244
261
 
262
+ private
245
263
 
246
264
 
247
- def create_dir_if_necessary
265
+ def create_dir_unless_exists()
248
266
 
249
- config_directory = File.dirname @file_path
250
- return if (File.exist? config_directory) && (File.directory? config_directory)
251
- FileUtils.mkdir_p config_directory
267
+ file_dir = File.dirname( @file_path )
268
+ return if (File.exist? file_dir) && (File.directory? file_dir)
269
+ FileUtils.mkdir_p( file_dir )
252
270
 
253
271
  end
254
272
 
@@ -9,6 +9,16 @@ module SafeDb
9
9
  # (put, add etc) <b>after reading and then decrypting it</b> from a
10
10
  # file and <b>before encrypting and then writing it</b> to a file.
11
11
  #
12
+ # == Difference Between DataStore and DataStore
13
+ #
14
+ # The DataStore is a JSON backed store that streams to and from INI formatted
15
+ # data.
16
+ # The DataStore is preferred for human readable data which is
17
+ # precisely 2 dimensional. The streamed DataMap is JSON which
18
+ # at scale isn't human readable but the data structure is
19
+ # N dimensional and it supports nested structures such as
20
+ # lists, maps, numbers and booleans.
21
+ #
12
22
  # It provides behaviour to which we can create, append (add), update
13
23
  # (change), read parts and delete essentially two structures
14
24
  #
@@ -37,7 +47,7 @@ module SafeDb
37
47
  # - other hashes
38
48
  # - booleans
39
49
  # - integers and floats
40
- class KeyDb < Hash
50
+ class DataStore < Hash
41
51
 
42
52
  # Return a key database data structure that is instantiated from
43
53
  # the parameter JSON string.
@@ -46,18 +56,43 @@ module SafeDb
46
56
  # this json formatted data structure will be converted into a
47
57
  # a Ruby hash (map) data structure and returned.
48
58
  #
49
- # @return [KeyDb]
59
+ # @return [DataStore]
50
60
  # a hash data structure that has been instantiated as per the
51
61
  # parameter json string content.
52
62
  def self.from_json( db_json_string )
53
63
 
54
- data_db = KeyDb.new()
64
+ data_db = DataStore.new()
55
65
  data_db.merge!( JSON.parse( db_json_string ) )
56
66
  return data_db
57
67
 
58
68
  end
59
69
 
60
70
 
71
+ # Set the section to use for future data exchanges via the ubiquitous {get}
72
+ # and {set} methods as well as the query {contains} key method.
73
+ #
74
+ # @param section [String]
75
+ # the non-nil and non whitespace only section name that will lead a
76
+ # set of key-value pairs in the INI formatted file.
77
+ def use section
78
+ raise ArgumentError, "Cannot use a Nil section." if section.nil?
79
+ @section = section
80
+ end
81
+
82
+
83
+ # Stash the setting directive and its value into the configuration file
84
+ # using the default settings group.
85
+ #
86
+ # @param key_name [String] the name of the key whose value is to be written
87
+ # @param key_value [String] the data item value of the key specified
88
+ def set key_name, key_value
89
+ raise ArgumentError, "Cannot set a Nil (section)" if @section.nil?
90
+ raise ArgumentError, "Cannot set a Nil key name." if key_name.nil?
91
+ raise ArgumentError, "Cannot set a Nil key value" if key_value.nil?
92
+ create_entry( @section, key_name, key_value )
93
+ end
94
+
95
+
61
96
 
62
97
  # Create a new key value entry inside a dictionary with the specified
63
98
  # name at the root of this database. Successful completion means the
@@ -223,107 +258,6 @@ module SafeDb
223
258
  end
224
259
 
225
260
 
226
- # Read and inject into this envelope, the data structure found in a
227
- # file at the path specified in the first parameter.
228
- #
229
- # Symmetric cryptography is mandatory for the envelope so we must
230
- # <b>encrypt before writing</b> and <b>decrypt after reading</b>.
231
- #
232
- # An argument error will result if a suitable key is not provided.
233
- #
234
- # If the file does not exist (denoting the first read) all this method
235
- # does is to stash the filepath as an instance variable and igore the
236
- # decryption key which can be nil (or ommitted).
237
- #
238
- # @param the_filepath [String]
239
- # absolute path to the file which acts as the persistent mirror to
240
- # this data structure envelope.
241
- #
242
- # @param decryption_key [String]
243
- # encryption at rest is a given so this mandatory parameter must
244
- # contain a robust symmetric decryption key. The key will be used
245
- # for decryption after the read and it will not linger (ie not cached
246
- # as an instance variable).
247
- #
248
- # @raise [ArgumentError] if the decryption key is not robust enough.
249
- def read the_filepath, decryption_key = nil
250
-
251
- # @todo -> this is confused - it uses INI but above methods use JSON
252
- # @todo -> this is confused - it uses INI but above methods use JSON
253
- # @todo -> this is confused - it uses INI but above methods use JSON
254
- # @todo -> this is confused - it uses INI but above methods use JSON
255
- # @todo -> this is confused - it uses INI but above methods use JSON
256
- # @todo -> this is confused - it uses INI but above methods use JSON
257
- # @todo -> this is confused - it uses INI but above methods use JSON
258
- # @todo -> this is confused - it uses INI but above methods use JSON
259
- # @todo -> this is confused - it uses INI but above methods use JSON
260
- # @todo -> this is confused - it uses INI but above methods use JSON
261
-
262
- raise RuntimeError, "This KeyDb.read() software is never called so how can I be here?"
263
-
264
- @filepath = the_filepath
265
- return unless File.exists? @filepath
266
-
267
- cipher_text = Base64.decode64( File.read( @filepath ).strip )
268
- plain_text = ToolBelt::Blowfish.decryptor( cipher_text, decryption_key )
269
-
270
- data_structure = JSON.parse plain_text
271
- self.merge! data_structure
272
-
273
- end
274
-
275
-
276
- # Write the data in this envelope hash map into a file-system
277
- # backed mirror whose path was specified in the {self.read} method.
278
- #
279
- # Technology for encryption at rest is supported by this dictionary
280
- # and to this aim, please endeavour to post a robust symmetric
281
- # encryption key.
282
- #
283
- # Calling this {self.write} method when the file at the prescribed path
284
- # does not exist results in the directory structure being created
285
- # (if necessary) and then the encrypted file being written.
286
- #
287
- # @param encryption_key [String]
288
- # encryption at rest is a given so this mandatory parameter must
289
- # contain a robust symmetric encryption key. The symmetric key will
290
- # be used for the decryption after the read. Note that the decryption
291
- # key does not linger meaning it isn't cached in an instance variable.
292
- def write encryption_key
293
-
294
- # @todo -> this is confused - it uses INI but above methods use JSON
295
- # @todo -> this is confused - it uses INI but above methods use JSON
296
- # @todo -> this is confused - it uses INI but above methods use JSON
297
- # @todo -> this is confused - it uses INI but above methods use JSON
298
- # @todo -> this is confused - it uses INI but above methods use JSON
299
- # @todo -> this is confused - it uses INI but above methods use JSON
300
- # @todo -> this is confused - it uses INI but above methods use JSON
301
- # @todo -> this is confused - it uses INI but above methods use JSON
302
- # @todo -> this is confused - it uses INI but above methods use JSON
303
-
304
- raise RuntimeError, "This KeyDb.write( key ) software is never called so how can I be here?"
305
-
306
- FileUtils.mkdir_p(File.dirname(@filepath))
307
- cipher_text = Base64.encode64 ToolBelt::Blowfish.encryptor( self.to_json, encryption_key )
308
- File.write @filepath, cipher_text
309
-
310
- puts ""
311
- puts "=== ============================"
312
- puts "=== Envelope State ============="
313
- puts "=== ============================"
314
-
315
- a_ini_file = IniFile.new
316
- self.each_key do |section_name|
317
- a_ini_file[section_name] = self[section_name]
318
- end
319
- puts a_ini_file.to_s
320
-
321
- puts "=== ============================"
322
- puts ""
323
-
324
- end
325
-
326
-
327
261
  end
328
262
 
329
263