safedb 0.5.1005 → 0.7.1001

Sign up to get free protection for your applications and to get access to all the features.
Files changed (69) hide show
  1. checksums.yaml +4 -4
  2. data/CONTRIBUTING.md +1 -1
  3. data/genius-decision.txt +25 -0
  4. data/lib/cli.rb +155 -8
  5. data/lib/controller/{admin/auth.rb → abstract/authenticate.rb} +1 -2
  6. data/lib/controller/{controller.rb → abstract/controller.rb} +45 -24
  7. data/lib/controller/{edit/editverse.rb → abstract/edit_verse.rb} +0 -0
  8. data/lib/controller/{query/queryverse.rb → abstract/query_verse.rb} +0 -0
  9. data/lib/controller/{admin → access}/README.md +0 -0
  10. data/lib/controller/access/banner.txt +6 -0
  11. data/lib/controller/{admin → access}/init.rb +4 -4
  12. data/lib/controller/{admin → access}/login.rb +28 -23
  13. data/lib/controller/{admin → access}/logout.rb +0 -0
  14. data/lib/controller/{admin → access}/token.rb +0 -0
  15. data/lib/controller/{admin → access}/use.rb +0 -0
  16. data/lib/controller/api/docker/docker.rb +4 -22
  17. data/lib/controller/api/git/git.rb +104 -0
  18. data/lib/controller/api/terraform/README.md +23 -2
  19. data/lib/controller/api/terraform/terraform.rb +38 -7
  20. data/lib/controller/{admin → book}/commit.rb +2 -3
  21. data/lib/controller/{admin → book}/diff.rb +0 -0
  22. data/lib/controller/{admin → book}/export.rb +0 -0
  23. data/lib/controller/{admin → book}/import.rb +0 -0
  24. data/lib/controller/{admin → book}/refresh.rb +2 -2
  25. data/lib/controller/{admin → book}/view.rb +0 -0
  26. data/lib/{modules/storage/git.store.rb → controller/db/model_git_service.rb} +0 -0
  27. data/lib/controller/db/pull.rb +69 -0
  28. data/lib/controller/db/push.rb +352 -0
  29. data/lib/controller/db/remote.rb +108 -0
  30. data/lib/controller/edit/generate.rb +1 -1
  31. data/lib/controller/edit/keys.rb +72 -0
  32. data/lib/controller/edit/paste.rb +36 -0
  33. data/lib/controller/files/write.rb +11 -3
  34. data/lib/controller/misc/wipe.rb +23 -0
  35. data/lib/controller/navigate/at.rb +42 -0
  36. data/lib/controller/{admin → navigate}/goto.rb +0 -0
  37. data/lib/controller/{admin → navigate}/open.rb +0 -0
  38. data/lib/controller/query/copy.rb +32 -95
  39. data/lib/controller/query/tell.rb +36 -0
  40. data/lib/controller/requirer.rb +4 -4
  41. data/lib/controller/visit/README.md +34 -0
  42. data/lib/controller/visit/visit.rb +33 -0
  43. data/lib/manual/copy-paste.md +19 -2
  44. data/lib/{modules/README.md → manual/crypto-math.md} +0 -0
  45. data/lib/manual/push-pull.md +46 -0
  46. data/lib/manual/remote.md +62 -0
  47. data/lib/model/coordinates.rb +59 -0
  48. data/lib/model/{safe_tree.rb → file_tree.rb} +11 -6
  49. data/lib/model/indices.rb +113 -8
  50. data/lib/model/master.rb +40 -0
  51. data/lib/model/{state.migrate.rb → state_evolve.rb} +13 -5
  52. data/lib/model/{state.inspect.rb → state_query.rb} +5 -1
  53. data/lib/plugin/github.rb +53 -0
  54. data/lib/{modules/cryptology → utils/ciphers}/aes-256.rb +0 -0
  55. data/lib/{modules/cryptology → utils/ciphers}/blowfish.rb +0 -0
  56. data/lib/{modules/cryptology → utils/ciphers}/cipher.rb +0 -0
  57. data/lib/{modules/cryptology → utils/ciphers}/crypt.io.rb +0 -0
  58. data/lib/utils/keys/key.rb +44 -0
  59. data/lib/utils/keys/keypair.rb +52 -0
  60. data/lib/utils/logs/logger.rb +1 -1
  61. data/lib/utils/store/datastore.rb +1 -1
  62. data/lib/utils/store/github.rb +27 -0
  63. data/lib/utils/time/timestamp.rb +91 -0
  64. data/lib/version.rb +1 -1
  65. data/safedb.gemspec +2 -0
  66. metadata +75 -32
  67. data/lib/controller/verse.rb +0 -20
  68. data/lib/modules/storage/coldstore.rb +0 -186
  69. data/lib/utils/store/test-commands.sh +0 -24
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 637a4011eceb0a65ec0139c499d2494576ff9cfbdbd90c84907e9ed734753438
4
- data.tar.gz: 48ac523f4c4f0d457bdd6a9ddfa1ca87e5c19ee1deb62c49bd14a7129cda9aae
3
+ metadata.gz: 32727ae3d52f041e5049daf92f2bb09aa5783b7d78e8f837f77025dae5a711d7
4
+ data.tar.gz: 8d26aad01a827d65f85d2445154e8ee38fbbbbce04570cbc51bd38c198c73c1d
5
5
  SHA512:
