Skip to content

Commit

Permalink
Ensure --airgap is available on all support commands (minio#4633)
Browse files Browse the repository at this point in the history
- remove deprecated and unused flags from `support diag`
- add missing registration check-in
  - call home status
  - proxy set|show|remove
  • Loading branch information
anjalshireesh committed Jul 17, 2023
1 parent 15ea112 commit e8f049c
Show file tree
Hide file tree
Showing 14 changed files with 37 additions and 43 deletions.
2 changes: 1 addition & 1 deletion cmd/license-info.go
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ var licenseInfoCmd = cli.Command{
OnUsageError: onUsageError,
Action: mainLicenseInfo,
Before: setGlobalsFromContext,
Flags: append(supportGlobalFlags, subnetCommonFlags...),
Flags: subnetCommonFlags,
CustomHelpTemplate: `NAME:
{{.HelpName}} - {{.Usage}}
Expand Down
2 changes: 1 addition & 1 deletion cmd/license-register.go
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ var licenseRegisterCmd = cli.Command{
OnUsageError: onUsageError,
Action: mainLicenseRegister,
Before: setGlobalsFromContext,
Flags: append(licenseRegisterFlags, supportGlobalFlags...),
Flags: licenseRegisterFlags,
CustomHelpTemplate: `NAME:
{{.HelpName}} - {{.Usage}}
Expand Down
2 changes: 1 addition & 1 deletion cmd/license-unregister.go
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ var licenseUnregisterCmd = cli.Command{
Action: mainLicenseUnregister,
Before: setGlobalsFromContext,
Hidden: true,
Flags: append(supportGlobalFlags, subnetCommonFlags...),
Flags: subnetCommonFlags,
CustomHelpTemplate: `NAME:
{{.HelpName}} - {{.Usage}}
Expand Down
16 changes: 5 additions & 11 deletions cmd/subnet-utils.go
Original file line number Diff line number Diff line change
Expand Up @@ -60,17 +60,11 @@ MHYwEAYHKoZIzj0CAQYFK4EEACIDYgAEbo+e1wpBY4tBq9AONKww3Kq7m6QP/TBQ
mr/cKCUyBL7rcAvg0zNq1vcSrUSGlAmY3SEDCu3GOKnjG/U4E7+p957ocWSV+mQU
9NKlTdQFGF3+aO6jbQ4hX/S5qPyF+a3z
-----END PUBLIC KEY-----` // https://localhost:9000/downloads/license-pubkey.pem
subnetCommonFlags = []cli.Flag{
cli.BoolFlag{
Name: "airgap",
Usage: "use in environments without network access to SUBNET (e.g. airgapped, firewalled, etc.)",
},
cli.StringFlag{
Name: "api-key",
Usage: "API Key of the account on SUBNET",
EnvVar: "_MC_SUBNET_API_KEY",
},
}
subnetCommonFlags = append(supportGlobalFlags, cli.StringFlag{
Name: "api-key",
Usage: "API Key of the account on SUBNET",
EnvVar: "_MC_SUBNET_API_KEY",
})
)

func subnetOfflinePublicKey() string {
Expand Down
14 changes: 5 additions & 9 deletions cmd/support-callhome.go
Original file line number Diff line number Diff line change
Expand Up @@ -149,6 +149,7 @@ func mainCallhome(ctx *cli.Context) error {

setSuccessMessageColor()
alias, arg := checkToggleCmdSyntax(ctx)
apiKey := validateClusterRegistered(alias, true)

diag, logs := parseCallhomeFlags(ctx)

Expand All @@ -157,7 +158,7 @@ func mainCallhome(ctx *cli.Context) error {
return nil
}

toggleCallhome(alias, arg == "enable", diag, logs)
toggleCallhome(alias, apiKey, arg == "enable", diag, logs)

return nil
}
Expand Down Expand Up @@ -187,24 +188,20 @@ func printCallhomeStatus(alias string, diag bool, logs bool) {
printMsg(resultMsg)
}

func toggleCallhome(alias string, enable bool, diag bool, logs bool) {
func toggleCallhome(alias string, apiKey string, enable bool, diag bool, logs bool) {
newStatus := featureStatusStr(enable)
resultMsg := supportCallhomeMessage{
Action: newStatus,
Feature: getFeature(diag, logs),
}

if enable {
validateClusterRegistered(alias, true)
}

if diag {
setCallhomeConfig(alias, enable)
resultMsg.Diag = newStatus
}

if logs {
configureSubnetWebhook(alias, enable)
configureSubnetWebhook(alias, apiKey, enable)
resultMsg.Logs = newStatus
}

Expand Down Expand Up @@ -241,14 +238,13 @@ func setCallhomeConfig(alias string, enableCallhome bool) {
fatalIf(probe.NewError(e), "Unable to set callhome config on minio")
}

func configureSubnetWebhook(alias string, enable bool) {
func configureSubnetWebhook(alias string, apiKey string, enable bool) {
// Create a new MinIO Admin Client
client, err := newAdminClient(alias)
fatalIf(err, "Unable to initialize admin connection.")

var input string
if enable {
apiKey := validateClusterRegistered(alias, true)
input = fmt.Sprintf("logger_webhook:subnet endpoint=%s auth_token=%s enable=on",
subnetLogWebhookURL(), apiKey)
} else {
Expand Down
12 changes: 1 addition & 11 deletions cmd/support-diag.go
Original file line number Diff line number Diff line change
Expand Up @@ -54,16 +54,6 @@ var supportDiagFlags = append([]cli.Flag{
Value: 1 * time.Hour,
Hidden: true,
},
cli.StringFlag{
Name: "license",
Usage: "SUBNET license key",
Hidden: true, // deprecated dec 2021
},
cli.StringFlag{
Name: "name",
Usage: "Specify the name to associate to this MinIO cluster in SUBNET",
Hidden: true, // deprecated may 2022
},
}, subnetCommonFlags...)

var supportDiagCmd = cli.Command{
Expand All @@ -73,7 +63,7 @@ var supportDiagCmd = cli.Command{
OnUsageError: onUsageError,
Action: mainSupportDiag,
Before: setGlobalsFromContext,
Flags: append(supportDiagFlags, supportGlobalFlags...),
Flags: supportDiagFlags,
CustomHelpTemplate: `NAME:
{{.HelpName}} - {{.Usage}}
Expand Down
2 changes: 1 addition & 1 deletion cmd/support-inspect.go
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ var supportInspectCmd = cli.Command{
Action: mainSupportInspect,
OnUsageError: onUsageError,
Before: setGlobalsFromContext,
Flags: append(supportInspectFlags, supportGlobalFlags...),
Flags: supportInspectFlags,
HideHelpCommand: true,
CustomHelpTemplate: `NAME:
{{.HelpName}} - {{.Usage}}
Expand Down
2 changes: 1 addition & 1 deletion cmd/support-perf.go
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,7 @@ var supportPerfCmd = cli.Command{
Action: mainSupportPerf,
OnUsageError: onUsageError,
Before: setGlobalsFromContext,
Flags: append(supportPerfFlags, supportGlobalFlags...),
Flags: supportPerfFlags,
HideHelpCommand: true,
CustomHelpTemplate: `NAME:
{{.HelpName}} - {{.Usage}}
Expand Down
2 changes: 1 addition & 1 deletion cmd/support-profile.go
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ var supportProfileCmd = cli.Command{
Action: mainSupportProfile,
OnUsageError: onUsageError,
Before: setGlobalsFromContext,
Flags: append(profileFlags, supportGlobalFlags...),
Flags: profileFlags,
HideHelpCommand: true,
CustomHelpTemplate: `NAME:
{{.HelpName}} - {{.Usage}}
Expand Down
3 changes: 3 additions & 0 deletions cmd/support-proxy-remove.go
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,9 @@ func mainSupportProxyRemove(ctx *cli.Context) error {
// Get the alias parameter from cli
args := ctx.Args()
aliasedURL := args.Get(0)
alias, _ := url2Alias(aliasedURL)

validateClusterRegistered(alias, false)

// Create a new MinIO Admin Client
client := getClient(aliasedURL)
Expand Down
3 changes: 3 additions & 0 deletions cmd/support-proxy-set.go
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,9 @@ func mainSupportProxySet(ctx *cli.Context) error {
// Get the alias parameter from cli
args := ctx.Args()
aliasedURL := args.Get(0)
alias, _ := url2Alias(aliasedURL)

validateClusterRegistered(alias, false)

// Create a new MinIO Admin Client
client := getClient(aliasedURL)
Expand Down
2 changes: 2 additions & 0 deletions cmd/support-proxy-show.go
Original file line number Diff line number Diff line change
Expand Up @@ -82,6 +82,8 @@ func mainSupportProxyShow(ctx *cli.Context) error {
aliasedURL := args.Get(0)
alias, _ := url2Alias(aliasedURL)

validateClusterRegistered(alias, false)

// Main execution
// get the subnet proxy config from MinIO if available
proxy, supported := getKeyFromSubnetConfig(alias, "proxy")
Expand Down
2 changes: 1 addition & 1 deletion cmd/support-register.go
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ var supportRegisterCmd = cli.Command{
OnUsageError: onUsageError,
Action: mainSupportRegister,
Before: setGlobalsFromContext,
Flags: append(supportRegisterFlags, supportGlobalFlags...),
Flags: supportRegisterFlags,
CustomHelpTemplate: "Please use 'mc license register'",
}

Expand Down
16 changes: 11 additions & 5 deletions cmd/support.go
Original file line number Diff line number Diff line change
Expand Up @@ -31,11 +31,17 @@ import (

const supportSuccessMsgTag = "SupportSuccessMessage"

var supportGlobalFlags = append(globalFlags, cli.BoolFlag{
Name: "dev",
Usage: "Development mode",
Hidden: true,
})
var supportGlobalFlags = append(globalFlags,
cli.BoolFlag{
Name: "dev",
Usage: "Development mode",
Hidden: true,
},
cli.BoolFlag{
Name: "airgap",
Usage: "use in environments without network access to SUBNET (e.g. airgapped, firewalled, etc.)",
},
)

var supportSubcommands = []cli.Command{
supportRegisterCmd,
Expand Down

0 comments on commit e8f049c

Please sign in to comment.