|
18 | 18 | package cli
|
19 | 19 |
|
20 | 20 | import (
|
| 21 | + "fmt" |
| 22 | + "math/rand" |
| 23 | + "strings" |
21 | 24 | "github.com/minio/cli"
|
22 | 25 | "github.com/minio/minio-go/v7"
|
23 | 26 | "github.com/minio/pkg/v2/console"
|
@@ -71,16 +74,43 @@ func mainPut(ctx *cli.Context) error {
|
71 | 74 | return runBench(ctx, &b)
|
72 | 75 | }
|
73 | 76 |
|
| 77 | +const metadataChars = "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ1234567890-_." |
| 78 | + |
74 | 79 | // putOpts retrieves put options from the context.
|
75 | 80 | func putOpts(ctx *cli.Context) minio.PutObjectOptions {
|
76 | 81 | pSize, _ := toSize(ctx.String("part.size"))
|
| 82 | + |
| 83 | + /* metadatas */ |
| 84 | + metadatas := make(map[string]string) |
| 85 | + for _, v := range ctx.StringSlice("metadata") { |
| 86 | + idx := strings.Index(v, "=") |
| 87 | + if idx <= 0 { |
| 88 | + console.Fatal("--metadata takes `key=value` argument") |
| 89 | + } |
| 90 | + key := v[:idx] |
| 91 | + value := v[idx+1:] |
| 92 | + if len(value) == 0 { |
| 93 | + console.Fatal("--metadata value can't be empty") |
| 94 | + } |
| 95 | + var rand_n int; |
| 96 | + if _, err := fmt.Sscanf(value, "rand:%d", &rand_n); err == nil { |
| 97 | + rng := rand.New(rand.NewSource(int64(rand.Uint64()))) |
| 98 | + value = "" |
| 99 | + for i:=0; i<rand_n; i++ { |
| 100 | + value = value + string(metadataChars[rng.Int()%len(metadataChars)]) |
| 101 | + } |
| 102 | + } |
| 103 | + metadatas[key] = value |
| 104 | + } |
| 105 | + |
77 | 106 | return minio.PutObjectOptions{
|
78 | 107 | ServerSideEncryption: newSSE(ctx),
|
79 | 108 | DisableMultipart: ctx.Bool("disable-multipart"),
|
80 | 109 | DisableContentSha256: ctx.Bool("disable-sha256-payload"),
|
81 | 110 | SendContentMd5: ctx.Bool("md5"),
|
82 | 111 | StorageClass: ctx.String("storage-class"),
|
83 | 112 | PartSize: pSize,
|
| 113 | + UserMetadata: metadatas, |
84 | 114 | }
|
85 | 115 | }
|
86 | 116 |
|
|
0 commit comments