github.com/minio/mc@v0.0.0-20240503112107-b471de8d1882/cmd/share-main.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  	"os"
    22  	"path/filepath"
    23  
    24  	"github.com/minio/cli"
    25  	"github.com/minio/mc/pkg/probe"
    26  	"github.com/minio/pkg/v2/console"
    27  )
    28  
    29  var shareFlags = []cli.Flag{}
    30  
    31  var shareSubcommands = []cli.Command{
    32  	shareDownload,
    33  	shareUpload,
    34  	shareList,
    35  }
    36  
    37  // Share documents via URL.
    38  var shareCmd = cli.Command{
    39  	Name:            "share",
    40  	Usage:           "generate URL for temporary access to an object",
    41  	Action:          mainShare,
    42  	Before:          setGlobalsFromContext,
    43  	Flags:           append(shareFlags, globalFlags...),
    44  	HideHelpCommand: true,
    45  	Subcommands:     shareSubcommands,
    46  }
    47  
    48  // migrateShare migrate to newest version sequentially.
    49  func migrateShare() {
    50  	if !isShareDirExists() {
    51  		return
    52  	}
    53  
    54  	// Shared URLs are now managed by sub-commands. So delete any old URLs file if found.
    55  	oldShareFile := filepath.Join(mustGetShareDir(), "urls.json")
    56  	if _, e := os.Stat(oldShareFile); e == nil {
    57  		// Old file exits.
    58  		e := os.Remove(oldShareFile)
    59  		fatalIf(probe.NewError(e), "Unable to delete old `"+oldShareFile+"`.")
    60  		console.Infof("Removed older version of share `%s` file.\n", oldShareFile)
    61  	}
    62  }
    63  
    64  // mainShare - main handler for mc share command.
    65  func mainShare(ctx *cli.Context) error {
    66  	commandNotFound(ctx, shareSubcommands)
    67  	return nil
    68  	// Sub-commands like "upload" and "download" have their own main.
    69  }