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: support setting the url style of s3 store #4304

Merged
merged 1 commit into from
Jan 21, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
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
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.UsePathStyle
})
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 use_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
usePathStyle:
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 use_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,
UsePathStyle: settingpb.S3Config.UsePathStyle,
}
}
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,
UsePathStyle: setting.S3Config.UsePathStyle,
}
}
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({
usePathStyle: 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">Use Path Style</span>
<Switch checked={workspaceStorageSetting.s3Config?.usePathStyle} onChange={handleS3ConfigUsePathStyleChanged} />
</div>
</>
)}
<div>
Expand Down
Loading