From c907159d135a7a7bfd2040e946b3647de4ba02ba Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?J=C3=A9r=C3=B4me=20LOYET?= <822436+fatpat@users.noreply.github.com> Date: Tue, 19 Nov 2024 09:50:53 +0100 Subject: [PATCH] add --metadata to add user metadata during put --- cli/flags.go | 4 ++++ cli/put.go | 30 ++++++++++++++++++++++++++++++ 2 files changed, 34 insertions(+) diff --git a/cli/flags.go b/cli/flags.go index 3ffe419..8186dfb 100644 --- a/cli/flags.go +++ b/cli/flags.go @@ -269,6 +269,10 @@ var ioFlags = []cli.Flag{ Value: 0, Usage: "Rate limit each instance to this number of requests per second (0 to disable)", }, + cli.StringSliceFlag{ + Name: "metadata", + Usage: "Set user metada to all objects using the format =. Random value can be set with 'rand:%length'. Can be used multiple times. Example: --metadata foo=bar --metadata randomValue=rand:1024.", + }, } func getCommon(ctx *cli.Context, src func() generator.Source) bench.Common { diff --git a/cli/put.go b/cli/put.go index 5c6d791..90393cb 100644 --- a/cli/put.go +++ b/cli/put.go @@ -18,6 +18,9 @@ package cli import ( + "fmt" + "math/rand" + "strings" "github.com/minio/cli" "github.com/minio/minio-go/v7" "github.com/minio/pkg/v2/console" @@ -71,9 +74,35 @@ func mainPut(ctx *cli.Context) error { return runBench(ctx, &b) } +const metadataChars = "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ1234567890-_." + // putOpts retrieves put options from the context. func putOpts(ctx *cli.Context) minio.PutObjectOptions { pSize, _ := toSize(ctx.String("part.size")) + + /* metadatas */ + metadatas := make(map[string]string) + for _, v := range ctx.StringSlice("metadata") { + idx := strings.Index(v, "=") + if idx <= 0 { + console.Fatal("--metadata takes `key=value` argument") + } + key := v[:idx] + value := v[idx+1:] + if len(value) == 0 { + console.Fatal("--metadata value can't be empty") + } + var rand_n int; + if _, err := fmt.Sscanf(value, "rand:%d", &rand_n); err == nil { + rng := rand.New(rand.NewSource(int64(rand.Uint64()))) + value = "" + for i:=0; i