6
- metadata.gz: c4064ea7b9b61840733de27aec02d99e2cd2fd9d60ad9b8b41b130a77cf0606a04c25229580b25c3bc5af472eab08727fbef4d33f0b13a970246091e64bc19ef
7
- data.tar.gz: 30c16510557f03cdcfdf4f78cf3c64f7701cfd8ca0418a6af2a11ff517071c5e2bbfced54cd401a31aa058bb1b50ae214f5894d4978a0d34d5daa1061bc601ea
6
+ metadata.gz: a552f7d3b9b958cfad7910f777d1f3d1bd3c91b6bca0b0625c19ddee0699683650d3109fe82934860474035dd51b4333ff3e212442cf56b317f567813ea60dfc
7
+ data.tar.gz: 25cec4ed1f64dcd2d0faa8b6423601d867eebb4527202266d31bff7d77df57d77687284d51fefb4fb6ea6befb4aa7398ead2e9632fe2a0c0fcc265efc2546ceb
data/CONTRIBUTING.md CHANGED
@@ -111,7 +111,7 @@ safe open <<chapter>> <<verse>>
111
111
  cd ~/.ssh
112
112
  safe eject github.ssh.config
113
113
  safe eject safedb.code.private.key
114
- chmod 600 safedb.code.private.key
114
+ chmod 600 safedb.code.private.key.pem
115
115
  cd <<repositories-folder>>
116
116
  ssh -i ~/.ssh/safedb.code.private.key.pem -vT git@safedb.code
117
117
  git clone https://github.com/devops4me/safedb.net safedb.net
