From 17526e5cb602edeea510be368eb40fbb934ec364 Mon Sep 17 00:00:00 2001 From: Harshavardhana Date: Sat, 14 Nov 2015 12:41:58 -0800 Subject: [PATCH] config: Add host for all matching entries. --- README.md | 17 +++++++++++------ config-host-main.go | 45 ++++++++++++++++++++++++++++++--------------- 2 files changed, 41 insertions(+), 21 deletions(-) diff --git a/README.md b/README.md index 62bca4ca..9fd80d9d 100644 --- a/README.md +++ b/README.md @@ -1,6 +1,6 @@ # Minio Client (mc) [![Gitter](https://badges.gitter.im/Join%20Chat.svg)](https://gitter.im/minio/minio?utm_source=badge&utm_medium=badge&utm_campaign=pr-badge&utm_content=badge) -``mc`` provides minimal tools to work with Amazon S3 compatible cloud storage and filesystems. It has features like resumable partial uploads, progress bar, parallel copy. ``mc`` is written in golang and released under [Apache license v2](./LICENSE). +``mc`` provides minimal tools to work with Amazon S3 compatible cloud storage and filesystems. It has features like resumable uploads, progress bar, parallel copy. ``mc`` is written in golang and released under [Apache license v2](./LICENSE). ## Commands @@ -78,22 +78,27 @@ Minio cloud storage server is hosted at ``https://play.minio.io:9000`` for publi ## Configuring mc for Amazon S3 -Get your AccessKeyID and SecretAccessKey by following [AWS Credentials Guide](http://docs.aws.amazon.com/AWSSimpleQueueService/latest/SQSGettingStartedGuide/AWSCredentials.html). +Get your AccessKeyID and SecretAccessKey by following [AWS Credentials Guide](http://docs.aws.amazon.com/AWSSimpleQueueService/latest/SQSGettingStartedGuide/AWSCredentials.html). Once you have them update your ``~/.mc/config.json`` configuration file. ``` -$ mc config host add S3v4 +$ mc config host add S3v4 ``` -NOTE: ``S3v4`` is default unless specified. +Example +``` +$ mc config host add s3.amazonaws.com BKIKJAA5BMMU2RHO6IBB V7f1CwQqAcwo80UEIJEjc5gVQUSSx5ohQ9GSrr12 +``` + +NOTE: ``S3v4`` is default if not specified. ## Configure mc for Google Cloud Storage -Get your AccessKeyID and SecretAccessKey by following [Google Credentials Guide](https://cloud.google.com/storage/docs/migrating?hl=en#keys). +Get your AccessKeyID and SecretAccessKey by following [Google Credentials Guide](https://cloud.google.com/storage/docs/migrating?hl=en#keys). Once you have them update your ``~/./mc/config.json`` configuration file. ``` -$ mc config host add storage.googleapis.com S3v2 +$ mc config host add storage.googleapis.com S3v2 ``` NOTE: Google Cloud Storage only supports Legacy Signature Version ``2``, so you have to pick - ``S3v2`` diff --git a/config-host-main.go b/config-host-main.go index ef566055..06cc4e03 100644 --- a/config-host-main.go +++ b/config-host-main.go @@ -3,6 +3,7 @@ package main import ( "encoding/json" "fmt" + "path/filepath" "regexp" "strings" @@ -205,6 +206,16 @@ func addHost(hostGlob, accessKeyID, secretAccessKey, api string) { if strings.TrimSpace(hostGlob) == "" { fatalIf(errDummy().Trace(), "Unable to proceed, empty arguments provided.") } + if len(accessKeyID) != 0 { + if !isValidAccessKey(accessKeyID) { + fatalIf(errInvalidArgument().Trace(), "Invalid access key id provided.") + } + } + if len(secretAccessKey) != 0 { + if !isValidSecretKey(secretAccessKey) { + fatalIf(errInvalidArgument().Trace(), "Invalid secret access key provided.") + } + } if strings.TrimSpace(api) == "" { api = "S3v4" } @@ -218,23 +229,27 @@ func addHost(hostGlob, accessKeyID, secretAccessKey, api string) { err = config.Load(configPath) fatalIf(err.Trace(configPath), "Unable to load config path") - if len(accessKeyID) != 0 { - if !isValidAccessKey(accessKeyID) { - fatalIf(errInvalidArgument().Trace(), "Invalid access key id provided.") - } - } - if len(secretAccessKey) != 0 { - if !isValidSecretKey(secretAccessKey) { - fatalIf(errInvalidArgument().Trace(), "Invalid secret access key provided.") - } - } - // convert interface{} back to its original struct newConf := config.Data().(*configV6) - newConf.Hosts[hostGlob] = hostConfig{ - AccessKeyID: accessKeyID, - SecretAccessKey: secretAccessKey, - API: api, + for globURL := range newConf.Hosts { + match, err := filepath.Match(globURL, hostGlob) + if err != nil { + fatalIf(errInvalidGlobURL(globURL, hostGlob).Trace(), "Unable to match.") + } + if match { + newConf.Hosts[globURL] = hostConfig{ + AccessKeyID: accessKeyID, + SecretAccessKey: secretAccessKey, + API: api, + } + } else { + newConf.Hosts[hostGlob] = hostConfig{ + AccessKeyID: accessKeyID, + SecretAccessKey: secretAccessKey, + API: api, + } + } } + newConfig, err := quick.New(newConf) fatalIf(err.Trace(globalMCConfigVersion), "Failed to initialize ‘quick’ configuration data structure.")