github.com/minio/mc@v0.0.0-20240503112107-b471de8d1882/cmd/ilm-tier-verify.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/mc/pkg/probe"
    23  )
    24  
    25  var adminTierVerifyCmd = cli.Command{
    26  	Name:         "verify",
    27  	Usage:        "verifies if remote tier configuration is valid",
    28  	Action:       mainAdminTierVerify,
    29  	Hidden:       true,
    30  	OnUsageError: onUsageError,
    31  	Before:       setGlobalsFromContext,
    32  	Flags:        globalFlags,
    33  	CustomHelpTemplate: `NAME:
    34    {{.HelpName}} - {{.Usage}}
    35  
    36  USAGE:
    37    {{.HelpName}} TARGET NAME
    38  
    39  NAME:
    40    Name of remote tier target. e.g WARM-TIER
    41  
    42  FLAGS:
    43    {{range .VisibleFlags}}{{.}}
    44    {{end}}
    45  EXAMPLES:
    46    1. Verify if a tier config is valid.
    47       {{.Prompt}} {{.HelpName}} myminio WARM-TIER
    48  `,
    49  }
    50  
    51  func mainAdminTierVerify(ctx *cli.Context) error {
    52  	args := ctx.Args()
    53  	nArgs := len(args)
    54  	if nArgs < 2 {
    55  		showCommandHelpAndExit(ctx, 1)
    56  	}
    57  	if nArgs != 2 {
    58  		fatalIf(errInvalidArgument().Trace(args.Tail()...),
    59  			"Incorrect number of arguments for tier verify command.")
    60  	}
    61  
    62  	aliasedURL := args.Get(0)
    63  	tierName := args.Get(1)
    64  	if tierName == "" {
    65  		fatalIf(errInvalidArgument(), "Tier name can't be empty")
    66  	}
    67  
    68  	// Create a new MinIO Admin Client
    69  	client, cerr := newAdminClient(aliasedURL)
    70  	fatalIf(cerr, "Unable to initialize admin connection.")
    71  
    72  	e := client.VerifyTier(globalContext, tierName)
    73  	fatalIf(probe.NewError(e).Trace(args...), "Unable to verify remote tier target")
    74  
    75  	printMsg(&tierMessage{
    76  		op:       ctx.Command.Name,
    77  		Status:   "success",
    78  		TierName: tierName,
    79  	})
    80  	return nil
    81  }