Beispiel #1
0
// Validate command line arguments.
func checkRmSyntax(ctx *cli.Context) {
	args := ctx.Args()

	ishelp := ctx.GlobalBool("help")
	isForce := ctx.Bool("force")

	if !args.Present() || ishelp {
		exitCode := 1
		cli.ShowCommandHelpAndExit(ctx, "rm", exitCode)
	}

	URLs, err := args2URLs(args)
	fatalIf(err.Trace(ctx.Args()...), "Unable to parse arguments.")

	// If input validation fails then provide context sensitive help without displaying generic help message.
	// The context sensitive help is shown per argument instead of all arguments to keep the help display
	// as well as the code simple. Also most of the times there will be just one arg
	for _, url := range URLs {
		u := client.NewURL(url)
		if strings.HasSuffix(url, string(u.Separator)) {
			fatalIf(errDummy().Trace(),
				"‘"+url+"’ is a folder. To remove this folder recursively, please try ‘"+url+"...’ as argument.")
		}
		if isURLRecursive(url) && !isForce {
			fatalIf(errDummy().Trace(),
				"Recursive removal requires --force option. Please review carefully before performing this operation.")
		}
	}
}
Beispiel #2
0
func registerBefore(ctx *cli.Context) error {
	setMcConfigDir(ctx.GlobalString("config-folder"))
	globalQuietFlag = ctx.GlobalBool("quiet")
	globalMimicFlag = ctx.GlobalBool("mimic")
	globalDebugFlag = ctx.GlobalBool("debug")
	globalJSONFlag = ctx.GlobalBool("json")

	if globalDebugFlag {
		console.NoDebugPrint = false
	}

	// Disable color themes.
	if ctx.GlobalBool("no-color") == true {
		console.SetColorOff()
	}

	// Verify golang runtime
	verifyMCRuntime()

	// Migrate any old version of config / state files to newer format.
	migrate()

	// Checkconfig if it can be read
	checkConfig()
	return nil
}
Beispiel #3
0
// Parse command arguments and set global variables accordingly
func setGlobalsFromContext(c *cli.Context) {
	// Set config dir
	switch {
	case c.IsSet("config-dir"):
		globalConfigDir = c.String("config-dir")
	case c.GlobalIsSet("config-dir"):
		globalConfigDir = c.GlobalString("config-dir")
	}
	if globalConfigDir == "" {
		console.Fatalf("Unable to get config file. Config directory is empty.")
	}
	// Set global quiet flag.
	globalQuiet = c.Bool("quiet") || c.GlobalBool("quiet")
}
Beispiel #4
0
// Set global states. NOTE: It is deliberately kept monolithic to ensure we dont miss out any flags.
func setGlobalsFromContext(ctx *cli.Context) {
	quiet := ctx.Bool("quiet") || ctx.GlobalBool("quiet")
	debug := ctx.Bool("debug") || ctx.GlobalBool("debug")
	json := ctx.Bool("json") || ctx.GlobalBool("json")
	noColor := ctx.Bool("no-color") || ctx.GlobalBool("no-color")
	insecure := ctx.Bool("insecure") || ctx.GlobalBool("insecure")
	setGlobals(quiet, debug, json, noColor, insecure)
}
Beispiel #5
0
func getControllerConfig(c *cli.Context) minioConfig {
	certFile := c.GlobalString("cert")
	keyFile := c.GlobalString("key")
	if (certFile != "" && keyFile == "") || (certFile == "" && keyFile != "") {
		Fatalln("Both certificate and key are required to enable https.")
	}
	tls := (certFile != "" && keyFile != "")
	return minioConfig{
		ControllerAddress: c.GlobalString("address-controller"),
		TLS:               tls,
		CertFile:          certFile,
		KeyFile:           keyFile,
		RateLimit:         c.GlobalInt("ratelimit"),
		Anonymous:         c.GlobalBool("anonymous"),
	}
}
func getServerConfig(c *cli.Context) fsConfig {
	certFile := c.GlobalString("cert")
	keyFile := c.GlobalString("key")
	if (certFile != "" && keyFile == "") || (certFile == "" && keyFile != "") {
		Fatalln("Both certificate and key are required to enable https.")
	}
	tls := (certFile != "" && keyFile != "")
	return fsConfig{
		Address:   c.GlobalString("address"),
		Path:      strings.TrimSpace(c.Args().First()),
		Anonymous: c.GlobalBool("anonymous"),
		TLS:       tls,
		CertFile:  certFile,
		KeyFile:   keyFile,
		RateLimit: c.GlobalInt("ratelimit"),
	}
}
Beispiel #7
0
func registerBefore(ctx *cli.Context) error {
	setMcConfigDir(ctx.GlobalString("config"))
	globalQuietFlag = ctx.GlobalBool("quiet")
	globalForceFlag = ctx.GlobalBool("force")
	globalAliasFlag = ctx.GlobalBool("alias")
	globalDebugFlag = ctx.GlobalBool("debug")
	globalJSONFlag = ctx.GlobalBool("json")
	themeName := ctx.GlobalString("theme")
	if globalDebugFlag {
		console.NoDebugPrint = false
	}
	switch {
	case console.IsValidTheme(themeName) != true:
		console.Errorf("Invalid theme, please choose from the following list: %s.\n", console.GetThemeNames())
		return errInvalidTheme{Theme: themeName}
	default:
		err := console.SetTheme(themeName)
		if err != nil {
			console.Errorf("Failed to set theme ‘%s’.", themeName)
			return err
		}
	}

	// Migrate any old version of config / state files to newer format.
	migrate()

	checkConfig()
	return nil
}
Beispiel #8
0
func registerBefore(ctx *cli.Context) error {
	setMcConfigDir(ctx.GlobalString("config-folder"))
	globalQuietFlag = ctx.GlobalBool("quiet")
	globalMimicFlag = ctx.GlobalBool("mimic")
	globalDebugFlag = ctx.GlobalBool("debug")
	globalJSONFlag = ctx.GlobalBool("json")
	if globalDebugFlag {
		console.NoDebugPrint = false
	}
	if ctx.GlobalBool("nocolor") {
		console.SetNoColor()
	}

	verifyMCRuntime()

	// Migrate any old version of config / state files to newer format.
	migrate()

	checkConfig()
	return nil
}
Beispiel #9
0
func registerBefore(ctx *cli.Context) error {
	setMcConfigDir(ctx.GlobalString("config-folder"))
	globalQuietFlag = ctx.GlobalBool("quiet")
	globalMimicFlag = ctx.GlobalBool("mimic")
	globalDebugFlag = ctx.GlobalBool("debug")
	globalJSONFlag = ctx.GlobalBool("json")
	if globalDebugFlag {
		console.NoDebugPrint = false
	}

	setMainPalette(ctx.GlobalString("colors"))

	// check if mc is being run as root
	checkUser()
	// verify golang runtime
	verifyMCRuntime()
	// Migrate any old version of config / state files to newer format.
	migrate()
	// checkConfig if it can be read
	checkConfig()
	return nil
}
Beispiel #10
0
func serverMain(c *cli.Context) {
	checkServerSyntax(c)

	perr := initServer()
	fatalIf(perr.Trace(), "Failed to read config for minio.", nil)

	certFile := c.GlobalString("cert")
	keyFile := c.GlobalString("key")
	if (certFile != "" && keyFile == "") || (certFile == "" && keyFile != "") {
		fatalIf(probe.NewError(errInvalidArgument), "Both certificate and key are required to enable https.", nil)
	}

	var minFreeDisk int64
	minFreeDiskSet := false
	// Default
	minFreeDisk = 10

	var expiration time.Duration
	expirationSet := false

	args := c.Args()
	for len(args) >= 2 {
		switch args.First() {
		case "min-free-disk":
			if minFreeDiskSet {
				fatalIf(probe.NewError(errInvalidArgument), "Minimum free disk should be set only once.", nil)
			}
			args = args.Tail()
			var err *probe.Error
			minFreeDisk, err = parsePercentToInt(args.First(), 64)
			fatalIf(err.Trace(args.First()), "Invalid minium free disk size "+args.First()+" passed.", nil)
			args = args.Tail()
			minFreeDiskSet = true
		case "expiry":
			if expirationSet {
				fatalIf(probe.NewError(errInvalidArgument), "Expiration should be set only once.", nil)
			}
			args = args.Tail()
			var err error
			expiration, err = time.ParseDuration(args.First())
			fatalIf(probe.NewError(err), "Invalid expiration time "+args.First()+" passed.", nil)
			args = args.Tail()
			expirationSet = true
		default:
			cli.ShowCommandHelpAndExit(c, "server", 1) // last argument is exit code
		}
	}

	path := strings.TrimSpace(c.Args().Last())
	// Last argument is always path
	if _, err := os.Stat(path); err != nil {
		fatalIf(probe.NewError(err), "Unable to validate the path", nil)
	}
	tls := (certFile != "" && keyFile != "")
	apiServerConfig := cloudServerConfig{
		Address:     c.GlobalString("address"),
		AccessLog:   c.GlobalBool("enable-accesslog"),
		Anonymous:   c.GlobalBool("anonymous"),
		Path:        path,
		MinFreeDisk: minFreeDisk,
		Expiry:      expiration,
		TLS:         tls,
		CertFile:    certFile,
		KeyFile:     keyFile,
		RateLimit:   c.GlobalInt("ratelimit"),
	}
	perr = startServer(apiServerConfig)
	errorIf(perr.Trace(), "Failed to start the minio server.", nil)
}
Beispiel #11
0
func serverMain(c *cli.Context) {
	checkServerSyntax(c)

	conf, err := initServer()
	fatalIf(err.Trace(), "Failed to read config for minio.", nil)

	certFile := c.GlobalString("cert")
	keyFile := c.GlobalString("key")
	if (certFile != "" && keyFile == "") || (certFile == "" && keyFile != "") {
		fatalIf(probe.NewError(errInvalidArgument), "Both certificate and key are required to enable https.", nil)
	}

	minFreeDisk, err := parsePercentToInt(c.String("min-free-disk"), 64)
	fatalIf(err.Trace(c.String("min-free-disk")), "Invalid minium free disk size "+c.String("min-free-disk")+" passed.", nil)

	path := strings.TrimSpace(c.Args().Last())
	// Last argument is always path
	if _, err := os.Stat(path); err != nil {
		fatalIf(probe.NewError(err), "Unable to validate the path", nil)
	}
	tls := (certFile != "" && keyFile != "")
	serverConfig := cloudServerConfig{
		Address:         c.GlobalString("address"),
		AccessLog:       c.GlobalBool("enable-accesslog"),
		AccessKeyID:     conf.Credentials.AccessKeyID,
		SecretAccessKey: conf.Credentials.SecretAccessKey,
		Path:            path,
		MinFreeDisk:     minFreeDisk,
		TLS:             tls,
		CertFile:        certFile,
		KeyFile:         keyFile,
	}

	// configure API server.
	apiServer, err := configureAPIServer(serverConfig)
	errorIf(err.Trace(), "Failed to configure API server.", nil)

	Println("\nMinio Object Storage:")
	printServerMsg(apiServer)

	// configure Web server.
	webServer, err := configureWebServer(serverConfig)
	errorIf(err.Trace(), "Failed to configure Web server.", nil)

	Println("\nMinio Browser:")
	printServerMsg(webServer)

	Println("\nTo configure Minio Client:")
	if runtime.GOOS == "windows" {
		Println("    Download \"mc\" from https://dl.minio.io/client/mc/release/" + runtime.GOOS + "-" + runtime.GOARCH + "/mc.exe")
		Println("    $ mc.exe config host add myminio http://localhost:9000 " + conf.Credentials.AccessKeyID + " " + conf.Credentials.SecretAccessKey)
	} else {
		Println("    $ wget https://dl.minio.io/client/mc/release/" + runtime.GOOS + "-" + runtime.GOARCH + "/mc")
		Println("    $ chmod 755 mc")
		Println("    $ ./mc config host add myminio http://localhost:9000 " + conf.Credentials.AccessKeyID + " " + conf.Credentials.SecretAccessKey)
	}

	// Start server.
	err = minhttp.ListenAndServe(apiServer, webServer)
	errorIf(err.Trace(), "Failed to start the minio server.", nil)
}