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 6fa7199
Show file tree
Hide file tree
Showing 8 changed files with 178 additions and 140 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 = s3Config.ForcePathStyle
})
return &Client{
Client: client,
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 @@ -89,6 +89,7 @@ message WorkspaceStorageSetting {
string endpoint = 3;
string region = 4;
string bucket = 5;
bool force_path_style = 6;
}
// The S3 config.
S3Config s3_config = 4;
Expand Down
176 changes: 93 additions & 83 deletions proto/gen/api/v1/workspace_setting_service.pb.go

Large diffs are not rendered by default.

2 changes: 2 additions & 0 deletions proto/gen/apidocs.swagger.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -1864,6 +1864,8 @@ definitions:
type: string
bucket:
type: string
forcePathStyle:
type: boolean
title: 'Reference: https://developers.cloudflare.com/r2/examples/aws/aws-sdk-go/'
apiHttpBody:
type: object
Expand Down
121 changes: 66 additions & 55 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 @@ -91,6 +91,7 @@ message StorageS3Config {
string endpoint = 3;
string region = 4;
string bucket = 5;
bool force_path_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,
ForcePathStyle: settingpb.S3Config.ForcePathStyle,
}
}
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,
ForcePathStyle: setting.S3Config.ForcePathStyle,
}
}
return settingpb
Expand Down
14 changes: 12 additions & 2 deletions web/src/components/Settings/StorageSection.tsx
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
import { Divider, List, ListItem, Radio, RadioGroup, Tooltip } from "@mui/joy";
import { Divider, List, ListItem, Radio, RadioGroup, Tooltip, Switch } 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";
Expand Down Expand Up @@ -98,6 +98,12 @@ const StorageSection = () => {
handlePartialS3ConfigChanged({ bucket: event.target.value });
};

const handleS3ConfigUsePathStyleChanged = (event: React.ChangeEvent<HTMLInputElement>) => {
handlePartialS3ConfigChanged({
forcePathStyle: event.target.checked,
});
};

const handleStorageTypeChanged = async (storageType: WorkspaceStorageSetting_StorageType) => {
const update: WorkspaceStorageSetting = {
...workspaceStorageSetting,
Expand Down Expand Up @@ -174,6 +180,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">Force Path Style</span>
<Switch checked={workspaceStorageSetting.s3Config?.forcePathStyle} onChange={handleS3ConfigUsePathStyleChanged} />
</div>
</>
)}
<div>
Expand Down

0 comments on commit 6fa7199

Please sign in to comment.