class DearS3::Cli::AuthenticationHelper

Attributes

authentication[R]

Public Class Methods

new(authentication) click to toggle source
# File lib/dears3/cli/authentication_helper.rb, line 6
def initialize authentication
  @authentication = authentication
end

Public Instance Methods

connect() click to toggle source
# File lib/dears3/cli/authentication_helper.rb, line 10
def connect
  begin
    authentication.connect
  rescue Errno::ENOENT
    say "Credentials file not found. Please run 's3:auth' to authenticate.", :red
    abort
  end
end
maybe_get_credentials() click to toggle source
# File lib/dears3/cli/authentication_helper.rb, line 23
def maybe_get_credentials
  if File.exists?(credentials_path) && !override_credentials?
    nil
  else
    request_credentials
  end
end
save_credentials!(credentials) click to toggle source
# File lib/dears3/cli/authentication_helper.rb, line 19
def save_credentials! credentials
  authentication.create_credentials_file! credentials
end

Private Instance Methods

credentials_path() click to toggle source
# File lib/dears3/cli/authentication_helper.rb, line 48
def credentials_path
  File.expand_path '~/.aws.json'
end
override_credentials?() click to toggle source
# File lib/dears3/cli/authentication_helper.rb, line 43
def override_credentials?
  choice = ask("Override existing '.aws.json' file? (y/n):")
  %w( y yes Y ok OK ).include? choice
end
request_credentials() click to toggle source
# File lib/dears3/cli/authentication_helper.rb, line 35
def request_credentials
  access_key_id = ask "Please enter your AWS access key id:"
  secret_access_key = ask "Please enter your AWS secret access key:", echo: false
  say

  { access_key_id: access_key_id, secret_access_key: secret_access_key }
end