-
Notifications
You must be signed in to change notification settings - Fork 4
Add Test dockerscript for rustfs #65
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: staging
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,113 @@ | ||
| package client | ||
|
|
||
| import ( | ||
| "context" | ||
| "os" | ||
| "time" | ||
|
|
||
| "github.com/aws/aws-sdk-go-v2/aws" | ||
| "github.com/aws/aws-sdk-go-v2/config" | ||
| "github.com/aws/aws-sdk-go-v2/credentials" | ||
| "github.com/aws/aws-sdk-go-v2/service/s3" | ||
| ) | ||
|
|
||
| type RustFSClient struct { | ||
| client *s3.Client | ||
| } | ||
|
|
||
| // Currently RustFSClient has solid s3.Client as its field, | ||
| // when logic get complex and needs for mocking arise, replace it with interface | ||
|
|
||
| func NewRustFSClient() (*RustFSClient, error) { | ||
| endpoint := os.Getenv("RUSTFS_ENDPOINT") | ||
| if endpoint == "" { | ||
| endpoint = "http://localhost:9001" | ||
| } | ||
|
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. minioadmin<-- docker-compose.test.yaml 파일의 인자를 일단 덮어쓰도록 했습니다. |
||
| accessKey := os.Getenv("RUSTFS_ACCESS_KEY") | ||
| if accessKey == "" { | ||
| accessKey = "minioadmin" | ||
| } | ||
| secretKey := os.Getenv("RUSTFS_SECRET_KEY") | ||
| if secretKey == "" { | ||
| secretKey = "minioadmin" | ||
| } | ||
| //TODO: replace unstable accesskey override when testing with proper method | ||
|
|
||
| cfg, err := config.LoadDefaultConfig(context.Background(), | ||
| config.WithRegion("us-east-1"), | ||
| config.WithCredentialsProvider(credentials.NewStaticCredentialsProvider(accessKey, secretKey, "")), | ||
| ) | ||
| if err != nil { | ||
| return nil, err | ||
| } | ||
|
|
||
| client := s3.NewFromConfig(cfg, func(o *s3.Options) { | ||
| o.BaseEndpoint = aws.String(endpoint) | ||
| o.UsePathStyle = true | ||
| }) | ||
|
|
||
| return &RustFSClient{client: client}, nil | ||
| } | ||
|
|
||
| func (c *RustFSClient) ListBuckets(ctx context.Context) ([]string, error) { | ||
| out, err := c.client.ListBuckets(ctx, &s3.ListBucketsInput{}) | ||
| if err != nil { | ||
| return nil, err | ||
| } | ||
| names := make([]string, len(out.Buckets)) | ||
| for i, b := range out.Buckets { | ||
| names[i] = aws.ToString(b.Name) | ||
| } | ||
| return names, nil | ||
| } | ||
|
|
||
| func (c *RustFSClient) CreateBucket(ctx context.Context, bucket string) error { | ||
| _, err := c.client.CreateBucket(ctx, &s3.CreateBucketInput{ | ||
| Bucket: aws.String(bucket), | ||
| }) | ||
| return err | ||
| } | ||
|
|
||
| // / Refer: https://pkg.go.dev/github.com/aws/aws-sdk-go-v2/service/s3#NewPresignClient | ||
| // Direct listing, generating bucket and presigned URL is the role for RustFSClient(control) | ||
| // This Presigned url should be passed to Core client, and core should use this url to upload/download file. | ||
| // This Presigend related functions are yet not fully tested, so there might be some issues. Please refer to AWS SDK for Go v2 documentation | ||
| // | ||
| // for more details and examples on how to use the PresignClient. | ||
| func (c *RustFSClient) PresignPutObject(ctx context.Context, bucket, key string, expires time.Duration) (string, error) { | ||
| presignClient := s3.NewPresignClient(c.client) | ||
| req, err := presignClient.PresignPutObject(ctx, &s3.PutObjectInput{ | ||
| Bucket: aws.String(bucket), | ||
| Key: aws.String(key), | ||
| }, s3.WithPresignExpires(expires)) | ||
| if err != nil { | ||
| return "", err | ||
| } | ||
| return req.URL, nil | ||
| } | ||
|
|
||
| func (c *RustFSClient) PresignGetObject(ctx context.Context, bucket, key string, expires time.Duration) (string, error) { | ||
| presignClient := s3.NewPresignClient(c.client) | ||
| req, err := presignClient.PresignGetObject(ctx, &s3.GetObjectInput{ | ||
| Bucket: aws.String(bucket), | ||
| Key: aws.String(key), | ||
| }, s3.WithPresignExpires(expires)) | ||
| if err != nil { | ||
| return "", err | ||
| } | ||
| return req.URL, nil | ||
| } | ||
|
|
||
| // newCLI := &RustFSClient{client: client} | ||
| // ctx, cancel := context.WithTimeout(context.Background(), time.Duration(20)*time.Second) | ||
| // defer cancel() | ||
| // err = newCLI.CreateBucket(ctx, "adsfasdfds") | ||
| // err = newCLI.CreateBucket(ctx, "asdfaifdsfn") | ||
| // err = newCLI.CreateBucket(ctx, "asdf") | ||
| // err = newCLI.CreateBucket(ctx, "zxvc") | ||
| // err = newCLI.CreateBucket(ctx, "asdfs") | ||
| // bucks, err := newCLI.ListBuckets(ctx) | ||
| // fmt.Println(bucks) | ||
| // if err != nil { | ||
| // fmt.Println(err) | ||
| // } | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,10 +1,14 @@ | ||
| module github.com/easy-cloud-Knet/KWS_Control | ||
|
|
||
| go 1.23.0 | ||
| go 1.24 | ||
|
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 1.23.0 <-> aws sdk 와 호환성 문제가 있어서 업데이트 했는데 혹시 관련해서 문제 있을까요 |
||
|
|
||
| toolchain go1.23.4 | ||
| toolchain go1.24.3 | ||
|
|
||
| require ( | ||
| github.com/aws/aws-sdk-go-v2 v1.41.7 | ||
| github.com/aws/aws-sdk-go-v2/config v1.32.18 | ||
| github.com/aws/aws-sdk-go-v2/credentials v1.19.17 | ||
| github.com/aws/aws-sdk-go-v2/service/s3 v1.101.0 | ||
| github.com/go-sql-driver/mysql v1.9.2 | ||
| github.com/redis/go-redis/v9 v9.11.0 | ||
| github.com/sirupsen/logrus v1.9.3 | ||
|
|
@@ -15,6 +19,20 @@ require ( | |
|
|
||
| require ( | ||
| filippo.io/edwards25519 v1.1.0 // indirect | ||
| github.com/aws/aws-sdk-go-v2/aws/protocol/eventstream v1.7.10 // indirect | ||
| github.com/aws/aws-sdk-go-v2/feature/ec2/imds v1.18.23 // indirect | ||
| github.com/aws/aws-sdk-go-v2/internal/configsources v1.4.23 // indirect | ||
| github.com/aws/aws-sdk-go-v2/internal/endpoints/v2 v2.7.23 // indirect | ||
| github.com/aws/aws-sdk-go-v2/internal/v4a v1.4.24 // indirect | ||
| github.com/aws/aws-sdk-go-v2/service/internal/accept-encoding v1.13.9 // indirect | ||
| github.com/aws/aws-sdk-go-v2/service/internal/checksum v1.9.15 // indirect | ||
| github.com/aws/aws-sdk-go-v2/service/internal/presigned-url v1.13.23 // indirect | ||
| github.com/aws/aws-sdk-go-v2/service/internal/s3shared v1.19.23 // indirect | ||
| github.com/aws/aws-sdk-go-v2/service/signin v1.0.11 // indirect | ||
| github.com/aws/aws-sdk-go-v2/service/sso v1.30.17 // indirect | ||
| github.com/aws/aws-sdk-go-v2/service/ssooidc v1.36.0 // indirect | ||
| github.com/aws/aws-sdk-go-v2/service/sts v1.42.1 // indirect | ||
| github.com/aws/smithy-go v1.25.1 // indirect | ||
| github.com/cespare/xxhash/v2 v2.3.0 // indirect | ||
| github.com/dgryski/go-rendezvous v0.0.0-20200823014737-9f7001d12a5f // indirect | ||
| golang.org/x/sys v0.33.0 // indirect | ||
|
|
||
Uh oh!
There was an error while loading. Please reload this page.