Prefix version suspension (#4064)
This commit is contained in:
+1
-1
@@ -1195,7 +1195,7 @@ func (f *fsClient) GetVersion(ctx context.Context) (minio.BucketVersioningConfig
|
||||
}
|
||||
|
||||
// SetVersion - Set version configuration on a bucket, not implemented
|
||||
func (f *fsClient) SetVersion(ctx context.Context, status string) *probe.Error {
|
||||
func (f *fsClient) SetVersion(ctx context.Context, status string, _ []string, _ bool) *probe.Error {
|
||||
return probe.NewError(APINotImplemented{
|
||||
API: "SetVersion",
|
||||
APIType: "filesystem",
|
||||
|
||||
+18
-2
@@ -2526,7 +2526,7 @@ func (c *S3Client) GetVersion(ctx context.Context) (config minio.BucketVersionin
|
||||
}
|
||||
|
||||
// SetVersion - Set version configuration on a bucket
|
||||
func (c *S3Client) SetVersion(ctx context.Context, status string) *probe.Error {
|
||||
func (c *S3Client) SetVersion(ctx context.Context, status string, prefixes []string, excludeFolders bool) *probe.Error {
|
||||
bucket, _ := c.url2BucketAndObject()
|
||||
if bucket == "" {
|
||||
return probe.NewError(BucketNameEmpty{})
|
||||
@@ -2534,7 +2534,23 @@ func (c *S3Client) SetVersion(ctx context.Context, status string) *probe.Error {
|
||||
var err error
|
||||
switch status {
|
||||
case "enable":
|
||||
err = c.api.EnableVersioning(ctx, bucket)
|
||||
|
||||
if len(prefixes) > 0 || excludeFolders {
|
||||
vc := minio.BucketVersioningConfiguration{
|
||||
Status: minio.Enabled,
|
||||
ExcludeFolders: excludeFolders,
|
||||
}
|
||||
if len(prefixes) > 0 {
|
||||
eprefixes := make([]minio.ExcludedPrefix, 0, len(prefixes))
|
||||
for _, prefix := range prefixes {
|
||||
eprefixes = append(eprefixes, minio.ExcludedPrefix{Prefix: prefix})
|
||||
}
|
||||
vc.ExcludedPrefixes = eprefixes
|
||||
}
|
||||
err = c.api.SetBucketVersioning(ctx, bucket, vc)
|
||||
} else {
|
||||
err = c.api.EnableVersioning(ctx, bucket)
|
||||
}
|
||||
case "suspend":
|
||||
err = c.api.SuspendVersioning(ctx, bucket)
|
||||
default:
|
||||
|
||||
+1
-1
@@ -154,7 +154,7 @@ type Client interface {
|
||||
|
||||
// Versioning operations
|
||||
GetVersion(ctx context.Context) (minio.BucketVersioningConfiguration, *probe.Error)
|
||||
SetVersion(ctx context.Context, status string) *probe.Error
|
||||
SetVersion(ctx context.Context, status string, prefixes []string, excludeFolders bool) *probe.Error
|
||||
// Replication operations
|
||||
GetReplication(ctx context.Context) (replication.Config, *probe.Error)
|
||||
SetReplication(ctx context.Context, cfg *replication.Config, opts replication.Options) *probe.Error
|
||||
|
||||
@@ -146,7 +146,8 @@ func isAliasURLDir(ctx context.Context, aliasURL string, keys map[string][]prefi
|
||||
|
||||
// getSourceStreamMetadataFromURL gets a reader from URL.
|
||||
func getSourceStreamMetadataFromURL(ctx context.Context, aliasedURL, versionID string, timeRef time.Time, encKeyDB map[string][]prefixSSEPair) (reader io.ReadCloser,
|
||||
metadata map[string]string, err *probe.Error) {
|
||||
metadata map[string]string, err *probe.Error,
|
||||
) {
|
||||
alias, urlStrFull, _, err := expandAlias(aliasedURL)
|
||||
if err != nil {
|
||||
return nil, nil, err.Trace(aliasedURL)
|
||||
|
||||
@@ -155,7 +155,8 @@ func getILMColumnWidthTable() map[string]int {
|
||||
// Multiple rows are required for display of data with tags.
|
||||
// Each 'key:value' pair is shown in 1 row and the rest of it is cells populated with blanks.
|
||||
func checkAddTableCellRows(rowArr *[]string, rowCheck map[string]int, showOpts showDetails,
|
||||
cellInfo tableCellInfo, ruleID string, newRows map[string][]string) {
|
||||
cellInfo tableCellInfo, ruleID string, newRows map[string][]string,
|
||||
) {
|
||||
var cellLabel string
|
||||
multLth := len(cellInfo.multLabels)
|
||||
if cellInfo.label != "" || multLth == 0 {
|
||||
|
||||
@@ -180,7 +180,8 @@ func fatalIfBucketLockNotEnabled(ctx context.Context, aliasedURL string) {
|
||||
|
||||
// Apply Retention for one object/version or many objects within a given prefix.
|
||||
func applyRetention(ctx context.Context, op lockOpType, target, versionID string, timeRef time.Time, withOlderVersions, isRecursive bool,
|
||||
mode minio.RetentionMode, validity uint64, unit minio.ValidityUnit, bypassGovernance bool) error {
|
||||
mode minio.RetentionMode, validity uint64, unit minio.ValidityUnit, bypassGovernance bool,
|
||||
) error {
|
||||
clnt, err := newClient(target)
|
||||
if err != nil {
|
||||
fatalIf(err.Trace(), "Unable to parse the provided url.")
|
||||
|
||||
@@ -129,7 +129,8 @@ func parseSetRetentionArgs(cliCtx *cli.Context) (target, versionID string, recur
|
||||
|
||||
// Set Retention for one object/version or many objects within a given prefix.
|
||||
func setRetention(ctx context.Context, target, versionID string, timeRef time.Time, withOlderVersions, isRecursive bool,
|
||||
mode minio.RetentionMode, validity uint64, unit minio.ValidityUnit, bypassGovernance bool) error {
|
||||
mode minio.RetentionMode, validity uint64, unit minio.ValidityUnit, bypassGovernance bool,
|
||||
) error {
|
||||
return applyRetention(ctx, lockOpSet, target, versionID, timeRef, withOlderVersions, isRecursive, mode, validity, unit, bypassGovernance)
|
||||
}
|
||||
|
||||
|
||||
+33
-4
@@ -20,6 +20,7 @@ package cmd
|
||||
import (
|
||||
"context"
|
||||
"fmt"
|
||||
"strings"
|
||||
|
||||
"github.com/fatih/color"
|
||||
"github.com/minio/cli"
|
||||
@@ -28,13 +29,24 @@ import (
|
||||
"github.com/minio/pkg/console"
|
||||
)
|
||||
|
||||
var versionEnableFlags = []cli.Flag{
|
||||
cli.StringFlag{
|
||||
Name: "excluded-prefixes",
|
||||
Usage: "exclude versioning on these prefix patterns",
|
||||
},
|
||||
cli.BoolFlag{
|
||||
Name: "exclude-folders",
|
||||
Usage: "exclude versioning on folder objects",
|
||||
},
|
||||
}
|
||||
|
||||
var versionEnableCmd = cli.Command{
|
||||
Name: "enable",
|
||||
Usage: "enable bucket versioning",
|
||||
Action: mainVersionEnable,
|
||||
OnUsageError: onUsageError,
|
||||
Before: setGlobalsFromContext,
|
||||
Flags: globalFlags,
|
||||
Flags: append(globalFlags, versionEnableFlags...),
|
||||
CustomHelpTemplate: `NAME:
|
||||
{{.HelpName}} - {{.Usage}}
|
||||
|
||||
@@ -47,6 +59,13 @@ FLAGS:
|
||||
EXAMPLES:
|
||||
1. Enable versioning on bucket "mybucket" for alias "myminio".
|
||||
{{.Prompt}} {{.HelpName}} myminio/mybucket
|
||||
|
||||
2. Enable versioning on bucket "mybucket" while excluding versioning on a few select prefixes.
|
||||
{{.Prompt}} {{.HelpName}} myminio/mybucket --excluded-prefixes "app1/*/_temporary/,app2/*/_staging/"
|
||||
|
||||
3. Enable versioning on bucket "mybucket" while excluding versioning on a few select prefixes and all folders.
|
||||
Note: this is useful on buckets used with Spark/Hadoop workloads.
|
||||
{{.Prompt}} {{.HelpName}} myminio/mybucket --excluded-prefixes "app1/*/_temporary/,app2/*/_staging/" --exclude-folders
|
||||
`,
|
||||
}
|
||||
|
||||
@@ -62,8 +81,10 @@ type versionEnableMessage struct {
|
||||
Status string `json:"status"`
|
||||
URL string `json:"url"`
|
||||
Versioning struct {
|
||||
Status string `json:"status"`
|
||||
MFADelete string `json:"MFADelete"`
|
||||
Status string `json:"status"`
|
||||
MFADelete string `json:"MFADelete"`
|
||||
ExcludedPrefixes []string `json:"ExcludedPrefixes,omitempty"`
|
||||
ExcludeFolders bool `json:"ExcludeFolders,,omitempty"`
|
||||
} `json:"versioning"`
|
||||
}
|
||||
|
||||
@@ -89,10 +110,18 @@ func mainVersionEnable(cliCtx *cli.Context) error {
|
||||
// Get the alias parameter from cli
|
||||
args := cliCtx.Args()
|
||||
aliasedURL := args.Get(0)
|
||||
|
||||
var excludedPrefixes []string
|
||||
prefixesStr := cliCtx.String("excluded-prefixes")
|
||||
if prefixesStr != "" {
|
||||
excludedPrefixes = strings.Split(prefixesStr, ",")
|
||||
}
|
||||
excludeFolders := cliCtx.Bool("exclude-folders")
|
||||
|
||||
// Create a new Client
|
||||
client, err := newClient(aliasedURL)
|
||||
fatalIf(err, "Unable to initialize connection.")
|
||||
fatalIf(client.SetVersion(ctx, "enable"), "Unable to enable versioning")
|
||||
fatalIf(client.SetVersion(ctx, "enable", excludedPrefixes, excludeFolders), "Unable to enable versioning")
|
||||
printMsg(versionEnableMessage{
|
||||
Op: "enable",
|
||||
Status: "success",
|
||||
|
||||
+13
-2
@@ -63,8 +63,10 @@ type versioningInfoMessage struct {
|
||||
Status string `json:"status"`
|
||||
URL string `json:"url"`
|
||||
Versioning struct {
|
||||
Status string `json:"status"`
|
||||
MFADelete string `json:"MFADelete"`
|
||||
Status string `json:"status"`
|
||||
MFADelete string `json:"MFADelete"`
|
||||
ExcludedPrefixes []string `json:"ExcludedPrefixes,omitempty"`
|
||||
ExcludeFolders bool `json:"ExcludeFolders,omitempty"`
|
||||
} `json:"versioning"`
|
||||
}
|
||||
|
||||
@@ -109,6 +111,15 @@ func mainVersionInfo(cliCtx *cli.Context) error {
|
||||
}
|
||||
vMsg.Versioning.Status = vConfig.Status
|
||||
vMsg.Versioning.MFADelete = vConfig.MFADelete
|
||||
vMsg.Versioning.ExcludeFolders = vConfig.ExcludeFolders
|
||||
if len(vConfig.ExcludedPrefixes) > 0 {
|
||||
prefixes := make([]string, 0, len(vConfig.ExcludedPrefixes))
|
||||
for _, eprefix := range vConfig.ExcludedPrefixes {
|
||||
prefixes = append(prefixes, eprefix.Prefix)
|
||||
}
|
||||
vMsg.Versioning.ExcludedPrefixes = prefixes
|
||||
}
|
||||
|
||||
printMsg(vMsg)
|
||||
return nil
|
||||
}
|
||||
|
||||
@@ -89,10 +89,11 @@ func mainVersionSuspend(cliCtx *cli.Context) error {
|
||||
// Get the alias parameter from cli
|
||||
args := cliCtx.Args()
|
||||
aliasedURL := args.Get(0)
|
||||
|
||||
// Create a new Client
|
||||
client, err := newClient(aliasedURL)
|
||||
fatalIf(err, "Unable to initialize connection.")
|
||||
fatalIf(client.SetVersion(ctx, "suspend"), "Unable to suspend versioning")
|
||||
fatalIf(client.SetVersion(ctx, "suspend", nil, false), "Unable to suspend versioning")
|
||||
printMsg(versionSuspendMessage{
|
||||
Op: "suspend",
|
||||
Status: "success",
|
||||
|
||||
@@ -21,7 +21,7 @@ require (
|
||||
github.com/minio/filepath v1.0.0
|
||||
github.com/minio/madmin-go v1.3.13
|
||||
github.com/minio/md5-simd v1.1.2 // indirect
|
||||
github.com/minio/minio-go/v7 v7.0.24
|
||||
github.com/minio/minio-go/v7 v7.0.26
|
||||
github.com/minio/pkg v1.1.22
|
||||
github.com/minio/selfupdate v0.4.0
|
||||
github.com/minio/sha256-simd v1.0.0
|
||||
|
||||
@@ -62,7 +62,6 @@ github.com/bketelsen/crypt v0.0.4/go.mod h1:aI6NrJ0pMGgvZKL1iVgXLnfIFJtfV+bKCoqO
|
||||
github.com/briandowns/spinner v1.18.1 h1:yhQmQtM1zsqFsouh09Bk/jCjd50pC3EOGsh28gLVvwY=
|
||||
github.com/briandowns/spinner v1.18.1/go.mod h1:mQak9GHqbspjC/5iUx3qMlIho8xBS/ppAL/hX5SmPJU=
|
||||
github.com/census-instrumentation/opencensus-proto v0.2.1/go.mod h1:f6KPmirojxKA12rnyqOA5BBL4O983OfeGPqjHWSTneU=
|
||||
github.com/cespare/xxhash v1.1.0 h1:a6HrQnmkObjyL+Gs60czilIUGqrzKutQD6XZog3p+ko=
|
||||
github.com/cespare/xxhash v1.1.0/go.mod h1:XrSqR1VqqWfGrhpAt58auRo0WTKS1nRRg3ghfAqPWnc=
|
||||
github.com/cespare/xxhash/v2 v2.1.1/go.mod h1:VGX0DQ3Q6kWi7AoAeZDth3/j3BFtOZR5XLFGgcrjCOs=
|
||||
github.com/cespare/xxhash/v2 v2.1.2 h1:YRXhKfTDauu4ajMg1TPgFO5jnlC2HCbmLXMcTG5cbYE=
|
||||
@@ -274,7 +273,6 @@ github.com/klauspost/compress v1.13.5/go.mod h1:/3/Vjq9QcHkK5uEr5lBEmyoZ1iFhe47e
|
||||
github.com/klauspost/compress v1.13.6 h1:P76CopJELS0TiO2mebmnzgWaajssP/EszplttgQxcgc=
|
||||
github.com/klauspost/compress v1.13.6/go.mod h1:/3/Vjq9QcHkK5uEr5lBEmyoZ1iFhe47etQ6QUkpK6sk=
|
||||
github.com/klauspost/cpuid v1.2.3/go.mod h1:Pj4uuM528wm8OyEC2QMXAi2YiTZ96dNQPGgoMS4s3ek=
|
||||
github.com/klauspost/cpuid v1.3.1 h1:5JNjFYYQrZeKRJ0734q51WCEEn2huer72Dc7K+R/b6s=
|
||||
github.com/klauspost/cpuid v1.3.1/go.mod h1:bYW4mA6ZgKPob1/Dlai2LviZJO7KGI3uoWLd42rAQw4=
|
||||
github.com/klauspost/cpuid/v2 v2.0.1/go.mod h1:FInQzS24/EEf25PyTYn52gqo7WaD8xa0213Md/qVLRg=
|
||||
github.com/klauspost/cpuid/v2 v2.0.4/go.mod h1:FInQzS24/EEf25PyTYn52gqo7WaD8xa0213Md/qVLRg=
|
||||
@@ -345,15 +343,14 @@ github.com/minio/colorjson v1.0.2/go.mod h1:JWxcL2n8T8JVf+NY6awl6kn5nK49aAzHOeQE
|
||||
github.com/minio/filepath v1.0.0 h1:fvkJu1+6X+ECRA6G3+JJETj4QeAYO9sV43I79H8ubDY=
|
||||
github.com/minio/filepath v1.0.0/go.mod h1:/nRZA2ldl5z6jT9/KQuvZcQlxZIMQoFFQPvEXx9T/Bw=
|
||||
github.com/minio/madmin-go v1.3.5/go.mod h1:vGKGboQgGIWx4DuDUaXixjlIEZOCIp6ivJkQoiVaACc=
|
||||
github.com/minio/madmin-go v1.3.11/go.mod h1:ez87VmMtsxP7DRxjKJKD4RDNW+nhO2QF9KSzwxBDQ98=
|
||||
github.com/minio/madmin-go v1.3.13 h1:157u3bFK9qh2EkkqjpJ/bwOw/5KonXUWqhKP3ZczAdY=
|
||||
github.com/minio/madmin-go v1.3.13/go.mod h1:ez87VmMtsxP7DRxjKJKD4RDNW+nhO2QF9KSzwxBDQ98=
|
||||
github.com/minio/md5-simd v1.1.0/go.mod h1:XpBqgZULrMYD3R+M28PcmP0CkI7PEMzB3U77ZrKZ0Gw=
|
||||
github.com/minio/md5-simd v1.1.2 h1:Gdi1DZK69+ZVMoNHRXJyNcxrMA4dSxoYHZSQbirFg34=
|
||||
github.com/minio/md5-simd v1.1.2/go.mod h1:MzdKDxYpY2BT9XQFocsiZf/NKVtR7nkE4RoEpN+20RM=
|
||||
github.com/minio/minio-go/v7 v7.0.23/go.mod h1:ei5JjmxwHaMrgsMrn4U/+Nmg+d8MKS1U2DAn1ou4+Do=
|
||||
github.com/minio/minio-go/v7 v7.0.24 h1:HPlHiET6L5gIgrHRaw1xFo1OaN4bEP/082asWh3WJtI=
|
||||
github.com/minio/minio-go/v7 v7.0.24/go.mod h1:x81+AX5gHSfCSqw7jxRKHvxUXMlE5uKX0Vb75Xk5yYg=
|
||||
github.com/minio/minio-go/v7 v7.0.26 h1:D0HK+8793etZfRY/vHhDmFaP+vmT41K3K4JV9vmZCBQ=
|
||||
github.com/minio/minio-go/v7 v7.0.26/go.mod h1:x81+AX5gHSfCSqw7jxRKHvxUXMlE5uKX0Vb75Xk5yYg=
|
||||
github.com/minio/pkg v1.1.20/go.mod h1:Xo7LQshlxGa9shKwJ7NzQbgW4s8T/Wc1cOStR/eUiMY=
|
||||
github.com/minio/pkg v1.1.22 h1:Fm3oPu9LJag0FhD5BjFxj0Ut+M8S8IkiPHaq5OAoZaM=
|
||||
github.com/minio/pkg v1.1.22/go.mod h1:z9PfmEI804KFkF6eY4LoGe8IDVvTCsYGVuaf58Dr0WI=
|
||||
|
||||
Reference in New Issue
Block a user