()
| 53 | ) |
| 54 | |
| 55 | func main() { |
| 56 | endpoint := os.Getenv("S3_OUTPOSTS_ENDPOINT") |
| 57 | bucket := os.Getenv("S3_OUTPOSTS_BUCKET") |
| 58 | region := os.Getenv("S3_OUTPOSTS_REGION") |
| 59 | if region == "" { |
| 60 | region = os.Getenv("AWS_REGION") |
| 61 | } |
| 62 | profile := os.Getenv("S3_OUTPOSTS_PROFILE") |
| 63 | |
| 64 | if endpoint == "" || bucket == "" || region == "" { |
| 65 | log.Fatalf("Missing required env: set S3_OUTPOSTS_ENDPOINT, S3_OUTPOSTS_BUCKET, and S3_OUTPOSTS_REGION (or AWS_REGION)") |
| 66 | } |
| 67 | |
| 68 | var creds *credentials.Credentials |
| 69 | if profile != "" { |
| 70 | creds = credentials.NewFileAWSCredentials("", profile) |
| 71 | } else { |
| 72 | accessKey := os.Getenv("AWS_ACCESS_KEY_ID") |
| 73 | secretKey := os.Getenv("AWS_SECRET_ACCESS_KEY") |
| 74 | if accessKey == "" || secretKey == "" { |
| 75 | log.Fatalf("Set S3_OUTPOSTS_PROFILE or both AWS_ACCESS_KEY_ID and AWS_SECRET_ACCESS_KEY") |
| 76 | } |
| 77 | creds = credentials.NewStaticV4(accessKey, secretKey, "") |
| 78 | } |
| 79 | |
| 80 | client, err := minio.New(endpoint, &minio.Options{ |
| 81 | Creds: creds, |
| 82 | Secure: true, |
| 83 | Region: region, |
| 84 | }) |
| 85 | if err != nil { |
| 86 | log.Fatalf("New client: %v", err) |
| 87 | } |
| 88 | |
| 89 | objectKey := "outposts-test/hello-minio-go.txt" |
| 90 | objectBody := "Hello from minio-go S3 on Outposts\n" |
| 91 | |
| 92 | ctx := context.Background() |
| 93 | |
| 94 | fmt.Println("PutObject...") |
| 95 | _, err = client.PutObject(ctx, bucket, objectKey, strings.NewReader(objectBody), int64(len(objectBody)), minio.PutObjectOptions{ |
| 96 | ContentType: "text/plain", |
| 97 | }) |
| 98 | if err != nil { |
| 99 | log.Fatalf("PutObject: %v", err) |
| 100 | } |
| 101 | fmt.Println("PutObject OK") |
| 102 | |
| 103 | fmt.Println("GetObject...") |
| 104 | obj, err := client.GetObject(ctx, bucket, objectKey, minio.GetObjectOptions{}) |
| 105 | if err != nil { |
| 106 | log.Fatalf("GetObject: %v", err) |
| 107 | } |
| 108 | defer obj.Close() |
| 109 | |
| 110 | data, err := io.ReadAll(obj) |
| 111 | if err != nil { |
| 112 | log.Fatalf("Read body: %v", err) |
nothing calls this directly
no test coverage detected