Class: Squidward::Command::Secured
- Defined in:
- lib/squidward/commands/secured.rb
Overview
Base command from where all the commands are secured and need credentials, hence it handles AWS credentials
Direct Known Subclasses
Instance Method Summary collapse
-
#ask ⇒ Object
Gets trimmed input from the user.
-
#ask_for_credentials ⇒ Object
Gets the AWS Credentials from the user.
-
#ask_for_password ⇒ Object
Gets trimmed input from the user but with echoing off.
-
#echo_off ⇒ Object
Turns off the standard output while writting the password.
-
#echo_on ⇒ Object
Turns on the standard output after writting the password.
-
#initialize ⇒ Secured
constructor
Creates a new instance and prompts the user for the credentials if they aren’t stored.
-
#read_credentials ⇒ Object
Reads credentials from the configuration file.
-
#store_credentials(credentials) ⇒ Object
Stores the users credentials on the configuration.
Methods inherited from Base
#configuration, #display, #logger, #store_configuration
Constructor Details
#initialize ⇒ Secured
Creates a new instance and prompts the user for the credentials if they aren’t stored
8 9 10 11 12 13 |
# File 'lib/squidward/commands/secured.rb', line 8 def initialize() unless (@credentials = read_credentials) @credentials = ask_for_credentials store_credentials(@credentials) end end |
Instance Method Details
#ask ⇒ Object
Gets trimmed input from the user
39 40 41 |
# File 'lib/squidward/commands/secured.rb', line 39 def ask gets.strip end |
#ask_for_credentials ⇒ Object
Gets the AWS Credentials from the user
16 17 18 19 20 21 22 23 24 25 26 |
# File 'lib/squidward/commands/secured.rb', line 16 def ask_for_credentials puts "Enter your AWS credentials." print "Access Key ID: " user = ask print "Secret Access Key: " password = ask_for_password return [user, password] end |
#ask_for_password ⇒ Object
Gets trimmed input from the user but with echoing off
44 45 46 47 48 49 50 |
# File 'lib/squidward/commands/secured.rb', line 44 def ask_for_password echo_off password = ask puts echo_on return password end |
#echo_off ⇒ Object
Turns off the standard output while writting the password
29 30 31 |
# File 'lib/squidward/commands/secured.rb', line 29 def echo_off system "stty -echo" end |
#echo_on ⇒ Object
Turns on the standard output after writting the password
34 35 36 |
# File 'lib/squidward/commands/secured.rb', line 34 def echo_on system "stty echo" end |
#read_credentials ⇒ Object
Reads credentials from the configuration file
53 54 55 56 57 |
# File 'lib/squidward/commands/secured.rb', line 53 def read_credentials conf = self.configuration return nil unless conf[:credentials] return [conf[:credentials][:access_key], conf[:credentials][:secret_key]] end |
#store_credentials(credentials) ⇒ Object
Stores the users credentials on the configuration.
60 61 62 63 64 65 |
# File 'lib/squidward/commands/secured.rb', line 60 def store_credentials(credentials) conf = configuration conf[:credentials] = {} conf[:credentials][:access_key], conf[:credentials][:secret_key] = credentials[0], credentials[1] store_configuration(conf) end |