Skip to content
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

improve: s3 store custom_domain #3717

Open
wants to merge 4 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions docs/apidocs.swagger.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -1968,6 +1968,8 @@ definitions:
type: string
bucket:
type: string
prefixUrl:
type: string
title: 'Reference: https://developers.cloudflare.com/r2/examples/aws/aws-sdk-go/'
apiHttpBody:
type: object
Expand Down
6 changes: 5 additions & 1 deletion plugin/storage/s3/s3.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package s3

import (
"context"
"fmt"
"io"
"time"

Expand Down Expand Up @@ -60,7 +61,10 @@ func (c *Client) UploadObject(ctx context.Context, key string, fileType string,
}

// PresignGetObject presigns an object in S3.
func (c *Client) PresignGetObject(ctx context.Context, key string) (string, error) {
func (c *Client) PresignGetObject(ctx context.Context, key string, s3Config *storepb.StorageS3Config) (string, error) {
if s3Config.PrefixUrl != "" {
return fmt.Sprintf("%s/%s", s3Config.PrefixUrl, key), nil
}
presignClient := s3.NewPresignClient(c.Client)
presignResult, err := presignClient.PresignGetObject(ctx, &s3.GetObjectInput{
Bucket: aws.String(*c.Bucket),
Expand Down
1 change: 1 addition & 0 deletions proto/api/v1/workspace_setting_service.proto
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,7 @@ message WorkspaceStorageSetting {
string endpoint = 3;
string region = 4;
string bucket = 5;
string prefix_url = 6;
}
// The S3 config.
S3Config s3_config = 4;
Expand Down
154 changes: 82 additions & 72 deletions proto/gen/api/v1/workspace_setting_service.pb.go

Large diffs are not rendered by default.

95 changes: 52 additions & 43 deletions proto/gen/store/workspace_setting.pb.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions proto/store/workspace_setting.proto
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,7 @@ message StorageS3Config {
string endpoint = 3;
string region = 4;
string bucket = 5;
string prefix_url = 6;
boojack marked this conversation as resolved.
Show resolved Hide resolved
boojack marked this conversation as resolved.
Show resolved Hide resolved
}

message WorkspaceMemoRelatedSetting {
Expand Down
2 changes: 1 addition & 1 deletion server/router/api/v1/resource_service.go
Original file line number Diff line number Diff line change
Expand Up @@ -386,7 +386,7 @@ func SaveResourceBlob(ctx context.Context, s *store.Store, create *store.Resourc
if err != nil {
return errors.Wrap(err, "Failed to upload via s3 client")
}
presignURL, err := s3Client.PresignGetObject(ctx, key)
presignURL, err := s3Client.PresignGetObject(ctx, key, s3Config)
boojack marked this conversation as resolved.
Show resolved Hide resolved
if err != nil {
return errors.Wrap(err, "Failed to presign via s3 client")
}
Expand Down
2 changes: 2 additions & 0 deletions server/router/api/v1/workspace_setting_service.go
Original file line number Diff line number Diff line change
Expand Up @@ -183,6 +183,7 @@ func convertWorkspaceStorageSettingFromStore(settingpb *storepb.WorkspaceStorage
Endpoint: settingpb.S3Config.Endpoint,
Region: settingpb.S3Config.Region,
Bucket: settingpb.S3Config.Bucket,
PrefixUrl: settingpb.S3Config.PrefixUrl,
}
}
return setting
Expand All @@ -204,6 +205,7 @@ func convertWorkspaceStorageSettingToStore(setting *v1pb.WorkspaceStorageSetting
Endpoint: setting.S3Config.Endpoint,
Region: setting.S3Config.Region,
Bucket: setting.S3Config.Bucket,
PrefixUrl: setting.S3Config.PrefixUrl,
}
}
return settingpb
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ func (p *S3ObjectPresigner) CheckAndPresign(ctx context.Context) {
continue
}

presignURL, err := s3Client.PresignGetObject(ctx, s3ObjectPayload.Key)
presignURL, err := s3Client.PresignGetObject(ctx, s3ObjectPayload.Key, s3Config)
if err != nil {
return
}
Expand Down
8 changes: 8 additions & 0 deletions web/src/components/Settings/StorageSection.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -97,6 +97,10 @@ const StorageSection = () => {
handlePartialS3ConfigChanged({ bucket: event.target.value });
};

const handleS3ConfigPrefixUrlChanged = async (event: React.FocusEvent<HTMLInputElement>) => {
handlePartialS3ConfigChanged({ prefixUrl: event.target.value });
};

const handleStorageTypeChanged = async (storageType: WorkspaceStorageSetting_StorageType) => {
const update: WorkspaceStorageSetting = {
...workspaceStorageSetting,
Expand Down Expand Up @@ -180,6 +184,10 @@ const StorageSection = () => {
<span className="text-gray-700 dark:text-gray-500 mr-1">Bucket</span>
<Input value={workspaceStorageSetting.s3Config?.bucket} placeholder="" onChange={handleS3ConfigBucketChanged} />
</div>
<div className="w-full flex flex-row justify-between items-center">
<span className="text-gray-700 dark:text-gray-500 mr-1">PrefixUrl</span>
<Input value={workspaceStorageSetting.s3Config?.prefixUrl} placeholder="" onChange={handleS3ConfigPrefixUrlChanged} />
</div>
</>
)}
<div>
Expand Down