-
Notifications
You must be signed in to change notification settings - Fork 549
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
mc admin config set/get/del/history/help
Related to minio/minio#8392
- Loading branch information
1 parent
80aecfd
commit 6867fc7
Showing
12 changed files
with
719 additions
and
104 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,131 @@ | ||
/* | ||
* 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 ( | ||
"fmt" | ||
"io/ioutil" | ||
"os" | ||
"strings" | ||
|
||
"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 adminConfigDelCmd = cli.Command{ | ||
Name: "del", | ||
Usage: "delete a key from MinIO server/cluster.", | ||
Before: setGlobalsFromContext, | ||
Action: mainAdminConfigDel, | ||
Flags: globalFlags, | ||
CustomHelpTemplate: `NAME: | ||
{{.HelpName}} - {{.Usage}} | ||
USAGE: | ||
{{.HelpName}} TARGET | ||
FLAGS: | ||
{{range .VisibleFlags}}{{.}} | ||
{{end}} | ||
EXAMPLES: | ||
1. Remove MQTT notifcation target 'target1' on MinIO server. | ||
{{.Prompt}} {{.HelpName}} myminio/ notify_mqtt:target1 | ||
`, | ||
} | ||
|
||
// configDelMessage container to hold locks information. | ||
type configDelMessage struct { | ||
Status string `json:"status"` | ||
delConfigStatus bool | ||
targetAlias string | ||
} | ||
|
||
// String colorized service status message. | ||
func (u configDelMessage) String() (msg string) { | ||
// Print the general set config status | ||
if u.delConfigStatus { | ||
msg += console.Colorize("DelConfigSuccess", | ||
"Deleting key has been successful.\n") | ||
suggestion := fmt.Sprintf("mc admin service restart %s", u.targetAlias) | ||
msg += console.Colorize("DelConfigSuccess", | ||
fmt.Sprintf("Please restart your server with `%s`.\n", suggestion)) | ||
} else { | ||
msg += console.Colorize("DelConfigFailure", | ||
"Deleting new MinIO configuration file has failed.\n") | ||
} | ||
return | ||
} | ||
|
||
// JSON jsonified service status message. | ||
func (u configDelMessage) JSON() string { | ||
if u.delConfigStatus { | ||
u.Status = "success" | ||
} else { | ||
u.Status = "error" | ||
} | ||
statusJSONBytes, e := json.MarshalIndent(u, "", " ") | ||
fatalIf(probe.NewError(e), "Unable to marshal into JSON.") | ||
|
||
return string(statusJSONBytes) | ||
} | ||
|
||
// checkAdminConfigDelSyntax - validate all the passed arguments | ||
func checkAdminConfigDelSyntax(ctx *cli.Context) { | ||
if !ctx.Args().Present() { | ||
cli.ShowCommandHelpAndExit(ctx, "del", 1) // last argument is exit code | ||
} | ||
} | ||
|
||
// main config set function | ||
func mainAdminConfigDel(ctx *cli.Context) error { | ||
|
||
// Check command arguments | ||
checkAdminConfigDelSyntax(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)) | ||
|
||
// 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.") | ||
|
||
// Call del config API | ||
input := strings.Join(args.Tail(), " ") | ||
if len(input) == 0 { | ||
b, err := ioutil.ReadAll(os.Stdin) | ||
fatalIf(probe.NewError(err), "Cannot set server configuration file.") | ||
input = string(b) | ||
} | ||
fatalIf(probe.NewError(client.DelConfigKV(input)), | ||
"Cannot set server configuration file.") | ||
|
||
// Print set config result | ||
printMsg(configDelMessage{ | ||
delConfigStatus: true, | ||
targetAlias: aliasedURL, | ||
}) | ||
|
||
return nil | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,112 @@ | ||
/* | ||
* 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. | ||
* 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 ( | ||
"encoding/base64" | ||
"io/ioutil" | ||
|
||
"github.com/minio/cli" | ||
json "github.com/minio/mc/pkg/colorjson" | ||
"github.com/minio/mc/pkg/probe" | ||
) | ||
|
||
var helpFlags = []cli.Flag{ | ||
cli.BoolFlag{ | ||
Name: "env", | ||
Usage: "list all the env only help", | ||
}, | ||
} | ||
|
||
var adminConfigHelpCmd = cli.Command{ | ||
Name: "help", | ||
Usage: "help returns help for each sub-system", | ||
Before: setGlobalsFromContext, | ||
Action: mainAdminConfigHelp, | ||
Flags: append(append([]cli.Flag{}, globalFlags...), helpFlags...), | ||
CustomHelpTemplate: `NAME: | ||
{{.HelpName}} - {{.Usage}} | ||
USAGE: | ||
{{.HelpName}} TARGET | ||
FLAGS: | ||
{{range .VisibleFlags}}{{.}} | ||
{{end}} | ||
EXAMPLES: | ||
1. Return help for 'region' settings on MinIO server. | ||
{{.Prompt}} {{.HelpName}} play/ region | ||
2. Return help for 'compression' settings, specifically 'extensions' key on MinIO server. | ||
{{.Prompt}} {{.HelpName}} myminio/ compression extensions | ||
`, | ||
} | ||
|
||
// configHelpMessage container to hold locks information. | ||
type configHelpMessage struct { | ||
Status string `json:"status"` | ||
Value string `json:"value"` | ||
} | ||
|
||
// String colorized service status message. | ||
func (u configHelpMessage) String() string { | ||
return u.Value | ||
} | ||
|
||
// JSON jsonified service status Message message. | ||
func (u configHelpMessage) JSON() string { | ||
u.Status = "success" | ||
u.Value = base64.StdEncoding.EncodeToString([]byte(u.Value)) | ||
statusJSONBytes, e := json.MarshalIndent(u, "", " ") | ||
fatalIf(probe.NewError(e), "Unable to marshal into JSON.") | ||
|
||
return string(statusJSONBytes) | ||
} | ||
|
||
// checkAdminConfigHelpSyntax - validate all the passed arguments | ||
func checkAdminConfigHelpSyntax(ctx *cli.Context) { | ||
if !ctx.Args().Present() || len(ctx.Args()) > 3 { | ||
cli.ShowCommandHelpAndExit(ctx, "help", 1) // last argument is exit code | ||
} | ||
} | ||
|
||
func mainAdminConfigHelp(ctx *cli.Context) error { | ||
|
||
checkAdminConfigHelpSyntax(ctx) | ||
|
||
// Help 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.") | ||
|
||
// Call get config API | ||
hr, e := client.HelpConfigKV(args.Get(1), args.Get(2), ctx.IsSet("env"), globalNoColor) | ||
fatalIf(probe.NewError(e), "Cannot get help for the sub-system") | ||
|
||
buf, e := ioutil.ReadAll(hr) | ||
fatalIf(probe.NewError(e), "Cannot get help for the sub-system") | ||
|
||
printMsg(configHelpMessage{ | ||
Value: string(buf), | ||
}) | ||
|
||
return nil | ||
} |
Oops, something went wrong.