Implemented basic client config for auth

This commit is contained in:
2024-07-07 20:48:32 -03:00
parent 2ddbda5a4f
commit 4aa307c65c
9 changed files with 81 additions and 11 deletions

29
src/commands/login.cr Normal file
View File

@ -0,0 +1,29 @@
module Faaso
module Commands
struct Login
def run(options) : Int32
server = Faaso.server
Log.info { "Enter password for #{server}" }
if STDIN.tty?
password = (STDIN.noecho &.gets.try &.chomp).to_s
else
password = STDIN.gets.to_s
end
# Testing with auth/ which is guaranteed locked
Crest.get(
"#{server}auth/", \
user: "admin", password: password).body
# If we got here the password is ok
CONFIG.hosts[server] = {"admin", password}
Config.save
0
rescue ex : Crest::Unauthorized
Log.error { "Wrong password" }
1
rescue ex : Socket::ConnectError
Log.error { "Connection refused" }
1
end
end
end
end