Add more fixes and helpful messaging
- check for config file for each command, prior to error out properly - hostconfig doesn't do any key verification, let client s3 verify it as needed - mc update change URL pointed to dl.minio.io minio server, still not functional yet
This commit is contained in:
+3
-1
@@ -31,7 +31,9 @@ func runAccessCmd(ctx *cli.Context) {
|
||||
if !ctx.Args().Present() || ctx.Args().First() == "help" {
|
||||
cli.ShowCommandHelpAndExit(ctx, "access", 1) // last argument is exit code
|
||||
}
|
||||
|
||||
if !isMcConfigExist() {
|
||||
console.Fatalln("\"mc\" is not configured. Please run \"mc config generate\".")
|
||||
}
|
||||
config, err := getMcConfig()
|
||||
if err != nil {
|
||||
log.Debug.Println(iodine.New(err, nil))
|
||||
|
||||
@@ -34,6 +34,9 @@ func runCatCmd(ctx *cli.Context) {
|
||||
if !ctx.Args().Present() || ctx.Args().First() == "help" {
|
||||
cli.ShowCommandHelpAndExit(ctx, "cat", 1) // last argument is exit code
|
||||
}
|
||||
if !isMcConfigExist() {
|
||||
console.Fatalln("\"mc\" is not configured. Please run \"mc config generate\".")
|
||||
}
|
||||
config, err := getMcConfig()
|
||||
if err != nil {
|
||||
log.Debug.Println(iodine.New(err, nil))
|
||||
|
||||
@@ -29,7 +29,9 @@ func runCopyCmd(ctx *cli.Context) {
|
||||
if len(ctx.Args()) < 2 || ctx.Args().First() == "help" {
|
||||
cli.ShowCommandHelpAndExit(ctx, "cp", 1) // last argument is exit code
|
||||
}
|
||||
|
||||
if !isMcConfigExist() {
|
||||
console.Fatalln("\"mc\" is not configured. Please run \"mc config generate\".")
|
||||
}
|
||||
config, err := getMcConfig()
|
||||
if err != nil {
|
||||
log.Debug.Println(iodine.New(err, nil))
|
||||
|
||||
@@ -32,6 +32,9 @@ func runListCmd(ctx *cli.Context) {
|
||||
if !ctx.Args().Present() || ctx.Args().First() == "help" {
|
||||
cli.ShowCommandHelpAndExit(ctx, "ls", 1) // last argument is exit code
|
||||
}
|
||||
if !isMcConfigExist() {
|
||||
console.Fatalln("\"mc\" is not configured. Please run \"mc config generate\".")
|
||||
}
|
||||
config, err := getMcConfig()
|
||||
if err != nil {
|
||||
log.Debug.Println(iodine.New(err, nil))
|
||||
|
||||
@@ -32,6 +32,9 @@ func runMakeBucketCmd(ctx *cli.Context) {
|
||||
if !ctx.Args().Present() || ctx.Args().First() == "help" {
|
||||
cli.ShowCommandHelpAndExit(ctx, "mb", 1) // last argument is exit code
|
||||
}
|
||||
if !isMcConfigExist() {
|
||||
console.Fatalln("\"mc\" is not configured. Please run \"mc config generate\".")
|
||||
}
|
||||
config, err := getMcConfig()
|
||||
if err != nil {
|
||||
log.Debug.Println(iodine.New(err, nil))
|
||||
|
||||
+2
-2
@@ -265,14 +265,14 @@ EXAMPLES:
|
||||
|
||||
USAGE:
|
||||
mc {{.Name}}{{if .Flags}} [ARGS...]{{end}} check
|
||||
mc {{.Name}}{{if .Flags}} [ARGS...]{{end}} yes
|
||||
mc {{.Name}}{{if .Flags}} [ARGS...]{{end}} install
|
||||
|
||||
EXAMPLES:
|
||||
1. Check for new updates
|
||||
$ mc update check
|
||||
|
||||
2. Download new minio client locally and update
|
||||
$ mc update yes
|
||||
$ mc update install
|
||||
|
||||
`,
|
||||
}
|
||||
|
||||
@@ -29,6 +29,9 @@ func runSyncCmd(ctx *cli.Context) {
|
||||
if len(ctx.Args()) < 2 || ctx.Args().First() == "help" {
|
||||
cli.ShowCommandHelpAndExit(ctx, "sync", 1) // last argument is exit code
|
||||
}
|
||||
if !isMcConfigExist() {
|
||||
console.Fatalln("\"mc\" is not configured. Please run \"mc config generate\".")
|
||||
}
|
||||
config, err := getMcConfig()
|
||||
if err != nil {
|
||||
log.Debug.Println(iodine.New(err, nil))
|
||||
|
||||
+10
-5
@@ -19,6 +19,7 @@ package main
|
||||
import (
|
||||
"errors"
|
||||
"fmt"
|
||||
"runtime"
|
||||
"time"
|
||||
|
||||
"encoding/json"
|
||||
@@ -31,7 +32,7 @@ import (
|
||||
)
|
||||
|
||||
const (
|
||||
mcUpdateURL = "http://dl.minio.io/updates/mc.json"
|
||||
mcUpdateURL = "http://dl.minio.io:9000/binaries/"
|
||||
)
|
||||
|
||||
type updateResults struct {
|
||||
@@ -56,17 +57,21 @@ func runUpdateCmd(ctx *cli.Context) {
|
||||
if !ctx.Args().Present() || ctx.Args().First() == "help" {
|
||||
cli.ShowCommandHelpAndExit(ctx, "update", 1) // last argument is exit code
|
||||
}
|
||||
if !isMcConfigExist() {
|
||||
console.Fatalln("\"mc\" is not configured. Please run \"mc config generate\".")
|
||||
}
|
||||
mcUpdateBinaryURL := mcUpdateURL + runtime.GOOS + "/mc"
|
||||
switch ctx.Args().First() {
|
||||
case "check":
|
||||
req, err := getRequest(mcUpdateURL)
|
||||
req, err := getRequest(mcUpdateBinaryURL)
|
||||
if err != nil {
|
||||
log.Debug.Println(iodine.New(err, nil))
|
||||
console.Fatalln("Unable to update:", mcUpdateURL)
|
||||
console.Fatalln("Unable to update:", mcUpdateBinaryURL)
|
||||
}
|
||||
res, err := http.DefaultTransport.RoundTrip(req)
|
||||
if err != nil {
|
||||
log.Debug.Println(iodine.New(err, nil))
|
||||
console.Fatalln("Unable to retrieve:", mcUpdateURL)
|
||||
console.Fatalln("Unable to retrieve:", mcUpdateBinaryURL)
|
||||
}
|
||||
if res.StatusCode != http.StatusOK {
|
||||
msg := fmt.Sprint("Received invalid HTTP status: ", res.StatusCode)
|
||||
@@ -91,7 +96,7 @@ func runUpdateCmd(ctx *cli.Context) {
|
||||
if latest.After(current) {
|
||||
printUpdateNotify("new", "old")
|
||||
}
|
||||
case "yes":
|
||||
case "install":
|
||||
console.Fatalln("Functionality not implemented yet")
|
||||
}
|
||||
}
|
||||
|
||||
@@ -138,8 +138,8 @@ func newConfigV1() *configV1 {
|
||||
func newConfig() (config quick.Config) {
|
||||
conf := newConfigV1()
|
||||
s3HostConf := new(hostConfig)
|
||||
s3HostConf.AccessKeyID = globalAccessKeyID
|
||||
s3HostConf.SecretAccessKey = globalSecretAccessKey
|
||||
s3HostConf.AccessKeyID = ""
|
||||
s3HostConf.SecretAccessKey = ""
|
||||
|
||||
playHostConfig := new(hostConfig)
|
||||
playHostConfig.AccessKeyID = ""
|
||||
|
||||
@@ -82,12 +82,6 @@ func getHostConfig(requestURL string) (*hostConfig, error) {
|
||||
if hostCfg == nil {
|
||||
return nil, iodine.New(errInvalidAuth{}, nil)
|
||||
}
|
||||
// verify Auth key validity for all hosts
|
||||
if hostCfg.AccessKeyID != globalAccessKeyID && hostCfg.SecretAccessKey != globalSecretAccessKey {
|
||||
if !client.IsValidAccessKey(hostCfg.AccessKeyID) || !client.IsValidSecretKey(hostCfg.SecretAccessKey) {
|
||||
return nil, iodine.New(errInvalidAuthKeys{}, nil)
|
||||
}
|
||||
}
|
||||
return hostCfg, nil
|
||||
}
|
||||
}
|
||||
|
||||
@@ -58,9 +58,16 @@ func (c *s3Client) listBucketsInternal() ([]*client.Item, error) {
|
||||
if err != nil {
|
||||
return nil, iodine.New(err, nil)
|
||||
}
|
||||
if c.AccessKeyID != "" && c.SecretAccessKey != "" {
|
||||
c.signRequest(req, c.Host)
|
||||
|
||||
// do not ignore signatures for 'listBuckets()'
|
||||
// it is never a public request,
|
||||
//
|
||||
// so lets aggressively verify
|
||||
if c.AccessKeyID == "" || c.SecretAccessKey == "" {
|
||||
msg := "Authorization key cannot be empty for listing buckets, please choose a valid bucketname if its a public request"
|
||||
return nil, iodine.New(errors.New(msg), nil)
|
||||
}
|
||||
c.signRequest(req, c.Host)
|
||||
|
||||
res, err = c.Transport.RoundTrip(req)
|
||||
if err != nil {
|
||||
|
||||
@@ -25,6 +25,7 @@ import (
|
||||
"net/http"
|
||||
"net/url"
|
||||
"os"
|
||||
"strings"
|
||||
"time"
|
||||
|
||||
"github.com/minio-io/mc/pkg/client"
|
||||
@@ -142,8 +143,22 @@ func (c *s3Client) listRecursive(itemCh chan client.ItemOnChannel) {
|
||||
}
|
||||
}
|
||||
|
||||
func (c *s3Client) isValidQueryURL(queryURL string) bool {
|
||||
u, err := url.Parse(queryURL)
|
||||
if err != nil {
|
||||
return false
|
||||
}
|
||||
if !strings.Contains(u.Scheme, "http") {
|
||||
return false
|
||||
}
|
||||
return true
|
||||
}
|
||||
|
||||
// populate s3 response and decode results into listBucketResults{}
|
||||
func (c *s3Client) decodeBucketResults(queryURL string) (*listBucketResults, error) {
|
||||
if !c.isValidQueryURL(queryURL) {
|
||||
return nil, iodine.New(InvalidQueryURL{URL: queryURL}, nil)
|
||||
}
|
||||
bres := &listBucketResults{}
|
||||
req, err := c.newRequest("GET", queryURL, nil)
|
||||
if err != nil {
|
||||
|
||||
@@ -111,8 +111,15 @@ func (c *s3Client) url2BucketAndObject() (bucketName, objectName string) {
|
||||
// storage implementation.
|
||||
func (c *s3Client) bucketURL(bucket string) string {
|
||||
var url string
|
||||
// TODO: Bucket names can contain ".". This second check should be removed.
|
||||
// when minio server supports buckets with "."
|
||||
// Avoid bucket names with "." in them
|
||||
// Citing - http://docs.aws.amazon.com/AmazonS3/latest/dev/VirtualHosting.html
|
||||
//
|
||||
// =====================
|
||||
// When using virtual hosted–style buckets with SSL, the SSL wild card certificate
|
||||
// only matches buckets that do not contain periods. To work around this, use HTTP
|
||||
// or write your own certificate verification logic.
|
||||
// =====================
|
||||
//
|
||||
if client.IsValidBucketName(bucket) && !strings.Contains(bucket, ".") {
|
||||
// if localhost use PathStyle
|
||||
if strings.Contains(c.Host, "localhost") || strings.Contains(c.Host, "127.0.0.1") {
|
||||
|
||||
@@ -103,11 +103,13 @@ func (e InvalidAuthorizationKey) Error() string {
|
||||
return e.Err.Error()
|
||||
}
|
||||
|
||||
// AuthorizationKeyEmpty - empty auth key provided
|
||||
type AuthorizationKeyEmpty GenericError
|
||||
// InvalidQueryURL - generic error
|
||||
type InvalidQueryURL struct {
|
||||
URL string
|
||||
}
|
||||
|
||||
func (e AuthorizationKeyEmpty) Error() string {
|
||||
return e.Err.Error()
|
||||
func (e InvalidQueryURL) Error() string {
|
||||
return "Invalid query URL: " + e.URL
|
||||
}
|
||||
|
||||
/* **** SAMPLE ERROR RESPONSE ****
|
||||
|
||||
Reference in New Issue
Block a user