add endpoint support
This commit is contained in:
parent
46148721e1
commit
d28a3fa28a
2 changed files with 19 additions and 9 deletions
8
docs/storage/driver/oss/oss.go
Executable file → Normal file
8
docs/storage/driver/oss/oss.go
Executable file → Normal file
|
@ -56,6 +56,7 @@ type DriverParameters struct {
|
|||
Secure bool
|
||||
ChunkSize int64
|
||||
RootDirectory string
|
||||
Endpoint string
|
||||
}
|
||||
|
||||
func init() {
|
||||
|
@ -175,6 +176,11 @@ func FromParameters(parameters map[string]interface{}) (*Driver, error) {
|
|||
rootDirectory = ""
|
||||
}
|
||||
|
||||
endpoint, ok := parameters["endpoint"]
|
||||
if !ok {
|
||||
endpoint = ""
|
||||
}
|
||||
|
||||
params := DriverParameters{
|
||||
AccessKeyID: fmt.Sprint(accessKey),
|
||||
AccessKeySecret: fmt.Sprint(secretKey),
|
||||
|
@ -185,6 +191,7 @@ func FromParameters(parameters map[string]interface{}) (*Driver, error) {
|
|||
Encrypt: encryptBool,
|
||||
Secure: secureBool,
|
||||
Internal: internalBool,
|
||||
Endpoint: fmt.Sprint(endpoint),
|
||||
}
|
||||
|
||||
return New(params)
|
||||
|
@ -195,6 +202,7 @@ func FromParameters(parameters map[string]interface{}) (*Driver, error) {
|
|||
func New(params DriverParameters) (*Driver, error) {
|
||||
|
||||
client := oss.NewOSSClient(params.Region, params.Internal, params.AccessKeyID, params.AccessKeySecret, params.Secure)
|
||||
client.SetEndpoint(params.Endpoint)
|
||||
bucket := client.Bucket(params.Bucket)
|
||||
|
||||
// Validate that the given credentials have at least read permissions in the
|
||||
|
|
20
docs/storage/driver/oss/oss_test.go
Executable file → Normal file
20
docs/storage/driver/oss/oss_test.go
Executable file → Normal file
|
@ -27,6 +27,7 @@ func init() {
|
|||
internal := os.Getenv("OSS_INTERNAL")
|
||||
encrypt := os.Getenv("OSS_ENCRYPT")
|
||||
secure := os.Getenv("OSS_SECURE")
|
||||
endpoint := os.Getenv("OSS_ENDPOINT")
|
||||
root, err := ioutil.TempDir("", "driver-")
|
||||
if err != nil {
|
||||
panic(err)
|
||||
|
@ -59,15 +60,16 @@ func init() {
|
|||
}
|
||||
|
||||
parameters := DriverParameters{
|
||||
accessKey,
|
||||
secretKey,
|
||||
bucket,
|
||||
alioss.Region(region),
|
||||
internalBool,
|
||||
encryptBool,
|
||||
secureBool,
|
||||
minChunkSize,
|
||||
rootDirectory,
|
||||
AccessKeyID: accessKey,
|
||||
AccessKeySecret: secretKey,
|
||||
Bucket: bucket,
|
||||
Region: alioss.Region(region),
|
||||
Internal: internalBool,
|
||||
ChunkSize: minChunkSize,
|
||||
RootDirectory: rootDirectory,
|
||||
Encrypt: encryptBool,
|
||||
Secure: secureBool,
|
||||
Endpoint: endpoint,
|
||||
}
|
||||
|
||||
return New(parameters)
|
||||
|
|
Loading…
Reference in a new issue