Class: HammerCLIForeman::BasicCredentials
- Inherits:
-
ApipieBindings::AbstractCredentials
- Object
- ApipieBindings::AbstractCredentials
- HammerCLIForeman::BasicCredentials
- Defined in:
- lib/hammer_cli_foreman/credentials.rb
Instance Method Summary collapse
- #clear ⇒ Object
- #empty? ⇒ Boolean
-
#initialize(params = {}) ⇒ BasicCredentials
constructor
Can keep username and passwords credentials and prompt for them when necessary.
-
#password ⇒ String
Get password.
-
#to_params ⇒ Hash
Convert credentials to hash usable for merging to RestClient configuration.
-
#username ⇒ String
Get username.
Constructor Details
#initialize(params = {}) ⇒ BasicCredentials
Can keep username and passwords credentials and prompt for them when necessary
18 19 20 21 |
# File 'lib/hammer_cli_foreman/credentials.rb', line 18 def initialize(params={}) @username = params[:username] @password = params[:password] end |
Instance Method Details
#clear ⇒ Object
41 42 43 44 45 |
# File 'lib/hammer_cli_foreman/credentials.rb', line 41 def clear super @username = nil @password = nil end |
#empty? ⇒ Boolean
37 38 39 |
# File 'lib/hammer_cli_foreman/credentials.rb', line 37 def empty? !@username && !@password end |
#password ⇒ String
Get password. Prompt for it when not set. Password characters are replaced with asterisks on the screen.
32 33 34 35 |
# 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 ⇒ Hash
Convert credentials to hash usable for merging to RestClient configuration.
49 50 51 52 53 54 |
# File 'lib/hammer_cli_foreman/credentials.rb', line 49 def to_params { :user => username, :password => password } end |
#username ⇒ String
Get username. Prompt for it when not set
25 26 27 28 |
# File 'lib/hammer_cli_foreman/credentials.rb', line 25 def username @username ||= ask_user(_("[Foreman] Username: ")) if HammerCLI.interactive? @username end |