Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 12 additions & 1 deletion pkg/download_s3_archive.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,11 +10,15 @@ import (
"net/http"
"os"
"path/filepath"
"regexp"
"strings"

"github.com/qovery/qovery-cli/utils"
)

var uuidRegex = regexp.MustCompile(`^[0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12}$`)
var uuidWithTimestampRegex = regexp.MustCompile(`^([0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12})-\d+$`)

type ArchiveTagsResponse struct {
Key string
Value string
Expand All @@ -26,13 +30,20 @@ type ArchiveResponse struct {
}

func DownloadS3Archive(executionId string, directory string) {
if matches := uuidWithTimestampRegex.FindStringSubmatch(executionId); matches != nil {
log.Warnf("Execution id '%s' contains a timestamp suffix, stripping it automatically", executionId)
executionId = matches[1]
} else if !uuidRegex.MatchString(executionId) {
log.Errorf("Invalid execution id format: '%s'. Expected a UUID (e.g. xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx)", executionId)
return
}

fileName := executionId + ".tgz"
res := download(utils.GetAdminUrl()+"/getS3ArchiveObject", fileName)

if !strings.Contains(res.Status, "200") {
result, _ := io.ReadAll(res.Body)
log.Errorf("Could not download archive for key %s: %s. %s", fileName, res.Status, string(result))
log.Info("For cluster execution id be sure to remove the last part (it's a timestamp)")
return
}

Expand Down
Loading