add endpoint support

This commit is contained in:
tgic 2015-06-15 20:03:32 +08:00
parent 46148721e1
commit d28a3fa28a
2 changed files with 19 additions and 9 deletions

8
docs/storage/driver/oss/oss.go Executable file → Normal file
View File

@ -56,6 +56,7 @@ type DriverParameters struct {
Secure bool Secure bool
ChunkSize int64 ChunkSize int64
RootDirectory string RootDirectory string
Endpoint string
} }
func init() { func init() {
@ -175,6 +176,11 @@ func FromParameters(parameters map[string]interface{}) (*Driver, error) {
rootDirectory = "" rootDirectory = ""
} }
endpoint, ok := parameters["endpoint"]
if !ok {
endpoint = ""
}
params := DriverParameters{ params := DriverParameters{
AccessKeyID: fmt.Sprint(accessKey), AccessKeyID: fmt.Sprint(accessKey),
AccessKeySecret: fmt.Sprint(secretKey), AccessKeySecret: fmt.Sprint(secretKey),
@ -185,6 +191,7 @@ func FromParameters(parameters map[string]interface{}) (*Driver, error) {
Encrypt: encryptBool, Encrypt: encryptBool,
Secure: secureBool, Secure: secureBool,
Internal: internalBool, Internal: internalBool,
Endpoint: fmt.Sprint(endpoint),
} }
return New(params) return New(params)
@ -195,6 +202,7 @@ func FromParameters(parameters map[string]interface{}) (*Driver, error) {
func New(params DriverParameters) (*Driver, error) { func New(params DriverParameters) (*Driver, error) {
client := oss.NewOSSClient(params.Region, params.Internal, params.AccessKeyID, params.AccessKeySecret, params.Secure) client := oss.NewOSSClient(params.Region, params.Internal, params.AccessKeyID, params.AccessKeySecret, params.Secure)
client.SetEndpoint(params.Endpoint)
bucket := client.Bucket(params.Bucket) bucket := client.Bucket(params.Bucket)
// Validate that the given credentials have at least read permissions in the // Validate that the given credentials have at least read permissions in the

20
docs/storage/driver/oss/oss_test.go Executable file → Normal file
View File

@ -27,6 +27,7 @@ func init() {
internal := os.Getenv("OSS_INTERNAL") internal := os.Getenv("OSS_INTERNAL")
encrypt := os.Getenv("OSS_ENCRYPT") encrypt := os.Getenv("OSS_ENCRYPT")
secure := os.Getenv("OSS_SECURE") secure := os.Getenv("OSS_SECURE")
endpoint := os.Getenv("OSS_ENDPOINT")
root, err := ioutil.TempDir("", "driver-") root, err := ioutil.TempDir("", "driver-")
if err != nil { if err != nil {
panic(err) panic(err)
@ -59,15 +60,16 @@ func init() {
} }
parameters := DriverParameters{ parameters := DriverParameters{
accessKey, AccessKeyID: accessKey,
secretKey, AccessKeySecret: secretKey,
bucket, Bucket: bucket,
alioss.Region(region), Region: alioss.Region(region),
internalBool, Internal: internalBool,
encryptBool, ChunkSize: minChunkSize,
secureBool, RootDirectory: rootDirectory,
minChunkSize, Encrypt: encryptBool,
rootDirectory, Secure: secureBool,
Endpoint: endpoint,
} }
return New(parameters) return New(parameters)