Check download auth
This commit is contained in:
parent
896ab0edc3
commit
f232e08945
4 changed files with 40 additions and 6 deletions
|
@ -11,10 +11,13 @@ import (
|
|||
"slices"
|
||||
"time"
|
||||
|
||||
"git.lastassault.de/speatzle/morffix/config"
|
||||
"git.lastassault.de/speatzle/morffix/constants"
|
||||
"git.lastassault.de/speatzle/morffix/types"
|
||||
"github.com/google/uuid"
|
||||
)
|
||||
|
||||
func downloadFile(ctx context.Context, l *slog.Logger, address string, path string, t *types.Task) error {
|
||||
func downloadFile(ctx context.Context, l *slog.Logger, conf config.Config, path string, t *types.Task) error {
|
||||
l.InfoContext(ctx, "Starting File Download", "task_id", t.ID, "file_id", t.FileID, "path", path, "md5", t.FileMD5)
|
||||
|
||||
out, err := os.Create(path)
|
||||
|
@ -23,11 +26,21 @@ func downloadFile(ctx context.Context, l *slog.Logger, address string, path stri
|
|||
}
|
||||
defer out.Close()
|
||||
|
||||
req, err := http.NewRequest(http.MethodGet, fmt.Sprintf("%v/files/%v", address, t.FileID), nil)
|
||||
req, err := http.NewRequest(http.MethodGet, fmt.Sprintf("%v/files/%v", conf.Worker.Address, t.FileID), nil)
|
||||
if err != nil {
|
||||
return fmt.Errorf("New Request: %w", err)
|
||||
}
|
||||
|
||||
uuid, err := uuid.Parse(conf.Worker.ID)
|
||||
if err != nil {
|
||||
return fmt.Errorf("Cannot Parse ID: %w", err)
|
||||
}
|
||||
|
||||
req.Header.Add(constants.SHARED_SECRET_HEADER, conf.SharedSecret)
|
||||
req.Header.Add(constants.NAME_HEADER, conf.Worker.Name)
|
||||
req.Header.Add(constants.UUID_HEADER, uuid.String())
|
||||
req.Header.Add(constants.WORKER_VERSION_HEADER, constants.WORKER_VERSION)
|
||||
|
||||
req.Close = true
|
||||
|
||||
var client = &http.Client{
|
||||
|
|
|
@ -37,7 +37,7 @@ func RunHealthCheck(conf config.Config, t *types.Task, data types.HealthCheckDat
|
|||
}
|
||||
}()
|
||||
|
||||
err := downloadFile(ctx, l, conf.Worker.Address, path, t)
|
||||
err := downloadFile(ctx, l, conf, path, t)
|
||||
if err != nil {
|
||||
l.ErrorContext(ctx, "File Download Failed", "err", err)
|
||||
return
|
||||
|
|
|
@ -46,7 +46,7 @@ func RunTranscode(conf config.Config, t *types.Task, data types.TranscodeData) {
|
|||
}
|
||||
}()
|
||||
|
||||
err := downloadFile(ctx, l, conf.Worker.Address, src_path, t)
|
||||
err := downloadFile(ctx, l, conf, src_path, t)
|
||||
if err != nil {
|
||||
l.ErrorContext(ctx, "Source File Download Failed", "err", err)
|
||||
return
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue