- Restructure handlers into file_commands/file_queries/file_handlers - Add gRPC auth client, JWT middleware, rate limiting, request ID - Add common utilities: logger, sanitizer, s3_errors - Add unit tests for config, mediator, auth, request_id, sanitize - Add proto definitions and generated code - Remove old web UI pages - Add .dockerignore and .env.example
57 lines
1.3 KiB
Go
57 lines
1.3 KiB
Go
package s3
|
|
|
|
import (
|
|
"context"
|
|
"rag/file-system/internal/common"
|
|
"log"
|
|
|
|
"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
|
|
presignClient *s3.PresignClient
|
|
}
|
|
|
|
func NewRustFSClient(cfg *common.Config) *RustFSClient {
|
|
customResolver := aws.EndpointResolverWithOptionsFunc(func(service, region string, options ...interface{}) (aws.Endpoint, error) {
|
|
return aws.Endpoint{
|
|
URL: cfg.RustFSEndpoint,
|
|
SigningRegion: cfg.RustFSRegion,
|
|
}, nil
|
|
})
|
|
|
|
awsCfg, err := config.LoadDefaultConfig(context.TODO(),
|
|
config.WithRegion(cfg.RustFSRegion),
|
|
config.WithEndpointResolverWithOptions(customResolver),
|
|
config.WithCredentialsProvider(credentials.NewStaticCredentialsProvider(
|
|
cfg.RustFSAccessKeyID,
|
|
cfg.RustFSSecretAccessKey,
|
|
"",
|
|
)),
|
|
)
|
|
if err != nil {
|
|
log.Fatalf("unable to load SDK config, %v", err)
|
|
}
|
|
|
|
client := s3.NewFromConfig(awsCfg, func(o *s3.Options) {
|
|
o.UsePathStyle = true
|
|
})
|
|
|
|
return &RustFSClient{
|
|
client: client,
|
|
presignClient: s3.NewPresignClient(client),
|
|
}
|
|
}
|
|
|
|
func (c *RustFSClient) S3Client() *s3.Client {
|
|
return c.client
|
|
}
|
|
|
|
func (c *RustFSClient) PresignClient() *s3.PresignClient {
|
|
return c.presignClient
|
|
}
|