Parent

Class/Module Index [+]

Quicksearch

HammerCLIForeman::BasicCredentials

Public Class Methods

new(params={}) click to toggle source

Can keep username and passwords credentials and prompt for them when necessary @param [Hash] params @option params [String] :username when nil, user is prompted when the attribute is accessed @option params [String] :password when nil, user is prompted when the attribute is accessed @example use container with prompt

c = HammerCLIForeman::BasicCredentials.new()
c.username
> [Foreman] Username: admin
=> "admin"

@example use container with preset value

c = HammerCLIForeman::BasicCredentials.new(:username => 'admin')
c.username
=> "admin"
# File lib/hammer_cli_foreman/credentials.rb, line 18
def initialize(params={})
  @username = params[:username]
  @password = params[:password]
end

Public Instance Methods

clear() click to toggle source
# File lib/hammer_cli_foreman/credentials.rb, line 41
def clear
  super
  @username = nil
  @password = nil
end
empty?() click to toggle source
# File lib/hammer_cli_foreman/credentials.rb, line 37
def empty?
  !@username && !@password
end
password() click to toggle source

Get password. Prompt for it when not set. Password characters are replaced with asterisks on the screen. @return [String]

# File lib/hammer_cli_foreman/credentials.rb, line 32
def password
  @password ||= ask_user(_("[Foreman] Password for %s: ") % username, true) if HammerCLI.interactive?
  @password
end
to_params() click to toggle source

Convert credentials to hash usable for merging to RestClient configuration. @return [Hash]

# File lib/hammer_cli_foreman/credentials.rb, line 49
def to_params
  {
    :user => username,
    :password => password
  }
end
username() click to toggle source

Get username. Prompt for it when not set @return [String]

# File lib/hammer_cli_foreman/credentials.rb, line 25
def username
  @username ||= ask_user(_("[Foreman] Username: ")) if HammerCLI.interactive?
  @username
end

[Validate]

Generated with the Darkfish Rdoc Generator 2.