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() {
|
||||
flag.Parse()
|
||||
|
||||
cr := &s3.Credentials{
|
||||
cfg := &s3.Config{
|
||||
AccessKeyID: *accessKeyID,
|
||||
SecretAccessKey: *secretAccessKey,
|
||||
Endpoint: *s3endpoint,
|
||||
Region: *region,
|
||||
}
|
||||
|
||||
driver, err := s3.NewS3(*nodeID, *endpoint, cr)
|
||||
driver, err := s3.NewS3(*nodeID, *endpoint, cfg)
|
||||
if err != nil {
|
||||
log.Fatal(err)
|
||||
}
|
||||
|
|
|
@ -1,7 +1,7 @@
|
|||
package s3
|
||||
|
||||
// Credentials holds s3 credentials and parameters
|
||||
type Credentials struct {
|
||||
// Config holds values to configure the driver
|
||||
type Config struct {
|
||||
AccessKeyID string
|
||||
SecretAccessKey string
|
||||
Region string
|
|
@ -11,11 +11,11 @@ import (
|
|||
|
||||
const defaultRegion = "us-east-1"
|
||||
|
||||
func goofysMount(bucket string, cr *Credentials, targetPath string) error {
|
||||
cfg := &goofys.Config{
|
||||
func goofysMount(bucket string, cfg *Config, targetPath string) error {
|
||||
goofysCfg := &goofys.Config{
|
||||
MountPoint: targetPath,
|
||||
Endpoint: cr.Endpoint,
|
||||
Region: cr.Region,
|
||||
Endpoint: cfg.Endpoint,
|
||||
Region: cfg.Region,
|
||||
DirMode: 0755,
|
||||
FileMode: 0644,
|
||||
MountOptions: map[string]string{
|
||||
|
@ -25,10 +25,10 @@ func goofysMount(bucket string, cr *Credentials, targetPath string) error {
|
|||
if cfg.Endpoint != "" {
|
||||
cfg.Region = defaultRegion
|
||||
}
|
||||
os.Setenv("AWS_ACCESS_KEY_ID", cr.AccessKeyID)
|
||||
os.Setenv("AWS_SECRET_ACCESS_KEY", cr.SecretAccessKey)
|
||||
os.Setenv("AWS_ACCESS_KEY_ID", cfg.AccessKeyID)
|
||||
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 {
|
||||
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]
|
||||
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
|
||||
}
|
||||
} 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
|
||||
}
|
||||
} else {
|
||||
|
|
|
@ -13,7 +13,7 @@ const (
|
|||
)
|
||||
|
||||
type s3Client struct {
|
||||
cr *Credentials
|
||||
cfg *Config
|
||||
minio *minio.Client
|
||||
}
|
||||
|
||||
|
@ -21,11 +21,11 @@ type bucketMetadata struct {
|
|||
CapacityBytes int64
|
||||
}
|
||||
|
||||
func newS3Client(cr *Credentials) (*s3Client, error) {
|
||||
func newS3Client(cfg *Config) (*s3Client, error) {
|
||||
var client = &s3Client{}
|
||||
|
||||
client.cr = cr
|
||||
u, err := url.Parse(client.cr.Endpoint)
|
||||
client.cfg = cfg
|
||||
u, err := url.Parse(client.cfg.Endpoint)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
@ -34,7 +34,7 @@ func newS3Client(cr *Credentials) (*s3Client, error) {
|
|||
if 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 {
|
||||
return nil, err
|
||||
}
|
||||
|
@ -47,7 +47,7 @@ func (client *s3Client) bucketExists(bucketName string) (bool, 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 {
|
||||
|
|
|
@ -27,7 +27,7 @@ type s3 struct {
|
|||
driver *csicommon.CSIDriver
|
||||
client *s3Client
|
||||
endpoint string
|
||||
cr *Credentials
|
||||
cfg *Config
|
||||
|
||||
ids *identityServer
|
||||
ns *nodeServer
|
||||
|
@ -47,13 +47,13 @@ var (
|
|||
)
|
||||
|
||||
// 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)
|
||||
if driver == nil {
|
||||
glog.Fatalln("Failed to initialize CSI Driver.")
|
||||
}
|
||||
|
||||
client, err := newS3Client(cr)
|
||||
client, err := newS3Client(cfg)
|
||||
if err != nil {
|
||||
glog.V(3).Infof("Failed to create s3 client: %v", err)
|
||||
return nil, err
|
||||
|
@ -62,7 +62,7 @@ func NewS3(nodeID string, endpoint string, cr *Credentials) (*s3, error) {
|
|||
endpoint: endpoint,
|
||||
driver: driver,
|
||||
client: client,
|
||||
cr: cr,
|
||||
cfg: cfg,
|
||||
}
|
||||
return s3Driver, nil
|
||||
}
|
||||
|
|
|
@ -32,12 +32,12 @@ func TestDriver(t *testing.T) {
|
|||
if err := os.Remove(socket); err != nil && !os.IsNotExist(err) {
|
||||
t.Fatalf("failed to remove unix domain socket file %s, error: %s", socket, err)
|
||||
}
|
||||
cr := &Credentials{
|
||||
cfg := &Config{
|
||||
AccessKeyID: "FJDSJ",
|
||||
SecretAccessKey: "DSG643HGDS",
|
||||
Endpoint: "http://127.0.0.1:9000",
|
||||
}
|
||||
driver, err := NewS3("test-node", endpoint, cr)
|
||||
driver, err := NewS3("test-node", endpoint, cfg)
|
||||
if err != nil {
|
||||
log.Fatal(err)
|
||||
}
|
||||
|
@ -49,10 +49,10 @@ func TestDriver(t *testing.T) {
|
|||
}
|
||||
defer os.RemoveAll(mntDir)
|
||||
|
||||
cfg := &sanity.Config{
|
||||
sanityCfg := &sanity.Config{
|
||||
TargetPath: mntDir,
|
||||
Address: endpoint,
|
||||
}
|
||||
|
||||
sanity.Test(t, cfg)
|
||||
sanity.Test(t, sanityCfg)
|
||||
}
|
||||
|
|
|
@ -6,8 +6,8 @@ import (
|
|||
"os/exec"
|
||||
)
|
||||
|
||||
func s3fsMount(bucket string, cr *Credentials, targetPath string) error {
|
||||
if err := writes3fsPass(cr); err != nil {
|
||||
func s3fsMount(bucket string, cfg *Config, targetPath string) error {
|
||||
if err := writes3fsPass(cfg); err != nil {
|
||||
return err
|
||||
}
|
||||
args := []string{
|
||||
|
@ -15,8 +15,8 @@ func s3fsMount(bucket string, cr *Credentials, targetPath string) error {
|
|||
fmt.Sprintf("%s", targetPath),
|
||||
"-o", "sigv2",
|
||||
"-o", "use_path_request_style",
|
||||
"-o", fmt.Sprintf("url=%s", cr.Endpoint),
|
||||
"-o", fmt.Sprintf("endpoint=%s", cr.Region),
|
||||
"-o", fmt.Sprintf("url=%s", cfg.Endpoint),
|
||||
"-o", fmt.Sprintf("endpoint=%s", cfg.Region),
|
||||
"-o", "allow_other",
|
||||
"-o", "mp_umask=000",
|
||||
}
|
||||
|
@ -28,13 +28,13 @@ func s3fsMount(bucket string, cr *Credentials, targetPath string) error {
|
|||
return nil
|
||||
}
|
||||
|
||||
func writes3fsPass(cr *Credentials) error {
|
||||
func writes3fsPass(cfg *Config) error {
|
||||
pwFileName := fmt.Sprintf("%s/.passwd-s3fs", os.Getenv("HOME"))
|
||||
pwFile, err := os.OpenFile(pwFileName, os.O_RDWR|os.O_CREATE, 0600)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
_, err = pwFile.WriteString(cr.AccessKeyID + ":" + cr.SecretAccessKey)
|
||||
_, err = pwFile.WriteString(cfg.AccessKeyID + ":" + cfg.SecretAccessKey)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue