Class: GoodData::Command::Auth
Class Method Summary collapse
-
.ask_for_credentials(credentials_file_path = Helpers::AuthHelper.credentials_file) ⇒ Hash
Ask for credentials.
- .ask_for_credentials_on_windows(credentials_file_path = Helpers::AuthHelper.credentials_file) ⇒ Object
-
.set_default_value(q, value, default = nil) ⇒ Object
Conditionally sets default value for prompt.
-
.store(credentials_file_path = Helpers::AuthHelper.credentials_file) ⇒ Object
Ask for credentials and store them.
-
.unstore(credentials_file_path = Helpers::AuthHelper.credentials_file) ⇒ Object
Delete stored credentials.
Class Method Details
.ask_for_credentials(credentials_file_path = Helpers::AuthHelper.credentials_file) ⇒ Hash
Ask for credentials
24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 |
# File 'lib/gooddata/commands/auth.rb', line 24 def ask_for_credentials(credentials_file_path = Helpers::AuthHelper.credentials_file) puts 'Enter your GoodData credentials.' old_credentials = Helpers::AuthHelper.read_credentials(credentials_file_path) # Ask for user email user = GoodData::CLI.terminal.ask('Email') do |q| set_default_value(q, old_credentials[:username]) end # Ask for password password = GoodData::CLI.terminal.ask('Password') do |q| # set_default_value(q, old_credentials[:password]) q.echo = '*' end # Ask for token auth_token = GoodData::CLI.terminal.ask('Authorization (Project) Token') do |q| set_default_value(q, old_credentials[:auth_token]) end # Read environment environment = GoodData::CLI.terminal.ask('Environment') do |q| set_default_value(q, old_credentials[:environment], GoodData::Project::DEFAULT_ENVIRONMENT) end # Read server server = GoodData::CLI.terminal.ask('Server') do |q| set_default_value(q, old_credentials[:server], 'https://secure.gooddata.com') end # Return as struct { :username => user, :password => password, :auth_token => auth_token, :environment => environment, :server => server } end |
.ask_for_credentials_on_windows(credentials_file_path = Helpers::AuthHelper.credentials_file) ⇒ Object
65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 |
# File 'lib/gooddata/commands/auth.rb', line 65 def ask_for_credentials_on_windows(credentials_file_path = Helpers::AuthHelper.credentials_file) puts 'Enter your GoodData credentials.' old_credentials = Helpers::AuthHelper.read_credentials(credentials_file_path) puts 'Email' input = $stdin.gets.chomp user = input.empty? ? old_credentials[:username] : input puts 'Password' input = $stdin.gets.chomp password = input.empty? ? old_credentials[:password] : input puts 'Authorization (Project) Token' input = $stdin.gets.chomp auth_token = input.empty? ? old_credentials[:auth_token] : input puts 'Environment' input = $stdin.gets.chomp environment = input.empty? ? old_credentials[:environment] : input # in windows console, an empty input does not flush the previous buffer # so if you do not fill any environment, the previous value is still present in $stdin # so this is a default environment = GoodData::Project::DEFAULT_ENVIRONMENT if environment == auth_token puts 'Server' input = $stdin.gets.chomp server = input.empty? ? old_credentials[:server] : input # Return as struct { :username => user, :password => password, :auth_token => auth_token, :environment => environment, :server => server } end |
.set_default_value(q, value, default = nil) ⇒ Object
Conditionally sets default value for prompt. Default value is set to 'value' or 'default'
136 137 138 139 140 141 142 |
# File 'lib/gooddata/commands/auth.rb', line 136 def set_default_value(q, value, default = nil) if !value.nil? && !value.empty? q.default = value elsif default q.default = default end end |
.store(credentials_file_path = Helpers::AuthHelper.credentials_file) ⇒ Object
Ask for credentials and store them
105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 |
# File 'lib/gooddata/commands/auth.rb', line 105 def store(credentials_file_path = Helpers::AuthHelper.credentials_file) puts 'This will store credentials to GoodData in an UNencrypted form to your harddrive to file ~/.gooddata.' overwrite = GoodData::CLI.terminal.ask('Do you want to continue? (y/n)') return if overwrite != 'y' credentials = GoodData::Helpers.running_on_windows? ? ask_for_credentials_on_windows : ask_for_credentials ovewrite = if File.exist?(credentials_file_path) GoodData::CLI.terminal.ask('Overwrite existing stored credentials (y/n)') else 'y' end if ovewrite == 'y' Helpers::AuthHelper.write_credentials(credentials, credentials_file_path) else puts 'Aborting...' end end |
.unstore(credentials_file_path = Helpers::AuthHelper.credentials_file) ⇒ Object
Delete stored credentials
126 127 128 |
# File 'lib/gooddata/commands/auth.rb', line 126 def unstore(credentials_file_path = Helpers::AuthHelper.credentials_file) Helpers::AuthHelper.remove_credentials_file(credentials_file_path) end |