Add support for Openstack Identity v3 API
Signed-off-by: Li Wenquan <wenquan.li@hp.com>
This commit is contained in:
parent
3f9e7ed169
commit
062d6266cf
2 changed files with 47 additions and 18 deletions
|
@ -10,6 +10,7 @@ package swift
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"bytes"
|
"bytes"
|
||||||
|
"crypto/tls"
|
||||||
"encoding/json"
|
"encoding/json"
|
||||||
"fmt"
|
"fmt"
|
||||||
"io"
|
"io"
|
||||||
|
@ -44,9 +45,13 @@ type DriverParameters struct {
|
||||||
Password string
|
Password string
|
||||||
AuthURL string
|
AuthURL string
|
||||||
Tenant string
|
Tenant string
|
||||||
|
TenantID string
|
||||||
|
Domain string
|
||||||
|
DomainID string
|
||||||
Region string
|
Region string
|
||||||
Container string
|
Container string
|
||||||
Prefix string
|
Prefix string
|
||||||
|
InsecureSkipVerify bool
|
||||||
ChunkSize int
|
ChunkSize int
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -90,6 +95,7 @@ type Driver struct {
|
||||||
func FromParameters(parameters map[string]interface{}) (*Driver, error) {
|
func FromParameters(parameters map[string]interface{}) (*Driver, error) {
|
||||||
params := DriverParameters{
|
params := DriverParameters{
|
||||||
ChunkSize: defaultChunkSize,
|
ChunkSize: defaultChunkSize,
|
||||||
|
InsecureSkipVerify: false,
|
||||||
}
|
}
|
||||||
|
|
||||||
if err := mapstructure.Decode(parameters, ¶ms); err != nil {
|
if err := mapstructure.Decode(parameters, ¶ms); err != nil {
|
||||||
|
@ -121,6 +127,12 @@ func FromParameters(parameters map[string]interface{}) (*Driver, error) {
|
||||||
|
|
||||||
// New constructs a new Driver with the given Openstack Swift credentials and container name
|
// New constructs a new Driver with the given Openstack Swift credentials and container name
|
||||||
func New(params DriverParameters) (*Driver, error) {
|
func New(params DriverParameters) (*Driver, error) {
|
||||||
|
transport := &http.Transport{
|
||||||
|
Proxy: http.ProxyFromEnvironment,
|
||||||
|
MaxIdleConnsPerHost: 2048,
|
||||||
|
TLSClientConfig: &tls.Config{InsecureSkipVerify: params.InsecureSkipVerify},
|
||||||
|
}
|
||||||
|
|
||||||
ct := swift.Connection{
|
ct := swift.Connection{
|
||||||
UserName: params.Username,
|
UserName: params.Username,
|
||||||
ApiKey: params.Password,
|
ApiKey: params.Password,
|
||||||
|
@ -128,6 +140,10 @@ func New(params DriverParameters) (*Driver, error) {
|
||||||
Region: params.Region,
|
Region: params.Region,
|
||||||
UserAgent: "distribution",
|
UserAgent: "distribution",
|
||||||
Tenant: params.Tenant,
|
Tenant: params.Tenant,
|
||||||
|
TenantId: params.TenantID,
|
||||||
|
Domain: params.Domain,
|
||||||
|
DomainId: params.DomainID,
|
||||||
|
Transport: transport,
|
||||||
ConnectTimeout: 60 * time.Second,
|
ConnectTimeout: 60 * time.Second,
|
||||||
Timeout: 15 * 60 * time.Second,
|
Timeout: 15 * 60 * time.Second,
|
||||||
}
|
}
|
||||||
|
|
|
@ -3,6 +3,7 @@ package swift
|
||||||
import (
|
import (
|
||||||
"io/ioutil"
|
"io/ioutil"
|
||||||
"os"
|
"os"
|
||||||
|
"strconv"
|
||||||
"testing"
|
"testing"
|
||||||
|
|
||||||
"github.com/ncw/swift/swifttest"
|
"github.com/ncw/swift/swifttest"
|
||||||
|
@ -25,9 +26,13 @@ func init() {
|
||||||
password string
|
password string
|
||||||
authURL string
|
authURL string
|
||||||
tenant string
|
tenant string
|
||||||
|
tenantID string
|
||||||
|
domain string
|
||||||
|
domainID string
|
||||||
container string
|
container string
|
||||||
region string
|
region string
|
||||||
prefix string
|
prefix string
|
||||||
|
insecureSkipVerify bool
|
||||||
swiftServer *swifttest.SwiftServer
|
swiftServer *swifttest.SwiftServer
|
||||||
err error
|
err error
|
||||||
)
|
)
|
||||||
|
@ -41,9 +46,13 @@ func init() {
|
||||||
authURL = os.Getenv("ST_AUTH")
|
authURL = os.Getenv("ST_AUTH")
|
||||||
}
|
}
|
||||||
tenant = os.Getenv("OS_TENANT_NAME")
|
tenant = os.Getenv("OS_TENANT_NAME")
|
||||||
|
tenantID = os.Getenv("OS_TENANT_ID")
|
||||||
|
domain = os.Getenv("OS_DOMAIN_NAME")
|
||||||
|
domainID = os.Getenv("OS_DOMAIN_ID")
|
||||||
container = os.Getenv("OS_CONTAINER_NAME")
|
container = os.Getenv("OS_CONTAINER_NAME")
|
||||||
region = os.Getenv("OS_REGION_NAME")
|
region = os.Getenv("OS_REGION_NAME")
|
||||||
prefix = os.Getenv("OS_CONTAINER_PREFIX")
|
prefix = os.Getenv("OS_CONTAINER_PREFIX")
|
||||||
|
insecureSkipVerify, _ = strconv.ParseBool(os.Getenv("ST_INSECURESKIPVERIFY"))
|
||||||
|
|
||||||
if username == "" || password == "" || authURL == "" || container == "" {
|
if username == "" || password == "" || authURL == "" || container == "" {
|
||||||
if swiftServer, err = swifttest.NewSwiftServer("localhost"); err != nil {
|
if swiftServer, err = swifttest.NewSwiftServer("localhost"); err != nil {
|
||||||
|
@ -67,9 +76,13 @@ func init() {
|
||||||
password,
|
password,
|
||||||
authURL,
|
authURL,
|
||||||
tenant,
|
tenant,
|
||||||
|
tenantID,
|
||||||
|
domain,
|
||||||
|
domainID,
|
||||||
region,
|
region,
|
||||||
container,
|
container,
|
||||||
prefix,
|
prefix,
|
||||||
|
insecureSkipVerify,
|
||||||
defaultChunkSize,
|
defaultChunkSize,
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue