Skip to content

Commit 8132a64

Browse files
committed
add env var for path prefix
1 parent 04d4d52 commit 8132a64

2 files changed

Lines changed: 16 additions & 4 deletions

File tree

lfs-broker/main.go

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -79,6 +79,7 @@ var (
7979
smClient *secretsmanager.Client
8080
bucketName string
8181
secretName string
82+
pathPrefix string
8283
apiKeyCache = &secretCache{}
8384
)
8485

@@ -93,6 +94,11 @@ func init() {
9394
log.Fatal("LFS_SECRET_NAME environment variable is required")
9495
}
9596

97+
pathPrefix = os.Getenv("PATH_PREFIX")
98+
if pathPrefix == "" {
99+
pathPrefix = "lfs/objects"
100+
}
101+
96102
cfg, err := config.LoadDefaultConfig(context.Background())
97103
if err != nil {
98104
log.Fatalf("failed to load AWS config: %v", err)
@@ -226,8 +232,8 @@ func handler(ctx context.Context, req events.LambdaFunctionURLRequest) (events.L
226232

227233
func processObject(ctx context.Context, operation string, obj LFSObject) (LFSObjectResult, error) {
228234
// S3 key derived from OID using standard LFS content-addressable layout
229-
// e.g. oid abc123... -> lfs/objects/ab/c1/abc123...
230-
key := fmt.Sprintf("lfs/objects/%s/%s/%s", obj.OID[:2], obj.OID[2:4], obj.OID)
235+
// e.g. oid abc123... -> <pathPrefix>/ab/c1/abc123...
236+
key := fmt.Sprintf("%s/%s/%s/%s", pathPrefix, obj.OID[:2], obj.OID[2:4], obj.OID)
231237

232238
var href string
233239
var err error

lfs-snapshot/main.go

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -64,6 +64,7 @@ var (
6464
lfsBucket string
6565
snapshotBucket string
6666
snapshotPrefix string
67+
pathPrefix string
6768
extraBuckets []string
6869
httpClient = &http.Client{}
6970
)
@@ -92,6 +93,11 @@ func init() {
9293
extraBuckets = strings.Split(raw, ",")
9394
}
9495

96+
pathPrefix = os.Getenv("PATH_PREFIX")
97+
if pathPrefix == "" {
98+
pathPrefix = "lfs/objects"
99+
}
100+
95101
cfg, err := config.LoadDefaultConfig(context.Background())
96102
if err != nil {
97103
log.Fatalf("failed to load AWS config: %v", err)
@@ -310,8 +316,8 @@ func streamLFSObjectToSnapshot(ctx context.Context, pointer *LFSPointer, destBuc
310316
}
311317

312318
// LFS content-addressable key
313-
srcKey := fmt.Sprintf("lfs/objects/%s/%s/%s",
314-
pointer.OID[:2], pointer.OID[2:4], pointer.OID)
319+
srcKey := fmt.Sprintf("%s/%s/%s/%s",
320+
pathPrefix, pointer.OID[:2], pointer.OID[2:4], pointer.OID)
315321

316322
// Get the object from the LFS bucket as a stream
317323
getResult, err := s3Client.GetObject(ctx, &s3.GetObjectInput{

0 commit comments

Comments
 (0)