Class: Interprete

Inherits:
Thor
  • Object
show all
Defined in:
lib/interprete.rb

Overview

This command line processor extends the Thor gem CLI tools in order to

  • read the posted commands, options and switches

  • maps the incoming string data to objects

  • assert that the mandatory options exist

  • assert the type of each parameter

  • ensure that the parameter values are in range

  • delegate processing to the registered handlers

Instance Method Summary collapse

Instance Method Details

#delete(entity_id) ⇒ Object

The delete use case can delete a single line (key/value pair), or a verse, chapter and even a book

Parameters:

  • entity_id (String)

    the ID of the entity to delete (line, verse, chapter or book)



288
289
290
291
292
293
# File 'lib/interprete.rb', line 288

def delete entity_id
  log.info(x) { "[usecase] ~> delete a safe entity with a key id [#{entity_id}]." }
  delete_uc = SafeDb::DeleteMe.new
  delete_uc.entity_id = entity_id
  delete_uc.flow_of_events
end

#docker(command = "login") ⇒ Object

This docker use case .…

safe docker 
safe docker logout

Parameters:

  • command (String) (defaults to: "login")

    the action to be taken which is currently limited to either login or logout



461
462
463
464
465
466
467
468
# File 'lib/interprete.rb', line 461

def docker( command = "login" )

  log.info(x) { "[usecase] ~> request to #{command} into or out of a docker repository." }
  docker_uc = SafeDb::Docker.new
  docker_uc.command = command
  docker_uc.flow_of_events

end

#eject(file_key) ⇒ Object

The eject use case writes out a file that was previously ingested and coccooned inside the safe typically with the file command.

Parameters:

  • file_key (String)

    the key that the file was ingested against



271
272
273
274
275
276
277
# File 'lib/interprete.rb', line 271

def eject file_key
  log.info(x) { "[usecase] ~> eject file at chapter/verse against specified key." }
  eject_uc = SafeDb::Eject.new
  eject_uc.file_key = file_key
  eject_uc.to_dir = options[:to_dir] if options[:to_dir]
  eject_uc.flow_of_events
end

#exportObject

