Skip to content

Commit

Permalink
improve: support setting the url style of s3 store
Browse files Browse the repository at this point in the history
Signed-off-by: ComixHe <[email protected]>
  • Loading branch information
ComixHe committed Jan 21, 2025
1 parent 702c092 commit 5488218
Show file tree
Hide file tree
Showing 8 changed files with 317 additions and 149 deletions.
1 change: 1 addition & 0 deletions plugin/storage/s3/s3.go
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ func NewClient(ctx context.Context, s3Config *storepb.StorageS3Config) (*Client,

client := s3.NewFromConfig(cfg, func(o *s3.Options) {
o.BaseEndpoint = aws.String(s3Config.Endpoint)
o.UsePathStyle = *aws.Bool(s3Config.UrlStyle == storepb.StorageS3Config_PATH)
})
return &Client{
Client: client,
Expand Down
6 changes: 6 additions & 0 deletions proto/api/v1/workspace_setting_service.proto
Original file line number Diff line number Diff line change
Expand Up @@ -84,11 +84,17 @@ message WorkspaceStorageSetting {
int64 upload_size_limit_mb = 3;
// Reference: https://developers.cloudflare.com/r2/examples/aws/aws-sdk-go/
message S3Config {
enum S3URLStyle {
VIRTUAL_HOST = 0;
PATH = 1;
}

string access_key_id = 1;
string access_key_secret = 2;
string endpoint = 3;
string region = 4;
string bucket = 5;
S3URLStyle url_style = 6;
}
// The S3 config.
S3Config s3_config = 4;
Expand Down
302 changes: 183 additions & 119 deletions proto/gen/api/v1/workspace_setting_service.pb.go

Large diffs are not rendered by default.

8 changes: 8 additions & 0 deletions proto/gen/apidocs.swagger.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -1864,7 +1864,15 @@ definitions:
type: string
bucket:
type: string
urlStyle:
$ref: '#/definitions/WorkspaceStorageSettingS3ConfigS3URLStyle'
title: 'Reference: https://developers.cloudflare.com/r2/examples/aws/aws-sdk-go/'
WorkspaceStorageSettingS3ConfigS3URLStyle:
type: string
enum:
- VIRTUAL_HOST
- PATH
default: VIRTUAL_HOST
apiHttpBody:
type: object
properties:
Expand Down
119 changes: 91 additions & 28 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.

6 changes: 6 additions & 0 deletions proto/store/workspace_setting.proto
Original file line number Diff line number Diff line change
Expand Up @@ -86,11 +86,17 @@ message WorkspaceStorageSetting {

// Reference: https://developers.cloudflare.com/r2/examples/aws/aws-sdk-go/
message StorageS3Config {
enum S3URLStyle {
VIRTUAL_HOST = 0;
PATH = 1;
}

string access_key_id = 1;
string access_key_secret = 2;
string endpoint = 3;
string region = 4;
string bucket = 5;
S3URLStyle url_style = 6;
}

message WorkspaceMemoRelatedSetting {
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 @@ -196,6 +196,7 @@ func convertWorkspaceStorageSettingFromStore(settingpb *storepb.WorkspaceStorage
Endpoint: settingpb.S3Config.Endpoint,
Region: settingpb.S3Config.Region,
Bucket: settingpb.S3Config.Bucket,
UrlStyle: v1pb.WorkspaceStorageSetting_S3Config_S3URLStyle(settingpb.S3Config.UrlStyle),
}
}
return setting
Expand All @@ -217,6 +218,7 @@ func convertWorkspaceStorageSettingToStore(setting *v1pb.WorkspaceStorageSetting
Endpoint: setting.S3Config.Endpoint,
Region: setting.S3Config.Region,
Bucket: setting.S3Config.Bucket,
UrlStyle: storepb.StorageS3Config_S3URLStyle(setting.S3Config.UrlStyle),
}
}
return settingpb
Expand Down
22 changes: 20 additions & 2 deletions web/src/components/Settings/StorageSection.tsx
Original file line number Diff line number Diff line change
@@ -1,14 +1,15 @@
import { Divider, List, ListItem, Radio, RadioGroup, Tooltip } from "@mui/joy";
import { Divider, List, ListItem, Radio, RadioGroup, Select, Option, Tooltip } from "@mui/joy";
import { Button, Input } from "@usememos/mui";
import { isEqual } from "lodash-es";
import { HelpCircleIcon } from "lucide-react";
import { useMemo, useState } from "react";
import React, { useMemo, useState } from "react";
import { toast } from "react-hot-toast";
import { Link } from "react-router-dom";
import { workspaceSettingNamePrefix, useWorkspaceSettingStore } from "@/store/v1";
import {
WorkspaceStorageSetting,
WorkspaceStorageSetting_S3Config,
WorkspaceStorageSetting_S3Config_S3URLStyle,
WorkspaceStorageSetting_StorageType,
} from "@/types/proto/api/v1/workspace_setting_service";
import { WorkspaceSettingKey } from "@/types/proto/store/workspace_setting";
Expand Down Expand Up @@ -98,6 +99,16 @@ const StorageSection = () => {
handlePartialS3ConfigChanged({ bucket: event.target.value });
};

const handleS3ConfigUrlStyleChanged = (_: React.SyntheticEvent | null, value: WorkspaceStorageSetting_S3Config_S3URLStyle | null) => {
if (value === null) {
return;
}

handlePartialS3ConfigChanged({
urlStyle: value,
});
};

const handleStorageTypeChanged = async (storageType: WorkspaceStorageSetting_StorageType) => {
const update: WorkspaceStorageSetting = {
...workspaceStorageSetting,
Expand Down Expand Up @@ -174,6 +185,13 @@ 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">URL Style</span>
<Select value={workspaceStorageSetting.s3Config?.urlStyle} placeholder="Select Style" onChange={handleS3ConfigUrlStyleChanged}>
<Option value={WorkspaceStorageSetting_S3Config_S3URLStyle.VIRTUAL_HOST}>VirtualHost</Option>
<Option value={WorkspaceStorageSetting_S3Config_S3URLStyle.PATH}>Path</Option>
</Select>
</div>
</>
)}
<div>
Expand Down

0 comments on commit 5488218

Please sign in to comment.