Skip to content

Commit

Permalink
fix for API change on minio server.
Browse files Browse the repository at this point in the history
  • Loading branch information
Poorna Krishnamoorthy committed May 26, 2020
1 parent e847b3a commit b2da582
Show file tree
Hide file tree
Showing 4 changed files with 55 additions and 21 deletions.
33 changes: 17 additions & 16 deletions cmd/admin-bucket-quota.go
Original file line number Diff line number Diff line change
Expand Up @@ -31,15 +31,15 @@ import (
var adminQuotaFlags = []cli.Flag{
cli.StringFlag{
Name: "fifo",
Usage: "Set fifo quota, allowing automatic deletion of older content",
Usage: "set fifo quota, allowing automatic deletion of older content",
},
cli.StringFlag{
Name: "hard",
Usage: "Set a hard quota, disallowing writes after quota is reached",
Usage: "set a hard quota, disallowing writes after quota is reached",
},
cli.BoolFlag{
Name: "clear",
Usage: "Clears bucket quota configured for bucket",
Usage: "clears bucket quota configured for bucket",
},
}

Expand All @@ -53,20 +53,20 @@ type quotaMessage struct {
}

func (q quotaMessage) String() string {
if q.op == "set" {
switch q.op {
case "set":
return console.Colorize("QuotaMessage",
fmt.Sprintf("Successfully set bucket quota of %s with %s type on `%s`", humanize.IBytes(q.Quota), q.QuotaType, q.Bucket))
}
if q.op == "unset" {
case "unset":
return console.Colorize("QuotaMessage",
fmt.Sprintf("Successfully cleared bucket quota configured on `%s`", q.Bucket))
default:
return console.Colorize("QuotaInfo",
fmt.Sprintf("Bucket `%s` has %s quota of %s", q.Bucket, q.QuotaType, humanize.IBytes(q.Quota)))
}
return console.Colorize("QuotaInfo",
fmt.Sprintf("Bucket `%s` has %s quota of %s", q.Bucket, q.QuotaType, humanize.IBytes(q.Quota)))
}

func (q quotaMessage) JSON() string {
q.Status = "success"
jsonMessageBytes, e := json.MarshalIndent(q, "", " ")
fatalIf(probe.NewError(e), "Unable to marshal into JSON.")

Expand Down Expand Up @@ -107,7 +107,6 @@ EXAMPLES:
4. Clear bucket quota configured for bucket "mybucket" on MinIO.
{{.Prompt}} {{.HelpName}} myminio/mybucket --clear
`,
}

Expand Down Expand Up @@ -152,25 +151,26 @@ func mainAdminBucketQuota(ctx *cli.Context) error {
if ctx.IsSet("hard") {
qType = madmin.HardQuota
}
quota, err := humanize.ParseBytes(quotaStr)
fatalIf(probe.NewError(err).Trace(quotaStr), "Unable to parse quota")
if err = client.SetBucketQuota(globalContext, targetURL, quota, qType); err != nil {
fatalIf(probe.NewError(err).Trace(args...), "Cannot set bucket quota")

quota, e := humanize.ParseBytes(quotaStr)
fatalIf(probe.NewError(e).Trace(quotaStr), "Unable to parse quota")
if e = client.SetBucketQuota(globalContext, targetURL, &madmin.BucketQuota{Quota: quota, Type: qType}); e != nil {
fatalIf(probe.NewError(e).Trace(args...), "Cannot set bucket quota")
}
printMsg(quotaMessage{
op: "set",
Bucket: targetURL,
Quota: quota,
QuotaType: string(qType),
Status: "success",
})
} else if ctx.Bool("clear") && len(args) == 1 {
if err := client.RemoveBucketQuota(globalContext, targetURL); err != nil {
if err := client.SetBucketQuota(globalContext, targetURL, &madmin.BucketQuota{}); err != nil {
fatalIf(probe.NewError(err).Trace(args...), "Cannot clear bucket quota config")
}
printMsg(quotaMessage{
op: "unset",
Bucket: targetURL,
Status: "success",
})

} else {
Expand All @@ -181,6 +181,7 @@ func mainAdminBucketQuota(ctx *cli.Context) error {
Bucket: targetURL,
Quota: qCfg.Quota,
QuotaType: string(qCfg.Type),
Status: "success",
})
}

Expand Down
2 changes: 1 addition & 1 deletion docs/minio-admin-complete-guide.md
Original file line number Diff line number Diff line change
Expand Up @@ -862,7 +862,7 @@ NAME:
mc admin bucket quota - manage bucket quota
USAGE:
mc admin bucket quota TARGET [--fifo | --hard] [QUOTA]
mc admin bucket quota TARGET [--fifo QUOTA | --hard QUOTA | --clear]
QUOTA
quota accepts human-readable case-insensitive number
Expand Down
9 changes: 5 additions & 4 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -12,12 +12,11 @@ require (
github.com/grpc-ecosystem/grpc-gateway v1.9.4 // indirect
github.com/inconshreveable/go-update v0.0.0-20160112193335-8152e7eb6ccf
github.com/klauspost/compress v1.10.3
github.com/mattn/go-colorable v0.1.4 // indirect
github.com/mattn/go-isatty v0.0.8
github.com/mattn/go-runewidth v0.0.5 // indirect
github.com/minio/cli v1.22.0
github.com/minio/minio v0.0.0-20200506184406-a2ccba69e563
github.com/minio/minio-go/v6 v6.0.56-0.20200502013257-a81c8c13cc3f
github.com/minio/minio-go/v6 v6.0.56-0.20200522164946-44a5f2e3b76b
github.com/minio/sha256-simd v0.1.1
github.com/mitchellh/go-homedir v1.1.0
github.com/pkg/profile v1.3.0
Expand All @@ -28,8 +27,10 @@ require (
golang.org/x/crypto v0.0.0-20200214034016-1d94cc7ab1c6
golang.org/x/net v0.0.0-20200324143707-d3edc9973b7e
golang.org/x/text v0.3.2
gopkg.in/check.v1 v1.0.0-20180628173108-788fd7840127
gopkg.in/check.v1 v1.0.0-20200227125254-8fa46927fb4f
gopkg.in/h2non/filetype.v1 v1.0.5
gopkg.in/ini.v1 v1.55.0 // indirect
gopkg.in/yaml.v2 v2.2.4
gopkg.in/yaml.v2 v2.2.8
)

replace github.com/minio/minio => ../minio

0 comments on commit b2da582

Please sign in to comment.