Skip to content

Commit

Permalink
[WIP] mc admin config set/get changes
Browse files Browse the repository at this point in the history
Related to minio/minio#8392
  • Loading branch information
harshavardhana committed Oct 14, 2019
1 parent 1582b1c commit 000fa5e
Show file tree
Hide file tree
Showing 5 changed files with 69 additions and 438 deletions.
26 changes: 11 additions & 15 deletions cmd/admin-config-get.go
@@ -1,5 +1,5 @@
/*
* MinIO Client (C) 2017 MinIO, Inc.
* MinIO Client (C) 2017-2019 MinIO, Inc.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
Expand All @@ -17,6 +17,8 @@
package cmd

import (
"strings"

"github.com/minio/cli"
json "github.com/minio/mc/pkg/colorjson"
"github.com/minio/mc/pkg/probe"
Expand All @@ -38,23 +40,21 @@ FLAGS:
{{range .VisibleFlags}}{{.}}
{{end}}
EXAMPLES:
1. Get server configuration of a MinIO server/cluster.
$ {{.HelpName}} play/
1. Get the current status of 'worm' mode on MinIO server/cluster.
$ {{.HelpName}} play/ worm
worm state=disabled
`,
}

// configGetMessage container to hold locks information.
type configGetMessage struct {
Status string `json:"status"`
Config map[string]interface{} `json:"config"`
Status string `json:"status"`
Value string `json:"value"`
}

// String colorized service status message.
func (u configGetMessage) String() string {
config, e := json.MarshalIndent(u.Config, "", " ")
fatalIf(probe.NewError(e), "Unable to marshal into JSON.")

return string(config)
return u.Value
}

// JSON jsonified service status Message message.
Expand Down Expand Up @@ -86,16 +86,12 @@ func mainAdminConfigGet(ctx *cli.Context) error {
fatalIf(err, "Cannot get a configured admin connection.")

// Call get config API
c, e := client.GetConfig()
buf, e := client.GetConfigKV(strings.Join(args.Tail(), " "))
fatalIf(probe.NewError(e), "Cannot get server configuration file.")

config := map[string]interface{}{}
e = json.Unmarshal(c, &config)
fatalIf(probe.NewError(e), "Cannot unmarshal server configuration file.")

// Print
printMsg(configGetMessage{
Config: config,
Value: string(buf),
})

return nil
Expand Down
13 changes: 7 additions & 6 deletions cmd/admin-config-set.go
@@ -1,5 +1,5 @@
/*
* MinIO Client (C) 2017 MinIO, Inc.
* MinIO Client (C) 2017-2019 MinIO, Inc.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
Expand All @@ -18,7 +18,7 @@ package cmd

import (
"fmt"
"os"
"strings"

"github.com/fatih/color"
"github.com/minio/cli"
Expand All @@ -43,8 +43,8 @@ FLAGS:
{{range .VisibleFlags}}{{.}}
{{end}}
EXAMPLES:
1. Set server configuration of a MinIO server/cluster.
$ cat myconfig | {{.HelpName}} myminio/
1. Enable worm mode on MinIO server/cluster.
$ {{.HelpName}} myminio/ worm state=enabled
`,
}

Expand Down Expand Up @@ -86,7 +86,7 @@ func (u configSetMessage) JSON() string {

// checkAdminConfigSetSyntax - validate all the passed arguments
func checkAdminConfigSetSyntax(ctx *cli.Context) {
if len(ctx.Args()) == 0 || len(ctx.Args()) > 2 {
if len(ctx.Args()) == 0 {
cli.ShowCommandHelpAndExit(ctx, "set", 1) // last argument is exit code
}
}
Expand All @@ -110,7 +110,8 @@ func mainAdminConfigSet(ctx *cli.Context) error {
fatalIf(err, "Cannot get a configured admin connection.")

// Call get config API
fatalIf(probe.NewError(client.SetConfig(os.Stdin)), "Cannot set server configuration file.")
fatalIf(probe.NewError(client.SetConfigKV(strings.Join(args.Tail(), " "))),
"Cannot set server configuration file.")

// Print set config result
printMsg(configSetMessage{
Expand Down
4 changes: 2 additions & 2 deletions cmd/admin-config.go
Expand Up @@ -20,13 +20,13 @@ import "github.com/minio/cli"

var adminConfigCmd = cli.Command{
Name: "config",
Usage: "manage configuration file",
Usage: "manage MinIO configuration",
Action: mainAdminConfig,
Before: setGlobalsFromContext,
Flags: globalFlags,
Subcommands: []cli.Command{
adminConfigGetCmd,
adminConfigSetCmd,
adminConfigGetCmd,
},
HideHelpCommand: true,
}
Expand Down
21 changes: 14 additions & 7 deletions go.mod
Expand Up @@ -4,24 +4,27 @@ go 1.12

require (
github.com/cheggaaa/pb v1.0.28
github.com/coreos/bbolt v1.3.3 // indirect
github.com/coreos/go-semver v0.3.0 // indirect
github.com/coreos/pkg v0.0.0-20180928190104-399ea9e2e55f // indirect
github.com/dustin/go-humanize v1.0.0
github.com/fatih/color v1.7.0
github.com/golang/groupcache v0.0.0-20191002201903-404acd9df4cc // indirect
github.com/gopherjs/gopherjs v0.0.0-20190328170749-bb2674552d8f // indirect
github.com/gorilla/websocket v1.4.0 // indirect
github.com/gorilla/websocket v1.4.1 // indirect
github.com/grpc-ecosystem/go-grpc-middleware v1.0.0 // indirect
github.com/grpc-ecosystem/go-grpc-prometheus v1.2.0 // indirect
github.com/hashicorp/go-cleanhttp v0.5.1 // indirect
github.com/howeyc/gopass v0.0.0-20170109162249-bf9dde6d0d2c // indirect
github.com/inconshreveable/go-update v0.0.0-20160112193335-8152e7eb6ccf
github.com/jonboulle/clockwork v0.1.0 // indirect
github.com/kr/pretty v0.1.0 // indirect
github.com/mattn/go-colorable v0.1.1
github.com/mattn/go-isatty v0.0.7
github.com/mattn/go-runewidth v0.0.4 // indirect
github.com/minio/cli v1.21.0
github.com/minio/minio v0.0.0-20190828220443-83d4c5763c3e
github.com/minio/minio-go/v6 v6.0.32
github.com/minio/sha256-simd v0.1.0
github.com/minio/cli v1.22.0
github.com/minio/minio v0.0.0-20191001201215-ff5bf519522f
github.com/minio/minio-go/v6 v6.0.39
github.com/minio/sha256-simd v0.1.1
github.com/mitchellh/go-homedir v1.1.0
github.com/pkg/profile v1.3.0
github.com/pkg/xattr v0.4.1
Expand All @@ -34,8 +37,10 @@ require (
github.com/tmc/grpc-websocket-proxy v0.0.0-20190109142713-0ad062ec5ee5 // indirect
github.com/ugorji/go v1.1.5-pre // indirect
github.com/xiang90/probing v0.0.0-20190116061207-43a291ad63a2 // indirect
go.etcd.io/bbolt v1.3.3 // indirect
go.uber.org/multierr v1.1.0 // indirect
golang.org/x/net v0.0.0-20190813141303-74dc4d7220e7
go.uber.org/zap v1.10.0 // indirect
golang.org/x/net v0.0.0-20190923162816-aa69164e4478
golang.org/x/text v0.3.2
golang.org/x/time v0.0.0-20190308202827-9d24e82272b4 // indirect
gopkg.in/check.v1 v1.0.0-20180628173108-788fd7840127
Expand All @@ -44,3 +49,5 @@ require (
)

replace github.com/gorilla/rpc v1.2.0+incompatible => github.com/gorilla/rpc v1.2.0

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

0 comments on commit 000fa5e

Please sign in to comment.