allow 'mc' flags to have ENV equivalent (#4720)

it simplifies the codebase a bit and also
allows for `mc` to easily be configured in
containerized environments.
This commit is contained in:
Harshavardhana
2023-10-16 22:51:25 -07:00
committed by GitHub
parent 377b71641b
commit 062f28c9cc
6 changed files with 37 additions and 41 deletions
+2 -6
View File
@@ -77,12 +77,8 @@ func parseKey(sseKeys string) (sse string, err *probe.Error) {
// parse and return encryption key pairs per alias.
func getEncKeys(ctx *cli.Context) (map[string][]prefixSSEPair, *probe.Error) {
sseServer := os.Getenv("MC_ENCRYPT")
if prefix := ctx.String("encrypt"); prefix != "" {
sseServer = prefix
}
sseKeys := os.Getenv("MC_ENCRYPT_KEY")
sseServer := ctx.String("encrypt")
var sseKeys string
if keyPrefix := ctx.String("encrypt-key"); keyPrefix != "" {
if sseServer != "" && strings.Contains(keyPrefix, sseServer) {
return nil, errConflictSSE(sseServer, keyPrefix).Trace(ctx.Args()...)
-4
View File
@@ -63,10 +63,6 @@ var (
Name: "storage-class, sc",
Usage: "set storage class for new object(s) on target",
},
cli.StringFlag{
Name: "encrypt",
Usage: "encrypt/decrypt objects (using server-side encryption with server managed keys)",
},
cli.StringFlag{
Name: "attr",
Usage: "add custom metadata for the object",
+35 -19
View File
@@ -23,40 +23,50 @@ import (
"github.com/minio/cli"
)
const envPrefix = "MC_"
// Collection of mc flags currently supported
var globalFlags = []cli.Flag{
cli.StringFlag{
Name: "config-dir, C",
Value: mustGetMcConfigDir(),
Usage: "path to configuration folder",
Name: "config-dir, C",
Value: mustGetMcConfigDir(),
Usage: "path to configuration folder",
EnvVar: envPrefix + "CONFIG_DIR",
},
cli.BoolFlag{
Name: "quiet, q",
Usage: "disable progress bar display",
Name: "quiet, q",
Usage: "disable progress bar display",
EnvVar: envPrefix + "QUIET",
},
cli.BoolFlag{
Name: "no-color",
Usage: "disable color theme",
Name: "no-color",
Usage: "disable color theme",
EnvVar: envPrefix + "NO_COLOR",
},
cli.BoolFlag{
Name: "json",
Usage: "enable JSON lines formatted output",
Name: "json",
Usage: "enable JSON lines formatted output",
EnvVar: envPrefix + "JSON",
},
cli.BoolFlag{
Name: "debug",
Usage: "enable debug output",
Name: "debug",
Usage: "enable debug output",
EnvVar: envPrefix + "DEBUG",
},
cli.BoolFlag{
Name: "insecure",
Usage: "disable SSL certificate verification",
Name: "insecure",
Usage: "disable SSL certificate verification",
EnvVar: envPrefix + "INSECURE",
},
cli.StringFlag{
Name: "limit-upload",
Usage: "limits uploads to a maximum rate in KiB/s, MiB/s, GiB/s. (default: unlimited)",
Name: "limit-upload",
Usage: "limits uploads to a maximum rate in KiB/s, MiB/s, GiB/s. (default: unlimited)",
EnvVar: envPrefix + "LIMIT_UPLOAD",
},
cli.StringFlag{
Name: "limit-download",
Usage: "limits downloads to a maximum rate in KiB/s, MiB/s, GiB/s. (default: unlimited)",
Name: "limit-download",
Usage: "limits downloads to a maximum rate in KiB/s, MiB/s, GiB/s. (default: unlimited)",
EnvVar: envPrefix + "LIMIT_DOWNLOAD",
},
cli.DurationFlag{
Name: "conn-read-deadline",
@@ -75,7 +85,13 @@ var globalFlags = []cli.Flag{
// Flags common across all I/O commands such as cp, mirror, stat, pipe etc.
var ioFlags = []cli.Flag{
cli.StringFlag{
Name: "encrypt-key",
Usage: "encrypt/decrypt objects (using server-side encryption with customer provided keys)",
Name: "encrypt-key",
Usage: "encrypt/decrypt objects (using server-side encryption with customer provided keys)",
EnvVar: envPrefix + "ENCRYPT_KEY",
},
cli.StringFlag{
Name: "encrypt",
Usage: "encrypt/decrypt objects (using server-side encryption with server managed keys)",
EnvVar: envPrefix + "ENCRYPT",
},
}
-4
View File
@@ -117,10 +117,6 @@ var (
Name: "storage-class, sc",
Usage: "specify storage class for new object(s) on target",
},
cli.StringFlag{
Name: "encrypt",
Usage: "encrypt/decrypt objects (using server-side encryption with server managed keys)",
},
cli.StringFlag{
Name: "attr",
Usage: "add custom metadata for all objects",
-4
View File
@@ -48,10 +48,6 @@ var (
Name: "storage-class, sc",
Usage: "set storage class for new object(s) on target",
},
cli.StringFlag{
Name: "encrypt",
Usage: "encrypt/decrypt objects (using server-side encryption with server managed keys)",
},
cli.StringFlag{
Name: "attr",
Usage: "add custom metadata for the object",
-4
View File
@@ -35,10 +35,6 @@ func defaultPartSize() string {
}
var pipeFlags = []cli.Flag{
cli.StringFlag{
Name: "encrypt",
Usage: "encrypt objects (using server-side encryption with server managed keys)",
},
cli.StringFlag{
Name: "storage-class, sc",
Usage: "set storage class for new object(s) on target",