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 735aa13 commit 196045a
Show file tree
Hide file tree
Showing 6 changed files with 77 additions and 450 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.
{{.Prompt}} {{.HelpName}} play/
1. Get the current status of 'worm' mode on MinIO server/cluster.
$ {{.HelpName}} play/ worm
state="off"
`,
}

// 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, "Unable to initialize 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.
{{.Prompt}} cat myconfig | {{.HelpName}} myminio/
1. Enable worm mode on MinIO server/cluster.
$ {{.HelpName}} myminio/ worm state="on"
`,
}

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, "Unable to initialize 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
2 changes: 1 addition & 1 deletion cmd/admin-console.go
Expand Up @@ -179,7 +179,7 @@ func mainAdminConsole(ctx *cli.Context) error {
defer close(doneCh)

// Start listening on all console log activity.
logCh := client.GetLogs(node, limit, doneCh)
logCh := client.GetLogs(node, limit, "all", doneCh)
for logInfo := range logCh {
if logInfo.Err != nil {
fatalIf(probe.NewError(logInfo.Err), "Cannot listen to console logs")
Expand Down
25 changes: 23 additions & 2 deletions go.mod
Expand Up @@ -4,27 +4,48 @@ go 1.13

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/dgrijalva/jwt-go v3.2.0+incompatible
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.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/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/minio/minio v0.0.0-20191001201215-ff5bf519522f
github.com/mattn/go-runewidth v0.0.4 // indirect
github.com/minio/cli v1.22.0
github.com/minio/minio v0.0.0-20190927193314-1c5b05c130fa
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
github.com/posener/complete v1.2.2-0.20190702141536-6ffe496ea953
github.com/rjeczalik/notify v0.9.2
github.com/smartystreets/assertions v0.0.0-20190401211740-f487f9de1cd3 // indirect
github.com/soheilhy/cmux v0.1.4 // indirect
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
go.uber.org/zap v1.10.0 // indirect
golang.org/x/net v0.0.0-20190923162816-aa69164e4478
golang.org/x/text v0.3.2
gopkg.in/check.v1 v1.0.0-20180628173108-788fd7840127
gopkg.in/cheggaaa/pb.v1 v1.0.28 // indirect
gopkg.in/h2non/filetype.v1 v1.0.5
gopkg.in/yaml.v2 v2.2.2
)

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 196045a

Please sign in to comment.