Skip to content

Commit

Permalink
feat(datastore): remove all leading slashes in object key prefixes (#379
Browse files Browse the repository at this point in the history
)

* feat(datastore): remove all leading slashes in object key prefixes

* fix(s3): add trailing slash to prefix for List call

---------

Co-authored-by: Luca Corrieri <[email protected]>
  • Loading branch information
LucasMrqes and corrieriluca authored Nov 15, 2024
1 parent 444bf94 commit 10685b1
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 7 deletions.
8 changes: 4 additions & 4 deletions internal/datastore/storage/common.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,12 +26,12 @@ const (
)

func computeLogsKey(namespace string, layer string, run string, attempt string) string {
return fmt.Sprintf("/%s/%s/%s/%s/%s/%s", LayersPrefix, namespace, layer, run, attempt, LogFile)
return fmt.Sprintf("%s/%s/%s/%s/%s/%s", LayersPrefix, namespace, layer, run, attempt, LogFile)
}

func computePlanKey(namespace string, layer string, run string, attempt string, format string) string {
key := ""
prefix := fmt.Sprintf("/%s/%s/%s/%s/%s", LayersPrefix, namespace, layer, run, attempt)
prefix := fmt.Sprintf("%s/%s/%s/%s/%s", LayersPrefix, namespace, layer, run, attempt)
switch format {
case "json":
key = fmt.Sprintf("%s/%s", prefix, PlanJsonFile)
Expand All @@ -48,7 +48,7 @@ func computePlanKey(namespace string, layer string, run string, attempt string,
}

func computeGitBundleKey(namespace string, repository string, branch string, commit string) string {
return fmt.Sprintf("/%s/%s/%s/%s/%s%s", RepositoriesPrefix, namespace, repository, branch, commit, GitBundleFileExtension)
return fmt.Sprintf("%s/%s/%s/%s/%s%s", RepositoriesPrefix, namespace, repository, branch, commit, GitBundleFileExtension)
}

type Storage struct {
Expand Down Expand Up @@ -119,7 +119,7 @@ func (s *Storage) PutPlan(namespace string, layer string, run string, attempt st
}

func (s *Storage) GetAttempts(namespace string, layer string, run string) (int, error) {
key := fmt.Sprintf("/%s/%s/%s/%s", LayersPrefix, namespace, layer, run)
key := fmt.Sprintf("%s/%s/%s/%s", LayersPrefix, namespace, layer, run)
attempts, err := s.Backend.List(key)
return len(attempts), err
}
Expand Down
4 changes: 1 addition & 3 deletions internal/datastore/storage/s3/s3.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@ import (
"context"
"fmt"
"io"
"strings"

sdk "github.com/aws/aws-sdk-go-v2/config"
storage "github.com/aws/aws-sdk-go-v2/service/s3"
Expand All @@ -15,7 +14,6 @@ import (

// Implements Storage interface using AWS S3
type S3 struct {
// GCS Blob Storage client
Client *storage.Client
Config config.S3Config
}
Expand Down Expand Up @@ -88,7 +86,7 @@ func (a *S3) Delete(key string) error {
func (a *S3) List(prefix string) ([]string, error) {
input := &storage.ListObjectsV2Input{
Bucket: &a.Config.Bucket,
Prefix: aws.String(fmt.Sprintf("%s/", strings.TrimPrefix(prefix, "/"))),
Prefix: aws.String(fmt.Sprintf("%s/", prefix)),
Delimiter: aws.String("/"),
}
result, err := a.Client.ListObjectsV2(context.TODO(), input)
Expand Down

0 comments on commit 10685b1

Please sign in to comment.