Use configurable auth everywhere (not tested)
This commit is contained in:
parent
4aa307c65c
commit
f14a8d1c39
@ -44,15 +44,16 @@ module Faaso
|
|||||||
outf << buf
|
outf << buf
|
||||||
end
|
end
|
||||||
|
|
||||||
url = "#{Faaso.server}funkos/build/"
|
url = "#{Config.server}funkos/build/"
|
||||||
|
|
||||||
begin
|
begin
|
||||||
Log.info { "Uploading funko to #{Faaso.server}" }
|
user, password = Config.auth
|
||||||
|
Log.info { "Uploading funko to #{Config.server}" }
|
||||||
Log.info { "Starting remote build:" }
|
Log.info { "Starting remote build:" }
|
||||||
Crest.post(
|
Crest.post(
|
||||||
url,
|
url,
|
||||||
{"funko.tgz" => File.open(tmp), "name" => "funko.tgz"},
|
{"funko.tgz" => File.open(tmp), "name" => "funko.tgz"},
|
||||||
user: "admin", password: "admin"
|
user: user, password: password
|
||||||
) do |response|
|
) do |response|
|
||||||
loop do
|
loop do
|
||||||
Log.info { response.body_io.gets }
|
Log.info { response.body_io.gets }
|
||||||
|
@ -2,7 +2,7 @@ module Faaso
|
|||||||
module Commands
|
module Commands
|
||||||
struct Login
|
struct Login
|
||||||
def run(options) : Int32
|
def run(options) : Int32
|
||||||
server = Faaso.server
|
server = Config.server
|
||||||
Log.info { "Enter password for #{server}" }
|
Log.info { "Enter password for #{server}" }
|
||||||
if STDIN.tty?
|
if STDIN.tty?
|
||||||
password = (STDIN.noecho &.gets.try &.chomp).to_s
|
password = (STDIN.noecho &.gets.try &.chomp).to_s
|
||||||
|
@ -27,11 +27,12 @@ module Faaso
|
|||||||
end
|
end
|
||||||
|
|
||||||
def remote(options, name, scale) : Int32
|
def remote(options, name, scale) : Int32
|
||||||
|
user, password = Config.auth
|
||||||
Faaso.check_version
|
Faaso.check_version
|
||||||
if !scale
|
if !scale
|
||||||
Crest.get(
|
Crest.get(
|
||||||
"#{Faaso.server}funkos/#{name}/scale/", \
|
"#{Config.server}funkos/#{name}/scale/", \
|
||||||
user: "admin", password: "admin") do |response|
|
user: user, password: password) do |response|
|
||||||
loop do
|
loop do
|
||||||
Log.info { response.body_io.gets }
|
Log.info { response.body_io.gets }
|
||||||
break if response.body_io.closed?
|
break if response.body_io.closed?
|
||||||
@ -39,8 +40,8 @@ module Faaso
|
|||||||
end
|
end
|
||||||
else
|
else
|
||||||
Crest.post(
|
Crest.post(
|
||||||
"#{Faaso.server}funkos/#{name}/scale/",
|
"#{Config.server}funkos/#{name}/scale/",
|
||||||
{"scale" => scale}, user: "admin", password: "admin") do |response|
|
{"scale" => scale}, user: user, password: password) do |response|
|
||||||
loop do
|
loop do
|
||||||
Log.info { response.body_io.gets }
|
Log.info { response.body_io.gets }
|
||||||
break if response.body_io.closed?
|
break if response.body_io.closed?
|
||||||
|
@ -14,19 +14,20 @@ module Faaso
|
|||||||
|
|
||||||
def remote(options, funko, name, secret) : Int32
|
def remote(options, funko, name, secret) : Int32
|
||||||
Faaso.check_version
|
Faaso.check_version
|
||||||
|
user, password = Config.auth
|
||||||
if options["--add"]
|
if options["--add"]
|
||||||
Crest.post(
|
Crest.post(
|
||||||
"#{Faaso.server}secrets/",
|
"#{Config.server}secrets/",
|
||||||
{
|
{
|
||||||
"funko" => funko,
|
"funko" => funko,
|
||||||
"name" => name,
|
"name" => name,
|
||||||
"value" => secret,
|
"value" => secret,
|
||||||
}, user: "admin", password: "admin")
|
}, user: user, password: password)
|
||||||
Log.info { "Secret created" }
|
Log.info { "Secret created" }
|
||||||
elsif options["--delete"]
|
elsif options["--delete"]
|
||||||
Crest.delete(
|
Crest.delete(
|
||||||
"#{Faaso.server}secrets/#{funko}/#{name}",
|
"#{Config.server}secrets/#{funko}/#{name}",
|
||||||
user: "admin", password: "admin")
|
user: user, password: password)
|
||||||
end
|
end
|
||||||
0
|
0
|
||||||
rescue ex : Crest::RequestFailed
|
rescue ex : Crest::RequestFailed
|
||||||
|
@ -27,9 +27,10 @@ module Faaso
|
|||||||
|
|
||||||
def remote(options, name) : Int32
|
def remote(options, name) : Int32
|
||||||
Faaso.check_version
|
Faaso.check_version
|
||||||
|
user, password = Config.auth
|
||||||
Crest.get(
|
Crest.get(
|
||||||
"#{Faaso.server}funkos/#{name}/status/", \
|
"#{Config.server}funkos/#{name}/status/", \
|
||||||
user: "admin", password: "admin") do |response|
|
user: user, password: password) do |response|
|
||||||
loop do
|
loop do
|
||||||
Log.info { response.body_io.gets }
|
Log.info { response.body_io.gets }
|
||||||
break if response.body_io.closed?
|
break if response.body_io.closed?
|
||||||
|
@ -23,4 +23,22 @@ class Config
|
|||||||
outf << CONFIG.to_yaml
|
outf << CONFIG.to_yaml
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
@@already_warned = false
|
||||||
|
|
||||||
|
def self.server : String
|
||||||
|
@@already_warned = true
|
||||||
|
url = ENV.fetch("FAASO_SERVER", nil)
|
||||||
|
if url.nil?
|
||||||
|
Log.warn { "FAASO_SERVER not set" } unless @@already_warned
|
||||||
|
url = "http://localhost:3000/"
|
||||||
|
end
|
||||||
|
url += "/" unless url.ends_with? "/"
|
||||||
|
Log.info { "Using server #{url}" } unless @@already_warned
|
||||||
|
url
|
||||||
|
end
|
||||||
|
|
||||||
|
def self.auth : {String, String}
|
||||||
|
CONFIG.hosts.fetch(server, {"admin", ""})
|
||||||
|
end
|
||||||
end
|
end
|
||||||
|
16
src/faaso.cr
16
src/faaso.cr
@ -28,22 +28,12 @@ module Faaso
|
|||||||
raise ex if ex.status_code != 409 # Network already exists
|
raise ex if ex.status_code != 409 # Network already exists
|
||||||
end
|
end
|
||||||
|
|
||||||
def self.server : String
|
|
||||||
url = ENV.fetch("FAASO_SERVER", nil)
|
|
||||||
if url.nil?
|
|
||||||
Log.warn { "FAASO_SERVER not set" }
|
|
||||||
url = "http://localhost:3000/"
|
|
||||||
end
|
|
||||||
url += "/" unless url.ends_with? "/"
|
|
||||||
Log.info { "Using server #{url}" }
|
|
||||||
url
|
|
||||||
end
|
|
||||||
|
|
||||||
# Compare version with server's
|
# Compare version with server's
|
||||||
def self.check_version
|
def self.check_version
|
||||||
|
user, password = Config.auth
|
||||||
server_version = Crest.get(
|
server_version = Crest.get(
|
||||||
"#{self.server}version/", \
|
"#{Config.server}version/", \
|
||||||
user: "admin", password: "admin").body
|
user: user, password: password).body
|
||||||
|
|
||||||
local_version = "#{version}"
|
local_version = "#{version}"
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user