mirror of
https://github.com/minio/mc.git
synced 2025-11-13 12:22:45 +03:00
Squash minio package into s3 package
This commit is contained in:
@@ -20,9 +20,12 @@ import (
|
||||
"bytes"
|
||||
"crypto/hmac"
|
||||
"crypto/sha1"
|
||||
"crypto/tls"
|
||||
"encoding/base64"
|
||||
"fmt"
|
||||
"io"
|
||||
"io/ioutil"
|
||||
"net"
|
||||
//"log"
|
||||
"net/http"
|
||||
"net/url"
|
||||
@@ -37,13 +40,20 @@ type Auth struct {
|
||||
AccessKey string
|
||||
SecretKey string
|
||||
|
||||
// Hostname is the S3 hostname to use.
|
||||
// If empty, the standard US region of "s3.amazonaws.com" is
|
||||
// used.
|
||||
// If empty, the standard US region of "s3.amazonaws.com" is used.
|
||||
Hostname string
|
||||
|
||||
// Used for SSL transport layer
|
||||
CertPEM string
|
||||
KeyPEM string
|
||||
}
|
||||
|
||||
const standardUSRegionAWS = "https://s3.amazonaws.com"
|
||||
type TlsConfig struct {
|
||||
CertPEMBlock []byte
|
||||
KeyPEMBlock []byte
|
||||
}
|
||||
|
||||
const standardUSRegionAWS = "s3.amazonaws.com"
|
||||
|
||||
func (a *Auth) hostname() string {
|
||||
// Prefix with https for Amazon hostnames
|
||||
@@ -54,7 +64,54 @@ func (a *Auth) hostname() string {
|
||||
return "http://" + a.Hostname
|
||||
}
|
||||
}
|
||||
return standardUSRegionAWS
|
||||
return "https://" + standardUSRegionAWS
|
||||
}
|
||||
|
||||
func (a *Auth) loadKeys(cert string, key string) (*TlsConfig, error) {
|
||||
certBlock, err := ioutil.ReadFile(cert)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
keyBlock, err := ioutil.ReadFile(key)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
t := &TlsConfig{}
|
||||
t.CertPEMBlock = certBlock
|
||||
t.KeyPEMBlock = keyBlock
|
||||
return t, nil
|
||||
}
|
||||
|
||||
func (a *Auth) getTlsTransport() (*http.Transport, error) {
|
||||
if a.CertPEM == "" || a.KeyPEM == "" {
|
||||
return &http.Transport{
|
||||
Dial: (&net.Dialer{
|
||||
Timeout: 30 * time.Second,
|
||||
KeepAlive: 30 * time.Second,
|
||||
}).Dial,
|
||||
TLSHandshakeTimeout: 10 * time.Second,
|
||||
}, nil
|
||||
}
|
||||
|
||||
tlsconfig, err := a.loadKeys(a.CertPEM, a.KeyPEM)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
var cert tls.Certificate
|
||||
cert, err = tls.X509KeyPair(tlsconfig.CertPEMBlock, tlsconfig.KeyPEMBlock)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
// Setup HTTPS client
|
||||
tlsConfig := &tls.Config{
|
||||
Certificates: []tls.Certificate{cert},
|
||||
InsecureSkipVerify: true,
|
||||
}
|
||||
|
||||
tlsConfig.BuildNameToCertificate()
|
||||
transport := &http.Transport{TLSClientConfig: tlsConfig}
|
||||
return transport, nil
|
||||
}
|
||||
|
||||
func (a *Auth) SignRequest(req *http.Request) {
|
||||
|
||||
Reference in New Issue
Block a user