Class: Interprete
- Inherits:
-
Thor
- Object
- Thor
- Interprete
- 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
-
#delete(entity_id) ⇒ Object
The delete use case can delete a single line (key/value pair), or a verse, chapter and even a book.
-
#docker(command = "login") ⇒ Object
This docker use case .…
-
#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.
-
#export ⇒ Object
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..
-
#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.
-
#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.
-
#id ⇒ Object
Put out the multiple formats of the current timestamp.
-
#init(domain_name, base_path = nil) ⇒ Object
Initialize the credentials manager, collect the human password and manufacture the strong asymmetric public / private keypair.
-
#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.
-
#login(domain_name = nil) ⇒ Object
Login in order to securely interact with your data.
-
#open(chapter, verse) ⇒ Object
Open up a conduit (path) to the place where we can issue read, create, update, and destroy commands.
-
#print(key_name) ⇒ Object
Print the value of the specified key belonging to a dictionary at the opened chapter and verse of the currently logged in book.
-
#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.
-
#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.
-
#show ⇒ Object
Show the secrets at the opened path.
-
#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.
-
#token ⇒ Object
Thetoken use cases prints out an encrypted session token tied to the workstation and shell environment.
-
#verse ⇒ Object
Print the name of the verse at the opened chapter and verse location.
-
#version ⇒ Object
Printout the version of this safedb.net command line interface.
-
#view ⇒ Object
Display a bird’s eye view of the domain’s database including its envelopes, their keys and imported objects such as files.
-
#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.
-
#write(file_url = nil) ⇒ Object
The write use case writes out a file that was previously ingested and coccooned inside the safe.
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
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 login
safe docker 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.
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 = [:to_dir] if [:to_dir] eject_uc.flow_of_events end |
#export ⇒ Object
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.
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.
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 |
#id ⇒ Object
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.
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 = [ :password ] if [ :password ] init_uc.domain_name = domain_name init_uc.base_path = File.( 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
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.
126 127 128 129 130 131 132 |
# File 'lib/interprete.rb', line 126 def login( domain_name = nil ) log.info(x) { "[usecase] ~> login to the book before interacting with it." } login_uc = SafeDb::Login.new login_uc.domain_name = domain_name unless domain_name.nil? login_uc.password = [ :password ] if [ :password ] login_uc.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.
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(key_name) ⇒ Object
Print the value of the specified key belonging to a dictionary at the opened chapter and verse of the currently logged in book.
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 = [:script].nil? ? false : [: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.
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
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 |
#show ⇒ Object
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>>
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 |
#token ⇒ Object
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 |
#verse ⇒ Object
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 = [:script].nil? ? false : [:script] verse_uc.flow_of_events end |
#version ⇒ Object
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 |
#view ⇒ Object
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.
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.
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 = [:script].nil? ? false : [:script] write_uc.file_url = file_url if file_url write_uc.flow_of_events end |