Rename credentials to config
This commit is contained in:
parent
f16c868b2a
commit
360d9bfe69
8 changed files with 33 additions and 33 deletions
|
@ -40,14 +40,14 @@ var (
|
||||||
func main() {
|
func main() {
|
||||||
flag.Parse()
|
flag.Parse()
|
||||||
|
|
||||||
cr := &s3.Credentials{
|
cfg := &s3.Config{
|
||||||
AccessKeyID: *accessKeyID,
|
AccessKeyID: *accessKeyID,
|
||||||
SecretAccessKey: *secretAccessKey,
|
SecretAccessKey: *secretAccessKey,
|
||||||
Endpoint: *s3endpoint,
|
Endpoint: *s3endpoint,
|
||||||
Region: *region,
|
Region: *region,
|
||||||
}
|
}
|
||||||
|
|
||||||
driver, err := s3.NewS3(*nodeID, *endpoint, cr)
|
driver, err := s3.NewS3(*nodeID, *endpoint, cfg)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
log.Fatal(err)
|
log.Fatal(err)
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,7 +1,7 @@
|
||||||
package s3
|
package s3
|
||||||
|
|
||||||
// Credentials holds s3 credentials and parameters
|
// Config holds values to configure the driver
|
||||||
type Credentials struct {
|
type Config struct {
|
||||||
AccessKeyID string
|
AccessKeyID string
|
||||||
SecretAccessKey string
|
SecretAccessKey string
|
||||||
Region string
|
Region string
|
|
@ -11,11 +11,11 @@ import (
|
||||||
|
|
||||||
const defaultRegion = "us-east-1"
|
const defaultRegion = "us-east-1"
|
||||||
|
|
||||||
func goofysMount(bucket string, cr *Credentials, targetPath string) error {
|
func goofysMount(bucket string, cfg *Config, targetPath string) error {
|
||||||
cfg := &goofys.Config{
|
goofysCfg := &goofys.Config{
|
||||||
MountPoint: targetPath,
|
MountPoint: targetPath,
|
||||||
Endpoint: cr.Endpoint,
|
Endpoint: cfg.Endpoint,
|
||||||
Region: cr.Region,
|
Region: cfg.Region,
|
||||||
DirMode: 0755,
|
DirMode: 0755,
|
||||||
FileMode: 0644,
|
FileMode: 0644,
|
||||||
MountOptions: map[string]string{
|
MountOptions: map[string]string{
|
||||||
|
@ -25,10 +25,10 @@ func goofysMount(bucket string, cr *Credentials, targetPath string) error {
|
||||||
if cfg.Endpoint != "" {
|
if cfg.Endpoint != "" {
|
||||||
cfg.Region = defaultRegion
|
cfg.Region = defaultRegion
|
||||||
}
|
}
|
||||||
os.Setenv("AWS_ACCESS_KEY_ID", cr.AccessKeyID)
|
os.Setenv("AWS_ACCESS_KEY_ID", cfg.AccessKeyID)
|
||||||
os.Setenv("AWS_SECRET_ACCESS_KEY", cr.SecretAccessKey)
|
os.Setenv("AWS_SECRET_ACCESS_KEY", cfg.SecretAccessKey)
|
||||||
|
|
||||||
_, _, err := goofys.Mount(context.Background(), bucket, cfg)
|
_, _, err := goofys.Mount(context.Background(), bucket, goofysCfg)
|
||||||
|
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return fmt.Errorf("Error mounting via goofys: %s", err)
|
return fmt.Errorf("Error mounting via goofys: %s", err)
|
||||||
|
|
|
@ -87,11 +87,11 @@ func (ns *nodeServer) NodePublishVolume(ctx context.Context, req *csi.NodePublis
|
||||||
|
|
||||||
mounter, exists := attrib[mounterKey]
|
mounter, exists := attrib[mounterKey]
|
||||||
if !exists || mounter == s3fsMounter {
|
if !exists || mounter == s3fsMounter {
|
||||||
if err := s3fsMount(volumeID, ns.s3.cr, targetPath); err != nil {
|
if err := s3fsMount(volumeID, ns.s3.cfg, targetPath); err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
} else if mounter == goofysMounter {
|
} else if mounter == goofysMounter {
|
||||||
if err := goofysMount(volumeID, ns.s3.cr, targetPath); err != nil {
|
if err := goofysMount(volumeID, ns.s3.cfg, targetPath); err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
|
|
|
@ -13,7 +13,7 @@ const (
|
||||||
)
|
)
|
||||||
|
|
||||||
type s3Client struct {
|
type s3Client struct {
|
||||||
cr *Credentials
|
cfg *Config
|
||||||
minio *minio.Client
|
minio *minio.Client
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -21,11 +21,11 @@ type bucketMetadata struct {
|
||||||
CapacityBytes int64
|
CapacityBytes int64
|
||||||
}
|
}
|
||||||
|
|
||||||
func newS3Client(cr *Credentials) (*s3Client, error) {
|
func newS3Client(cfg *Config) (*s3Client, error) {
|
||||||
var client = &s3Client{}
|
var client = &s3Client{}
|
||||||
|
|
||||||
client.cr = cr
|
client.cfg = cfg
|
||||||
u, err := url.Parse(client.cr.Endpoint)
|
u, err := url.Parse(client.cfg.Endpoint)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
|
@ -34,7 +34,7 @@ func newS3Client(cr *Credentials) (*s3Client, error) {
|
||||||
if u.Port() != "" {
|
if u.Port() != "" {
|
||||||
endpoint = u.Hostname() + ":" + u.Port()
|
endpoint = u.Hostname() + ":" + u.Port()
|
||||||
}
|
}
|
||||||
minioClient, err := minio.New(endpoint, client.cr.AccessKeyID, client.cr.SecretAccessKey, ssl)
|
minioClient, err := minio.New(endpoint, client.cfg.AccessKeyID, client.cfg.SecretAccessKey, ssl)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
|
@ -47,7 +47,7 @@ func (client *s3Client) bucketExists(bucketName string) (bool, error) {
|
||||||
}
|
}
|
||||||
|
|
||||||
func (client *s3Client) createBucket(bucketName string) error {
|
func (client *s3Client) createBucket(bucketName string) error {
|
||||||
return client.minio.MakeBucket(bucketName, client.cr.Region)
|
return client.minio.MakeBucket(bucketName, client.cfg.Region)
|
||||||
}
|
}
|
||||||
|
|
||||||
func (client *s3Client) removeBucket(bucketName string) error {
|
func (client *s3Client) removeBucket(bucketName string) error {
|
||||||
|
|
|
@ -27,7 +27,7 @@ type s3 struct {
|
||||||
driver *csicommon.CSIDriver
|
driver *csicommon.CSIDriver
|
||||||
client *s3Client
|
client *s3Client
|
||||||
endpoint string
|
endpoint string
|
||||||
cr *Credentials
|
cfg *Config
|
||||||
|
|
||||||
ids *identityServer
|
ids *identityServer
|
||||||
ns *nodeServer
|
ns *nodeServer
|
||||||
|
@ -47,13 +47,13 @@ var (
|
||||||
)
|
)
|
||||||
|
|
||||||
// NewS3 initializes the driver
|
// NewS3 initializes the driver
|
||||||
func NewS3(nodeID string, endpoint string, cr *Credentials) (*s3, error) {
|
func NewS3(nodeID string, endpoint string, cfg *Config) (*s3, error) {
|
||||||
driver := csicommon.NewCSIDriver(driverName, vendorVersion, nodeID)
|
driver := csicommon.NewCSIDriver(driverName, vendorVersion, nodeID)
|
||||||
if driver == nil {
|
if driver == nil {
|
||||||
glog.Fatalln("Failed to initialize CSI Driver.")
|
glog.Fatalln("Failed to initialize CSI Driver.")
|
||||||
}
|
}
|
||||||
|
|
||||||
client, err := newS3Client(cr)
|
client, err := newS3Client(cfg)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
glog.V(3).Infof("Failed to create s3 client: %v", err)
|
glog.V(3).Infof("Failed to create s3 client: %v", err)
|
||||||
return nil, err
|
return nil, err
|
||||||
|
@ -62,7 +62,7 @@ func NewS3(nodeID string, endpoint string, cr *Credentials) (*s3, error) {
|
||||||
endpoint: endpoint,
|
endpoint: endpoint,
|
||||||
driver: driver,
|
driver: driver,
|
||||||
client: client,
|
client: client,
|
||||||
cr: cr,
|
cfg: cfg,
|
||||||
}
|
}
|
||||||
return s3Driver, nil
|
return s3Driver, nil
|
||||||
}
|
}
|
||||||
|
|
|
@ -32,12 +32,12 @@ func TestDriver(t *testing.T) {
|
||||||
if err := os.Remove(socket); err != nil && !os.IsNotExist(err) {
|
if err := os.Remove(socket); err != nil && !os.IsNotExist(err) {
|
||||||
t.Fatalf("failed to remove unix domain socket file %s, error: %s", socket, err)
|
t.Fatalf("failed to remove unix domain socket file %s, error: %s", socket, err)
|
||||||
}
|
}
|
||||||
cr := &Credentials{
|
cfg := &Config{
|
||||||
AccessKeyID: "FJDSJ",
|
AccessKeyID: "FJDSJ",
|
||||||
SecretAccessKey: "DSG643HGDS",
|
SecretAccessKey: "DSG643HGDS",
|
||||||
Endpoint: "http://127.0.0.1:9000",
|
Endpoint: "http://127.0.0.1:9000",
|
||||||
}
|
}
|
||||||
driver, err := NewS3("test-node", endpoint, cr)
|
driver, err := NewS3("test-node", endpoint, cfg)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
log.Fatal(err)
|
log.Fatal(err)
|
||||||
}
|
}
|
||||||
|
@ -49,10 +49,10 @@ func TestDriver(t *testing.T) {
|
||||||
}
|
}
|
||||||
defer os.RemoveAll(mntDir)
|
defer os.RemoveAll(mntDir)
|
||||||
|
|
||||||
cfg := &sanity.Config{
|
sanityCfg := &sanity.Config{
|
||||||
TargetPath: mntDir,
|
TargetPath: mntDir,
|
||||||
Address: endpoint,
|
Address: endpoint,
|
||||||
}
|
}
|
||||||
|
|
||||||
sanity.Test(t, cfg)
|
sanity.Test(t, sanityCfg)
|
||||||
}
|
}
|
||||||
|
|
|
@ -6,8 +6,8 @@ import (
|
||||||
"os/exec"
|
"os/exec"
|
||||||
)
|
)
|
||||||
|
|
||||||
func s3fsMount(bucket string, cr *Credentials, targetPath string) error {
|
func s3fsMount(bucket string, cfg *Config, targetPath string) error {
|
||||||
if err := writes3fsPass(cr); err != nil {
|
if err := writes3fsPass(cfg); err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
args := []string{
|
args := []string{
|
||||||
|
@ -15,8 +15,8 @@ func s3fsMount(bucket string, cr *Credentials, targetPath string) error {
|
||||||
fmt.Sprintf("%s", targetPath),
|
fmt.Sprintf("%s", targetPath),
|
||||||
"-o", "sigv2",
|
"-o", "sigv2",
|
||||||
"-o", "use_path_request_style",
|
"-o", "use_path_request_style",
|
||||||
"-o", fmt.Sprintf("url=%s", cr.Endpoint),
|
"-o", fmt.Sprintf("url=%s", cfg.Endpoint),
|
||||||
"-o", fmt.Sprintf("endpoint=%s", cr.Region),
|
"-o", fmt.Sprintf("endpoint=%s", cfg.Region),
|
||||||
"-o", "allow_other",
|
"-o", "allow_other",
|
||||||
"-o", "mp_umask=000",
|
"-o", "mp_umask=000",
|
||||||
}
|
}
|
||||||
|
@ -28,13 +28,13 @@ func s3fsMount(bucket string, cr *Credentials, targetPath string) error {
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func writes3fsPass(cr *Credentials) error {
|
func writes3fsPass(cfg *Config) error {
|
||||||
pwFileName := fmt.Sprintf("%s/.passwd-s3fs", os.Getenv("HOME"))
|
pwFileName := fmt.Sprintf("%s/.passwd-s3fs", os.Getenv("HOME"))
|
||||||
pwFile, err := os.OpenFile(pwFileName, os.O_RDWR|os.O_CREATE, 0600)
|
pwFile, err := os.OpenFile(pwFileName, os.O_RDWR|os.O_CREATE, 0600)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
_, err = pwFile.WriteString(cr.AccessKeyID + ":" + cr.SecretAccessKey)
|
_, err = pwFile.WriteString(cfg.AccessKeyID + ":" + cfg.SecretAccessKey)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue