-
Notifications
You must be signed in to change notification settings - Fork 9
/
main.go
44 lines (37 loc) · 1.26 KB
/
main.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
// Copyright 2022 Namespace Labs Inc; All rights reserved.
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
package main
import (
"context"
"encoding/json"
"flag"
"log"
"namespacelabs.dev/foundation/universe/aws/s3"
devs3 "namespacelabs.dev/foundation/universe/development/localstack/s3"
)
var (
localstackEndpoint = flag.String("init_localstack_endpoint", "", "Localstack endpoint configuration.")
)
func main() {
flag.Parse()
log.Printf("Starting with endpoint %s\n", *localstackEndpoint)
ctx := context.Background()
// BucketConfigs are passed as additional arguments without flag names.
for _, jsonBucketConfig := range flag.Args() {
bc := &devs3.BucketConfig{}
if err := json.Unmarshal([]byte(jsonBucketConfig), bc); err != nil {
log.Fatalf("Failed to unmarshal bucket config with error: %s", err)
}
s3client, err := devs3.CreateLocalstackS3Client(ctx, devs3.LocalstackConfig{
Region: bc.Region,
LocalstackEndpoint: *localstackEndpoint,
})
if err != nil {
log.Fatalf("Failed to create s3 client with: %v", err)
}
if err := s3.EnsureBucketExists(ctx, s3client, bc); err != nil {
log.Fatalf("Failed to create s3 bucket: %v", err)
}
}
}