update minio-go/v7 APIs again (#3305)
This commit is contained in:
+4
-4
@@ -33,13 +33,13 @@ import (
|
||||
"github.com/pkg/xattr"
|
||||
"github.com/rjeczalik/notify"
|
||||
|
||||
"github.com/minio/mc/cmd/ilm"
|
||||
"github.com/minio/mc/pkg/disk"
|
||||
"github.com/minio/mc/pkg/hookreader"
|
||||
"github.com/minio/mc/pkg/ioutils"
|
||||
"github.com/minio/mc/pkg/probe"
|
||||
minio "github.com/minio/minio-go/v7"
|
||||
"github.com/minio/minio-go/v7/pkg/encrypt"
|
||||
"github.com/minio/minio-go/v7/pkg/lifecycle"
|
||||
)
|
||||
|
||||
// filesystem client
|
||||
@@ -1114,15 +1114,15 @@ func (f *fsClient) DeleteTags(ctx context.Context) *probe.Error {
|
||||
}
|
||||
|
||||
// Get lifecycle configuration for a given bucket, not implemented.
|
||||
func (f *fsClient) GetLifecycle(ctx context.Context) (ilm.LifecycleConfiguration, *probe.Error) {
|
||||
return ilm.LifecycleConfiguration{}, probe.NewError(APINotImplemented{
|
||||
func (f *fsClient) GetLifecycle(ctx context.Context) (*lifecycle.Configuration, *probe.Error) {
|
||||
return nil, probe.NewError(APINotImplemented{
|
||||
API: "GetLifecycle",
|
||||
APIType: "filesystem",
|
||||
})
|
||||
}
|
||||
|
||||
// Set lifecycle configuration for a given bucket, not implemented.
|
||||
func (f *fsClient) SetLifecycle(ctx context.Context, _ ilm.LifecycleConfiguration) *probe.Error {
|
||||
func (f *fsClient) SetLifecycle(ctx context.Context, _ *lifecycle.Configuration) *probe.Error {
|
||||
return probe.NewError(APINotImplemented{
|
||||
API: "SetLifecycle",
|
||||
APIType: "filesystem",
|
||||
|
||||
+34
-48
@@ -21,7 +21,6 @@ import (
|
||||
"context"
|
||||
"crypto/tls"
|
||||
"encoding/json"
|
||||
"encoding/xml"
|
||||
"errors"
|
||||
"fmt"
|
||||
"hash/fnv"
|
||||
@@ -37,12 +36,13 @@ import (
|
||||
"sync"
|
||||
"time"
|
||||
|
||||
"github.com/minio/mc/cmd/ilm"
|
||||
"github.com/minio/mc/pkg/httptracer"
|
||||
"github.com/minio/mc/pkg/probe"
|
||||
minio "github.com/minio/minio-go/v7"
|
||||
"github.com/minio/minio-go/v7/pkg/credentials"
|
||||
"github.com/minio/minio-go/v7/pkg/encrypt"
|
||||
"github.com/minio/minio-go/v7/pkg/lifecycle"
|
||||
"github.com/minio/minio-go/v7/pkg/notification"
|
||||
"github.com/minio/minio-go/v7/pkg/policy"
|
||||
"github.com/minio/minio-go/v7/pkg/s3utils"
|
||||
"github.com/minio/minio-go/v7/pkg/tags"
|
||||
@@ -246,18 +246,18 @@ func (c *S3Client) AddNotificationConfig(ctx context.Context, arn string, events
|
||||
return probe.NewError(e)
|
||||
}
|
||||
|
||||
accountArn := minio.NewArn(fields[1], fields[2], fields[3], fields[4], fields[5])
|
||||
nc := minio.NewNotificationConfig(accountArn)
|
||||
accountArn := notification.NewArn(fields[1], fields[2], fields[3], fields[4], fields[5])
|
||||
nc := notification.NewConfig(accountArn)
|
||||
|
||||
// Configure events
|
||||
for _, event := range events {
|
||||
switch event {
|
||||
case "put":
|
||||
nc.AddEvents(minio.ObjectCreatedAll)
|
||||
nc.AddEvents(notification.ObjectCreatedAll)
|
||||
case "delete":
|
||||
nc.AddEvents(minio.ObjectRemovedAll)
|
||||
nc.AddEvents(notification.ObjectRemovedAll)
|
||||
case "get":
|
||||
nc.AddEvents(minio.ObjectAccessedAll)
|
||||
nc.AddEvents(notification.ObjectAccessedAll)
|
||||
default:
|
||||
return errInvalidArgument().Trace(events...)
|
||||
}
|
||||
@@ -316,22 +316,22 @@ func (c *S3Client) RemoveNotificationConfig(ctx context.Context, arn string, eve
|
||||
if len(fields) != 6 {
|
||||
return errInvalidArgument().Trace(fields...)
|
||||
}
|
||||
accountArn := minio.NewArn(fields[1], fields[2], fields[3], fields[4], fields[5])
|
||||
accountArn := notification.NewArn(fields[1], fields[2], fields[3], fields[4], fields[5])
|
||||
|
||||
// if we are passed filters for either events, suffix or prefix, then only delete the single event that matches
|
||||
// the arguments
|
||||
if event != "" || suffix != "" || prefix != "" {
|
||||
// Translate events to type events for comparison
|
||||
events := strings.Split(event, ",")
|
||||
var eventsTyped []minio.NotificationEventType
|
||||
var eventsTyped []notification.EventType
|
||||
for _, e := range events {
|
||||
switch e {
|
||||
case "put":
|
||||
eventsTyped = append(eventsTyped, minio.ObjectCreatedAll)
|
||||
eventsTyped = append(eventsTyped, notification.ObjectCreatedAll)
|
||||
case "delete":
|
||||
eventsTyped = append(eventsTyped, minio.ObjectRemovedAll)
|
||||
eventsTyped = append(eventsTyped, notification.ObjectRemovedAll)
|
||||
case "get":
|
||||
eventsTyped = append(eventsTyped, minio.ObjectAccessedAll)
|
||||
eventsTyped = append(eventsTyped, notification.ObjectAccessedAll)
|
||||
default:
|
||||
return errInvalidArgument().Trace(events...)
|
||||
}
|
||||
@@ -392,7 +392,7 @@ func (c *S3Client) ListNotificationConfigs(ctx context.Context, arn string) ([]N
|
||||
}
|
||||
|
||||
// Generate pretty event names from event types
|
||||
prettyEventNames := func(eventsTypes []minio.NotificationEventType) []string {
|
||||
prettyEventNames := func(eventsTypes []notification.EventType) []string {
|
||||
var result []string
|
||||
for _, eventType := range eventsTypes {
|
||||
result = append(result, string(eventType))
|
||||
@@ -400,7 +400,7 @@ func (c *S3Client) ListNotificationConfigs(ctx context.Context, arn string) ([]N
|
||||
return result
|
||||
}
|
||||
|
||||
getFilters := func(config minio.NotificationConfig) (prefix, suffix string) {
|
||||
getFilters := func(config notification.Config) (prefix, suffix string) {
|
||||
if config.Filter == nil {
|
||||
return
|
||||
}
|
||||
@@ -420,7 +420,7 @@ func (c *S3Client) ListNotificationConfigs(ctx context.Context, arn string) ([]N
|
||||
if arn != "" && config.Topic != arn {
|
||||
continue
|
||||
}
|
||||
prefix, suffix := getFilters(config.NotificationConfig)
|
||||
prefix, suffix := getFilters(config.Config)
|
||||
configs = append(configs, NotificationConfig{ID: config.ID,
|
||||
Arn: config.Topic,
|
||||
Events: prettyEventNames(config.Events),
|
||||
@@ -432,7 +432,7 @@ func (c *S3Client) ListNotificationConfigs(ctx context.Context, arn string) ([]N
|
||||
if arn != "" && config.Queue != arn {
|
||||
continue
|
||||
}
|
||||
prefix, suffix := getFilters(config.NotificationConfig)
|
||||
prefix, suffix := getFilters(config.Config)
|
||||
configs = append(configs, NotificationConfig{ID: config.ID,
|
||||
Arn: config.Queue,
|
||||
Events: prettyEventNames(config.Events),
|
||||
@@ -444,7 +444,7 @@ func (c *S3Client) ListNotificationConfigs(ctx context.Context, arn string) ([]N
|
||||
if arn != "" && config.Lambda != arn {
|
||||
continue
|
||||
}
|
||||
prefix, suffix := getFilters(config.NotificationConfig)
|
||||
prefix, suffix := getFilters(config.Config)
|
||||
configs = append(configs, NotificationConfig{ID: config.ID,
|
||||
Arn: config.Lambda,
|
||||
Events: prettyEventNames(config.Events),
|
||||
@@ -626,7 +626,7 @@ func (c *S3Client) Select(ctx context.Context, expression string, sse encrypt.Se
|
||||
return reader, nil
|
||||
}
|
||||
|
||||
func (c *S3Client) notificationToEventsInfo(ninfo minio.NotificationInfo) []EventInfo {
|
||||
func (c *S3Client) notificationToEventsInfo(ninfo notification.Info) []EventInfo {
|
||||
var eventsInfo = make([]EventInfo, len(ninfo.Records))
|
||||
for i, record := range ninfo.Records {
|
||||
bucketName := record.S3.Bucket.Name
|
||||
@@ -700,7 +700,7 @@ func (c *S3Client) notificationToEventsInfo(ninfo minio.NotificationInfo) []Even
|
||||
Port: record.Source.Port,
|
||||
UserAgent: record.Source.UserAgent,
|
||||
}
|
||||
} else if record.EventName == minio.ObjectAccessedGet {
|
||||
} else if record.EventName == notification.ObjectAccessedGet {
|
||||
eventsInfo[i] = EventInfo{
|
||||
Time: record.EventTime,
|
||||
Size: record.S3.Object.Size,
|
||||
@@ -711,7 +711,7 @@ func (c *S3Client) notificationToEventsInfo(ninfo minio.NotificationInfo) []Even
|
||||
Port: record.Source.Port,
|
||||
UserAgent: record.Source.UserAgent,
|
||||
}
|
||||
} else if record.EventName == minio.ObjectAccessedHead {
|
||||
} else if record.EventName == notification.ObjectAccessedHead {
|
||||
eventsInfo[i] = EventInfo{
|
||||
Time: record.EventTime,
|
||||
Size: record.S3.Object.Size,
|
||||
@@ -737,11 +737,11 @@ func (c *S3Client) Watch(ctx context.Context, options WatchOptions) (*WatchObjec
|
||||
for _, event := range options.Events {
|
||||
switch event {
|
||||
case "put":
|
||||
events = append(events, string(minio.ObjectCreatedAll))
|
||||
events = append(events, string(notification.ObjectCreatedAll))
|
||||
case "delete":
|
||||
events = append(events, string(minio.ObjectRemovedAll))
|
||||
events = append(events, string(notification.ObjectRemovedAll))
|
||||
case "get":
|
||||
events = append(events, string(minio.ObjectAccessedAll))
|
||||
events = append(events, string(notification.ObjectAccessedAll))
|
||||
default:
|
||||
return nil, errInvalidArgument().Trace(event)
|
||||
}
|
||||
@@ -2199,12 +2199,12 @@ func (c *S3Client) GetTags(ctx context.Context) (map[string]string, *probe.Error
|
||||
return tags.ToMap(), nil
|
||||
}
|
||||
|
||||
tagMap, err := c.api.GetObjectTagging(ctx, bucketName, objectName, minio.GetObjectTaggingOptions{})
|
||||
tags, err := c.api.GetObjectTagging(ctx, bucketName, objectName, minio.GetObjectTaggingOptions{})
|
||||
if err != nil {
|
||||
return nil, probe.NewError(err)
|
||||
}
|
||||
|
||||
return tagMap, nil
|
||||
return tags.ToMap(), nil
|
||||
}
|
||||
|
||||
// SetTags - Set tags of bucket or object.
|
||||
@@ -2222,7 +2222,7 @@ func (c *S3Client) SetTags(ctx context.Context, tagString string) *probe.Error {
|
||||
if objectName == "" {
|
||||
err = c.api.SetBucketTagging(ctx, bucketName, tags)
|
||||
} else {
|
||||
err = c.api.PutObjectTagging(ctx, bucketName, objectName, tags.ToMap(), minio.PutObjectTaggingOptions{})
|
||||
err = c.api.PutObjectTagging(ctx, bucketName, objectName, tags, minio.PutObjectTaggingOptions{})
|
||||
}
|
||||
|
||||
if err != nil {
|
||||
@@ -2241,7 +2241,7 @@ func (c *S3Client) DeleteTags(ctx context.Context) *probe.Error {
|
||||
|
||||
var err error
|
||||
if objectName == "" {
|
||||
err = c.api.DeleteBucketTagging(ctx, bucketName)
|
||||
err = c.api.RemoveBucketTagging(ctx, bucketName)
|
||||
} else {
|
||||
err = c.api.RemoveObjectTagging(ctx, bucketName, objectName, minio.RemoveObjectTaggingOptions{})
|
||||
}
|
||||
@@ -2254,42 +2254,28 @@ func (c *S3Client) DeleteTags(ctx context.Context) *probe.Error {
|
||||
}
|
||||
|
||||
// GetLifecycle - Get current lifecycle configuration.
|
||||
func (c *S3Client) GetLifecycle(ctx context.Context) (ilm.LifecycleConfiguration, *probe.Error) {
|
||||
func (c *S3Client) GetLifecycle(ctx context.Context) (*lifecycle.Configuration, *probe.Error) {
|
||||
bucket, _ := c.url2BucketAndObject()
|
||||
if bucket == "" {
|
||||
return ilm.LifecycleConfiguration{}, probe.NewError(BucketNameEmpty{})
|
||||
return nil, probe.NewError(BucketNameEmpty{})
|
||||
}
|
||||
|
||||
lifecycleXML, e := c.api.GetBucketLifecycle(ctx, bucket)
|
||||
config, e := c.api.GetBucketLifecycle(ctx, bucket)
|
||||
if e != nil {
|
||||
return ilm.LifecycleConfiguration{}, probe.NewError(e)
|
||||
return nil, probe.NewError(e)
|
||||
}
|
||||
|
||||
lfcCfg := ilm.LifecycleConfiguration{}
|
||||
if e = xml.Unmarshal([]byte(lifecycleXML), &lfcCfg); e != nil && e != io.EOF {
|
||||
return lfcCfg, probe.NewError(e)
|
||||
}
|
||||
|
||||
return lfcCfg, nil
|
||||
return config, nil
|
||||
}
|
||||
|
||||
// SetLifecycle - Set lifecycle configuration on a bucket
|
||||
func (c *S3Client) SetLifecycle(ctx context.Context, ilmCfg ilm.LifecycleConfiguration) *probe.Error {
|
||||
func (c *S3Client) SetLifecycle(ctx context.Context, config *lifecycle.Configuration) *probe.Error {
|
||||
bucket, _ := c.url2BucketAndObject()
|
||||
if bucket == "" {
|
||||
return probe.NewError(BucketNameEmpty{})
|
||||
}
|
||||
|
||||
var lifecycleXML []byte
|
||||
if len(ilmCfg.Rules) != 0 {
|
||||
var e error
|
||||
lifecycleXML, e = xml.Marshal(ilmCfg)
|
||||
if e != nil {
|
||||
return probe.NewError(e)
|
||||
}
|
||||
}
|
||||
|
||||
if e := c.api.SetBucketLifecycle(ctx, bucket, string(lifecycleXML)); e != nil {
|
||||
if e := c.api.SetBucketLifecycle(ctx, bucket, config); e != nil {
|
||||
return probe.NewError(e)
|
||||
}
|
||||
|
||||
|
||||
+3
-3
@@ -22,10 +22,10 @@ import (
|
||||
"os"
|
||||
"time"
|
||||
|
||||
"github.com/minio/mc/cmd/ilm"
|
||||
"github.com/minio/mc/pkg/probe"
|
||||
minio "github.com/minio/minio-go/v7"
|
||||
"github.com/minio/minio-go/v7/pkg/encrypt"
|
||||
"github.com/minio/minio-go/v7/pkg/lifecycle"
|
||||
)
|
||||
|
||||
// DirOpt - list directory option.
|
||||
@@ -94,8 +94,8 @@ type Client interface {
|
||||
DeleteTags(ctx context.Context) *probe.Error
|
||||
|
||||
// Lifecycle operations
|
||||
GetLifecycle(ctx context.Context) (ilm.LifecycleConfiguration, *probe.Error)
|
||||
SetLifecycle(ctx context.Context, lfcCfg ilm.LifecycleConfiguration) *probe.Error
|
||||
GetLifecycle(ctx context.Context) (*lifecycle.Configuration, *probe.Error)
|
||||
SetLifecycle(ctx context.Context, config *lifecycle.Configuration) *probe.Error
|
||||
}
|
||||
|
||||
// ClientContent - Content container for content metadata
|
||||
|
||||
@@ -20,8 +20,6 @@ import (
|
||||
"context"
|
||||
"errors"
|
||||
|
||||
"github.com/minio/minio-go/v7"
|
||||
|
||||
"github.com/fatih/color"
|
||||
"github.com/minio/cli"
|
||||
json "github.com/minio/mc/pkg/colorjson"
|
||||
@@ -136,9 +134,6 @@ func mainEventRemove(cliCtx *cli.Context) error {
|
||||
|
||||
err = s3Client.RemoveNotificationConfig(ctx, arn, event, prefix, suffix)
|
||||
if err != nil {
|
||||
if err.Cause == minio.ErrNoNotificationConfigMatch {
|
||||
fatalIf(err, "Remove event failed.")
|
||||
}
|
||||
fatalIf(err, "Cannot disable notification on the specified bucket.")
|
||||
}
|
||||
|
||||
|
||||
+8
-8
@@ -21,9 +21,9 @@ import (
|
||||
"errors"
|
||||
|
||||
"github.com/minio/cli"
|
||||
"github.com/minio/mc/cmd/ilm"
|
||||
json "github.com/minio/mc/pkg/colorjson"
|
||||
"github.com/minio/mc/pkg/probe"
|
||||
"github.com/minio/minio-go/v7/pkg/lifecycle"
|
||||
)
|
||||
|
||||
var ilmExportCmd = cli.Command{
|
||||
@@ -51,13 +51,13 @@ EXAMPLES:
|
||||
}
|
||||
|
||||
type ilmExportMessage struct {
|
||||
Status string `json:"status"`
|
||||
Target string `json:"target"`
|
||||
ILMConfig ilm.LifecycleConfiguration `json:"ilmConfig"`
|
||||
Status string `json:"status"`
|
||||
Target string `json:"target"`
|
||||
Config *lifecycle.Configuration `json:"config"`
|
||||
}
|
||||
|
||||
func (i ilmExportMessage) String() string {
|
||||
msgBytes, e := json.MarshalIndent(i.ILMConfig, "", " ")
|
||||
msgBytes, e := json.MarshalIndent(i.Config, "", " ")
|
||||
fatalIf(probe.NewError(e), "Unable to export ILM configuration")
|
||||
|
||||
return string(msgBytes)
|
||||
@@ -98,9 +98,9 @@ func mainILMExport(cliCtx *cli.Context) error {
|
||||
}
|
||||
|
||||
printMsg(ilmExportMessage{
|
||||
Status: "success",
|
||||
Target: urlStr,
|
||||
ILMConfig: ilmCfg,
|
||||
Status: "success",
|
||||
Target: urlStr,
|
||||
Config: ilmCfg,
|
||||
})
|
||||
|
||||
return nil
|
||||
|
||||
+8
-6
@@ -21,9 +21,9 @@ import (
|
||||
"os"
|
||||
|
||||
"github.com/minio/cli"
|
||||
"github.com/minio/mc/cmd/ilm"
|
||||
json "github.com/minio/mc/pkg/colorjson"
|
||||
"github.com/minio/mc/pkg/probe"
|
||||
"github.com/minio/minio-go/v7/pkg/lifecycle"
|
||||
"github.com/minio/minio/pkg/console"
|
||||
)
|
||||
|
||||
@@ -67,15 +67,17 @@ func (i ilmImportMessage) JSON() string {
|
||||
}
|
||||
|
||||
// readILMConfig read from stdin, returns XML.
|
||||
func readILMConfig() (ilm.LifecycleConfiguration, *probe.Error) {
|
||||
func readILMConfig() (*lifecycle.Configuration, *probe.Error) {
|
||||
// User is expected to enter the lifecycleConfiguration instance contents in JSON format
|
||||
var ilmCfg ilm.LifecycleConfiguration
|
||||
var cfg = lifecycle.NewConfiguration()
|
||||
|
||||
// Consume json from STDIN
|
||||
dec := json.NewDecoder(os.Stdin)
|
||||
if e := dec.Decode(&ilmCfg); e != nil {
|
||||
return ilmCfg, probe.NewError(e)
|
||||
if e := dec.Decode(cfg); e != nil {
|
||||
return cfg, probe.NewError(e)
|
||||
}
|
||||
return ilmCfg, nil
|
||||
|
||||
return cfg, nil
|
||||
}
|
||||
|
||||
// checkILMImportSyntax - validate arguments passed by user
|
||||
|
||||
+10
-9
@@ -27,6 +27,7 @@ import (
|
||||
"github.com/minio/mc/cmd/ilm"
|
||||
json "github.com/minio/mc/pkg/colorjson"
|
||||
"github.com/minio/mc/pkg/probe"
|
||||
"github.com/minio/minio-go/v7/pkg/lifecycle"
|
||||
"github.com/minio/minio/pkg/console"
|
||||
)
|
||||
|
||||
@@ -82,10 +83,10 @@ EXAMPLES:
|
||||
}
|
||||
|
||||
type ilmListMessage struct {
|
||||
Status string `json:"status"`
|
||||
Target string `json:"target"`
|
||||
Context *cli.Context `json:"-"`
|
||||
ILMConfig ilm.LifecycleConfiguration `json:"ilmConfig"`
|
||||
Status string `json:"status"`
|
||||
Target string `json:"target"`
|
||||
Context *cli.Context `json:"-"`
|
||||
Config *lifecycle.Configuration `json:"config"`
|
||||
}
|
||||
|
||||
func (i ilmListMessage) String() string {
|
||||
@@ -102,7 +103,7 @@ func (i ilmListMessage) String() string {
|
||||
var tagRows map[string][]string
|
||||
var tbl PrettyTable
|
||||
|
||||
ilm.PopulateILMDataForDisplay(i.ILMConfig, &hdrLabelIndexMap, &alignedHdrLabels,
|
||||
ilm.PopulateILMDataForDisplay(i.Config, &hdrLabelIndexMap, &alignedHdrLabels,
|
||||
&cellDataNoTags, &cellDataWithTags, &tagRows,
|
||||
showAll, showMinimum, showExpiry, showTransition)
|
||||
|
||||
@@ -276,10 +277,10 @@ func mainILMList(cliCtx *cli.Context) error {
|
||||
}
|
||||
|
||||
printMsg(ilmListMessage{
|
||||
Status: "success",
|
||||
Target: urlStr,
|
||||
Context: cliCtx,
|
||||
ILMConfig: ilmCfg,
|
||||
Status: "success",
|
||||
Target: urlStr,
|
||||
Context: cliCtx,
|
||||
Config: ilmCfg,
|
||||
})
|
||||
|
||||
return nil
|
||||
|
||||
+1
-2
@@ -56,7 +56,6 @@ USAGE:
|
||||
FLAGS:
|
||||
{{range .VisibleFlags}}{{.}}
|
||||
{{end}}
|
||||
|
||||
DESCRIPTION:
|
||||
Remove a lifecycle configuration rule for the bucket by ID, optionally you can remove
|
||||
all the lifecycle rules on a bucket with '--all --force' option.
|
||||
@@ -65,7 +64,7 @@ EXAMPLES:
|
||||
1. Remove the lifecycle management configuration rule given by ID "Documents" for testbucket on alias 'myminio'. ID is case sensitive.
|
||||
{{.Prompt}} {{.HelpName}} --id "Documents" myminio/testbucket
|
||||
|
||||
2. Remove ALL the lifecycle management configuration rules for testbucket on alias 'myminio'.
|
||||
2. Remove ALL the lifecycle management configuration rules for testbucket on alias 'myminio'.
|
||||
Because the result is complete removal, the use of --force flag is enforced.
|
||||
{{.Prompt}} {{.HelpName}} --all --force myminio/testbucket
|
||||
`,
|
||||
|
||||
@@ -1,105 +0,0 @@
|
||||
/*
|
||||
* MinIO Client (C) 2020 MinIO, Inc.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
// Package ilm contains all the ilm related functionality. TO BE ACCESSED VIA GET FUNCTIONS or Operation-related Global functions.
|
||||
package ilm
|
||||
|
||||
import (
|
||||
"encoding/xml"
|
||||
"time"
|
||||
)
|
||||
|
||||
// AbortIncompleteMultipartUpload structure
|
||||
type AbortIncompleteMultipartUpload struct {
|
||||
XMLName xml.Name `xml:"AbortIncompleteMultipartUpload,omitempty" json:"-"`
|
||||
DaysAfterInitiation int64 `xml:"DaysAfterInitiation,omitempty" json:"DaysAfterInitiation,omitempty"`
|
||||
}
|
||||
|
||||
// NoncurrentVersionTransition structure
|
||||
type NoncurrentVersionTransition struct {
|
||||
XMLName xml.Name `xml:"NoncurrentVersionTransition,omitempty" json:"-"`
|
||||
StorageClass string `xml:"StorageClass,omitempty" json:"StorageClass,omitempty"`
|
||||
TransitionInDays int `xml:"TransitionInDays,omitempty" json:"TransitionInDays,omitempty"`
|
||||
}
|
||||
|
||||
// LifecycleTag structure key/value pair representing an object tag to apply lifecycle configuration
|
||||
type LifecycleTag struct {
|
||||
XMLName xml.Name `xml:"Tag,omitempty" json:"-"`
|
||||
Key string `xml:"Key,omitempty" json:"Key,omitempty"`
|
||||
Value string `xml:"Value,omitempty" json:"Value,omitempty"`
|
||||
}
|
||||
|
||||
// LifecycleTransition structure - transition details of lifecycle configuration
|
||||
type LifecycleTransition struct {
|
||||
XMLName xml.Name `xml:"Transition" json:"-"`
|
||||
TransitionDate *time.Time `xml:"Date,omitempty" json:"Date,omitempty"`
|
||||
StorageClass string `xml:"StorageClass,omitempty" json:"StorageClass,omitempty"`
|
||||
TransitionInDays int `xml:"Days,omitempty" json:"Days,omitempty"`
|
||||
}
|
||||
|
||||
// IsSet is transition set
|
||||
func (t LifecycleTransition) IsSet() bool {
|
||||
return t.TransitionDate != nil && !t.TransitionDate.IsZero() || t.TransitionInDays > 0
|
||||
}
|
||||
|
||||
// LifecycleAndOperator And Rule for LifecycleTag, to be used in LifecycleRuleFilter
|
||||
type LifecycleAndOperator struct {
|
||||
XMLName xml.Name `xml:"And,omitempty" json:"-"`
|
||||
Prefix string `xml:"Prefix,omitempty" json:"Prefix,omitempty"`
|
||||
Tags []LifecycleTag `xml:"Tag,omitempty" json:"Tags,omitempty"`
|
||||
}
|
||||
|
||||
// LifecycleRuleFilter will be used in selecting rule(s) for lifecycle configuration
|
||||
type LifecycleRuleFilter struct {
|
||||
XMLName xml.Name `xml:"Filter" json:"-"`
|
||||
And *LifecycleAndOperator `xml:"And,omitempty" json:"And,omitempty"`
|
||||
Prefix string `xml:"Prefix,omitempty" json:"Prefix,omitempty"`
|
||||
Tag *LifecycleTag `xml:"Tag,omitempty" json:"-"`
|
||||
}
|
||||
|
||||
// LifecycleExpiration structure - expiration details of lifecycle configuration
|
||||
type LifecycleExpiration struct {
|
||||
XMLName xml.Name `xml:"Expiration,omitempty" json:"-"`
|
||||
ExpirationDate *time.Time `xml:"Date,omitempty" json:"Date,omitempty"`
|
||||
ExpirationInDays int `xml:"Days,omitempty" json:"Days,omitempty"`
|
||||
}
|
||||
|
||||
// IsSet - is LifecycleExpiration set?
|
||||
func (e LifecycleExpiration) IsSet() bool {
|
||||
return e.ExpirationDate != nil && !e.ExpirationDate.IsZero() || e.ExpirationInDays > 0
|
||||
}
|
||||
|
||||
// LifecycleRule represents a single rule in lifecycle configuration
|
||||
type LifecycleRule struct {
|
||||
XMLName xml.Name `xml:"Rule,omitempty" json:"-"`
|
||||
AbortIncompleteMultipartUpload *AbortIncompleteMultipartUpload `xml:"AbortIncompleteMultipartUpload,omitempty" json:"AbortIncompleteMultipartUpload,omitempty"`
|
||||
Expiration *LifecycleExpiration `xml:"Expiration,omitempty" json:"Expiration,omitempty"`
|
||||
ID string `xml:"ID" json:"ID"`
|
||||
RuleFilter *LifecycleRuleFilter `xml:"Filter,omitempty" json:"Filter,omitempty"`
|
||||
NoncurrentVersionTransition *NoncurrentVersionTransition `xml:"NoncurrentVersionTransition,omitempty" json:"NoncurrentVersionTransition,omitempty"`
|
||||
NoncurrentVersionTransitions []NoncurrentVersionTransition `xml:"NoncurrentVersionTransitions,omitempty" json:"NoncurrentVersionTransitions,omitempty"`
|
||||
Prefix string `xml:"Prefix,omitempty" json:"Prefix,omitempty"`
|
||||
Status string `xml:"Status" json:"Status"`
|
||||
Transition *LifecycleTransition `xml:"Transition,omitempty" json:"Transition,omitempty"`
|
||||
Transitions []LifecycleTransition `xml:"Transitions,omitempty" json:"Transitions,omitempty"`
|
||||
TagFilters []LifecycleTag `xml:"Tag,omitempty" json:"Tags,omitempty"`
|
||||
}
|
||||
|
||||
// LifecycleConfiguration is a collection of LifecycleRule objects.
|
||||
type LifecycleConfiguration struct {
|
||||
XMLName xml.Name `xml:"LifecycleConfiguration,omitempty" json:"-"`
|
||||
Rules []LifecycleRule `xml:"Rule"`
|
||||
}
|
||||
+24
-29
@@ -23,6 +23,7 @@ import (
|
||||
|
||||
"github.com/minio/cli"
|
||||
"github.com/minio/mc/pkg/probe"
|
||||
"github.com/minio/minio-go/v7/pkg/lifecycle"
|
||||
)
|
||||
|
||||
const defaultILMDateFormat string = "2006-01-02"
|
||||
@@ -73,7 +74,10 @@ func getRightAligned(label string, maxLen int) string {
|
||||
}
|
||||
|
||||
// RemoveILMRule - Remove the ILM rule (with ilmID) from the configuration in XML that is provided.
|
||||
func RemoveILMRule(lfcCfg LifecycleConfiguration, ilmID string) (LifecycleConfiguration, *probe.Error) {
|
||||
func RemoveILMRule(lfcCfg *lifecycle.Configuration, ilmID string) (*lifecycle.Configuration, *probe.Error) {
|
||||
if lfcCfg == nil {
|
||||
return lfcCfg, probe.NewError(fmt.Errorf("lifecycle configuration not set"))
|
||||
}
|
||||
if len(lfcCfg.Rules) == 0 {
|
||||
return lfcCfg, probe.NewError(fmt.Errorf("lifecycle configuration not set"))
|
||||
}
|
||||
@@ -105,69 +109,60 @@ type lifecycleOptions struct {
|
||||
StorageClass string
|
||||
}
|
||||
|
||||
func (opts lifecycleOptions) ToConfig(lfcCfg LifecycleConfiguration) (LifecycleConfiguration, *probe.Error) {
|
||||
ilmExpiry, err := parseExpiry(opts.ExpiryDate, opts.ExpiryDays)
|
||||
func (opts lifecycleOptions) ToConfig(config *lifecycle.Configuration) (*lifecycle.Configuration, *probe.Error) {
|
||||
expiry, err := parseExpiry(opts.ExpiryDate, opts.ExpiryDays)
|
||||
if err != nil {
|
||||
return lfcCfg, err.Trace(opts.ExpiryDate, opts.ExpiryDays)
|
||||
return nil, err.Trace(opts.ExpiryDate, opts.ExpiryDays)
|
||||
}
|
||||
|
||||
ilmTransition, err := parseTransition(opts.StorageClass, opts.TransitionDate, opts.TransitionDays)
|
||||
transition, err := parseTransition(opts.StorageClass, opts.TransitionDate, opts.TransitionDays)
|
||||
if err != nil {
|
||||
return lfcCfg, err.Trace(opts.StorageClass, opts.TransitionDate, opts.TransitionDays)
|
||||
return nil, err.Trace(opts.StorageClass, opts.TransitionDate, opts.TransitionDays)
|
||||
}
|
||||
|
||||
andVal := LifecycleAndOperator{
|
||||
andVal := lifecycle.And{
|
||||
Tags: extractILMTags(opts.Tags),
|
||||
}
|
||||
|
||||
filter := LifecycleRuleFilter{Prefix: opts.Prefix}
|
||||
filter := lifecycle.Filter{Prefix: opts.Prefix}
|
||||
if len(andVal.Tags) > 0 {
|
||||
filter.And = &andVal
|
||||
filter.And = andVal
|
||||
filter.And.Prefix = opts.Prefix
|
||||
filter.Prefix = ""
|
||||
}
|
||||
|
||||
var expP *LifecycleExpiration
|
||||
var transP *LifecycleTransition
|
||||
if ilmTransition.IsSet() {
|
||||
transP = &ilmTransition
|
||||
}
|
||||
if ilmExpiry.IsSet() {
|
||||
expP = &ilmExpiry
|
||||
}
|
||||
|
||||
newRule := LifecycleRule{
|
||||
newRule := lifecycle.Rule{
|
||||
ID: opts.ID,
|
||||
RuleFilter: &filter,
|
||||
RuleFilter: filter,
|
||||
Status: func() string {
|
||||
if opts.Status {
|
||||
return "Enabled"
|
||||
}
|
||||
return "Disabled"
|
||||
}(),
|
||||
Expiration: expP,
|
||||
Transition: transP,
|
||||
Expiration: expiry,
|
||||
Transition: transition,
|
||||
}
|
||||
|
||||
if err := validateILMRule(newRule); err != nil {
|
||||
return lfcCfg, err.Trace(opts.ID)
|
||||
return nil, err.Trace(opts.ID)
|
||||
}
|
||||
|
||||
ruleFound := false
|
||||
for i, rule := range lfcCfg.Rules {
|
||||
for i, rule := range config.Rules {
|
||||
if rule.ID != newRule.ID {
|
||||
continue
|
||||
}
|
||||
lfcCfg.Rules[i] = newRule
|
||||
config.Rules[i] = newRule
|
||||
ruleFound = true
|
||||
break
|
||||
}
|
||||
|
||||
if !ruleFound {
|
||||
lfcCfg.Rules = append(lfcCfg.Rules, newRule)
|
||||
config.Rules = append(config.Rules, newRule)
|
||||
}
|
||||
|
||||
return lfcCfg, nil
|
||||
return config, nil
|
||||
}
|
||||
|
||||
func getLifecycleOptions(ctx *cli.Context) lifecycleOptions {
|
||||
@@ -186,7 +181,7 @@ func getLifecycleOptions(ctx *cli.Context) lifecycleOptions {
|
||||
|
||||
// ApplyNewILMConfig apply new lifecycle rules to existing lifecycle configuration, this
|
||||
// function returns modified/overwritten rules if any.
|
||||
func ApplyNewILMConfig(ctx *cli.Context, lfcCfg LifecycleConfiguration) (LifecycleConfiguration, *probe.Error) {
|
||||
func ApplyNewILMConfig(ctx *cli.Context, config *lifecycle.Configuration) (*lifecycle.Configuration, *probe.Error) {
|
||||
opts := getLifecycleOptions(ctx)
|
||||
return opts.ToConfig(lfcCfg)
|
||||
return opts.ToConfig(config)
|
||||
}
|
||||
|
||||
+46
-46
@@ -23,17 +23,18 @@ import (
|
||||
"time"
|
||||
|
||||
"github.com/minio/mc/pkg/probe"
|
||||
"github.com/minio/minio-go/v7/pkg/lifecycle"
|
||||
)
|
||||
|
||||
// Extracts the tags provided by user. The tagfilter array will be put in lifecycleRule structure.
|
||||
func extractILMTags(tagLabelVal string) []LifecycleTag {
|
||||
var ilmTagKVList []LifecycleTag
|
||||
func extractILMTags(tagLabelVal string) []lifecycle.Tag {
|
||||
var ilmTagKVList []lifecycle.Tag
|
||||
for _, tag := range strings.Split(tagLabelVal, tagSeperator) {
|
||||
if tag == "" {
|
||||
// split returns empty for empty tagLabelVal, skip it.
|
||||
continue
|
||||
}
|
||||
lfcTag := LifecycleTag{}
|
||||
lfcTag := lifecycle.Tag{}
|
||||
kvs := strings.SplitN(tag, keyValSeperator, 2)
|
||||
if len(kvs) == 2 {
|
||||
lfcTag.Key = kvs[0]
|
||||
@@ -49,41 +50,40 @@ func extractILMTags(tagLabelVal string) []LifecycleTag {
|
||||
// Some of these rules are enforced by Amazon S3 standards.
|
||||
// For example: Transition has to happen before Expiry.
|
||||
// Storage class must be specified if transition date/days is provided.
|
||||
func validateTranExpDate(rule LifecycleRule) error {
|
||||
expirySet := (rule.Expiration != nil)
|
||||
expiryDateSet := expirySet && rule.Expiration.ExpirationDate != nil && !rule.Expiration.ExpirationDate.IsZero()
|
||||
expiryDaySet := expirySet && rule.Expiration.ExpirationInDays > 0
|
||||
func validateTranExpDate(rule lifecycle.Rule) error {
|
||||
expiryDateSet := rule.Expiration.IsDateNull()
|
||||
expiryDaySet := rule.Expiration.IsDaysNull()
|
||||
|
||||
transitionSet := (rule.Transition != nil)
|
||||
transitionDateSet := transitionSet && (rule.Transition.TransitionDate != nil && !rule.Transition.TransitionDate.IsZero())
|
||||
transitionDaySet := transitionSet && (rule.Transition.TransitionInDays > 0)
|
||||
transitionSet := !rule.Transition.IsNull()
|
||||
transitionDateSet := transitionSet && !rule.Transition.IsDateNull()
|
||||
transitionDaySet := transitionSet && !rule.Transition.IsDaysNull()
|
||||
errMsg := "Error in Transition/Expiration Date/days compatibility. Transition should happen before Expiration"
|
||||
if transitionDateSet && expiryDateSet {
|
||||
if rule.Expiration.ExpirationDate.Before(*(rule.Transition.TransitionDate)) {
|
||||
if rule.Expiration.Date.Before(rule.Transition.Date.Time) {
|
||||
return errors.New(errMsg)
|
||||
}
|
||||
}
|
||||
if transitionDaySet && expiryDaySet {
|
||||
if rule.Transition.TransitionInDays >= rule.Expiration.ExpirationInDays {
|
||||
if rule.Transition.Days >= rule.Expiration.Days {
|
||||
return errors.New(errMsg)
|
||||
}
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
func validateTranDays(rule LifecycleRule) error {
|
||||
transitionSet := (rule.Transition != nil)
|
||||
transitionDaySet := transitionSet && (rule.Transition.TransitionInDays > 0)
|
||||
if transitionDaySet && rule.Transition.TransitionInDays < 30 && strings.ToLower(rule.Transition.StorageClass) == "standard_ia" {
|
||||
func validateTranDays(rule lifecycle.Rule) error {
|
||||
transitionSet := !rule.Transition.IsNull()
|
||||
transitionDaySet := transitionSet && !rule.Transition.IsDaysNull()
|
||||
if transitionDaySet && rule.Transition.Days < 30 && strings.ToLower(rule.Transition.StorageClass) == "standard_ia" {
|
||||
return errors.New("Transition Date/Days are less than or equal to 30 when Storage class is STANDARD_IA")
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
// Amazon S3 requires a minimum of one action for a rule to be added.
|
||||
func validateRuleAction(rule LifecycleRule) error {
|
||||
expirySet := (rule.Expiration != nil)
|
||||
transitionSet := (rule.Transition != nil)
|
||||
func validateRuleAction(rule lifecycle.Rule) error {
|
||||
expirySet := !rule.Expiration.IsNull()
|
||||
transitionSet := !rule.Transition.IsNull()
|
||||
if !expirySet && !transitionSet {
|
||||
errMsg := "At least one action (Expiry or Transition) needs to be specified in a rule."
|
||||
return errors.New(errMsg)
|
||||
@@ -92,28 +92,28 @@ func validateRuleAction(rule LifecycleRule) error {
|
||||
}
|
||||
|
||||
// Check if any date is before than cur date
|
||||
func validateTranExpCurdate(rule LifecycleRule) error {
|
||||
var err error
|
||||
expirySet := (rule.Expiration != nil)
|
||||
transitionSet := (rule.Transition != nil)
|
||||
transitionDateSet := transitionSet && (rule.Transition.TransitionDate != nil && !rule.Transition.TransitionDate.IsZero())
|
||||
expiryDateSet := expirySet && rule.Expiration.ExpirationDate != nil && !rule.Expiration.ExpirationDate.IsZero()
|
||||
func validateTranExpCurdate(rule lifecycle.Rule) error {
|
||||
var e error
|
||||
expirySet := !rule.Expiration.IsNull()
|
||||
transitionSet := !rule.Transition.IsNull()
|
||||
transitionDateSet := transitionSet && !rule.Transition.IsDateNull()
|
||||
expiryDateSet := expirySet && !rule.Expiration.IsDateNull()
|
||||
currentTime := time.Now()
|
||||
curTimeStr := currentTime.Format(defaultILMDateFormat)
|
||||
currentTime, err = time.Parse(defaultILMDateFormat, curTimeStr)
|
||||
if err != nil {
|
||||
return err
|
||||
currentTime, e = time.Parse(defaultILMDateFormat, curTimeStr)
|
||||
if e != nil {
|
||||
return e
|
||||
}
|
||||
if expirySet && expiryDateSet && rule.Expiration.ExpirationDate.Before(currentTime) {
|
||||
err = errors.New("Expiry date falls before or on today's date")
|
||||
} else if transitionSet && transitionDateSet && rule.Transition.TransitionDate.Before(currentTime) {
|
||||
err = errors.New("Transition date falls before or on today's date")
|
||||
if expirySet && expiryDateSet && rule.Expiration.Date.Before(currentTime) {
|
||||
e = errors.New("Expiry date falls before or on today's date")
|
||||
} else if transitionSet && transitionDateSet && rule.Transition.Date.Before(currentTime) {
|
||||
e = errors.New("Transition date falls before or on today's date")
|
||||
}
|
||||
return err
|
||||
return e
|
||||
}
|
||||
|
||||
// Check S3 compatibility for the new rule and some other basic checks.
|
||||
func validateILMRule(rule LifecycleRule) *probe.Error {
|
||||
func validateILMRule(rule lifecycle.Rule) *probe.Error {
|
||||
if e := validateRuleAction(rule); e != nil {
|
||||
return probe.NewError(e)
|
||||
}
|
||||
@@ -130,23 +130,23 @@ func validateILMRule(rule LifecycleRule) *probe.Error {
|
||||
}
|
||||
|
||||
// Returns valid lifecycleTransition to be included in lifecycleRule
|
||||
func parseTransition(storageClass, transitionDateStr, transitionDayStr string) (transition LifecycleTransition, err *probe.Error) {
|
||||
func parseTransition(storageClass, transitionDateStr, transitionDayStr string) (transition lifecycle.Transition, err *probe.Error) {
|
||||
storageClass = strings.ToUpper(storageClass) // Just-in-case the user has entered lower case characters.
|
||||
if storageClass != "" {
|
||||
if transitionDateStr != "" {
|
||||
transitionDate, e := time.Parse(defaultILMDateFormat, transitionDateStr)
|
||||
if e != nil {
|
||||
return LifecycleTransition{}, probe.NewError(e)
|
||||
return lifecycle.Transition{}, probe.NewError(e)
|
||||
}
|
||||
transition.TransitionDate = &transitionDate
|
||||
transition.Date = lifecycle.ExpirationDate{Time: transitionDate}
|
||||
} else if transitionDayStr != "" {
|
||||
transitionDay, e := strconv.Atoi(transitionDayStr)
|
||||
if e != nil {
|
||||
return LifecycleTransition{}, probe.NewError(e)
|
||||
return lifecycle.Transition{}, probe.NewError(e)
|
||||
}
|
||||
transition.TransitionInDays = transitionDay
|
||||
transition.Days = lifecycle.ExpirationDays(transitionDay)
|
||||
} else {
|
||||
return LifecycleTransition{}, probe.NewError(errors.New("if storage class is set a valid transitionDate or transitionDay must be set"))
|
||||
return lifecycle.Transition{}, probe.NewError(errors.New("if storage class is set a valid transitionDate or transitionDay must be set"))
|
||||
}
|
||||
transition.StorageClass = storageClass
|
||||
}
|
||||
@@ -155,16 +155,16 @@ func parseTransition(storageClass, transitionDateStr, transitionDayStr string) (
|
||||
}
|
||||
|
||||
// Returns lifecycleExpiration to be included in lifecycleRule
|
||||
func parseExpiry(expiryDateStr, expiryDayStr string) (lfcExp LifecycleExpiration, err *probe.Error) {
|
||||
func parseExpiry(expiryDateStr, expiryDayStr string) (lfcExp lifecycle.Expiration, err *probe.Error) {
|
||||
if expiryDateStr != "" {
|
||||
date, e := time.Parse(defaultILMDateFormat, expiryDateStr)
|
||||
if e != nil {
|
||||
return LifecycleExpiration{}, probe.NewError(e)
|
||||
return lifecycle.Expiration{}, probe.NewError(e)
|
||||
}
|
||||
if date.IsZero() {
|
||||
return LifecycleExpiration{}, probe.NewError(errors.New("expiration date cannot be set to zero"))
|
||||
return lifecycle.Expiration{}, probe.NewError(errors.New("expiration date cannot be set to zero"))
|
||||
}
|
||||
lfcExp.ExpirationDate = &date
|
||||
lfcExp.Date = lifecycle.ExpirationDate{Time: date}
|
||||
}
|
||||
|
||||
if expiryDayStr != "" {
|
||||
@@ -173,9 +173,9 @@ func parseExpiry(expiryDateStr, expiryDayStr string) (lfcExp LifecycleExpiration
|
||||
return lfcExp, probe.NewError(e)
|
||||
}
|
||||
if days == 0 {
|
||||
return LifecycleExpiration{}, probe.NewError(errors.New("expiration days cannot be set to zero"))
|
||||
return lifecycle.Expiration{}, probe.NewError(errors.New("expiration days cannot be set to zero"))
|
||||
}
|
||||
lfcExp.ExpirationInDays = days
|
||||
lfcExp.Days = lifecycle.ExpirationDays(days)
|
||||
}
|
||||
|
||||
return lfcExp, nil
|
||||
|
||||
+49
-64
@@ -18,6 +18,8 @@ package ilm
|
||||
|
||||
import (
|
||||
"strconv"
|
||||
|
||||
"github.com/minio/minio-go/v7/pkg/lifecycle"
|
||||
)
|
||||
|
||||
const (
|
||||
@@ -100,7 +102,7 @@ type showDetails struct {
|
||||
|
||||
// PopulateILMDataForDisplay based on showDetails determined by user input, populate the ILM display
|
||||
// table with information. Table is constructed row-by-row. Headers are first, then the rest of the rows.
|
||||
func PopulateILMDataForDisplay(ilmCfg LifecycleConfiguration, rowCheck *map[string]int, alignedHdrLabels *[]string,
|
||||
func PopulateILMDataForDisplay(ilmCfg *lifecycle.Configuration, rowCheck *map[string]int, alignedHdrLabels *[]string,
|
||||
cellDataNoTags *[][]string, cellDataWithTags *[][]string, tagRows *map[string][]string,
|
||||
showAll, showMin, showExpiry, showTransition bool) {
|
||||
|
||||
@@ -201,18 +203,16 @@ func checkAddTableCellRows(rowArr *[]string, rowCheck map[string]int, showOpts s
|
||||
}
|
||||
|
||||
// The right kind of tick is returned. Cross-tick if expiry is not set.
|
||||
func getExpiryTick(rule LifecycleRule) string {
|
||||
func getExpiryTick(rule lifecycle.Rule) string {
|
||||
expiryTick := crossTickCell
|
||||
expiryDateSet := rule.Expiration != nil && rule.Expiration.ExpirationDate != nil && !rule.Expiration.ExpirationDate.IsZero()
|
||||
expirySet := rule.Expiration != nil && (expiryDateSet || rule.Expiration.ExpirationInDays > 0)
|
||||
if expirySet {
|
||||
if !rule.Expiration.IsNull() {
|
||||
expiryTick = tickCell
|
||||
}
|
||||
return expiryTick
|
||||
}
|
||||
|
||||
// The right kind of tick is returned. Cross-tick if status is 'Disabled' & tick if status is 'Enabled'.
|
||||
func getStatusTick(rule LifecycleRule) string {
|
||||
func getStatusTick(rule lifecycle.Rule) string {
|
||||
statusTick := crossTickCell
|
||||
if rule.Status == statusLabelKey {
|
||||
statusTick = tickCell
|
||||
@@ -221,26 +221,22 @@ func getStatusTick(rule LifecycleRule) string {
|
||||
}
|
||||
|
||||
// Expiry date. 'YYYY-MM-DD'. Set for 00:00:00 GMT as per the standard.
|
||||
func getExpiryDateVal(rule LifecycleRule) string {
|
||||
func getExpiryDateVal(rule lifecycle.Rule) string {
|
||||
expiryDate := blankCell
|
||||
expirySet := (rule.Expiration != nil)
|
||||
expiryDateSet := expirySet && rule.Expiration.ExpirationDate != nil && !rule.Expiration.ExpirationDate.IsZero()
|
||||
if expiryDateSet {
|
||||
expiryDate = strconv.Itoa(rule.Expiration.ExpirationDate.Day()) + " " +
|
||||
rule.Expiration.ExpirationDate.Month().String()[0:3] + " " +
|
||||
strconv.Itoa(rule.Expiration.ExpirationDate.Year())
|
||||
} else if expirySet && rule.Expiration.ExpirationInDays > 0 {
|
||||
expiryDate = strconv.Itoa(rule.Expiration.ExpirationInDays) + " day(s)"
|
||||
if !rule.Expiration.IsDateNull() {
|
||||
expiryDate = strconv.Itoa(rule.Expiration.Date.Day()) + " " +
|
||||
rule.Expiration.Date.Month().String()[0:3] + " " +
|
||||
strconv.Itoa(rule.Expiration.Date.Year())
|
||||
} else if !rule.Expiration.IsDateNull() {
|
||||
expiryDate = strconv.Itoa(int(rule.Expiration.Days)) + " day(s)"
|
||||
}
|
||||
return expiryDate
|
||||
}
|
||||
|
||||
// Cross-tick if Transition is not set.
|
||||
func getTransitionTick(rule LifecycleRule) string {
|
||||
transitionSet := rule.Transition != nil
|
||||
transitionDateSet := transitionSet && ((rule.Transition.TransitionDate != nil &&
|
||||
!rule.Transition.TransitionDate.IsZero()) ||
|
||||
rule.Transition.TransitionInDays > 0)
|
||||
func getTransitionTick(rule lifecycle.Rule) string {
|
||||
transitionSet := !rule.Transition.IsNull()
|
||||
transitionDateSet := transitionSet && !rule.Transition.IsDateNull()
|
||||
if !transitionSet || !transitionDateSet {
|
||||
return crossTickCell
|
||||
}
|
||||
@@ -248,26 +244,25 @@ func getTransitionTick(rule LifecycleRule) string {
|
||||
}
|
||||
|
||||
// Transition date. 'YYYY-MM-DD'. Set for 00:00:00 GMT as per the standard.
|
||||
func getTransitionDate(rule LifecycleRule) string {
|
||||
func getTransitionDate(rule lifecycle.Rule) string {
|
||||
transitionDate := blankCell
|
||||
transitionSet := (rule.Transition != nil)
|
||||
transitionDateSet := transitionSet && (rule.Transition.TransitionDate != nil &&
|
||||
!rule.Transition.TransitionDate.IsZero())
|
||||
transitionDaySet := transitionSet && (rule.Transition.TransitionInDays > 0)
|
||||
transitionSet := !rule.Transition.IsNull()
|
||||
transitionDateSet := transitionSet && !rule.Transition.IsDateNull()
|
||||
transitionDaySet := transitionSet && !rule.Transition.IsDaysNull()
|
||||
if transitionDateSet {
|
||||
transitionDate = strconv.Itoa(rule.Transition.TransitionDate.Day()) + " " +
|
||||
rule.Transition.TransitionDate.Month().String()[0:3] + " " +
|
||||
strconv.Itoa(rule.Transition.TransitionDate.Year())
|
||||
transitionDate = strconv.Itoa(rule.Transition.Date.Day()) + " " +
|
||||
rule.Transition.Date.Month().String()[0:3] + " " +
|
||||
strconv.Itoa(rule.Transition.Date.Year())
|
||||
} else if transitionDaySet {
|
||||
transitionDate = strconv.Itoa(rule.Transition.TransitionInDays) + " day(s)"
|
||||
transitionDate = strconv.Itoa(int(rule.Transition.Days)) + " day(s)"
|
||||
}
|
||||
return transitionDate
|
||||
}
|
||||
|
||||
// Storage class name for transition.
|
||||
func getStorageClassName(rule LifecycleRule) string {
|
||||
func getStorageClassName(rule lifecycle.Rule) string {
|
||||
storageClass := blankCell
|
||||
transitionSet := (rule.Transition != nil)
|
||||
transitionSet := !rule.Transition.IsNull()
|
||||
storageClassAvail := transitionSet && (rule.Transition.StorageClass != "")
|
||||
if storageClassAvail {
|
||||
storageClass = rule.Transition.StorageClass
|
||||
@@ -276,13 +271,12 @@ func getStorageClassName(rule LifecycleRule) string {
|
||||
}
|
||||
|
||||
// Array of Tag strings, each in key:value format
|
||||
func getTagArr(rule LifecycleRule) []string {
|
||||
tagArr := rule.TagFilters
|
||||
tagLth := len(rule.TagFilters)
|
||||
if len(rule.TagFilters) == 0 && rule.RuleFilter != nil && rule.RuleFilter.And != nil {
|
||||
tagLth = len(rule.RuleFilter.And.Tags)
|
||||
tagArr = rule.RuleFilter.And.Tags
|
||||
func getTagArr(rule lifecycle.Rule) []string {
|
||||
if rule.RuleFilter.And.IsEmpty() {
|
||||
return []string{}
|
||||
}
|
||||
tagArr := rule.RuleFilter.And.Tags
|
||||
tagLth := len(tagArr)
|
||||
tagCellArr := make([]string, len(tagArr))
|
||||
for tagIdx := 0; tagIdx < tagLth; tagIdx++ {
|
||||
tagCellArr[tagIdx] = (tagArr[tagIdx].Key + ":" + tagArr[tagIdx].Value)
|
||||
@@ -311,22 +305,20 @@ func checkAddTableCell(rowArr *[]string, rowCheck map[string]int, cellInfo table
|
||||
}
|
||||
|
||||
// GetILMShowDataWithoutTags - Without tags
|
||||
func getILMShowDataWithoutTags(cellInfo *[][]string, rowCheck map[string]int, info LifecycleConfiguration, showOpts showDetails) {
|
||||
func getILMShowDataWithoutTags(cellInfo *[][]string, rowCheck map[string]int, info *lifecycle.Configuration, showOpts showDetails) {
|
||||
*cellInfo = make([][]string, 0)
|
||||
count := 0
|
||||
for index := 0; index < len(info.Rules); index++ {
|
||||
rule := info.Rules[index]
|
||||
|
||||
showExpiry := (rule.Expiration != nil) && ((rule.Expiration.ExpirationDate != nil && !rule.Expiration.ExpirationDate.IsZero()) ||
|
||||
rule.Expiration.ExpirationInDays > 0)
|
||||
transitionSet := (rule.Transition != nil) && ((rule.Transition.TransitionDate != nil && !rule.Transition.TransitionDate.IsZero()) ||
|
||||
rule.Transition.TransitionInDays > 0)
|
||||
showExpiry := !rule.Expiration.IsNull()
|
||||
transitionSet := !rule.Transition.IsNull()
|
||||
skipExpTran := (showOpts.expiry && !showExpiry) || (showOpts.transition && !transitionSet)
|
||||
if skipExpTran {
|
||||
continue
|
||||
}
|
||||
tagPresent := (rule.RuleFilter != nil) && (rule.RuleFilter.And != nil)
|
||||
if len(rule.TagFilters) > 0 || (tagPresent && len(rule.RuleFilter.And.Tags) > 0) {
|
||||
tagPresent := !rule.RuleFilter.And.IsEmpty()
|
||||
if tagPresent {
|
||||
continue
|
||||
}
|
||||
*cellInfo = append(*cellInfo, make([]string, 0))
|
||||
@@ -353,16 +345,14 @@ func getILMShowDataWithoutTags(cellInfo *[][]string, rowCheck map[string]int, in
|
||||
}
|
||||
|
||||
// GetILMShowDataWithTags Just the data with extra rows for extra tags
|
||||
func getILMShowDataWithTags(cellInfo *[][]string, newRows map[string][]string, rowCheck map[string]int, info LifecycleConfiguration, showOpts showDetails) {
|
||||
func getILMShowDataWithTags(cellInfo *[][]string, newRows map[string][]string, rowCheck map[string]int, info *lifecycle.Configuration, showOpts showDetails) {
|
||||
*cellInfo = make([][]string, 0)
|
||||
count := 0
|
||||
for index := 0; index < len(info.Rules); index++ {
|
||||
rule := info.Rules[index]
|
||||
|
||||
showExpiry := (rule.Expiration != nil) && ((rule.Expiration.ExpirationDate != nil && !rule.Expiration.ExpirationDate.IsZero()) ||
|
||||
rule.Expiration.ExpirationInDays > 0)
|
||||
transitionSet := (rule.Transition != nil) && ((rule.Transition.TransitionDate != nil && !rule.Transition.TransitionDate.IsZero()) ||
|
||||
rule.Transition.TransitionInDays > 0)
|
||||
showExpiry := !rule.Expiration.IsNull()
|
||||
transitionSet := !rule.Transition.IsNull()
|
||||
skipExpTran := (showOpts.expiry && !showExpiry) || (showOpts.transition && !transitionSet)
|
||||
if skipExpTran {
|
||||
continue
|
||||
@@ -394,26 +384,24 @@ func getILMShowDataWithTags(cellInfo *[][]string, newRows map[string][]string, r
|
||||
}
|
||||
}
|
||||
|
||||
func getPrefixVal(rule LifecycleRule) string {
|
||||
func getPrefixVal(rule lifecycle.Rule) string {
|
||||
prefixVal := ""
|
||||
switch {
|
||||
case rule.Prefix != "":
|
||||
prefixVal = rule.Prefix
|
||||
case rule.RuleFilter != nil && rule.RuleFilter.And != nil && rule.RuleFilter.And.Prefix != "":
|
||||
case !rule.RuleFilter.And.IsEmpty():
|
||||
prefixVal = rule.RuleFilter.And.Prefix
|
||||
case rule.RuleFilter != nil && rule.RuleFilter.Prefix != "":
|
||||
case rule.RuleFilter.Prefix != "":
|
||||
prefixVal = rule.RuleFilter.Prefix
|
||||
}
|
||||
return prefixVal
|
||||
}
|
||||
|
||||
func showExpiryDetails(rule LifecycleRule, showOpts showDetails) bool {
|
||||
func showExpiryDetails(rule lifecycle.Rule, showOpts showDetails) bool {
|
||||
if showOpts.allAvailable {
|
||||
return true
|
||||
}
|
||||
expirySet := (rule.Expiration != nil) &&
|
||||
((rule.Expiration.ExpirationDate != nil && !rule.Expiration.ExpirationDate.IsZero()) ||
|
||||
rule.Expiration.ExpirationInDays > 0)
|
||||
expirySet := !rule.Expiration.IsNull()
|
||||
|
||||
return (expirySet && (showOpts.allAvailable || showOpts.expiry))
|
||||
|
||||
@@ -427,27 +415,24 @@ func showTransitionTick(showOpts showDetails) bool {
|
||||
return (showOpts.allAvailable || showOpts.minimum)
|
||||
}
|
||||
|
||||
func showTransitionDetails(rule LifecycleRule, showOpts showDetails) bool {
|
||||
func showTransitionDetails(rule lifecycle.Rule, showOpts showDetails) bool {
|
||||
if showOpts.allAvailable {
|
||||
return true
|
||||
}
|
||||
transitionSet := (rule.Transition != nil) &&
|
||||
((rule.Transition.TransitionDate != nil && !rule.Transition.TransitionDate.IsZero()) ||
|
||||
rule.Transition.TransitionInDays > 0)
|
||||
transitionSet := !rule.Transition.IsNull()
|
||||
transitionDetailsShow := (showOpts.allAvailable || showOpts.transition)
|
||||
return transitionSet && transitionDetailsShow
|
||||
}
|
||||
|
||||
func showTags(rule LifecycleRule, showOpts showDetails) bool {
|
||||
func showTags(rule lifecycle.Rule, showOpts showDetails) bool {
|
||||
if showOpts.minimum {
|
||||
return false
|
||||
}
|
||||
tagSet := showOpts.allAvailable ||
|
||||
(len(rule.TagFilters) > 0 || (rule.RuleFilter != nil && rule.RuleFilter.And != nil && (len(rule.RuleFilter.And.Tags) > 0)))
|
||||
tagSet := showOpts.allAvailable || !rule.RuleFilter.And.IsEmpty()
|
||||
return tagSet
|
||||
}
|
||||
|
||||
func getColumns(info LifecycleConfiguration, rowCheck map[string]int, alignedHdrLabels *[]string, showOpts showDetails) {
|
||||
func getColumns(info *lifecycle.Configuration, rowCheck map[string]int, alignedHdrLabels *[]string, showOpts showDetails) {
|
||||
tagIn := false // Keep tag in the end
|
||||
colIdx := 0
|
||||
colWidthTbl := getILMColumnWidthTable()
|
||||
|
||||
+7
-1
@@ -27,6 +27,7 @@ import (
|
||||
"github.com/minio/cli"
|
||||
json "github.com/minio/mc/pkg/colorjson"
|
||||
"github.com/minio/mc/pkg/probe"
|
||||
"github.com/minio/minio-go/v7"
|
||||
"github.com/minio/minio/pkg/console"
|
||||
)
|
||||
|
||||
@@ -114,7 +115,12 @@ func mainListTag(cliCtx *cli.Context) error {
|
||||
fatalIf(err, "Unable to initialize target "+targetURL)
|
||||
|
||||
tagsMap, err := clnt.GetTags(ctx)
|
||||
fatalIf(err, "Unable to fetch tags for "+targetURL)
|
||||
if err != nil {
|
||||
if minio.ToErrorResponse(err.ToGoError()).Code == "NoSuchTagSet" {
|
||||
fatalIf(probe.NewError(errors.New("check 'mc tag set --help' on how to set tags")), "No tags found for "+targetURL)
|
||||
}
|
||||
fatalIf(err, "Unable to fetch tags for "+targetURL)
|
||||
}
|
||||
|
||||
if len(tagsMap) == 0 {
|
||||
fatalIf(probe.NewError(errors.New("check 'mc tag set --help' on how to set tags")), "No tags found for "+targetURL)
|
||||
|
||||
@@ -13,7 +13,7 @@ require (
|
||||
github.com/mattn/go-isatty v0.0.8
|
||||
github.com/minio/cli v1.22.0
|
||||
github.com/minio/minio v0.0.0-20200714163805-778e9c864f67
|
||||
github.com/minio/minio-go/v7 v7.0.0-20200714085548-47e386e2cde8
|
||||
github.com/minio/minio-go/v7 v7.0.0-20200717002236-16b4b137ee4b
|
||||
github.com/minio/sha256-simd v0.1.1
|
||||
github.com/mitchellh/go-homedir v1.1.0
|
||||
github.com/niemeyer/pretty v0.0.0-20200227124842-a10e7caefd8e // indirect
|
||||
|
||||
@@ -279,6 +279,8 @@ github.com/minio/minio v0.0.0-20200714163805-778e9c864f67 h1:xMg87xvLhrw2jeE6xGx
|
||||
github.com/minio/minio v0.0.0-20200714163805-778e9c864f67/go.mod h1:0WThPBMICOt5eEGT3XyaUy0cxYmoGhmJEvvRbiVqbYU=
|
||||
github.com/minio/minio-go/v7 v7.0.0-20200714085548-47e386e2cde8 h1:Xh5yHlXj/367YMabi7tWHol1AslXcuAFWaedBtGgbU0=
|
||||
github.com/minio/minio-go/v7 v7.0.0-20200714085548-47e386e2cde8/go.mod h1:QTstSRgetEDVpqiEpFniLoCslH4d9cNAa4BtjuRQrwE=
|
||||
github.com/minio/minio-go/v7 v7.0.0-20200717002236-16b4b137ee4b h1:aNa+ApHn0FYMFdwfI9IqLFLajN/FoHpqLdN20emn+Ck=
|
||||
github.com/minio/minio-go/v7 v7.0.0-20200717002236-16b4b137ee4b/go.mod h1:dJ80Mv2HeGkYLH1sqS/ksz07ON6csH3S6JUMSQ2zAns=
|
||||
github.com/minio/sha256-simd v0.1.1 h1:5QHSlgo3nt5yKOJrC7W8w7X+NFl8cMPZm96iu8kKUJU=
|
||||
github.com/minio/sha256-simd v0.1.1/go.mod h1:B5e1o+1/KgNmWrSQK08Y6Z1Vb5pwIktudl0J58iy0KM=
|
||||
github.com/minio/simdjson-go v0.1.5-0.20200303142138-b17fe061ea37 h1:pDeao6M5AEd8hwTtGmE0pVKomlL56JFRa5SiXDZAuJE=
|
||||
|
||||
Reference in New Issue
Block a user