feat(storage): add multi-instance storage backends per workspace
Introduce tenant-scoped storage backend registry so workspaces can register multiple storage instances and bind each knowledge base to a specific backend, with migration from legacy tenant-level storage config and new settings UI.
This commit is contained in:
@@ -30,7 +30,7 @@ type s3FileService struct {
|
||||
}
|
||||
|
||||
// newS3Client creates a bare s3FileService with just the SDK client initialised.
|
||||
func newS3Client(endpoint, accessKey, secretKey, bucketName, region, pathPrefix string) (*s3FileService, error) {
|
||||
func newS3Client(endpoint, accessKey, secretKey, bucketName, region, pathPrefix string, forcePathStyle bool) (*s3FileService, error) {
|
||||
var cfg aws.Config
|
||||
var err error
|
||||
|
||||
@@ -49,7 +49,7 @@ func newS3Client(endpoint, accessKey, secretKey, bucketName, region, pathPrefix
|
||||
// (endpoint/bucket/key) instead of virtual-hosted style (bucket.endpoint/key).
|
||||
var client *s3.Client
|
||||
if endpoint != "" {
|
||||
usePathStyle := !strings.Contains(endpoint, "amazonaws.com")
|
||||
usePathStyle := forcePathStyle || !strings.Contains(endpoint, "amazonaws.com")
|
||||
client = s3.NewFromConfig(cfg, func(o *s3.Options) {
|
||||
o.BaseEndpoint = aws.String(endpoint)
|
||||
o.UsePathStyle = usePathStyle
|
||||
@@ -76,7 +76,7 @@ func newS3Client(endpoint, accessKey, secretKey, bucketName, region, pathPrefix
|
||||
func NewS3FileService(endpoint,
|
||||
accessKey, secretKey, bucketName, region, pathPrefix string,
|
||||
) (interfaces.FileService, error) {
|
||||
svc, err := newS3Client(endpoint, accessKey, secretKey, bucketName, region, pathPrefix)
|
||||
svc, err := newS3Client(endpoint, accessKey, secretKey, bucketName, region, pathPrefix, false)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
@@ -96,6 +96,25 @@ func NewS3FileService(endpoint,
|
||||
return svc, nil
|
||||
}
|
||||
|
||||
// NewS3FileServiceWithOptions is the instance-aware S3 constructor. Existing
|
||||
// callers keep the historical endpoint-based path-style inference.
|
||||
func NewS3FileServiceWithOptions(endpoint, accessKey, secretKey, bucketName, region, pathPrefix string, forcePathStyle bool) (interfaces.FileService, error) {
|
||||
svc, err := newS3Client(endpoint, accessKey, secretKey, bucketName, region, pathPrefix, forcePathStyle)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
exists, err := svc.bucketExists(context.Background())
|
||||
if err != nil {
|
||||
return nil, fmt.Errorf("failed to check bucket: %w", err)
|
||||
}
|
||||
if !exists {
|
||||
if err = svc.createBucket(context.Background()); err != nil {
|
||||
return nil, fmt.Errorf("failed to create bucket: %w", err)
|
||||
}
|
||||
}
|
||||
return svc, nil
|
||||
}
|
||||
|
||||
// bucketExists checks if the bucket exists
|
||||
func (s *s3FileService) bucketExists(ctx context.Context) (bool, error) {
|
||||
_, err := s.client.HeadBucket(ctx, &s3.HeadBucketInput{
|
||||
@@ -145,7 +164,11 @@ func (s *s3FileService) CheckConnectivity(ctx context.Context) error {
|
||||
// CheckS3Connectivity tests S3 connectivity using the provided credentials.
|
||||
// It creates a temporary service instance internally and delegates to CheckConnectivity.
|
||||
func CheckS3Connectivity(ctx context.Context, endpoint, accessKey, secretKey, bucketName, region string) error {
|
||||
svc, err := newS3Client(endpoint, accessKey, secretKey, bucketName, region, "")
|
||||
return CheckS3ConnectivityWithOptions(ctx, endpoint, accessKey, secretKey, bucketName, region, false)
|
||||
}
|
||||
|
||||
func CheckS3ConnectivityWithOptions(ctx context.Context, endpoint, accessKey, secretKey, bucketName, region string, forcePathStyle bool) error {
|
||||
svc, err := newS3Client(endpoint, accessKey, secretKey, bucketName, region, "", forcePathStyle)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user