Add finalized command line options (#2979)
This commit is contained in:
@@ -18,16 +18,14 @@ package cmd
|
||||
|
||||
import (
|
||||
"encoding/json"
|
||||
"strings"
|
||||
|
||||
"github.com/minio/cli"
|
||||
"github.com/minio/mc/pkg/probe"
|
||||
"github.com/minio/minio/pkg/madmin"
|
||||
)
|
||||
|
||||
var adminConfigExportCmd = cli.Command{
|
||||
Name: "export",
|
||||
Usage: "export config of a MinIO server/cluster",
|
||||
Usage: "export all config keys to STDOUT",
|
||||
Before: setGlobalsFromContext,
|
||||
Action: mainAdminConfigExport,
|
||||
Flags: globalFlags,
|
||||
@@ -48,30 +46,13 @@ EXAMPLES:
|
||||
|
||||
// configExportMessage container to hold locks information.
|
||||
type configExportMessage struct {
|
||||
Status string `json:"status"`
|
||||
Value madmin.Targets `json:"value"`
|
||||
Status string `json:"status"`
|
||||
Value []byte `json:"value"`
|
||||
}
|
||||
|
||||
// String colorized service status message.
|
||||
func (u configExportMessage) String() string {
|
||||
var s strings.Builder
|
||||
count := u.Value.Count()
|
||||
// Print all "on" states entries
|
||||
for _, targetKV := range u.Value {
|
||||
kv := targetKV.KVS
|
||||
count--
|
||||
if kv.Get(madmin.StateKey) == madmin.StateOff {
|
||||
s.WriteString(madmin.KvComment)
|
||||
s.WriteString(madmin.KvSpaceSeparator)
|
||||
}
|
||||
s.WriteString(targetKV.SubSystem)
|
||||
s.WriteString(madmin.KvSpaceSeparator)
|
||||
s.WriteString(kv.String())
|
||||
if len(u.Value) > 1 && count > 0 {
|
||||
s.WriteString(madmin.KvNewline)
|
||||
}
|
||||
}
|
||||
return s.String()
|
||||
return string(u.Value)
|
||||
}
|
||||
|
||||
// JSON jsonified service status Message message.
|
||||
@@ -106,12 +87,9 @@ func mainAdminConfigExport(ctx *cli.Context) error {
|
||||
buf, e := client.GetConfig()
|
||||
fatalIf(probe.NewError(e), "Cannot get server config")
|
||||
|
||||
tgts, e := madmin.ParseSubSysTarget(buf)
|
||||
fatalIf(probe.NewError(e), "Cannot get server config")
|
||||
|
||||
// Print
|
||||
printMsg(configExportMessage{
|
||||
Value: tgts,
|
||||
Value: buf,
|
||||
})
|
||||
|
||||
return nil
|
||||
|
||||
@@ -27,7 +27,7 @@ import (
|
||||
|
||||
var adminConfigGetCmd = cli.Command{
|
||||
Name: "get",
|
||||
Usage: "get config of a MinIO server/cluster",
|
||||
Usage: "interactively retrieve a config key parameters",
|
||||
Before: setGlobalsFromContext,
|
||||
Action: mainAdminConfigGet,
|
||||
Flags: globalFlags,
|
||||
|
||||
@@ -1,100 +0,0 @@
|
||||
/*
|
||||
* MinIO Client (C) 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.
|
||||
* 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 cmd
|
||||
|
||||
import (
|
||||
"github.com/fatih/color"
|
||||
"github.com/minio/cli"
|
||||
json "github.com/minio/mc/pkg/colorjson"
|
||||
"github.com/minio/mc/pkg/console"
|
||||
"github.com/minio/mc/pkg/probe"
|
||||
)
|
||||
|
||||
var adminConfigHistoryClearCmd = cli.Command{
|
||||
Name: "clear",
|
||||
Usage: "clear a history key value on MinIO server",
|
||||
Before: setGlobalsFromContext,
|
||||
Action: mainAdminConfigHistoryClear,
|
||||
Flags: globalFlags,
|
||||
CustomHelpTemplate: `NAME:
|
||||
{{.HelpName}} - {{.Usage}}
|
||||
|
||||
USAGE:
|
||||
{{.HelpName}} TARGET RESTOREID
|
||||
|
||||
FLAGS:
|
||||
{{range .VisibleFlags}}{{.}}
|
||||
{{end}}
|
||||
EXAMPLES:
|
||||
1. Clear a history key value on MinIO server.
|
||||
{{.Prompt}} {{.HelpName}} play/ <restore-id>
|
||||
`,
|
||||
}
|
||||
|
||||
// configHistoryClearMessage container to hold locks information.
|
||||
type configHistoryClearMessage struct {
|
||||
Status string `json:"status"`
|
||||
RestoreID string `json:"restoreID"`
|
||||
}
|
||||
|
||||
// String colorized service status message.
|
||||
func (u configHistoryClearMessage) String() string {
|
||||
if u.RestoreID == "all" {
|
||||
return console.Colorize("ConfigHistoryClearMessage", "Cleared all keys successfully.")
|
||||
}
|
||||
return console.Colorize("ConfigHistoryClearMessage", "Cleared "+u.RestoreID+" successfully.")
|
||||
}
|
||||
|
||||
// JSON jsonified service status Message message.
|
||||
func (u configHistoryClearMessage) JSON() string {
|
||||
u.Status = "success"
|
||||
statusJSONBytes, e := json.MarshalIndent(u, "", " ")
|
||||
fatalIf(probe.NewError(e), "Unable to marshal into JSON.")
|
||||
|
||||
return string(statusJSONBytes)
|
||||
}
|
||||
|
||||
// checkAdminConfigHistoryClearSyntax - validate all the passed arguments
|
||||
func checkAdminConfigHistoryClearSyntax(ctx *cli.Context) {
|
||||
if !ctx.Args().Present() || len(ctx.Args()) > 2 {
|
||||
cli.ShowCommandHelpAndExit(ctx, "clear", 1) // last argument is exit code
|
||||
}
|
||||
}
|
||||
|
||||
func mainAdminConfigHistoryClear(ctx *cli.Context) error {
|
||||
|
||||
checkAdminConfigHistoryClearSyntax(ctx)
|
||||
|
||||
console.SetColor("ConfigHistoryClearMessage", color.New(color.FgGreen))
|
||||
|
||||
// Get the alias parameter from cli
|
||||
args := ctx.Args()
|
||||
aliasedURL := args.Get(0)
|
||||
|
||||
// Create a new MinIO Admin Client
|
||||
client, err := newAdminClient(aliasedURL)
|
||||
fatalIf(err, "Unable to initialize admin connection.")
|
||||
|
||||
fatalIf(probe.NewError(client.ClearConfigHistoryKV(args.Get(1))), "Cannot clear server configuration.")
|
||||
|
||||
// Print
|
||||
printMsg(configHistoryClearMessage{
|
||||
RestoreID: args.Get(1),
|
||||
})
|
||||
|
||||
return nil
|
||||
}
|
||||
@@ -1,145 +0,0 @@
|
||||
/*
|
||||
* MinIO Client (C) 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.
|
||||
* 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 cmd
|
||||
|
||||
import (
|
||||
"strings"
|
||||
"text/tabwriter"
|
||||
"text/template"
|
||||
|
||||
"github.com/fatih/color"
|
||||
"github.com/minio/cli"
|
||||
json "github.com/minio/mc/pkg/colorjson"
|
||||
"github.com/minio/mc/pkg/console"
|
||||
"github.com/minio/mc/pkg/probe"
|
||||
"github.com/minio/minio/pkg/madmin"
|
||||
)
|
||||
|
||||
var historyListFlags = []cli.Flag{
|
||||
cli.IntFlag{
|
||||
Name: "count, n",
|
||||
Usage: "list only 'n' lines of history output",
|
||||
Value: 10,
|
||||
},
|
||||
}
|
||||
|
||||
var adminConfigHistoryListCmd = cli.Command{
|
||||
Name: "list",
|
||||
Usage: "list all previously set keys on MinIO server",
|
||||
Before: setGlobalsFromContext,
|
||||
Action: mainAdminConfigHistoryList,
|
||||
Flags: append(append([]cli.Flag{}, globalFlags...), historyListFlags...),
|
||||
CustomHelpTemplate: `NAME:
|
||||
{{.HelpName}} - {{.Usage}}
|
||||
|
||||
USAGE:
|
||||
{{.HelpName}} TARGET
|
||||
|
||||
FLAGS:
|
||||
{{range .VisibleFlags}}{{.}}
|
||||
{{end}}
|
||||
EXAMPLES:
|
||||
1. List all history entries sorted by set time.
|
||||
{{.Prompt}} {{.HelpName}} play/
|
||||
`,
|
||||
}
|
||||
|
||||
// HistoryList template used by all sub-systems
|
||||
const HistoryList = `{{range .}}{{colorYellowBold "RestoreId:"}} {{colorYellowBold .RestoreID}}
|
||||
Date: {{.CreateTime}}
|
||||
|
||||
{{.Targets}}
|
||||
|
||||
{{end}}`
|
||||
|
||||
// HistoryListTemplate - captures history list template
|
||||
var HistoryListTemplate = template.Must(template.New("history-list").Funcs(funcMap).Parse(HistoryList))
|
||||
|
||||
type historyEntry struct {
|
||||
RestoreID string `json:"restoreId"`
|
||||
CreateTime string `json:"createTime"`
|
||||
Targets madmin.Targets `json:"targets"`
|
||||
}
|
||||
|
||||
// configHistoryListMessage container to hold locks information.
|
||||
type configHistoryListMessage struct {
|
||||
Status string `json:"status"`
|
||||
Entries []historyEntry `json:"entries"`
|
||||
}
|
||||
|
||||
// String colorized service status message.
|
||||
func (u configHistoryListMessage) String() string {
|
||||
var s strings.Builder
|
||||
w := tabwriter.NewWriter(&s, 1, 8, 2, ' ', 0)
|
||||
e := HistoryListTemplate.Execute(w, u.Entries)
|
||||
fatalIf(probe.NewError(e), "Cannot initialize template writer")
|
||||
|
||||
w.Flush()
|
||||
return s.String()
|
||||
}
|
||||
|
||||
// JSON jsonified service status Message message.
|
||||
func (u configHistoryListMessage) JSON() string {
|
||||
u.Status = "success"
|
||||
statusJSONBytes, e := json.MarshalIndent(u, "", " ")
|
||||
fatalIf(probe.NewError(e), "Unable to marshal into JSON.")
|
||||
|
||||
return string(statusJSONBytes)
|
||||
}
|
||||
|
||||
// checkAdminConfigHistoryListSyntax - validate all the passed arguments
|
||||
func checkAdminConfigHistoryListSyntax(ctx *cli.Context) {
|
||||
if !ctx.Args().Present() || len(ctx.Args()) > 1 {
|
||||
cli.ShowCommandHelpAndExit(ctx, "list", 1) // last argument is exit code
|
||||
}
|
||||
}
|
||||
|
||||
func mainAdminConfigHistoryList(ctx *cli.Context) error {
|
||||
|
||||
checkAdminConfigHistoryListSyntax(ctx)
|
||||
|
||||
console.SetColor("ConfigHistoryListMessageRestoreID", color.New(color.Bold))
|
||||
console.SetColor("ConfigHistoryListMessageTime", color.New(color.FgGreen))
|
||||
|
||||
// Get the alias parameter from cli
|
||||
args := ctx.Args()
|
||||
aliasedURL := args.Get(0)
|
||||
|
||||
// Create a new MinIO Admin Client
|
||||
client, err := newAdminClient(aliasedURL)
|
||||
fatalIf(err, "Unable to initialize admin connection.")
|
||||
|
||||
chEntries, e := client.ListConfigHistoryKV(ctx.Int("count"))
|
||||
fatalIf(probe.NewError(e), "Cannot list server history configuration.")
|
||||
|
||||
hentries := make([]historyEntry, len(chEntries))
|
||||
for i, chEntry := range chEntries {
|
||||
hentries[i] = historyEntry{
|
||||
RestoreID: chEntry.RestoreID,
|
||||
CreateTime: chEntry.CreateTimeFormatted(),
|
||||
}
|
||||
hentries[i].Targets, e = madmin.ParseSubSysTarget([]byte(chEntry.Data))
|
||||
fatalIf(probe.NewError(e), "Unable to parse invalid history entry.")
|
||||
}
|
||||
|
||||
// Print
|
||||
printMsg(configHistoryListMessage{
|
||||
Entries: hentries,
|
||||
})
|
||||
|
||||
return nil
|
||||
}
|
||||
+129
-12
@@ -16,25 +16,142 @@
|
||||
|
||||
package cmd
|
||||
|
||||
import "github.com/minio/cli"
|
||||
import (
|
||||
"strings"
|
||||
"text/tabwriter"
|
||||
"text/template"
|
||||
|
||||
"github.com/fatih/color"
|
||||
"github.com/minio/cli"
|
||||
json "github.com/minio/mc/pkg/colorjson"
|
||||
"github.com/minio/mc/pkg/console"
|
||||
"github.com/minio/mc/pkg/probe"
|
||||
"github.com/minio/minio/pkg/madmin"
|
||||
)
|
||||
|
||||
var historyListFlags = []cli.Flag{
|
||||
cli.IntFlag{
|
||||
Name: "count, n",
|
||||
Usage: "list only last 'n' entries",
|
||||
Value: 10,
|
||||
},
|
||||
cli.BoolFlag{
|
||||
Name: "clear, c",
|
||||
Usage: "clear all history",
|
||||
},
|
||||
}
|
||||
|
||||
var adminConfigHistoryCmd = cli.Command{
|
||||
Name: "history",
|
||||
Usage: "history restores, clears and lists any previous successful 'mc admin config set' key values.",
|
||||
Usage: "show all historic configuration changes",
|
||||
Before: setGlobalsFromContext,
|
||||
Action: mainAdminConfigHistory,
|
||||
Flags: globalFlags,
|
||||
Subcommands: []cli.Command{
|
||||
adminConfigHistoryRestoreCmd,
|
||||
adminConfigHistoryListCmd,
|
||||
adminConfigHistoryClearCmd,
|
||||
},
|
||||
HideHelpCommand: true,
|
||||
Flags: append(append([]cli.Flag{}, globalFlags...), historyListFlags...),
|
||||
CustomHelpTemplate: `NAME:
|
||||
{{.HelpName}} - {{.Usage}}
|
||||
|
||||
USAGE:
|
||||
{{.HelpName}} TARGET
|
||||
|
||||
FLAGS:
|
||||
{{range .VisibleFlags}}{{.}}
|
||||
{{end}}
|
||||
EXAMPLES:
|
||||
1. List all history entries sorted by time.
|
||||
{{.Prompt}} {{.HelpName}} play/
|
||||
`,
|
||||
}
|
||||
|
||||
// mainAdminConfigHistory is the handle for "mc admin config history" command.
|
||||
// History template used by all sub-systems
|
||||
const History = `{{range .}}{{colorYellowBold "RestoreId:"}} {{colorYellowBold .RestoreID}}
|
||||
Date: {{.CreateTime}}
|
||||
|
||||
{{.Targets}}
|
||||
|
||||
{{end}}`
|
||||
|
||||
// HistoryTemplate - captures history list template
|
||||
var HistoryTemplate = template.Must(template.New("history-list").Funcs(funcMap).Parse(History))
|
||||
|
||||
type historyEntry struct {
|
||||
RestoreID string `json:"restoreId"`
|
||||
CreateTime string `json:"createTime"`
|
||||
Targets madmin.Targets `json:"targets"`
|
||||
}
|
||||
|
||||
// configHistoryMessage container to hold locks information.
|
||||
type configHistoryMessage struct {
|
||||
Status string `json:"status"`
|
||||
Entries []historyEntry `json:"entries"`
|
||||
}
|
||||
|
||||
// String colorized service status message.
|
||||
func (u configHistoryMessage) String() string {
|
||||
var s strings.Builder
|
||||
w := tabwriter.NewWriter(&s, 1, 8, 2, ' ', 0)
|
||||
e := HistoryTemplate.Execute(w, u.Entries)
|
||||
fatalIf(probe.NewError(e), "Cannot initialize template writer")
|
||||
|
||||
w.Flush()
|
||||
return s.String()
|
||||
}
|
||||
|
||||
// JSON jsonified service status Message message.
|
||||
func (u configHistoryMessage) JSON() string {
|
||||
u.Status = "success"
|
||||
statusJSONBytes, e := json.MarshalIndent(u, "", " ")
|
||||
fatalIf(probe.NewError(e), "Unable to marshal into JSON.")
|
||||
|
||||
return string(statusJSONBytes)
|
||||
}
|
||||
|
||||
// checkAdminConfigHistorySyntax - validate all the passed arguments
|
||||
func checkAdminConfigHistorySyntax(ctx *cli.Context) {
|
||||
if !ctx.Args().Present() || len(ctx.Args()) > 1 {
|
||||
cli.ShowCommandHelpAndExit(ctx, "history", 1) // last argument is exit code
|
||||
}
|
||||
}
|
||||
|
||||
func mainAdminConfigHistory(ctx *cli.Context) error {
|
||||
cli.ShowCommandHelp(ctx, ctx.Args().First())
|
||||
|
||||
checkAdminConfigHistorySyntax(ctx)
|
||||
|
||||
console.SetColor("ConfigHistoryMessageRestoreID", color.New(color.Bold))
|
||||
console.SetColor("ConfigHistoryMessageTime", color.New(color.FgGreen))
|
||||
|
||||
// Get the alias parameter from cli
|
||||
args := ctx.Args()
|
||||
aliasedURL := args.Get(0)
|
||||
|
||||
// Create a new MinIO Admin Client
|
||||
client, err := newAdminClient(aliasedURL)
|
||||
fatalIf(err, "Unable to initialize admin connection.")
|
||||
|
||||
if ctx.IsSet("clear") {
|
||||
fatalIf(probe.NewError(client.ClearConfigHistoryKV("all")), "Cannot clear server configuration.")
|
||||
|
||||
// Print
|
||||
printMsg(configHistoryMessage{})
|
||||
return nil
|
||||
}
|
||||
|
||||
chEntries, e := client.ListConfigHistoryKV(ctx.Int("count"))
|
||||
fatalIf(probe.NewError(e), "Cannot list server history configuration.")
|
||||
|
||||
hentries := make([]historyEntry, len(chEntries))
|
||||
for i, chEntry := range chEntries {
|
||||
hentries[i] = historyEntry{
|
||||
RestoreID: chEntry.RestoreID,
|
||||
CreateTime: chEntry.CreateTimeFormatted(),
|
||||
}
|
||||
hentries[i].Targets, e = madmin.ParseSubSysTarget([]byte(chEntry.Data))
|
||||
fatalIf(probe.NewError(e), "Unable to parse invalid history entry.")
|
||||
}
|
||||
|
||||
// Print
|
||||
printMsg(configHistoryMessage{
|
||||
Entries: hentries,
|
||||
})
|
||||
|
||||
return nil
|
||||
// Sub-commands like "restore", "clear", "list" have their own main.
|
||||
}
|
||||
|
||||
@@ -29,7 +29,7 @@ import (
|
||||
|
||||
var adminConfigImportCmd = cli.Command{
|
||||
Name: "import",
|
||||
Usage: "import a config to MinIO server/cluster",
|
||||
Usage: "import multiple config keys from STDIN",
|
||||
Before: setGlobalsFromContext,
|
||||
Action: mainAdminConfigImport,
|
||||
Flags: globalFlags,
|
||||
|
||||
@@ -34,11 +34,11 @@ var adminConfigEnvFlags = []cli.Flag{
|
||||
},
|
||||
}
|
||||
|
||||
var adminConfigDelCmd = cli.Command{
|
||||
Name: "del",
|
||||
Usage: "delete a key from MinIO server/cluster.",
|
||||
var adminConfigResetCmd = cli.Command{
|
||||
Name: "reset",
|
||||
Usage: "interactively reset a config key parameters",
|
||||
Before: setGlobalsFromContext,
|
||||
Action: mainAdminConfigDel,
|
||||
Action: mainAdminConfigReset,
|
||||
Flags: append(adminConfigEnvFlags, globalFlags...),
|
||||
CustomHelpTemplate: `NAME:
|
||||
{{.HelpName}} - {{.Usage}}
|
||||
@@ -55,24 +55,24 @@ EXAMPLES:
|
||||
`,
|
||||
}
|
||||
|
||||
// configDelMessage container to hold locks information.
|
||||
type configDelMessage struct {
|
||||
// configResetMessage container to hold locks information.
|
||||
type configResetMessage struct {
|
||||
Status string `json:"status"`
|
||||
targetAlias string
|
||||
}
|
||||
|
||||
// String colorized service status message.
|
||||
func (u configDelMessage) String() (msg string) {
|
||||
msg += console.Colorize("DelConfigSuccess",
|
||||
"Deleting key has been successful.\n")
|
||||
func (u configResetMessage) String() (msg string) {
|
||||
msg += console.Colorize("ResetConfigSuccess",
|
||||
"Reseteting key has been successful.\n")
|
||||
suggestion := fmt.Sprintf("mc admin service restart %s", u.targetAlias)
|
||||
msg += console.Colorize("DelConfigSuccess",
|
||||
msg += console.Colorize("ResetConfigSuccess",
|
||||
fmt.Sprintf("Please restart your server with `%s`.\n", suggestion))
|
||||
return
|
||||
}
|
||||
|
||||
// JSON jsonified service status message.
|
||||
func (u configDelMessage) JSON() string {
|
||||
func (u configResetMessage) JSON() string {
|
||||
u.Status = "success"
|
||||
statusJSONBytes, e := json.MarshalIndent(u, "", " ")
|
||||
fatalIf(probe.NewError(e), "Unable to marshal into JSON.")
|
||||
@@ -80,22 +80,22 @@ func (u configDelMessage) JSON() string {
|
||||
return string(statusJSONBytes)
|
||||
}
|
||||
|
||||
// checkAdminConfigDelSyntax - validate all the passed arguments
|
||||
func checkAdminConfigDelSyntax(ctx *cli.Context) {
|
||||
// checkAdminConfigResetSyntax - validate all the passed arguments
|
||||
func checkAdminConfigResetSyntax(ctx *cli.Context) {
|
||||
if !ctx.Args().Present() {
|
||||
cli.ShowCommandHelpAndExit(ctx, "del", 1) // last argument is exit code
|
||||
cli.ShowCommandHelpAndExit(ctx, "reset", 1) // last argument is exit code
|
||||
}
|
||||
}
|
||||
|
||||
// main config set function
|
||||
func mainAdminConfigDel(ctx *cli.Context) error {
|
||||
func mainAdminConfigReset(ctx *cli.Context) error {
|
||||
|
||||
// Check command arguments
|
||||
checkAdminConfigDelSyntax(ctx)
|
||||
checkAdminConfigResetSyntax(ctx)
|
||||
|
||||
// Del color preference of command outputs
|
||||
console.SetColor("DelConfigSuccess", color.New(color.FgGreen, color.Bold))
|
||||
console.SetColor("DelConfigFailure", color.New(color.FgRed, color.Bold))
|
||||
// Reset color preference of command outputs
|
||||
console.SetColor("ResetConfigSuccess", color.New(color.FgGreen, color.Bold))
|
||||
console.SetColor("ResetConfigFailure", color.New(color.FgRed, color.Bold))
|
||||
|
||||
// Get the alias parameter from cli
|
||||
args := ctx.Args()
|
||||
@@ -119,13 +119,13 @@ func mainAdminConfigDel(ctx *cli.Context) error {
|
||||
return nil
|
||||
}
|
||||
|
||||
// Call del config API
|
||||
// Call reset config API
|
||||
input := strings.Join(args.Tail(), " ")
|
||||
fatalIf(probe.NewError(client.DelConfigKV(input)),
|
||||
"Cannot delete '%s' on the server", input)
|
||||
"Cannot reset '%s' on the server", input)
|
||||
|
||||
// Print set config result
|
||||
printMsg(configDelMessage{
|
||||
printMsg(configResetMessage{
|
||||
targetAlias: aliasedURL,
|
||||
})
|
||||
|
||||
@@ -26,11 +26,11 @@ import (
|
||||
"github.com/minio/mc/pkg/probe"
|
||||
)
|
||||
|
||||
var adminConfigHistoryRestoreCmd = cli.Command{
|
||||
var adminConfigRestoreCmd = cli.Command{
|
||||
Name: "restore",
|
||||
Usage: "restore a history key value on MinIO server",
|
||||
Usage: "rollback back changes to a specific config history",
|
||||
Before: setGlobalsFromContext,
|
||||
Action: mainAdminConfigHistoryRestore,
|
||||
Action: mainAdminConfigRestore,
|
||||
Flags: globalFlags,
|
||||
CustomHelpTemplate: `NAME:
|
||||
{{.HelpName}} - {{.Usage}}
|
||||
@@ -47,24 +47,24 @@ EXAMPLES:
|
||||
`,
|
||||
}
|
||||
|
||||
// configHistoryRestoreMessage container to hold locks information.
|
||||
type configHistoryRestoreMessage struct {
|
||||
// configRestoreMessage container to hold locks information.
|
||||
type configRestoreMessage struct {
|
||||
Status string `json:"status"`
|
||||
RestoreID string `json:"restoreID"`
|
||||
targetAlias string
|
||||
}
|
||||
|
||||
// String colorized service status message.
|
||||
func (u configHistoryRestoreMessage) String() (msg string) {
|
||||
func (u configRestoreMessage) String() (msg string) {
|
||||
suggestion := fmt.Sprintf("mc admin service restart %s", u.targetAlias)
|
||||
msg += console.Colorize("ConfigHistoryRestoreMessage",
|
||||
msg += console.Colorize("ConfigRestoreMessage",
|
||||
fmt.Sprintf("Please restart your server with `%s`.\n", suggestion))
|
||||
msg += console.Colorize("ConfigHistoryRestoreMessage", "Restored "+u.RestoreID+" kv successfully.")
|
||||
msg += console.Colorize("ConfigRestoreMessage", "Restored "+u.RestoreID+" kv successfully.")
|
||||
return msg
|
||||
}
|
||||
|
||||
// JSON jsonified service status Message message.
|
||||
func (u configHistoryRestoreMessage) JSON() string {
|
||||
func (u configRestoreMessage) JSON() string {
|
||||
u.Status = "success"
|
||||
statusJSONBytes, e := json.MarshalIndent(u, "", " ")
|
||||
fatalIf(probe.NewError(e), "Unable to marshal into JSON.")
|
||||
@@ -72,18 +72,18 @@ func (u configHistoryRestoreMessage) JSON() string {
|
||||
return string(statusJSONBytes)
|
||||
}
|
||||
|
||||
// checkAdminConfigHistoryRestoreSyntax - validate all the passed arguments
|
||||
func checkAdminConfigHistoryRestoreSyntax(ctx *cli.Context) {
|
||||
// checkAdminConfigRestoreSyntax - validate all the passed arguments
|
||||
func checkAdminConfigRestoreSyntax(ctx *cli.Context) {
|
||||
if !ctx.Args().Present() || len(ctx.Args()) > 2 {
|
||||
cli.ShowCommandHelpAndExit(ctx, "restore", 1) // last argument is exit code
|
||||
}
|
||||
}
|
||||
|
||||
func mainAdminConfigHistoryRestore(ctx *cli.Context) error {
|
||||
func mainAdminConfigRestore(ctx *cli.Context) error {
|
||||
|
||||
checkAdminConfigHistoryRestoreSyntax(ctx)
|
||||
checkAdminConfigRestoreSyntax(ctx)
|
||||
|
||||
console.SetColor("ConfigHistoryRestoreMessage", color.New(color.FgGreen))
|
||||
console.SetColor("ConfigRestoreMessage", color.New(color.FgGreen))
|
||||
|
||||
// Get the alias parameter from cli
|
||||
args := ctx.Args()
|
||||
@@ -97,7 +97,7 @@ func mainAdminConfigHistoryRestore(ctx *cli.Context) error {
|
||||
fatalIf(probe.NewError(client.RestoreConfigHistoryKV(args.Get(1))), "Cannot restore server configuration.")
|
||||
|
||||
// Print
|
||||
printMsg(configHistoryRestoreMessage{
|
||||
printMsg(configRestoreMessage{
|
||||
RestoreID: args.Get(1),
|
||||
targetAlias: aliasedURL,
|
||||
})
|
||||
@@ -30,7 +30,7 @@ import (
|
||||
|
||||
var adminConfigSetCmd = cli.Command{
|
||||
Name: "set",
|
||||
Usage: "set key to MinIO server/cluster.",
|
||||
Usage: "interactively set a config key parameters",
|
||||
Before: setGlobalsFromContext,
|
||||
Action: mainAdminConfigSet,
|
||||
Flags: append(adminConfigEnvFlags, globalFlags...),
|
||||
|
||||
+6
-5
@@ -20,17 +20,18 @@ import "github.com/minio/cli"
|
||||
|
||||
var adminConfigCmd = cli.Command{
|
||||
Name: "config",
|
||||
Usage: "manage MinIO configuration",
|
||||
Usage: "manage MinIO server configuration",
|
||||
Action: mainAdminConfig,
|
||||
Before: setGlobalsFromContext,
|
||||
Flags: globalFlags,
|
||||
Subcommands: []cli.Command{
|
||||
adminConfigSetCmd,
|
||||
adminConfigGetCmd,
|
||||
adminConfigDelCmd,
|
||||
adminConfigImportCmd,
|
||||
adminConfigExportCmd,
|
||||
adminConfigSetCmd,
|
||||
adminConfigResetCmd,
|
||||
adminConfigHistoryCmd,
|
||||
adminConfigRestoreCmd,
|
||||
adminConfigExportCmd,
|
||||
adminConfigImportCmd,
|
||||
},
|
||||
HideHelpCommand: true,
|
||||
}
|
||||
|
||||
@@ -15,7 +15,7 @@ require (
|
||||
github.com/mattn/go-isatty v0.0.7
|
||||
github.com/mattn/go-runewidth v0.0.5 // indirect
|
||||
github.com/minio/cli v1.22.0
|
||||
github.com/minio/minio v0.0.0-20191203185020-794eb54da8c6
|
||||
github.com/minio/minio v0.0.0-20191204233237-c9940d8c3f1f
|
||||
github.com/minio/minio-go/v6 v6.0.43
|
||||
github.com/minio/sha256-simd v0.1.1
|
||||
github.com/mitchellh/go-homedir v1.1.0
|
||||
@@ -23,7 +23,7 @@ require (
|
||||
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/ugorji/go/codec v1.1.7 // indirect
|
||||
github.com/ugorji/go v1.1.7 // indirect
|
||||
go.uber.org/zap v1.11.0 // indirect
|
||||
golang.org/x/net v0.0.0-20190923162816-aa69164e4478
|
||||
golang.org/x/text v0.3.2
|
||||
|
||||
@@ -441,8 +441,8 @@ github.com/minio/minio v0.0.0-20190510004154-ac3b59645e92/go.mod h1:yFbQSwuA61mB
|
||||
github.com/minio/minio v0.0.0-20190903181048-8a71b0ec5a72/go.mod h1:H8OUaOxwJIALXHlfMpk2ESvk81dW+F7tSnrZi7rln/k=
|
||||
github.com/minio/minio v0.0.0-20190927193314-1c5b05c130fa/go.mod h1:47wx8w7yKTFAPw/hbmYPL4prsPivh6QuUqjTykftGgg=
|
||||
github.com/minio/minio v0.0.0-20191001201215-ff5bf519522f/go.mod h1:+vpJpzImdz4NCQto3r6/vF/24jWeEs5i3lsDfRmEcl4=
|
||||
github.com/minio/minio v0.0.0-20191203185020-794eb54da8c6 h1:WQlRSXTJrBETABbkU5L4sKj6aSV8PuYvGRa07skGx9E=
|
||||
github.com/minio/minio v0.0.0-20191203185020-794eb54da8c6/go.mod h1:3bY3lz9Uby83qOp5RsnPu4JJwiskVK088E7F4CRSdxI=
|
||||
github.com/minio/minio v0.0.0-20191204233237-c9940d8c3f1f h1:0Gm4h5JyOTpOfA8RRWdmE5ZGwCVp/TynsCdSt1BF1Mc=
|
||||
github.com/minio/minio v0.0.0-20191204233237-c9940d8c3f1f/go.mod h1:3bY3lz9Uby83qOp5RsnPu4JJwiskVK088E7F4CRSdxI=
|
||||
github.com/minio/minio-go v0.0.0-20190227180923-59af836a7e6d h1:gptD0/Hnam7h4Iq9D/33fscRpHfzOOUqUbH2nPw9HcU=
|
||||
github.com/minio/minio-go v0.0.0-20190227180923-59af836a7e6d/go.mod h1:/haSOWG8hQNx2+JOfLJ9GKp61EAmgPwRVw/Sac0NzaM=
|
||||
github.com/minio/minio-go v0.0.0-20190313212832-5d20267d970d/go.mod h1:/haSOWG8hQNx2+JOfLJ9GKp61EAmgPwRVw/Sac0NzaM=
|
||||
|
||||
Reference in New Issue
Block a user