feat: some safety checks

This commit is contained in:
rony5394
2026-04-18 16:35:45 +02:00
parent d0d5168fd2
commit 87d8388810
4 changed files with 50 additions and 7 deletions

View File

@@ -1,10 +1,13 @@
package host
import (
"bytes"
"encoding/json"
"io"
"log/slog"
"net/http"
"bytes"
"os"
cfg "github.com/rony5394/blazena/config"
);
@@ -19,12 +22,15 @@ func exchangeKeys(Config cfg.Config, sshKeyPem string)string{
if err != nil {
panic("Failed to marshal body."+ err.Error());
slog.Error("Failed to marshal body.", slog.Any("propagatedError", err), slog.String("note", "Input for this marshal operation is that ssh pk. So the kebab is going on!"))
os.Exit(42);
}
rq, err := http.NewRequest("POST", Config.DockerManagerBaseUrl + "/keys", bytes.NewBuffer(bodyEncoded));
if err != nil{
panic("Failed to create http request"+ err.Error());
slog.Error("Failed to create request", slog.Any("propagatedError", err), slog.String("note", "not send just create the object"));
os.Exit(1);
}
rq.Header.Set("Authorization", "Bearer "+ token);
@@ -32,7 +38,8 @@ func exchangeKeys(Config cfg.Config, sshKeyPem string)string{
rs, err := http.DefaultClient.Do(rq);
if err != nil{
panic("Failed to send http request"+ err.Error());
slog.Error("Failed to send http request", slog.Any("propagatedError", err));
os.Exit(1);
}
defer rs.Body.Close();
@@ -40,7 +47,8 @@ func exchangeKeys(Config cfg.Config, sshKeyPem string)string{
rsBodyRaw, err := io.ReadAll(rs.Body);
if err != nil{
panic("Failed to read response's body!"+err.Error());
slog.Error("Failed to read response body!" , slog.Any("propagatedError", err));
os.Exit(1);
}
var rsBody struct{
@@ -49,7 +57,8 @@ func exchangeKeys(Config cfg.Config, sshKeyPem string)string{
err = json.Unmarshal(rsBodyRaw, &rsBody);
if err != nil{
panic("Failed to unmarshal rsBodyRaw!"+ err.Error());
slog.Error("Failed to unmarshal rsBodyRaw!", slog.Any("propagatedError", err));
os.Exit(1);
}

View File

@@ -102,6 +102,8 @@ func Run(Config cfg.Config) {
slog.Error("Failed to shutdown docker api!");
os.Exit(1);
}
slog.Info("Finished whole backup run.");
}
func getServices(Config cfg.Config)[]aService{