Files
mc/cmd/globals.go
T
Shireesh Anjal e4d4bf6641 Add register sub-command to mc admin subnet (#3808)
By default, it will run in `online` mode and try to register the cluster
on subnet. If the subnet license is not available in minio/mc config, it
will

- ask the user for login credentials
- use the credentials for authentication and call the registration api
- get the license from response of the api and store it in config
- use the stored license for any subsequent calls

In case the user belongs to multiple organizations in subnet, they will
be prompted to choose the appropriate organization from the list.

If the client machine is in an airgapped environment, user can choose to
use the `--offline` flag when running the command. In this case, it will

- generate and print the registration token
- ask the user to paste it in the subnet registration screen
- accept the license generated by subnet and store it in config

As part of this work, the `health` sub-command is also enhanced to:
- run in `online` mode by default, which tries to upload the health
report to subnet. Here the user will be prompted for subnet credentials
(if license not available in config) _before_ generating the health
report as it is a long running process.
- support a new flag `--offline` which can be used when subnet is not
reachable. When used, the health report will be generated in a local
json.gz file, which can then be uploaded on subnet.

The examples in help text of both the sub-commands are enhanced to list
multiple use cases.

When saving license to config, first preference is given to minio
config. If the minio server supports the `subnet license` key, the
license will be stored here. In case it is an older version of minio
that doesn't support this key, then the license will be stored in mc
host config.
2021-10-07 11:20:28 -07:00

119 lines
3.8 KiB
Go

// Copyright (c) 2015-2021 MinIO, Inc.
//
// This file is part of MinIO Object Storage stack
//
// This program is free software: you can redistribute it and/or modify
// it under the terms of the GNU Affero General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.
//
// This program is distributed in the hope that it will be useful
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU Affero General Public License for more details.
//
// You should have received a copy of the GNU Affero General Public License
// along with this program. If not, see <http://www.gnu.org/licenses/>.
// Package cmd contains all the global variables and constants. ONLY TO BE ACCESSED VIA GET/SET FUNCTIONS.
package cmd
import (
"context"
"crypto/x509"
"net/url"
"github.com/minio/cli"
"github.com/minio/pkg/console"
)
const (
globalMCConfigVersion = "10"
globalMCConfigFile = "config.json"
globalMCCertsDir = "certs"
globalMCCAsDir = "CAs"
// session config and shared urls related constants
globalSessionDir = "session"
globalSharedURLsDataDir = "share"
globalSessionConfigVersion = "8"
// Profile directory for dumping profiler outputs.
globalProfileDir = "profile"
// Global error exit status.
globalErrorExitStatus = 1
// Global CTRL-C (SIGINT, #2) exit status.
globalCancelExitStatus = 130
// Global SIGKILL (#9) exit status.
globalKillExitStatus = 137
// Global SIGTERM (#15) exit status
globalTerminatExitStatus = 143
)
var (
globalQuiet = false // Quiet flag set via command line
globalJSON = false // Json flag set via command line
globalJSONLine = false // Print json as single line.
globalDebug = false // Debug flag set via command line
globalNoColor = false // No Color flag set via command line
globalInsecure = false // Insecure flag set via command line
globalDevMode = false // dev flag set via command line
globalSubnetProxyURL *url.URL // Proxy to be used for communication with subnet
globalContext, globalCancel = context.WithCancel(context.Background())
)
var (
// Terminal width
globalTermWidth int
// CA root certificates, a nil value means system certs pool will be used
globalRootCAs *x509.CertPool
)
// Set global states. NOTE: It is deliberately kept monolithic to ensure we dont miss out any flags.
func setGlobals(quiet, debug, json, noColor, insecure, devMode bool, subnetProxyURL *url.URL) {
globalQuiet = globalQuiet || quiet
globalDebug = globalDebug || debug
globalJSONLine = !isTerminal() && json
globalJSON = globalJSON || json
globalNoColor = globalNoColor || noColor || globalJSONLine
globalInsecure = globalInsecure || insecure
globalDevMode = globalDevMode || devMode
globalSubnetProxyURL = subnetProxyURL
// Disable colorified messages if requested.
if globalNoColor || globalQuiet {
console.SetColorOff()
}
}
// Set global states. NOTE: It is deliberately kept monolithic to ensure we dont miss out any flags.
func setGlobalsFromContext(ctx *cli.Context) error {
quiet := ctx.IsSet("quiet") || ctx.GlobalIsSet("quiet")
debug := ctx.IsSet("debug") || ctx.GlobalIsSet("debug")
json := ctx.IsSet("json") || ctx.GlobalIsSet("json")
noColor := ctx.IsSet("no-color") || ctx.GlobalIsSet("no-color")
insecure := ctx.IsSet("insecure") || ctx.GlobalIsSet("insecure")
devMode := ctx.IsSet("dev") || ctx.GlobalIsSet("dev")
subnetProxy := ctx.String("subnet-proxy")
var proxyURL *url.URL
var e error
if value := ctx.String("subnet-proxy"); value != "" {
proxyURL, e = url.Parse(subnetProxy)
if e != nil {
return e
}
}
setGlobals(quiet, debug, json, noColor, insecure, devMode, proxyURL)
return nil
}