1
0
mirror of https://github.com/minio/mc.git synced 2025-11-10 13:42:32 +03:00

admin: fatal message for unknown aliases (#1953)

This change issues a fatal message when the provided alias in cli is not known
This commit is contained in:
Anis Elleuch
2017-01-09 17:47:43 +01:00
committed by Harshavardhana
parent c6cb6595be
commit 94bd9564d0
8 changed files with 23 additions and 26 deletions

View File

@@ -117,9 +117,7 @@ func mainAdminLockClear(ctx *cli.Context) error {
// Create a new Minio Admin Client // Create a new Minio Admin Client
client, err := newAdminClient(aliasedURL) client, err := newAdminClient(aliasedURL)
if err != nil { fatalIf(err, "Cannot get a configured admin connection.")
return err.ToGoError()
}
aliasedURL = filepath.ToSlash(aliasedURL) aliasedURL = filepath.ToSlash(aliasedURL)

View File

@@ -117,9 +117,7 @@ func mainAdminLockList(ctx *cli.Context) error {
// Create a new Minio Admin Client // Create a new Minio Admin Client
client, err := newAdminClient(aliasedURL) client, err := newAdminClient(aliasedURL)
if err != nil { fatalIf(err, "Cannot get a configured admin connection.")
return err.ToGoError()
}
aliasedURL = filepath.ToSlash(aliasedURL) aliasedURL = filepath.ToSlash(aliasedURL)

View File

@@ -67,9 +67,7 @@ func mainAdminServiceRestart(ctx *cli.Context) error {
aliasedURL := args.Get(0) aliasedURL := args.Get(0)
client, err := newAdminClient(aliasedURL) client, err := newAdminClient(aliasedURL)
if err != nil { fatalIf(err, "Cannot get a configured admin connection.")
return err.ToGoError()
}
// Restart the specified Minio server // Restart the specified Minio server
e := client.ServiceRestart() e := client.ServiceRestart()

View File

@@ -97,9 +97,7 @@ func mainAdminServiceStatus(ctx *cli.Context) error {
// Create a new Minio Admin Client // Create a new Minio Admin Client
client, err := newAdminClient(aliasedURL) client, err := newAdminClient(aliasedURL)
if err != nil { fatalIf(err, "Cannot get a configured admin connection.")
return err.ToGoError()
}
// Fetch the storage info of the specified Minio server // Fetch the storage info of the specified Minio server
status, e := client.ServiceStatus() status, e := client.ServiceStatus()

View File

@@ -68,9 +68,7 @@ func mainAdminServiceStop(ctx *cli.Context) error {
// Create a new Minio Admin Client // Create a new Minio Admin Client
client, err := newAdminClient(aliasedURL) client, err := newAdminClient(aliasedURL)
if err != nil { fatalIf(err, "Cannot get a configured admin connection.")
return err.ToGoError()
}
// Stop the specified Minio server // Stop the specified Minio server
e := client.ServiceStop() e := client.ServiceStop()

View File

@@ -36,7 +36,10 @@ func newAdminFactory() func(config *Config) (*madmin.AdminClient, *probe.Error)
// Return New function. // Return New function.
return func(config *Config) (*madmin.AdminClient, *probe.Error) { return func(config *Config) (*madmin.AdminClient, *probe.Error) {
// Creates a parsed URL. // Creates a parsed URL.
targetURL, _ := url.Parse(config.HostURL) targetURL, e := url.Parse(config.HostURL)
if e != nil {
return nil, probe.NewError(e)
}
// By default enable HTTPs. // By default enable HTTPs.
useTLS := true useTLS := true
if targetURL.Scheme == "http" { if targetURL.Scheme == "http" {
@@ -99,7 +102,10 @@ func newAdminFactory() func(config *Config) (*madmin.AdminClient, *probe.Error)
// alias entry in the mc config file. If no matching host config entry // alias entry in the mc config file. If no matching host config entry
// is found, fs client is returned. // is found, fs client is returned.
func newAdminClientFromAlias(alias string, urlStr string) (*madmin.AdminClient, *probe.Error) { func newAdminClientFromAlias(alias string, urlStr string) (*madmin.AdminClient, *probe.Error) {
s3Config := buildConfig(alias, urlStr) s3Config, err := buildS3Config(alias, urlStr)
if err != nil {
return nil, err
}
s3Client, err := s3AdminNew(s3Config) s3Client, err := s3AdminNew(s3Config)
if err != nil { if err != nil {
return nil, err.Trace(alias, urlStr) return nil, err.Trace(alias, urlStr)

View File

@@ -146,13 +146,13 @@ func uploadSourceToTargetURL(urls URLs, progress io.Reader) URLs {
// alias entry in the mc config file. If no matching host config entry // alias entry in the mc config file. If no matching host config entry
// is found, fs client is returned. // is found, fs client is returned.
func newClientFromAlias(alias string, urlStr string) (Client, *probe.Error) { func newClientFromAlias(alias string, urlStr string) (Client, *probe.Error) {
s3Config := buildConfig(alias, urlStr) s3Config, err := buildS3Config(alias, urlStr)
if s3Config == nil { if err != nil {
// No matching host config. So we treat it like a // No matching host config. So we treat it like a
// filesystem. // filesystem.
fsClient, err := fsNew(urlStr) fsClient, fsErr := fsNew(urlStr)
if err != nil { if fsErr != nil {
return nil, err.Trace(alias, urlStr) return nil, fsErr.Trace(alias, urlStr)
} }
return fsClient, nil return fsClient, nil
} }

View File

@@ -18,6 +18,7 @@ package cmd
import ( import (
"crypto/tls" "crypto/tls"
"errors"
"io" "io"
"math/rand" "math/rand"
"os" "os"
@@ -89,12 +90,12 @@ func splitStr(path, sep string, n int) []string {
return splits return splits
} }
// buildConfig fetches config related to the specified alias // buildS3Config fetches config related to the specified alias
// to create a new config structure // to create a new config structure
func buildConfig(alias, urlStr string) *Config { func buildS3Config(alias, urlStr string) (*Config, *probe.Error) {
hostCfg := mustGetHostConfig(alias) hostCfg := mustGetHostConfig(alias)
if hostCfg == nil { if hostCfg == nil {
return nil return nil, probe.NewError(errors.New("The specified alias cannot be found"))
} }
// We have a valid alias and hostConfig. We populate the // We have a valid alias and hostConfig. We populate the
@@ -127,5 +128,5 @@ func buildConfig(alias, urlStr string) *Config {
s3Config.Debug = globalDebug s3Config.Debug = globalDebug
s3Config.Insecure = globalInsecure s3Config.Insecure = globalInsecure
return s3Config return s3Config, nil
} }