mirror of
https://github.com/eduardolat/pgbackweb.git
synced 2026-05-12 14:38:28 -05:00
Add GetExecutionDownloadLink function to Service
This commit is contained in:
@@ -0,0 +1,33 @@
|
||||
package executions
|
||||
|
||||
import (
|
||||
"context"
|
||||
"fmt"
|
||||
"time"
|
||||
|
||||
"github.com/eduardolat/pgbackweb/internal/database/dbgen"
|
||||
"github.com/google/uuid"
|
||||
)
|
||||
|
||||
func (s *Service) GetExecutionDownloadLink(
|
||||
ctx context.Context, executionID uuid.UUID,
|
||||
) (string, error) {
|
||||
data, err := s.dbgen.ExecutionsServiceGetDownloadLinkData(
|
||||
ctx, dbgen.ExecutionsServiceGetDownloadLinkDataParams{
|
||||
ExecutionID: executionID,
|
||||
DecryptionKey: *s.env.PBW_ENCRYPTION_KEY,
|
||||
},
|
||||
)
|
||||
if err != nil {
|
||||
return "", err
|
||||
}
|
||||
|
||||
if !data.Path.Valid {
|
||||
return "", fmt.Errorf("execution has no file associated")
|
||||
}
|
||||
|
||||
return s.ints.S3Client.GetDownloadLink(
|
||||
data.DecryptedAccessKey, data.DecryptedSecretKey, data.Region,
|
||||
data.Endpoint, data.BucketName, data.Path.String, time.Hour*12,
|
||||
)
|
||||
}
|
||||
@@ -0,0 +1,12 @@
|
||||
-- name: ExecutionsServiceGetDownloadLinkData :one
|
||||
SELECT
|
||||
executions.path AS path,
|
||||
destinations.bucket_name AS bucket_name,
|
||||
destinations.region AS region,
|
||||
destinations.endpoint AS endpoint,
|
||||
pgp_sym_decrypt(destinations.access_key, sqlc.arg('decryption_key')::TEXT) AS decrypted_access_key,
|
||||
pgp_sym_decrypt(destinations.secret_key, sqlc.arg('decryption_key')::TEXT) AS decrypted_secret_key
|
||||
FROM executions
|
||||
JOIN backups ON backups.id = executions.backup_id
|
||||
JOIN destinations ON destinations.id = backups.destination_id
|
||||
WHERE executions.id = @execution_id;
|
||||
Reference in New Issue
Block a user