Class: Bosh::Cli::UaaLoginStrategy

Inherits:
Object
  • Object
show all
Defined in:
lib/cli/uaa_login_strategy.rb

Instance Method Summary collapse

Constructor Details

#initialize(terminal, uaa_client, interactive) ⇒ UaaLoginStrategy

Returns a new instance of UaaLoginStrategy


7
8
9
10
11
# File 'lib/cli/uaa_login_strategy.rb', line 7

def initialize(terminal, uaa_client, interactive)
  @terminal = terminal
  @uaa_client = uaa_client
  @interactive = interactive
end

Instance Method Details

#login(target, username = nil, password = nil) ⇒ Object


13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
# File 'lib/cli/uaa_login_strategy.rb', line 13

def (target, username = nil, password = nil)
  if @interactive
    credentials = {}
    @uaa_client.prompts.map do |prompt|
      if prompt.password?
        credentials[prompt.field] = @terminal.ask_password("#{prompt.display_text}: ")
      else
        credentials[prompt.field] = @terminal.ask("#{prompt.display_text}: ")
      end
    end

    if access_info = @uaa_client.access_info(credentials)
      @terminal.say_green("Logged in as '#{access_info.username}'")
    else
      err('Failed to log in')
    end
  else
    err('Non-interactive UAA login is not supported.')
  end
end