@@ -0,0 +1,25 @@
1
+
2
+ ###########################################################################
3
+ Put the JSOn files together with the crypts in the same git repository
4
+ ###########################################################################
5
+
6
+
7
+ The bottom line to simplify is that everything goes up - the file
8
+
9
+ safe pull does not need any authentication
10
+ safe push requires you to be authenticated
11
+
12
+
13
+ Maybe safe pull will create a subdirectory in .safedb.net and then writes into a config (say json) file in ~/.safedb.net the directory name.
14
+ Maybe safe switch changes the safe database folder by writing that config file
15
+
16
+
17
+
18
+
19
+ Simplify the Safe
20
+
21
+ - safe pull https://github.com..../repo-name?branch-or-commit-name
22
+ - pull backs up the current directory into ~/.safe-backups
23
+
24
+ - safe push (will send wherever the pull came from)
25
+ - or safe push (from a verse uses the config in the verse to do the push
data/lib/cli.rb CHANGED
@@ -128,6 +128,17 @@ class CLI < Thor
128
128
 
129
129
 
130
130
 
131
+ # Description of the tell use case command line call.
132
+ desc "tell", "detail the secret key/value pairs that start with the @ symbol"
133
+
134
+ # Detail the secret key/value pairs that start with the @ symbol.
135
+ def tell
136
+ log.info(x) { "tell the secret key/value pairs that begin with the @ symbol." }
137
+ SafeDb::Tell.new().flow()
138
+ end
139
+
140
+
141
+
131
142
  # Description of the print use case command line call.
132
143
  desc "print <key_name>", "print the key value at the opened chapter and verse"
133
144
 
@@ -144,14 +155,48 @@ class CLI < Thor
144
155
 
145
156
 
146
157
 
147
- # Description of the verse use case command line call.
148
- desc "verse", "print the verse name at the opened chapter and verse"
158
+ # Description of the copy use case command line call.
159
+ desc "copy <line>", "copy a line value (at the current chapter/verse) into the clipboard."
160
+
161
+ # Copy into the clipboard the value held by the named line at the
162
+ # current book's open chapter and verse.
163
+ #
164
+ # This is more accurate and more secure than echoing the password and
165
+ # then performing a SELECT then COPY and then PASTE.
166
+ #
167
+ # Use <b>safe clear</b> to wipe (overwrite) the sensitive value in
168
+ # the clipboard.
169
+ #
170
+ # @param line [String] the name of the line whose data will be copied.
171
+ # If no line is given the default @password is assumed.
172
+ def copy( line = nil )
173
+ log.info(x) { "copy the line value at the current chpater/verse into the clipboard." }
174
+ copy_uc = SafeDb::Copy.new
175
+ copy_uc.line = line
176
+ copy_uc.flow()
177
+ end
178
+
179
+
180
+
181
+ # Description of the paste use case command line call.
182
+ desc "paste <line>", "paste a value into the line key which defaults to @password if not provided."
149
183
 
150
- # Print the name of the verse at the opened chapter and verse location.
151
- def verse
152
- log.info(x) { "print the verse name at the opened chapter and verse." }
153
- verse_uc = SafeDb::Verse.new
154
- verse_uc.flow()
184
+ # Paste the current clipboard or selection text into the specified line
185
+ # at the current book's open chapter and verse.
186
+ #
187
+ # Sensitive values now neither need to be put on the commnad line (safe put)
188
+ # or inputted perhaps with a typo when using (safe input).
189
+ #
190
+ # Use <b>safe wipe</b> to wipe (overwrite) any sensitive values that has
191
+ # been placed on the clipboard.
192
+ #
193
+ # @param line [String] the name of the line that the copied data will be
194
+ # placed alongside. The line either may or may not exist.
195
+ def paste( line = nil )
196
+ log.info(x) { "paste the line value within the clipboard into the current chpater/verse." }
197
+ paste_uc = SafeDb::Paste.new
198
+ paste_uc.line = line
199
+ paste_uc.flow()
155
200
  end
156
201
 
157
202
 
@@ -168,6 +213,17 @@ class CLI < Thor
168
213
 
169
214
 
170
215
 
216
+ # Description of the safe wipe use case.
217
+ desc "wipe", "Wipe both clipboards of any sensitive data that may exist there."
218
+
219
+ # The<b>wipe</b> use case clears out any sensitive information from the clipboard.
220
+ def wipe
221
+ log.info(x) { "wipe out any sensitive information from the clipboard." }
222
+ SafeDb::Wipe.new.flow()
223
+ end
224
+
225
+
226
+
171
227
  # Description of the open use case command.
172
228
  desc "open <chapter> <verse>", "open a chapter and verse to read from or write to"
173
229
 
@@ -293,6 +349,80 @@ class CLI < Thor
293
349
 
294
350
 
295
351
 
352
+ # Description of the remote command.
353
+ desc "remote --provision", "Create (provision) remote storage for the safe database (backend) crypt files."
354
+
355
+ # The <tt>--provision</tt> option conveys that we want to carve out
356
+ # some remote storage so that our database can be accessed by multiple
357
+ # machines in different corners of the globe.
358
+ method_option :provision, :type => :boolean, :aliases => "-p"
359
+
360
+ # Creates remote storage for the safe database crypt files.
361
+ def remote
362
+ log.info(x) { "performing a remote storage use case. The provision flag is set to #{options[ :provision ]}." }
363
+ remote_uc = SafeDb::Remote.new()
364
+ remote_uc.provision = true if options[ :provision ]
365
+ remote_uc.provision = false unless options[ :provision ]
366
+ remote_uc.flow()
367
+ end
368
+
369
+
370
+
371
+ # Description of the safe git command.
372
+ desc "git --clone", "Clone the remote repository whose properties are in the current chapter and verse."
373
+
374
+ # If the --clone switch is included this class will expect to be at a verse
375
+ # that contains either a github token, username, reponame combination or a
376
+ # publicly publicly clonable url, or ssh url with the private keys and SSH host
377
+ # configuration already setup.
378
+
379
+ # If the --push switch is included this class will expect to be at a verse
380
+ # that has a path to a git url within it. If this is missing the present working
381
+ # directory is assumed to be the git repository in question.
382
+ #
383
+ # If the verse contains a branch name which is not the current branch then
384
+ # we raise a query to the user instead of pushing to the wrong place. This is
385
+ # a good double (sanity) check.
386
+
387
+
388
+ # If the --push switch is included this class will expect to be at a verse
389
+ # that has a path to a git url within it. If this is missing the present working
390
+ # directory is assumed to be the git repository in question.
391
+
392
+ # If the --no-ssl-verify switch is passed into this class it will urge git not
393
+ # to worry when a site does not have a (presently) trusted SSL certificate.
394
+
395
+ # If the --to switch has a value which is a path to a local (possibly non-existing)
396
+ # folder to clone to - this will override the verse line git.clone.path
397
+
398
+ ##### method_option :provision, :type => :boolean, :aliases => "-p"
399
+
400
+
401
+ def git
402
+ log.info(x) { "performing a git repository interaction." }
403
+ #### git_uc = SafeDb::Git.new()
404
+ ##### remote_uc.provision = true if options[ :provision ]
405
+ ##### remote_uc.provision = false unless options[ :provision ]
406
+ #### git_uc.flow()
407
+ SafeDb::Git.new().flow()
408
+ end
409
+
410
+
411
+
412
+ # Description of the safe database push command.
413
+ desc "push", "push crypts to github and put index keys on removable drive"
414
+
415
+ # After backing up local assets the <b>push use case</b> creates a remoe github
416
+ # repository if necessary and initializes the master crypts as a git repository
417
+ # if necessary and then adds, commits and pushes the crypts up to the github
418
+ # remote for safe keeping.
419
+ def push
420
+ log.info(x) { "push crypt assets to github and refresh the index keys on removable drive." }
421
+ SafeDb::Push.new().flow()
422
+ end
423
+
424
+
425
+
296
426
  # Description of the set configuration directives command.
297
427
  desc "set <directive_name> <directive_value>", "set book-scoped configuration directive"
298
428
 
@@ -362,6 +492,21 @@ class CLI < Thor
362
492
  end
363
493
 
364
494
 
495
+ # Description of the safe keys command.
496
+ desc "keys <name>", "create a public/private keypair against the given name."
497
+
498
+ # The default action of the <b>keys use case</b> is to create a private and
499
+ # public keypair and store them within the open chapter and verse.
500
+ # @param keypair_name [String] optional name of the keypair (for example gitlab)
501
+ def keys( keypair_name = nil )
502
+ log.info(x) { "Generate an elliptic curve private and public cryptographic keys." }
503
+ log.info(x) { "The keypair name [ #{keypair_name} ] was given." } if keypair_name
504
+ keys_uc = SafeDb::Keys.new
505
+ keys_uc.keypair_name = keypair_name if keypair_name
506
+ keys_uc.flow()
507
+ end
508
+
509
+
365
510
 
366
511
  # Description of the read command.
367
512
  desc "read <file_url>", "read file into the open chapter and verse for safe keeping."
@@ -381,7 +526,7 @@ class CLI < Thor
381
526
 
382
527
 
383
528
  # Description of the write command.
384
- desc "write <file_key>", "write out file to current folder or use --to_dir=</path/to/dir."
529
+ desc "write <file_key>", "write out file to current folder or use --to_dir=/path/to/dir."
385
530
 
386
531
  # The <b>write use case</b> writes out a file that was previously ingested
387
532
  # and coccooned inside the safe.
@@ -464,6 +609,8 @@ class CLI < Thor
464
609
  log.info(x) { "will export IAM credentials then invoke $ terraform #{command}" }
465
610
  terraform_uc = SafeDb::Terraform.new
466
611
  terraform_uc.command = command if command
612
+ terraform_uc.debug = true if options[ :debug ]
613
+ terraform_uc.debug = false unless options[ :debug ]
467
614
  terraform_uc.flow()
468
615
  end
469
616
 
@@ -4,7 +4,7 @@ module SafeDb
4
4
 
5
5
  # Parent to use cases like Init and Login that perform early
6
6
  # initialize workflows.
7
- class Auth < Controller
7
+ class Authenticate < Controller
8
8
 
9
9
  # This authorization use case should always have a book name
10
10
  # provided and sometimes may have a password parameter.
@@ -21,7 +21,6 @@ module SafeDb
21
21
  # at the <b>next login</b>.
22
22
  def is_book_initialized?()
23
23
 
24
- KeyError.not_new( @book_name, self )
25
24
  return false unless File.exists?( Indices::MASTER_INDICES_FILEPATH )
26
25
  data_map = DataMap.new( Indices::MASTER_INDICES_FILEPATH )
27
26
  return false unless data_map.has_section?( @book_id )
@@ -39,7 +39,7 @@ module SafeDb
39
39
  return if is_no_token_uc
40
40
  exit(100) unless ops_key_exists?
41
41
 
42
- is_login_uc = class_name.eql?( "login" )
42
+ is_login_uc = [ "login", "push", "pull" ].include? class_name
43
43
  return if is_login_uc
44
44
 
45
45
  not_logged_in = StateInspect.not_logged_in?()
@@ -65,6 +65,49 @@ module SafeDb
65
65
  end
66
66
 
67
67
 
68
+ # Login to the book and open the chapter and verse location that holds
69
+ # information about the remote backend that we push and pull to.
70
+ #
71
+ # To do this we must discover which book, chapter and verse holds
72
+ # the backend storage properties. This information should be available
73
+ # in the master keys file set by <tt>safe remote --provision</tt>
74
+ #
75
+ # After this call the @verse key/value map will contain properties
76
+ # pertaining to the safe#s backend remote store.
77
+ def open_remote_backend_location
78
+
79
+ verse_coordinates = Master.new().get_backend_coordinates()
80
+ the_book_id = verse_coordinates.split("/")[0]
81
+ the_chapter = verse_coordinates.split("/")[1]
82
+ the_verse = verse_coordinates.split("/")[2]
83
+
84
+ puts ""
85
+ puts "Will login to book with id #{the_book_id}"
86
+
87
+ login_uc = Login.new()
88
+ login_uc.login_book_id = the_book_id
89
+ login_uc.suppress_output = true
90
+ login_uc.flow()
91
+
92
+ puts "Login successful. Opening #{the_chapter}/#{the_verse}"
93
+
94
+ @book = Book.new()
95
+ @book.set_open_chapter_name( the_chapter )
96
+ @book.set_open_verse_name( the_verse )
97
+ @verse = @book.get_open_verse_data()
98
+ @book.write_open_chapter()
99
+
100
+ end
101
+
102
+
103
+
104
+ # Set the verse data structure for this controller. Usually called
105
+ # from another controller that wants to pass in a predefined map.
106
+ # @param incoming_verse [Hash] the incoming verse map to set
107
+ def set_verse( incoming_verse )
108
+ @verse = incoming_verse
109
+ end
110
+
68
111
  # This parental behaviour decrypts and reads the ubiquitous chapter and verse
69
112
  # data structures and indices.
70
113
  def read_verse()
@@ -198,14 +241,12 @@ module SafeDb
198
241
 
199
242
  def ops_key_exists?
200
243
 
201
- log_env()
202
-
203
244
  if ( ENV.has_key? ENV_VAR_KEY_NAME )
204
245
  return true
205
246
  end
206
247
 
207
248
  puts ""
208
- puts "safe needs you to create a branch key."
249
+ puts "safe needs you to create a shell token."
209
250
  puts "To automate this step see the documentation."
210
251
  puts "To create the key run the below command."
211
252
  puts ""
@@ -220,26 +261,6 @@ module SafeDb
220
261
  end
221
262
 
222
263
 
223
- def log_env()
224
-
225
- log.debug(x) { "Gem Root Folder => #{Gem.dir()}" }
226
- log.debug(x) { "Gem Config File => #{Gem.config_file()}" }
227
- log.debug(x) { "Gem Binary Path => #{Gem.default_bindir()}" }
228
- log.debug(x) { "Gem Host Path => #{Gem.host()}" }
229
- log.debug(x) { "Gem Caller Folder => #{Gem.location_of_caller()}" }
230
- log.debug(x) { "Gem Paths List => #{Gem.path()}" }
231
- log.debug(x) { "Gem Platforms => #{Gem.platforms()}" }
232
- log.debug(x) { "Gem Ruby Version X => #{Gem.ruby()}" }
233
- log.debug(x) { "Gem Ruby Version Y => #{Gem::VERSION}" }
234
- log.debug(x) { "Gem Ruby Version Z => #{Gem.latest_rubygems_version()}" }
235
- log.debug(x) { "Gem User Folder => #{Gem.user_dir()}" }
236
- log.debug(x) { "Gem User Home => #{Gem.user_home()}" }
237
-
238
- return
239
-
240
- end
241
-
242
-
243
264
  end
244
265
 
245
266
 
File without changes
@@ -0,0 +1,6 @@
1
+
2
+
3
+ __| __| __|
4
+ _| ( \__ \ The World's First Personal Database
5
+ ____|\___|____/
6
+
@@ -28,12 +28,12 @@ module SafeDb
28
28
  # - the book name ( maybe from SAFE_BOOK_NAME ) follows convention
29
29
  # - the shell must have a SAFE_TTY_TOKEN environment variable
30
30
  #
31
- class Init < Auth
31
+ class Init < Authenticate
32
32
 
33
33
 
34
34
  def execute
35
35
 
36
- # @todo => in parent class Auth validate the book name
36
+ # @todo => in parent class Authenticate validate the book name
37
37
 
38
38
 
39
39
  @book_id = Identifier.derive_ergonomic_identifier( @book_name, Indices::SAFE_BOOK_ID_LENGTH )
@@ -43,7 +43,7 @@ module SafeDb
43
43
  return
44
44
  end
45
45
 
46
- StateMigrate.create_book( @book_id )
46
+ EvolveState.create_book( @book_id )
47
47
 
48
48
  # @todo => search for password in environment variable
49
49
 
@@ -53,7 +53,7 @@ module SafeDb
53
53
  master_keys = DataMap.new( Indices::MASTER_INDICES_FILEPATH )
54
54
  master_keys.use( @book_id )
55
55
 
56
- StateMigrate.recycle_both_keys(
56
+ EvolveState.recycle_both_keys(
57
57
  @book_id,
58
58
  book_secret,
59
59
  master_keys,
@@ -23,18 +23,29 @@ module SafeDb
23
23
  # - a file in the present directory (with a pre-agreed name)
24
24
  # - a URL from a parameter or pre-agreed
25
25
  # - the shell's secure password reader
26
- class Login < Auth
26
+ class Login < Authenticate
27
+
28
+ # DELETE ME ####################### attr_writer :clip, :login_book_id, :suppress_output
27
29
 
28
30
  # If the clip switch is present it signifies that the password should
29
31
  # be read in from the clipboard. Any text selection puts text into the
30
32
  # the clipboard - no need specifically to use Ctrl-c (copy).
31
33
  attr_writer :clip
32
34
 
33
- def execute
35
+ # Either the @book_name or the @login_book_id may be provided. The
36
+ # @login_book_id takes precedence if both are provided.
37
+ attr_writer :login_book_id
34
38
 
35
- # @todo => in parent class Auth validate the book name
39
+ # The view of chapter and verse names within the book is not printed out
40
+ # after a successful login if this suppress_output flag is set to true.
41
+ attr_writer :suppress_output
42
+
43
+ def execute
36
44
 
37
- @book_id = Identifier.derive_ergonomic_identifier( @book_name, Indices::SAFE_BOOK_ID_LENGTH )
45
+ @book_id = @login_book_id if @login_book_id
46
+ @book_id = Identifier.derive_ergonomic_identifier( @book_name, Indices::SAFE_BOOK_ID_LENGTH ) unless @login_book_id
47
+ @book_reference = @login_book_id if @login_book_id
48
+ @book_reference = @book_name unless @login_book_id
38
49
 
39
50
  unless ( is_book_initialized?() )
40
51
  print_not_initialized
@@ -42,24 +53,22 @@ module SafeDb
42
53
  end
43
54
 
44
55
  if( StateInspect.is_logged_in?( @book_id ) )
45
- StateMigrate.use_book( @book_id )
46
- View.new().flow()
56
+ EvolveState.use_book( @book_id )
57
+ View.new().flow() unless @suppress_output
47
58
  return
48
59
  end
49
60
 
50
- # @todo => search for password in environment variable
51
-
52
61
  book_password = Clipboard.read_password() if @clip
53
62
  book_password = KeyPass.password_from_shell( false ) if( @password.nil?() && !@clip )
54
63
  book_password = @password unless @password.nil?()
55
64
 
56
- # @todo => if password is correct - if not print out an error.
57
-
58
65
  book_keys = DataMap.new( Indices::MASTER_INDICES_FILEPATH )
59
66
  book_keys.use( @book_id )
67
+ is_login_successful = EvolveState.login( book_keys, book_password )
68
+ print_login_failure() unless is_login_successful
69
+ return unless is_login_successful
60
70
 
61
- StateMigrate.login( book_keys, book_password )
62
- View.new().flow()
71
+ View.new().flow() unless @suppress_output
63
72
 
64
73
  end
65
74
 
@@ -67,28 +76,24 @@ module SafeDb
67
76
  private
68
77
 
69
78
 
70
- def print_already_logged_in
79
+ def print_login_failure()
71
80
 
72
81
  puts ""
73
- puts "We are already logged in. Open a secret envelope, put, then seal."
74
- puts ""
75
- puts " #{COMMANDMENT} open aws.credentials:s3reader"
76
- puts " #{COMMANDMENT} put access_key ABCD1234"
77
- puts " #{COMMANDMENT} put secret_key FGHIJ56789"
78
- puts " #{COMMANDMENT} put region_key eu-central-1"
79
- puts " #{COMMANDMENT} seal"
82
+ puts "The login into book [ #{@book_reference} ] has failed."
83
+ puts "Please check the book name and password combination."
84
+ puts "Also visit login docs on how to present passwords."
80
85
  puts ""
81
86
 
82
87
  end
83
88
 
84
89
 
85
- def print_not_initialized
90
+ def print_not_initialized()
86
91
 
87
92
  puts ""
88
- puts "This book [ #{@book_name} ] has not yet been initialized."
93
+ puts "This book [ #{@book_reference} ] has not yet been initialized."
89
94
  puts "Please initialize it with this command."
90
95
  puts ""
91
- puts " #{COMMANDMENT} init #{@book_name}"
96
+ puts " #{COMMANDMENT} init #{@book_reference}"
92
97
  puts ""
93
98
 
94
99
  end
File without changes
File without changes
File without changes
@@ -7,34 +7,16 @@ module SafeDb
7
7
  # safe docker login
8
8
  # safe docker logout
9
9
 
10
- class Docker < Controller
10
+ class Docker < QueryVerse
11
11
 
12
12
  # The command which currently must be login, logout or
13
13
  # an empty string.
14
14
  attr_writer :command
15
15
 
16
- def execute
16
+ def query_verse()
17
17
 
18
- return unless ops_key_exists?
19
- master_db = get_master_database()
20
- return if unopened_envelope?( master_db )
21
-
22
- # Get the open chapter identifier (id).
23
- # Decide whether chapter already exists.
24
- # Then get (or instantiate) the chapter's hash data structure
25
- chapter_id = ENVELOPE_KEY_PREFIX + master_db[ ENV_PATH ]
26
- verse_id = master_db[ KEY_PATH ]
27
- chapter_exists = KeyApi.db_envelope_exists?( master_db[ chapter_id ] )
28
-
29
- # Unlock the chapter data structure by supplying
30
- # key/value mini-dictionary breadcrumbs sitting
31
- # within the master database at the section labelled
32
- # envelope@<<actual_chapter_id>>.
33
- chapter_data = DataStore.from_json( Lock.content_unlock( master_db[ chapter_id ] ) )
34
-
35
- key_value_dictionary = chapter_data[ verse_id ]
36
- docker_username = key_value_dictionary[ "docker.username" ]
37
- docker_password = key_value_dictionary[ "@docker.password" ]
18
+ docker_username = @verse[ "docker.username" ]
19
+ docker_password = @verse[ "@docker.password" ]
38
20
  docker_login_cmd = "docker login --username #{docker_username} --password #{docker_password} 2>/dev/null"
39
21
  docker_logout_cmd = "docker logout"
40
22
  docker_cmd = @command.eql?( "logout" ) ? docker_logout_cmd : docker_login_cmd
@@ -0,0 +1,104 @@
1
+ #!/usr/bin/ruby
2
+
3
+ module SafeDb
4
+
5
+ class Git < QueryVerse
6
+
7
+ # If the --clone switch is included this class will expect to be at a verse
8
+ # that contains either a github token, username, reponame combination or a
9
+ # publicly publicly clonable url, or ssh url with the private keys and SSH host
10
+ # configuration already setup.
11
+ attr_writer :clone
12
+
13
+ # If the --push switch is included this class will expect to be at a verse
14
+ # that has a path to a git url within it. If this is missing the present working
15
+ # directory is assumed to be the git repository in question.
16
+ #
17
+ # If the verse contains a branch name which is not the current branch then
18
+ # we raise a query to the user instead of pushing to the wrong place. This is
19
+ # a good double (sanity) check.
20
+ attr_writer :push
21
+
22
+ # If the --push switch is included this class will expect to be at a verse
23
+ # that has a path to a git url within it. If this is missing the present working
24
+ # directory is assumed to be the git repository in question.
25
+ attr_writer :pull
26
+
27
+ # If the --no-ssl-verify switch is passed into this class it will urge git not
28
+ # to worry when a site does not have a (presently) trusted SSL certificate.
29
+ attr_writer :no_ssl_verify
30
+
31
+ # If the --to switch has a value which is a path to a local (possibly non-existing)
32
+ # folder to clone to - this will override the verse line git.clone.path
33
+ attr_writer :to
34
+
35
+
36
+ def query_verse()
37
+
38
+ puts ""
39
+
40
+ require "octokit"
41
+
42
+ git_repository_name = @verse[ Indices::GIT_REPOSITORY_NAME_KEYNAME ]
43
+ git_repository_user = @verse[ Indices::GIT_REPOSITORY_USER_KEYNAME ]
44
+ git_repository_host = @verse[ Indices::GIT_REPOSITORY_HOST_KEYNAME ]
45
+ git_repository_id = "#{git_repository_user}/#{git_repository_name}"
46
+
47
+ =begin
48
+ # Clone repo using the github token
49
+ github_access_token = @verse[ Indices::GITHUB_ACCESS_TOKEN ]
50
+ git_repository_url = "https://#{github_access_token}@github.com/#{git_repository_id}"
51
+ =end
52
+
53
+ # Clone repo using a SSH public/private keypair
54
+ git_repository_url = "git@#{git_repository_host}:#{git_repository_id}"
55
+ non_existent_path = File.join( get_clone_directory(), git_repository_name )
56
+
57
+ log.info(x) { "[gitflow] cloning remote repository called #{git_repository_name}" }
58
+ log.info(x) { "[gitflow] git repository user : #{git_repository_user}" }
59
+ log.info(x) { "[gitflow] git repository host : #{git_repository_host}" }
60
+ log.info(x) { "[gitflow] git repository clone path : #{non_existent_path}" }
61
+
62
+ git_clone_cmd = "git clone #{git_repository_url} #{non_existent_path}"
63
+ git_clone_output = %x[ #{ git_clone_cmd } ]
64
+ log.info(x) { "[gitflow] git clone output : #{git_clone_output}" }
65
+
66
+ puts ""
67
+
68
+ end
69
+
70
+
71
+ # The git clone directory destination can be deemed from one of 3 places with
72
+ # the precedence order shown below.
73
+ #
74
+ # - the --to switch passed on the command line
75
+ # - the GIT_CLONE_BASE_PATH keyname within indices
76
+ # - the present working directory
77
+ #
78
+ # This method returns a File object which it could possibly create if the
79
+ # first two options denote a path that does not exist (but could).
80
+ #
81
+ # Failure is not yet handled but should be.
82
+ def get_clone_directory()
83
+
84
+ if @to
85
+ folder_exists = File.directory?( @to )
86
+ FileUtils.mkdir_p( @to ) unless folder_exists
87
+ return @to
88
+ end
89
+
90
+ if @verse.has_key?( Indices::GIT_CLONE_BASE_PATH )
91
+ folder_exists = File.directory?( @verse[ Indices::GIT_CLONE_BASE_PATH ] )
92
+ FileUtils.mkdir_p( @verse[ Indices::GIT_CLONE_BASE_PATH ] ) unless folder_exists
93
+ return @verse[ Indices::GIT_CLONE_BASE_PATH ]
94
+ end
95
+
96
+ return Dir.pwd()
97
+
98
+ end
99
+
100
+
101
+ end
102
+
103
+
104
+ end