Merge pull request #54 from harshavardhana/pr_out_move_hostname_to_endpoint_remove_md5sum_calculation_for_now

This commit is contained in:
Harshavardhana
2015-02-24 14:04:04 -08:00
7 changed files with 37 additions and 55 deletions
+1 -1
View File
@@ -59,7 +59,7 @@ func getAWSEnvironment() (auth *s3.Auth, err error) {
auth = &s3.Auth{
AccessKey: accessKey,
SecretAccessKey: secretKey,
Hostname: "s3.amazonaws.com",
Endpoint: "s3.amazonaws.com",
}
} else {
var n int
+11 -7
View File
@@ -10,28 +10,32 @@ import (
"github.com/minio-io/mc/pkg/s3"
)
func parseConfigureInput(c *cli.Context) (accessKey, secretKey string, err error) {
func parseConfigureInput(c *cli.Context) (accessKey, secretKey, endpoint string, err error) {
accessKey = c.String("accesskey")
secretKey = c.String("secretkey")
endpoint = c.String("endpoint")
if accessKey == "" {
return "", "", configAccessErr
return "", "", "", configAccessErr
}
if secretKey == "" {
return "", "", configSecretErr
return "", "", "", configSecretErr
}
return accessKey, secretKey, nil
if endpoint == "" {
return "", "", "", configEndpointErr
}
return accessKey, secretKey, endpoint, nil
}
func doConfigure(c *cli.Context) {
var err error
var jAuth []byte
var accessKey, secretKey string
accessKey, secretKey, err = parseConfigureInput(c)
var accessKey, secretKey, endpoint string
accessKey, secretKey, endpoint, err = parseConfigureInput(c)
if err != nil {
log.Fatal(err)
}
auth := s3.NewAuth(accessKey, secretKey, "s3.amazonaws.com")
auth := s3.NewAuth(accessKey, secretKey, endpoint)
jAuth, err = json.Marshal(auth)
if err != nil {
log.Fatal(err)
+7 -7
View File
@@ -41,7 +41,7 @@ type Auth struct {
SecretAccessKey string
// If empty, the standard US region of "s3.amazonaws.com" is used.
Hostname string
Endpoint string
// Used for SSL transport layer
CertPEM string
@@ -57,11 +57,11 @@ const standardUSRegionAWS = "s3.amazonaws.com"
func (a *Auth) hostname() string {
// Prefix with https for Amazon hostnames
if a.Hostname != "" {
if strings.HasSuffix(a.Hostname, "amazonaws.com") {
return "https://" + a.Hostname
if a.Endpoint != "" {
if strings.HasSuffix(a.Endpoint, "amazonaws.com") {
return "https://" + a.Endpoint
} else {
return "http://" + a.Hostname
return "http://" + a.Endpoint
}
}
return "https://" + standardUSRegionAWS
@@ -219,7 +219,7 @@ var subResList = []string{"acl", "lifecycle", "location", "logging", "notificati
// <HTTP-Request-URI, from the protocol name up to the query string> +
// [ sub-resource, if present. For example "?acl", "?location", "?logging", or "?torrent"];
func (a *Auth) writeCanonicalizedResource(buf *bytes.Buffer, req *http.Request) {
bucket := a.bucketFromHostname(req)
bucket := a.bucketFromEndpoint(req)
if bucket != "" {
buf.WriteByte('/')
buf.WriteString(bucket)
@@ -251,7 +251,7 @@ func hasDotSuffix(s string, suffix string) bool {
return len(s) >= len(suffix)+1 && strings.HasSuffix(s, suffix) && s[len(s)-len(suffix)-1] == '.'
}
func (a *Auth) bucketFromHostname(req *http.Request) string {
func (a *Auth) bucketFromEndpoint(req *http.Request) string {
host := req.Host
if host == "" {
host = req.URL.Host
+2 -1
View File
@@ -377,7 +377,8 @@ func NewAuth(accessKey, secretKey, hostname string) (auth *Auth) {
auth = &Auth{
AccessKey: accessKey,
SecretAccessKey: secretKey,
Hostname: hostname}
Endpoint: hostname,
}
return
}
+1
View File
@@ -31,6 +31,7 @@ var fsKeyErr = errors.New("Key is needed to get the file")
// configure
var configAccessErr = errors.New("accesskey is mandatory")
var configSecretErr = errors.New("secretkey is mandatory")
var configEndpointErr = errors.New("endpoint is missing")
// common
var missingAccessSecretErr = errors.New("You can configure your credentials by running `mc configure`")
+9 -38
View File
@@ -17,9 +17,6 @@
package main
import (
"bytes"
"crypto/md5"
"hash"
"io"
"log"
"os"
@@ -35,32 +32,6 @@ import (
// - <S3Path> <S3Bucket>
// - <LocalDir> <S3Bucket>
func getPutMetadata(reader io.Reader) (md5hash hash.Hash, bodyBuf io.Reader, size int64, err error) {
md5hash = md5.New()
var length int
var bodyBuffer bytes.Buffer
for err == nil {
byteBuffer := make([]byte, 1024*1024)
length, err = reader.Read(byteBuffer)
// While hash.Write() wouldn't mind a Nil byteBuffer
// It is necessary for us to verify this and break
if length == 0 {
break
}
byteBuffer = byteBuffer[0:length]
_, err = bodyBuffer.Write(byteBuffer)
if err != nil {
break
}
md5hash.Write(byteBuffer)
}
if err != io.EOF {
return nil, nil, 0, err
}
return md5hash, &bodyBuffer, int64(bodyBuffer.Len()), nil
}
func parseCpOptions(c *cli.Context) (fsoptions fsOptions, err error) {
switch len(c.Args()) {
case 1:
@@ -121,21 +92,21 @@ func doFsCopy(c *cli.Context) {
}
if fsoptions.isput {
stat, err := os.Stat(fsoptions.body)
if os.IsNotExist(err) {
log.Fatal(err)
}
if stat.IsDir() {
log.Fatal("Is a directory")
}
size := stat.Size()
bodyFile, err = os.Open(fsoptions.body)
defer bodyFile.Close()
if err != nil {
log.Fatal(err)
}
var bodyBuffer io.Reader
var size int64
var md5hash hash.Hash
md5hash, bodyBuffer, size, err = getPutMetadata(bodyFile)
if err != nil {
log.Fatal(err)
}
err = s3c.Put(fsoptions.bucket, fsoptions.key, md5hash, size, bodyBuffer)
err = s3c.Put(fsoptions.bucket, fsoptions.key, nil, size, bodyFile)
if err != nil {
log.Fatal(err)
}
+6 -1
View File
@@ -52,7 +52,7 @@ var Configure = cli.Command{
Name: "configure",
Usage: "",
Description: `Configure minio client configuration data. If your config
file does not exist (the default location is ~/.s3auth), it will be
file does not exist (the default location is ~/.auth), it will be
automatically created for you. Note that the configure command only writes
values to the config file. It does not use any configuration values from
the environment variables.`,
@@ -68,6 +68,11 @@ var Configure = cli.Command{
Value: "",
Usage: "AWS secret key id",
},
cli.StringFlag{
Name: "endpoint",
Value: "s3.amazonaws.com",
Usage: "S3 Endpoint URL default is 's3.amazonaws.com'",
},
},
}