forked from arschles/object-storage-cli
/
swift.go
48 lines (44 loc) · 1.93 KB
/
swift.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
package config
import (
"github.com/docker/distribution/registry/storage/driver"
"github.com/docker/distribution/registry/storage/driver/factory"
// this blank import is used to register the swift driver with the storage driver factory
_ "github.com/docker/distribution/registry/storage/driver/swift"
)
// Swift is the Config implementation for the Swift client
type Swift struct {
UserName string `envconfig:"USER_NAME_FILE" default:"/var/run/secrets/deis/objectstore/creds/username"`
Password string `envconfig:"PASSWORD_FILE" default:"/var/run/secrets/deis/objectstore/creds/password"`
ContainerFile string `envconfig:"CONTAINER_FILE" default:"/var/run/secrets/deis/objectstore/creds/container"`
AuthURL string `envconfig:"AUTHURL_FILE" default:"/var/run/secrets/deis/objectstore/creds/authurl"`
Tenant string `envconfig:"TENANT_FILE" default:"/var/run/secrets/deis/objectstore/creds/tenant"`
AuthVersion string `envconfig:"AUTH_VERSION_FILE" default:"/var/run/secrets/deis/objectstore/creds/authversion"`
}
// CreateDriver is the Config interface implementation
func (s Swift) CreateDriver() (driver.StorageDriver, error) {
files, err := readFiles(true, s.UserName, s.Password, s.ContainerFile, s.AuthURL)
if err != nil {
return nil, err
}
username, password, container, authurl := files[0], files[1], files[2], files[3]
params := map[string]interface{}{
"username": username,
"password": password,
"container": container,
"authurl": authurl,
}
//tenant and authversion are not mandatory and hence need not panc if not present
tenantfile, err := readFiles(true, s.Tenant)
if err == nil {
params["tenant"] = tenantfile[0]
}
authversionfile, err := readFiles(true, s.AuthVersion)
if err == nil {
params["authversion"] = authversionfile[0]
}
return factory.Create("swift", params)
}
// Name is the fmt.Stringer interface implementation
func (s Swift) String() string {
return SwiftStorageType.String()
}