Export the entire book if no chapter and verse is specified (achieved with a safe close), or the chapter if only the chapter is open (safe shut or safe open <<chapter>>, or the mini-dictionary at the verse if both chapter and verse are open.



220
221
222
223
# File 'lib/interprete.rb', line 220

def export
  log.info(x) { "[usecase] ~> export book chapter content or dictionary at verse in JSON format." }
  SafeDb::Export.new.flow_of_events
end

#file(file_key, file_url) ⇒ Object

The file use case pulls a read in from either an accessible readsystem or from a remote http, https, git, S3, GoogleDrive and/or ssh source.

Parameters:

  • file_key (String)

    keyname representing the file that is being read in

  • file_url (String)

    url of file to ingest and assimilate into the safe



253
254
255
256
257
258
259
260
# File 'lib/interprete.rb', line 253

def file file_key, file_url
  log.info(x) { "[usecase] ~> file read against key [[ #{file_key} ]]" }
  log.info(x) { "[usecase] ~> file read from url [[ #{file_url} ]]" }
  file_uc = SafeDb::FileMe.new
  file_uc.file_key = file_key
  file_uc.file_url = file_url
  file_uc.flow_of_events
end

#goto(index) ⇒ Object

Goto is a shortcut (or alias even) for the open command that takes an integer index that effectively specifies which <envelope> and <key> to open.

Parameters:

  • index (Number)

    the integer index chosen from the list procured by the view command.



370
371
372
373
374
375
376
# File 'lib/interprete.rb', line 370

def goto index
  log.info(x) { "[usecase] ~> opens the chapter and verse at index [#{index}]." }
  goto_uc = SafeDb::Goto.new
  goto_uc.index = index
  goto_uc.flow_of_events

end

#idObject

Put out the multiple formats of the current timestamp.



494
495
496
497
498
# File 'lib/interprete.rb', line 494

def id
  log.info(x) { "[usecase] ~> prints out the current timestamp identifiers." }
  id_uc = SafeDb::Id.new
  id_uc.flow_of_events
end

#init(domain_name, base_path = nil) ⇒ Object

Initialize the credentials manager, collect the human password and manufacture the strong asymmetric public / private keypair.

Parameters:

  • domain_name (String)

    the domain the software operates under

  • base_path (String) (defaults to: nil)

    the path to the base operating directory



105
106
107
108
109
110
111
112
# File 'lib/interprete.rb', line 105

def init( domain_name, base_path = nil )
  log.info(x) { "initialize the safe book on this device." }
  init_uc = SafeDb::Init.new
  init_uc.password = options[ :password ] if options[ :password ]
  init_uc.domain_name = domain_name
  init_uc.base_path = File.expand_path( base_path ) unless base_path.nil?
  init_uc.flow_of_events
end

#jenkins(command, service, url) ⇒ Object

This Jenkins use case injects for example the AWS IAM user access key, secret key and region key into a running Jenkins CI (Continuous Integration) service at the specified (url) location.

safe jenkins post aws http://localhost:8080

Parameters:

  • command (String)

    the action to be taken which is currently limited to be [post].

  • service (String)

    Which service do the credentials being posted originate from? The crrent list includes

    - aws      ( the 3 IAM user credentials )
    - docker   ( the username / password of docker repository )
    - git      ( the username/password of Git repository )
    - rubygems ( the username / password of RubyGems package manager account )
    
  • url (String)

    the full url of the jenkins service for example localhost:8080 which includes the scheme (http|https) the hostname or ip address and the port jenkins is listening on (if not the default 80 or 443).



435
436
437
438
439
440
441
442
443
444
445
446
# File 'lib/interprete.rb', line 435

def jenkins( command, service, url )

  log.info(x) { "[usecase] ~> request to #{command} #{service} credentials to Jenkins at #{url}" }
  jenkins_uc = SafeDb::Jenkins.new

  jenkins_uc.command = command if command
  jenkins_uc.service = service if service
  jenkins_uc.url     = url     if url

  jenkins_uc.flow_of_events

end

#login(domain_name = nil) ⇒ Object

Login in order to securely interact with your data.

Parameters:

  • domain_name (String) (defaults to: nil)

    the domain the software operates under



126
127
128
129
130
131
132
# File 'lib/interprete.rb', line 126

def ( domain_name = nil )
  log.info(x) { "[usecase] ~> login to the book before interacting with it." }
   = SafeDb::Login.new
  .domain_name = domain_name unless domain_name.nil?
  .password = options[ :password ] if options[ :password ]
  .flow_of_events
end

#open(chapter, verse) ⇒ Object

Open up a conduit (path) to the place where we can issue read, create, update, and destroy commands.

The allowed characters that makeup chapter and verse aside from alphanumerics are

  • dollar signs

  • percent signs

  • ampersands

  • hyphens

  • underscores

  • plus signs

  • equal signs

  • @ signs

  • period characters and

  • question marks

Notably whitespace including spaces and tabs are not allowed.

Parameters:

  • chapter (String)

    the chapter of the logged in book to open

  • verse (String)

    the verse of the logged in book and specified chapter to open



204
205
206
207
208
209
210
# File 'lib/interprete.rb', line 204

def open chapter, verse
  log.info(x) { "[usecase] ~> open a chapter and verse to read from or write to." }
  open_uc = SafeDb::Open.new
  open_uc.env_path = chapter
  open_uc.key_path = verse
  open_uc.flow_of_events
end

Print the value of the specified key belonging to a dictionary at the opened chapter and verse of the currently logged in book.

Parameters:

  • key_name (String)

    the key whose value is to be printed



143
144
145
146
147
148
149
# File 'lib/interprete.rb', line 143

def print key_name
  log.info(x) { "[usecase] ~> print the key value at the opened chapter and verse." }
  print_uc = SafeDb::Print.new
  print_uc.key_name = key_name
  print_uc.from_script = options[:script].nil? ? false : options[:script]
  print_uc.flow_of_events
end

#put(secret_id, secret_value) ⇒ Object

Put a secret with an id like login/username and a value like joebloggs into the context (eg work/laptop) that was opened with the open command.

Parameters:

  • secret_id (String)

    the id of the secret to put into the opened context

  • secret_value (String)

    the value of the secret to put into the opened context



235
236
237
238
239
240
241
# File 'lib/interprete.rb', line 235

def put secret_id, secret_value
  log.info(x) { "[usecase] ~> put key/value pair into dictionary at open chapter and verse." }
  put_uc = SafeDb::Put.new
  put_uc.secret_id = secret_id
  put_uc.secret_value = secret_value
  put_uc.flow_of_events
end

#read(file_url) ⇒ Object

The read use case pulls a read in from either an accessible readsystem 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

Parameters:

  • file_url (String)

    url of file to ingest and assimilate into the safe



311
312
313
314
315
316
# File 'lib/interprete.rb', line 311

def read file_url
  log.info(x) { "[usecase] ~> read (reread) file from optional url [[ #{file_url} ]]" }
  read_uc = SafeDb::Read.new
  read_uc.file_url = file_url
  read_uc.flow_of_events
end

#showObject

Show the secrets at the opened path. These secrets are simply written out to the shell console.



342
343
344
345
# File 'lib/interprete.rb', line 342

def show
  log.info(x) { "[usecase] ~> show dictionary at the opened chapter and verse." }
  SafeDb::Show.new.flow_of_events
end

#terraform(command = nil) ⇒ Object

This terraform use case exports the AWS IAM user access key, secret key and region key into (very safe) environment variables and then runs terraform plan, apply or destroy.

This is both ultra secure and extremely convenient because the credentials do not leave the safe and exist within (environment variable) memory only for the duration of the terraform command.

It is safe because you do not need to expose your AWS credentials in plain text. It is convenient because switching IAM users and AWS regions is as easy as typing the now ubiquitous safe open command.

safe open <<chapter>> <<verse>>

Parameters:

  • command (String) (defaults to: nil)

    the terraform command to run which is currently limited to plan, apply and destroy. This parameter is optional and if nothing is given then “apply” is assumed.



399
400
401
402
403
404
# File 'lib/interprete.rb', line 399

def terraform( command = nil )
  log.info(x) { "[usecase] ~> will export IAM credentials then invoke $ terraform #{command}" }
  terraform_uc = SafeDb::Terraform.new
  terraform_uc.command = command if command
  terraform_uc.flow_of_events
end

#tokenObject

Thetoken use cases prints out an encrypted session token tied to the workstation and shell environment.



171
172
173
174
# File 'lib/interprete.rb', line 171

def token
  log.info(x) { "[usecase] ~> generate and print out an encrypted (shell bound) session token" }
  SafeDb::Token.new.flow_of_events
end

#verseObject

Print the name of the verse at the opened chapter and verse location.



157
158
159
160
161
162
# File 'lib/interprete.rb', line 157

def verse
  log.info(x) { "[usecase] ~> print the verse name at the opened chapter and verse." }
  verse_uc = SafeDb::Verse.new
  verse_uc.from_script = options[:script].nil? ? false : options[:script]
  verse_uc.flow_of_events
end

#versionObject

Printout the version of this safedb.net command line interface. The version should be extracted whether the user types in

  • either safe --version

  • or safe version



78
79
80
81
82
83
84
85
86
87
88
# File 'lib/interprete.rb', line 78

def version
  log.info(x) { "[usecase] ~> print the version of this safedb.net personal database." }

  puts ""
  puts "safedb gem version => v#{SafeDb::VERSION}"
  puts "time and date now  => #{SafeDb::KeyNow.human_readable()}"
  puts "safedb @github.com => https://github.com/devops4me/safedb.net"
  puts "safe @rubygems.org => https://rubygems.org/gems/safedb"
  puts ""

end

#viewObject

Display a bird’s eye view of the domain’s database including its envelopes, their keys and imported objects such as files.



354
355
356
357
358
# File 'lib/interprete.rb', line 354

def view
  log.info(x) { "[usecase] ~> print list of chapter and verse combos to console." }
  view_uc = SafeDb::View.new
  view_uc.flow_of_events
end

#vpn(command = nil) ⇒ Object

This VPN use case connects to the VPN whose specifics are recorded within the vpn.ini factfile living in the same directory as the vpn.rb usecase class.

Parameters:

  • command (String) (defaults to: nil)

    the vpn command to run which is currently limited to up or down This parameter is optional and if nothing is given then “up” is assumed.



481
482
483
484
485
486
# File 'lib/interprete.rb', line 481

def vpn( command = nil )
  log.info(x) { "[usecase] ~> VPN connection command #{command} has been issued." }
  vpn_uc = SafeDb::Vpn.new
  vpn_uc.command = command if command
  vpn_uc.flow_of_events
end

#write(file_url = nil) ⇒ Object

The write use case writes out a file that was previously ingested and coccooned inside the safe.

Parameters:

  • file_url (String) (defaults to: nil)

    optional file url marking where to write the file



327
328
329
330
331
332
333
# File 'lib/interprete.rb', line 327

def write( file_url = nil )
  log.info(x) { "[usecase] ~> write out file at chapter/verse to (optional) file url." }
  write_uc = SafeDb::Write.new
  write_uc.from_script = options[:script].nil? ? false : options[:script]
  write_uc.file_url = file_url if file_url
  write_uc.flow_of_events
end