github.com/minio/mc@v0.0.0-20240503112107-b471de8d1882/cmd/support-proxy-show.go (about)

     1  // Copyright (c) 2015-2022 MinIO, Inc.
     2  //
     3  // This file is part of MinIO Object Storage stack
     4  //
     5  // This program is free software: you can redistribute it and/or modify
     6  // it under the terms of the GNU Affero General Public License as published by
     7  // the Free Software Foundation, either version 3 of the License, or
     8  // (at your option) any later version.
     9  //
    10  // This program is distributed in the hope that it will be useful
    11  // but WITHOUT ANY WARRANTY; without even the implied warranty of
    12  // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
    13  // GNU Affero General Public License for more details.
    14  //
    15  // You should have received a copy of the GNU Affero General Public License
    16  // along with this program.  If not, see <http://www.gnu.org/licenses/>.
    17  
    18  package cmd
    19  
    20  import (
    21  	"github.com/minio/cli"
    22  	"github.com/minio/pkg/v2/console"
    23  )
    24  
    25  var supportProxyShowCmd = cli.Command{
    26  	Name:            "show",
    27  	Usage:           "Show the configured proxy",
    28  	Action:          mainSupportProxyShow,
    29  	OnUsageError:    onUsageError,
    30  	Before:          setGlobalsFromContext,
    31  	Flags:           globalFlags,
    32  	HideHelpCommand: true,
    33  	CustomHelpTemplate: `NAME:
    34    {{.HelpName}} - {{.Usage}}
    35  
    36  USAGE:
    37    {{.HelpName}} [FLAGS] TARGET
    38  
    39  FLAGS:
    40    {{range .VisibleFlags}}{{.}}
    41    {{end}}
    42  EXAMPLES:
    43    1. Show the proxy configured for cluster with alias 'myminio'
    44       {{.Prompt}} {{.HelpName}} myminio
    45  `,
    46  }
    47  
    48  type supportProxyShowMessage struct {
    49  	Status string `json:"status"`
    50  	Proxy  string `json:"proxy"`
    51  }
    52  
    53  // String colorized proxy show message
    54  func (s supportProxyShowMessage) String() string {
    55  	msg := s.Proxy
    56  	if len(msg) == 0 {
    57  		msg = "Proxy is not configured"
    58  	}
    59  	return console.Colorize(supportSuccessMsgTag, msg)
    60  }
    61  
    62  // JSON jsonified proxy show message
    63  func (s supportProxyShowMessage) JSON() string {
    64  	s.Status = "success"
    65  	return toJSON(s)
    66  }
    67  
    68  func checkSupportProxyShowSyntax(ctx *cli.Context) {
    69  	if len(ctx.Args()) != 1 {
    70  		showCommandHelpAndExit(ctx, 1) // last argument is exit code
    71  	}
    72  }
    73  
    74  // mainSupportProxyShow is the handler for "mc support proxy show" command.
    75  func mainSupportProxyShow(ctx *cli.Context) error {
    76  	// Check for command syntax
    77  	checkSupportProxyShowSyntax(ctx)
    78  	setSuccessMessageColor()
    79  
    80  	// Get the alias parameter from cli
    81  	args := ctx.Args()
    82  	aliasedURL := args.Get(0)
    83  	alias, _ := url2Alias(aliasedURL)
    84  
    85  	validateClusterRegistered(alias, false)
    86  
    87  	// Main execution
    88  	// get the subnet proxy config from MinIO if available
    89  	proxy, supported := getKeyFromSubnetConfig(alias, "proxy")
    90  	if !supported {
    91  		fatal(errDummy().Trace(), "Proxy configuration not supported in this version of MinIO.")
    92  	}
    93  
    94  	printMsg(supportProxyShowMessage{Proxy: proxy})
    95  	return nil
    96  }