Class: CivoCLI::APIKey
- Inherits:
-
Thor
- Object
- Thor
- CivoCLI::APIKey
- Defined in:
- lib/apikey.rb
Instance Method Summary collapse
Instance Method Details
#add(name, key) ⇒ Object
21 22 23 24 25 |
# File 'lib/apikey.rb', line 21 def add(name, key) CivoCLI::Config.set_apikey(name, key) puts "Saved the API Key #{key.colorize(:green)} as #{name.colorize(:green)}" current(name) end |
#current(name = nil) ⇒ Object
42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 |
# File 'lib/apikey.rb', line 42 def current(name = nil) currentkey = CivoCLI::Config.get_current_apikey_name if name.nil? && currentkey puts "The current API Key is #{currentkey.colorize(:green)}" elsif name.nil? && !currentkey puts "No current API Key set".colorize(:red) else keys = CivoCLI::Config.get_apikeys if keys.keys.include?(name) CivoCLI::Config.(:current_apikey, name) puts "The current API Key is now #{CivoCLI::Config.get_current_apikey_name.colorize(:green)}" else puts "The API Key #{name.colorize(:red)} couldn't be found, so it could not be set as default" exit 1 end end end |
#list ⇒ Object
4 5 6 7 8 9 10 11 12 13 14 15 16 17 |
# File 'lib/apikey.rb', line 4 def list keys = CivoCLI::Config.get_apikeys default = CivoCLI::Config.(:current_apikey) rows = [] keys.each do |label, key| if label == default rows << [label, key, "<====="] else rows << [label, key, ""] end end puts Terminal::Table.new headings: ['Name', 'Key', 'Default?'], rows: rows end |
#remove(name) ⇒ Object
28 29 30 31 32 33 34 35 36 37 38 |
# File 'lib/apikey.rb', line 28 def remove(name) keys = CivoCLI::Config.get_apikeys if keys.keys.include?(name) CivoCLI::Config.delete_apikey(name) puts "Removed the API Key #{name.colorize(:green)}" current(nil) else puts "The API Key #{name.colorize(:red)} couldn't be found." exit 1 end end |