config: Add host for all matching entries.

This commit is contained in:
Harshavardhana
2015-11-14 12:56:21 -08:00
parent 6731541217
commit 17526e5cb6
2 changed files with 41 additions and 21 deletions
+11 -6
View File
@@ -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 <your_s3_endpoint> <your_access_key> <your_secret_key> S3v4
$ mc config host add <YOUR-S3-ENDPOINT> <YOUR-ACCESS-KEY> <YOUR-SECRET-KEY> 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 <your_access_key> <your_secret_key> S3v2
$ mc config host add storage.googleapis.com <YOUR-ACCESS-KEY> <YOUR-SECRET-KEY> S3v2
```
NOTE: Google Cloud Storage only supports Legacy Signature Version ``2``, so you have to pick - ``S3v2``
+30 -15
View File
@@ -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.")