Module: Wpxf::Cli::Creds
- Included in:
- Console
- Defined in:
- lib/wpxf/cli/creds.rb
Overview
A mixin to provide functions to interact with credentials stored in the database.
Instance Method Summary collapse
Instance Method Details
#creds(*args) ⇒ Object
44 45 46 47 48 49 50 51 52 53 |
# File 'lib/wpxf/cli/creds.rb', line 44 def creds(*args) return list_credentials if args.length.zero? case args[0] when '-d' delete_credential(args[1]) else print_warning 'Invalid option for "creds"' end end |
#delete_credential(id) ⇒ Object
7 8 9 10 11 12 13 14 15 16 17 18 19 |
# File 'lib/wpxf/cli/creds.rb', line 7 def delete_credential(id) item = Wpxf::Models::Credential.first( id: id.to_i, workspace: active_workspace ) unless item.nil? item.destroy return print_good "Deleted credential #{id}" end print_bad "Could not find credential #{id} in the current workspace" end |
#list_credentials ⇒ Object
21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 |
# File 'lib/wpxf/cli/creds.rb', line 21 def list_credentials rows = [] rows.push( id: 'ID', host: 'Host', username: 'Username', password: 'Password', type: 'Type' ) Wpxf::Models::Credential.where(workspace: active_workspace).each do |cred| rows.push( id: cred.id, host: "#{cred.host}:#{cred.port}", username: cred.username, password: cred.password, type: cred.type ) end print_table rows end |