Commit b0aad6f6 authored by Steven's avatar Steven

chore: tweak resource payload

parent 0c251f9a
...@@ -1850,6 +1850,20 @@ definitions: ...@@ -1850,6 +1850,20 @@ definitions:
expiresAt: expiresAt:
type: string type: string
format: date-time format: date-time
WorkspaceStorageSettingS3Config:
type: object
properties:
accessKeyId:
type: string
accessKeySecret:
type: string
endpoint:
type: string
region:
type: string
bucket:
type: string
title: 'Reference: https://developers.cloudflare.com/r2/examples/aws/aws-sdk-go/'
apiHttpBody: apiHttpBody:
type: object type: object
properties: properties:
...@@ -2086,22 +2100,8 @@ definitions: ...@@ -2086,22 +2100,8 @@ definitions:
format: int64 format: int64
description: The max upload size in megabytes. description: The max upload size in megabytes.
s3Config: s3Config:
$ref: '#/definitions/apiv1WorkspaceStorageSettingS3Config' $ref: '#/definitions/WorkspaceStorageSettingS3Config'
description: The S3 config. description: The S3 config.
apiv1WorkspaceStorageSettingS3Config:
type: object
properties:
accessKeyId:
type: string
accessKeySecret:
type: string
endpoint:
type: string
region:
type: string
bucket:
type: string
title: 'Reference: https://developers.cloudflare.com/r2/examples/aws/aws-sdk-go/'
apiv1WorkspaceStorageSettingStorageType: apiv1WorkspaceStorageSettingStorageType:
type: string type: string
enum: enum:
......
...@@ -20,7 +20,7 @@ type Client struct { ...@@ -20,7 +20,7 @@ type Client struct {
Bucket *string Bucket *string
} }
func NewClient(ctx context.Context, s3Config *storepb.WorkspaceStorageSetting_S3Config) (*Client, error) { func NewClient(ctx context.Context, s3Config *storepb.StorageS3Config) (*Client, error) {
resolver := aws.EndpointResolverWithOptionsFunc(func(service, region string, options ...any) (aws.Endpoint, error) { resolver := aws.EndpointResolverWithOptionsFunc(func(service, region string, options ...any) (aws.Endpoint, error) {
return aws.Endpoint{ return aws.Endpoint{
URL: s3Config.Endpoint, URL: s3Config.Endpoint,
......
...@@ -145,11 +145,12 @@ type ResourcePayload_S3Object struct { ...@@ -145,11 +145,12 @@ type ResourcePayload_S3Object struct {
sizeCache protoimpl.SizeCache sizeCache protoimpl.SizeCache
unknownFields protoimpl.UnknownFields unknownFields protoimpl.UnknownFields
S3Config *StorageS3Config `protobuf:"bytes,1,opt,name=s3_config,json=s3Config,proto3" json:"s3_config,omitempty"`
// key is the S3 object key. // key is the S3 object key.
Key string `protobuf:"bytes,1,opt,name=key,proto3" json:"key,omitempty"` Key string `protobuf:"bytes,2,opt,name=key,proto3" json:"key,omitempty"`
// last_presigned_time is the last time the object was presigned. // last_presigned_time is the last time the object was presigned.
// This is used to determine if the presigned URL is still valid. // This is used to determine if the presigned URL is still valid.
LastPresignedTime *timestamppb.Timestamp `protobuf:"bytes,2,opt,name=last_presigned_time,json=lastPresignedTime,proto3" json:"last_presigned_time,omitempty"` LastPresignedTime *timestamppb.Timestamp `protobuf:"bytes,3,opt,name=last_presigned_time,json=lastPresignedTime,proto3" json:"last_presigned_time,omitempty"`
} }
func (x *ResourcePayload_S3Object) Reset() { func (x *ResourcePayload_S3Object) Reset() {
...@@ -184,6 +185,13 @@ func (*ResourcePayload_S3Object) Descriptor() ([]byte, []int) { ...@@ -184,6 +185,13 @@ func (*ResourcePayload_S3Object) Descriptor() ([]byte, []int) {
return file_store_resource_proto_rawDescGZIP(), []int{0, 0} return file_store_resource_proto_rawDescGZIP(), []int{0, 0}
} }
func (x *ResourcePayload_S3Object) GetS3Config() *StorageS3Config {
if x != nil {
return x.S3Config
}
return nil
}
func (x *ResourcePayload_S3Object) GetKey() string { func (x *ResourcePayload_S3Object) GetKey() string {
if x != nil { if x != nil {
return x.Key return x.Key
...@@ -205,36 +213,41 @@ var file_store_resource_proto_rawDesc = []byte{ ...@@ -205,36 +213,41 @@ var file_store_resource_proto_rawDesc = []byte{
0x2e, 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x12, 0x0b, 0x6d, 0x65, 0x6d, 0x6f, 0x73, 0x2e, 0x73, 0x74, 0x2e, 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x12, 0x0b, 0x6d, 0x65, 0x6d, 0x6f, 0x73, 0x2e, 0x73, 0x74,
0x6f, 0x72, 0x65, 0x1a, 0x1f, 0x67, 0x6f, 0x6f, 0x67, 0x6c, 0x65, 0x2f, 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x72, 0x65, 0x1a, 0x1f, 0x67, 0x6f, 0x6f, 0x67, 0x6c, 0x65, 0x2f, 0x70, 0x72, 0x6f, 0x74,
0x6f, 0x62, 0x75, 0x66, 0x2f, 0x74, 0x69, 0x6d, 0x65, 0x73, 0x74, 0x61, 0x6d, 0x70, 0x2e, 0x70, 0x6f, 0x62, 0x75, 0x66, 0x2f, 0x74, 0x69, 0x6d, 0x65, 0x73, 0x74, 0x61, 0x6d, 0x70, 0x2e, 0x70,
0x72, 0x6f, 0x74, 0x6f, 0x22, 0xcc, 0x01, 0x0a, 0x0f, 0x52, 0x65, 0x73, 0x6f, 0x75, 0x72, 0x63, 0x72, 0x6f, 0x74, 0x6f, 0x1a, 0x1d, 0x73, 0x74, 0x6f, 0x72, 0x65, 0x2f, 0x77, 0x6f, 0x72, 0x6b,
0x65, 0x50, 0x61, 0x79, 0x6c, 0x6f, 0x61, 0x64, 0x12, 0x44, 0x0a, 0x09, 0x73, 0x33, 0x5f, 0x6f, 0x73, 0x70, 0x61, 0x63, 0x65, 0x5f, 0x73, 0x65, 0x74, 0x74, 0x69, 0x6e, 0x67, 0x2e, 0x70, 0x72,
0x62, 0x6a, 0x65, 0x63, 0x74, 0x18, 0x01, 0x20, 0x01, 0x28, 0x0b, 0x32, 0x25, 0x2e, 0x6d, 0x65, 0x6f, 0x74, 0x6f, 0x22, 0x88, 0x02, 0x0a, 0x0f, 0x52, 0x65, 0x73, 0x6f, 0x75, 0x72, 0x63, 0x65,
0x6d, 0x6f, 0x73, 0x2e, 0x73, 0x74, 0x6f, 0x72, 0x65, 0x2e, 0x52, 0x65, 0x73, 0x6f, 0x75, 0x72, 0x50, 0x61, 0x79, 0x6c, 0x6f, 0x61, 0x64, 0x12, 0x44, 0x0a, 0x09, 0x73, 0x33, 0x5f, 0x6f, 0x62,
0x63, 0x65, 0x50, 0x61, 0x79, 0x6c, 0x6f, 0x61, 0x64, 0x2e, 0x53, 0x33, 0x4f, 0x62, 0x6a, 0x65, 0x6a, 0x65, 0x63, 0x74, 0x18, 0x01, 0x20, 0x01, 0x28, 0x0b, 0x32, 0x25, 0x2e, 0x6d, 0x65, 0x6d,
0x63, 0x74, 0x48, 0x00, 0x52, 0x08, 0x73, 0x33, 0x4f, 0x62, 0x6a, 0x65, 0x63, 0x74, 0x1a, 0x68, 0x6f, 0x73, 0x2e, 0x73, 0x74, 0x6f, 0x72, 0x65, 0x2e, 0x52, 0x65, 0x73, 0x6f, 0x75, 0x72, 0x63,
0x0a, 0x08, 0x53, 0x33, 0x4f, 0x62, 0x6a, 0x65, 0x63, 0x74, 0x12, 0x10, 0x0a, 0x03, 0x6b, 0x65, 0x65, 0x50, 0x61, 0x79, 0x6c, 0x6f, 0x61, 0x64, 0x2e, 0x53, 0x33, 0x4f, 0x62, 0x6a, 0x65, 0x63,
0x79, 0x18, 0x01, 0x20, 0x01, 0x28, 0x09, 0x52, 0x03, 0x6b, 0x65, 0x79, 0x12, 0x4a, 0x0a, 0x13, 0x74, 0x48, 0x00, 0x52, 0x08, 0x73, 0x33, 0x4f, 0x62, 0x6a, 0x65, 0x63, 0x74, 0x1a, 0xa3, 0x01,
0x6c, 0x61, 0x73, 0x74, 0x5f, 0x70, 0x72, 0x65, 0x73, 0x69, 0x67, 0x6e, 0x65, 0x64, 0x5f, 0x74, 0x0a, 0x08, 0x53, 0x33, 0x4f, 0x62, 0x6a, 0x65, 0x63, 0x74, 0x12, 0x39, 0x0a, 0x09, 0x73, 0x33,
0x69, 0x6d, 0x65, 0x18, 0x02, 0x20, 0x01, 0x28, 0x0b, 0x32, 0x1a, 0x2e, 0x67, 0x6f, 0x6f, 0x67, 0x5f, 0x63, 0x6f, 0x6e, 0x66, 0x69, 0x67, 0x18, 0x01, 0x20, 0x01, 0x28, 0x0b, 0x32, 0x1c, 0x2e,
0x6c, 0x65, 0x2e, 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x62, 0x75, 0x66, 0x2e, 0x54, 0x69, 0x6d, 0x65, 0x6d, 0x65, 0x6d, 0x6f, 0x73, 0x2e, 0x73, 0x74, 0x6f, 0x72, 0x65, 0x2e, 0x53, 0x74, 0x6f, 0x72,
0x73, 0x74, 0x61, 0x6d, 0x70, 0x52, 0x11, 0x6c, 0x61, 0x73, 0x74, 0x50, 0x72, 0x65, 0x73, 0x69, 0x61, 0x67, 0x65, 0x53, 0x33, 0x43, 0x6f, 0x6e, 0x66, 0x69, 0x67, 0x52, 0x08, 0x73, 0x33, 0x43,
0x67, 0x6e, 0x65, 0x64, 0x54, 0x69, 0x6d, 0x65, 0x42, 0x09, 0x0a, 0x07, 0x70, 0x61, 0x79, 0x6c, 0x6f, 0x6e, 0x66, 0x69, 0x67, 0x12, 0x10, 0x0a, 0x03, 0x6b, 0x65, 0x79, 0x18, 0x02, 0x20, 0x01,
0x6f, 0x61, 0x64, 0x2a, 0x5d, 0x0a, 0x13, 0x52, 0x65, 0x73, 0x6f, 0x75, 0x72, 0x63, 0x65, 0x53, 0x28, 0x09, 0x52, 0x03, 0x6b, 0x65, 0x79, 0x12, 0x4a, 0x0a, 0x13, 0x6c, 0x61, 0x73, 0x74, 0x5f,
0x74, 0x6f, 0x72, 0x61, 0x67, 0x65, 0x54, 0x79, 0x70, 0x65, 0x12, 0x25, 0x0a, 0x21, 0x52, 0x45, 0x70, 0x72, 0x65, 0x73, 0x69, 0x67, 0x6e, 0x65, 0x64, 0x5f, 0x74, 0x69, 0x6d, 0x65, 0x18, 0x03,
0x53, 0x4f, 0x55, 0x52, 0x43, 0x45, 0x5f, 0x53, 0x54, 0x4f, 0x52, 0x41, 0x47, 0x45, 0x5f, 0x54, 0x20, 0x01, 0x28, 0x0b, 0x32, 0x1a, 0x2e, 0x67, 0x6f, 0x6f, 0x67, 0x6c, 0x65, 0x2e, 0x70, 0x72,
0x59, 0x50, 0x45, 0x5f, 0x55, 0x4e, 0x53, 0x50, 0x45, 0x43, 0x49, 0x46, 0x49, 0x45, 0x44, 0x10, 0x6f, 0x74, 0x6f, 0x62, 0x75, 0x66, 0x2e, 0x54, 0x69, 0x6d, 0x65, 0x73, 0x74, 0x61, 0x6d, 0x70,
0x00, 0x12, 0x09, 0x0a, 0x05, 0x4c, 0x4f, 0x43, 0x41, 0x4c, 0x10, 0x01, 0x12, 0x06, 0x0a, 0x02, 0x52, 0x11, 0x6c, 0x61, 0x73, 0x74, 0x50, 0x72, 0x65, 0x73, 0x69, 0x67, 0x6e, 0x65, 0x64, 0x54,
0x53, 0x33, 0x10, 0x02, 0x12, 0x0c, 0x0a, 0x08, 0x45, 0x58, 0x54, 0x45, 0x52, 0x4e, 0x41, 0x4c, 0x69, 0x6d, 0x65, 0x42, 0x09, 0x0a, 0x07, 0x70, 0x61, 0x79, 0x6c, 0x6f, 0x61, 0x64, 0x2a, 0x5d,
0x10, 0x03, 0x42, 0x98, 0x01, 0x0a, 0x0f, 0x63, 0x6f, 0x6d, 0x2e, 0x6d, 0x65, 0x6d, 0x6f, 0x73, 0x0a, 0x13, 0x52, 0x65, 0x73, 0x6f, 0x75, 0x72, 0x63, 0x65, 0x53, 0x74, 0x6f, 0x72, 0x61, 0x67,
0x2e, 0x73, 0x74, 0x6f, 0x72, 0x65, 0x42, 0x0d, 0x52, 0x65, 0x73, 0x6f, 0x75, 0x72, 0x63, 0x65, 0x65, 0x54, 0x79, 0x70, 0x65, 0x12, 0x25, 0x0a, 0x21, 0x52, 0x45, 0x53, 0x4f, 0x55, 0x52, 0x43,
0x50, 0x72, 0x6f, 0x74, 0x6f, 0x50, 0x01, 0x5a, 0x29, 0x67, 0x69, 0x74, 0x68, 0x75, 0x62, 0x2e, 0x45, 0x5f, 0x53, 0x54, 0x4f, 0x52, 0x41, 0x47, 0x45, 0x5f, 0x54, 0x59, 0x50, 0x45, 0x5f, 0x55,
0x63, 0x6f, 0x6d, 0x2f, 0x75, 0x73, 0x65, 0x6d, 0x65, 0x6d, 0x6f, 0x73, 0x2f, 0x6d, 0x65, 0x6d, 0x4e, 0x53, 0x50, 0x45, 0x43, 0x49, 0x46, 0x49, 0x45, 0x44, 0x10, 0x00, 0x12, 0x09, 0x0a, 0x05,
0x6f, 0x73, 0x2f, 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x2f, 0x67, 0x65, 0x6e, 0x2f, 0x73, 0x74, 0x6f, 0x4c, 0x4f, 0x43, 0x41, 0x4c, 0x10, 0x01, 0x12, 0x06, 0x0a, 0x02, 0x53, 0x33, 0x10, 0x02, 0x12,
0x72, 0x65, 0xa2, 0x02, 0x03, 0x4d, 0x53, 0x58, 0xaa, 0x02, 0x0b, 0x4d, 0x65, 0x6d, 0x6f, 0x73, 0x0c, 0x0a, 0x08, 0x45, 0x58, 0x54, 0x45, 0x52, 0x4e, 0x41, 0x4c, 0x10, 0x03, 0x42, 0x98, 0x01,
0x2e, 0x53, 0x74, 0x6f, 0x72, 0x65, 0xca, 0x02, 0x0b, 0x4d, 0x65, 0x6d, 0x6f, 0x73, 0x5c, 0x53, 0x0a, 0x0f, 0x63, 0x6f, 0x6d, 0x2e, 0x6d, 0x65, 0x6d, 0x6f, 0x73, 0x2e, 0x73, 0x74, 0x6f, 0x72,
0x74, 0x6f, 0x72, 0x65, 0xe2, 0x02, 0x17, 0x4d, 0x65, 0x6d, 0x6f, 0x73, 0x5c, 0x53, 0x74, 0x6f, 0x65, 0x42, 0x0d, 0x52, 0x65, 0x73, 0x6f, 0x75, 0x72, 0x63, 0x65, 0x50, 0x72, 0x6f, 0x74, 0x6f,
0x72, 0x65, 0x5c, 0x47, 0x50, 0x42, 0x4d, 0x65, 0x74, 0x61, 0x64, 0x61, 0x74, 0x61, 0xea, 0x02, 0x50, 0x01, 0x5a, 0x29, 0x67, 0x69, 0x74, 0x68, 0x75, 0x62, 0x2e, 0x63, 0x6f, 0x6d, 0x2f, 0x75,
0x0c, 0x4d, 0x65, 0x6d, 0x6f, 0x73, 0x3a, 0x3a, 0x53, 0x74, 0x6f, 0x72, 0x65, 0x62, 0x06, 0x70, 0x73, 0x65, 0x6d, 0x65, 0x6d, 0x6f, 0x73, 0x2f, 0x6d, 0x65, 0x6d, 0x6f, 0x73, 0x2f, 0x70, 0x72,
0x72, 0x6f, 0x74, 0x6f, 0x33, 0x6f, 0x74, 0x6f, 0x2f, 0x67, 0x65, 0x6e, 0x2f, 0x73, 0x74, 0x6f, 0x72, 0x65, 0xa2, 0x02, 0x03,
0x4d, 0x53, 0x58, 0xaa, 0x02, 0x0b, 0x4d, 0x65, 0x6d, 0x6f, 0x73, 0x2e, 0x53, 0x74, 0x6f, 0x72,
0x65, 0xca, 0x02, 0x0b, 0x4d, 0x65, 0x6d, 0x6f, 0x73, 0x5c, 0x53, 0x74, 0x6f, 0x72, 0x65, 0xe2,
0x02, 0x17, 0x4d, 0x65, 0x6d, 0x6f, 0x73, 0x5c, 0x53, 0x74, 0x6f, 0x72, 0x65, 0x5c, 0x47, 0x50,
0x42, 0x4d, 0x65, 0x74, 0x61, 0x64, 0x61, 0x74, 0x61, 0xea, 0x02, 0x0c, 0x4d, 0x65, 0x6d, 0x6f,
0x73, 0x3a, 0x3a, 0x53, 0x74, 0x6f, 0x72, 0x65, 0x62, 0x06, 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x33,
} }
var ( var (
...@@ -255,16 +268,18 @@ var file_store_resource_proto_goTypes = []interface{}{ ...@@ -255,16 +268,18 @@ var file_store_resource_proto_goTypes = []interface{}{
(ResourceStorageType)(0), // 0: memos.store.ResourceStorageType (ResourceStorageType)(0), // 0: memos.store.ResourceStorageType
(*ResourcePayload)(nil), // 1: memos.store.ResourcePayload (*ResourcePayload)(nil), // 1: memos.store.ResourcePayload
(*ResourcePayload_S3Object)(nil), // 2: memos.store.ResourcePayload.S3Object (*ResourcePayload_S3Object)(nil), // 2: memos.store.ResourcePayload.S3Object
(*timestamppb.Timestamp)(nil), // 3: google.protobuf.Timestamp (*StorageS3Config)(nil), // 3: memos.store.StorageS3Config
(*timestamppb.Timestamp)(nil), // 4: google.protobuf.Timestamp
} }
var file_store_resource_proto_depIdxs = []int32{ var file_store_resource_proto_depIdxs = []int32{
2, // 0: memos.store.ResourcePayload.s3_object:type_name -> memos.store.ResourcePayload.S3Object 2, // 0: memos.store.ResourcePayload.s3_object:type_name -> memos.store.ResourcePayload.S3Object
3, // 1: memos.store.ResourcePayload.S3Object.last_presigned_time:type_name -> google.protobuf.Timestamp 3, // 1: memos.store.ResourcePayload.S3Object.s3_config:type_name -> memos.store.StorageS3Config
2, // [2:2] is the sub-list for method output_type 4, // 2: memos.store.ResourcePayload.S3Object.last_presigned_time:type_name -> google.protobuf.Timestamp
2, // [2:2] is the sub-list for method input_type 3, // [3:3] is the sub-list for method output_type
2, // [2:2] is the sub-list for extension type_name 3, // [3:3] is the sub-list for method input_type
2, // [2:2] is the sub-list for extension extendee 3, // [3:3] is the sub-list for extension type_name
0, // [0:2] is the sub-list for field type_name 3, // [3:3] is the sub-list for extension extendee
0, // [0:3] is the sub-list for field type_name
} }
func init() { file_store_resource_proto_init() } func init() { file_store_resource_proto_init() }
...@@ -272,6 +287,7 @@ func file_store_resource_proto_init() { ...@@ -272,6 +287,7 @@ func file_store_resource_proto_init() {
if File_store_resource_proto != nil { if File_store_resource_proto != nil {
return return
} }
file_store_workspace_setting_proto_init()
if !protoimpl.UnsafeEnabled { if !protoimpl.UnsafeEnabled {
file_store_resource_proto_msgTypes[0].Exporter = func(v interface{}, i int) interface{} { file_store_resource_proto_msgTypes[0].Exporter = func(v interface{}, i int) interface{} {
switch v := v.(*ResourcePayload); i { switch v := v.(*ResourcePayload); i {
......
This diff is collapsed.
...@@ -3,6 +3,7 @@ syntax = "proto3"; ...@@ -3,6 +3,7 @@ syntax = "proto3";
package memos.store; package memos.store;
import "google/protobuf/timestamp.proto"; import "google/protobuf/timestamp.proto";
import "store/workspace_setting.proto";
option go_package = "gen/store"; option go_package = "gen/store";
...@@ -19,10 +20,11 @@ message ResourcePayload { ...@@ -19,10 +20,11 @@ message ResourcePayload {
} }
message S3Object { message S3Object {
StorageS3Config s3_config = 1;
// key is the S3 object key. // key is the S3 object key.
string key = 1; string key = 2;
// last_presigned_time is the last time the object was presigned. // last_presigned_time is the last time the object was presigned.
// This is used to determine if the presigned URL is still valid. // This is used to determine if the presigned URL is still valid.
google.protobuf.Timestamp last_presigned_time = 2; google.protobuf.Timestamp last_presigned_time = 3;
} }
} }
...@@ -70,16 +70,17 @@ message WorkspaceStorageSetting { ...@@ -70,16 +70,17 @@ message WorkspaceStorageSetting {
string filepath_template = 2; string filepath_template = 2;
// The max upload size in megabytes. // The max upload size in megabytes.
int64 upload_size_limit_mb = 3; int64 upload_size_limit_mb = 3;
// Reference: https://developers.cloudflare.com/r2/examples/aws/aws-sdk-go/ // The S3 config.
message S3Config { StorageS3Config s3_config = 4;
}
// Reference: https://developers.cloudflare.com/r2/examples/aws/aws-sdk-go/
message StorageS3Config {
string access_key_id = 1; string access_key_id = 1;
string access_key_secret = 2; string access_key_secret = 2;
string endpoint = 3; string endpoint = 3;
string region = 4; string region = 4;
string bucket = 5; string bucket = 5;
}
// The S3 config.
S3Config s3_config = 4;
} }
message WorkspaceMemoRelatedSetting { message WorkspaceMemoRelatedSetting {
......
...@@ -93,7 +93,7 @@ func (s *APIV1Service) ListMemos(ctx context.Context, request *v1pb.ListMemosReq ...@@ -93,7 +93,7 @@ func (s *APIV1Service) ListMemos(ctx context.Context, request *v1pb.ListMemosReq
ExcludeComments: true, ExcludeComments: true,
} }
if err := s.buildMemoFindWithFilter(ctx, memoFind, request.Filter); err != nil { if err := s.buildMemoFindWithFilter(ctx, memoFind, request.Filter); err != nil {
return nil, status.Errorf(codes.InvalidArgument, "failed to build find memos with filter") return nil, status.Errorf(codes.InvalidArgument, "failed to build find memos with filter: %v", err)
} }
var limit, offset int var limit, offset int
...@@ -151,12 +151,12 @@ func (s *APIV1Service) SearchMemos(ctx context.Context, request *v1pb.SearchMemo ...@@ -151,12 +151,12 @@ func (s *APIV1Service) SearchMemos(ctx context.Context, request *v1pb.SearchMemo
} }
err := s.buildMemoFindWithFilter(ctx, memoFind, request.Filter) err := s.buildMemoFindWithFilter(ctx, memoFind, request.Filter)
if err != nil { if err != nil {
return nil, status.Errorf(codes.InvalidArgument, "failed to build find memos with filter") return nil, status.Errorf(codes.InvalidArgument, "failed to build find memos with filter: %v", err)
} }
memos, err := s.Store.ListMemos(ctx, memoFind) memos, err := s.Store.ListMemos(ctx, memoFind)
if err != nil { if err != nil {
return nil, status.Errorf(codes.Internal, "failed to search memos") return nil, status.Errorf(codes.Internal, "failed to search memos: %v", err)
} }
memoMessages := []*v1pb.Memo{} memoMessages := []*v1pb.Memo{}
...@@ -519,7 +519,7 @@ func (s *APIV1Service) ExportMemos(ctx context.Context, request *v1pb.ExportMemo ...@@ -519,7 +519,7 @@ func (s *APIV1Service) ExportMemos(ctx context.Context, request *v1pb.ExportMemo
ExcludeComments: true, ExcludeComments: true,
} }
if err := s.buildMemoFindWithFilter(ctx, memoFind, request.Filter); err != nil { if err := s.buildMemoFindWithFilter(ctx, memoFind, request.Filter); err != nil {
return nil, status.Errorf(codes.Internal, "failed to build find memos with filter: %v", err) return nil, status.Errorf(codes.InvalidArgument, "failed to build find memos with filter: %v", err)
} }
memos, err := s.Store.ListMemos(ctx, memoFind) memos, err := s.Store.ListMemos(ctx, memoFind)
...@@ -610,7 +610,7 @@ func (s *APIV1Service) ListMemoTags(ctx context.Context, request *v1pb.ListMemoT ...@@ -610,7 +610,7 @@ func (s *APIV1Service) ListMemoTags(ctx context.Context, request *v1pb.ListMemoT
memoFind.ID = &memoID memoFind.ID = &memoID
} }
if err := s.buildMemoFindWithFilter(ctx, memoFind, request.Filter); err != nil { if err := s.buildMemoFindWithFilter(ctx, memoFind, request.Filter); err != nil {
return nil, status.Errorf(codes.Internal, "failed to build find memos with filter: %v", err) return nil, status.Errorf(codes.InvalidArgument, "failed to build find memos with filter: %v", err)
} }
memos, err := s.Store.ListMemos(ctx, memoFind) memos, err := s.Store.ListMemos(ctx, memoFind)
......
...@@ -373,6 +373,7 @@ func SaveResourceBlob(ctx context.Context, s *store.Store, create *store.Resourc ...@@ -373,6 +373,7 @@ func SaveResourceBlob(ctx context.Context, s *store.Store, create *store.Resourc
create.Payload = &storepb.ResourcePayload{ create.Payload = &storepb.ResourcePayload{
Payload: &storepb.ResourcePayload_S3Object_{ Payload: &storepb.ResourcePayload_S3Object_{
S3Object: &storepb.ResourcePayload_S3Object{ S3Object: &storepb.ResourcePayload_S3Object{
S3Config: s3Config,
Key: key, Key: key,
LastPresignedTime: timestamppb.New(time.Now()), LastPresignedTime: timestamppb.New(time.Now()),
}, },
......
...@@ -193,7 +193,7 @@ func convertWorkspaceStorageSettingToStore(setting *v1pb.WorkspaceStorageSetting ...@@ -193,7 +193,7 @@ func convertWorkspaceStorageSettingToStore(setting *v1pb.WorkspaceStorageSetting
UploadSizeLimitMb: setting.UploadSizeLimitMb, UploadSizeLimitMb: setting.UploadSizeLimitMb,
} }
if setting.S3Config != nil { if setting.S3Config != nil {
settingpb.S3Config = &storepb.WorkspaceStorageSetting_S3Config{ settingpb.S3Config = &storepb.StorageS3Config{
AccessKeyId: setting.S3Config.AccessKeyId, AccessKeyId: setting.S3Config.AccessKeyId,
AccessKeySecret: setting.S3Config.AccessKeySecret, AccessKeySecret: setting.S3Config.AccessKeySecret,
Endpoint: setting.S3Config.Endpoint, Endpoint: setting.S3Config.Endpoint,
......
...@@ -2,6 +2,7 @@ package s3objectpresigner ...@@ -2,6 +2,7 @@ package s3objectpresigner
import ( import (
"context" "context"
"log/slog"
"time" "time"
"google.golang.org/protobuf/types/known/timestamppb" "google.golang.org/protobuf/types/known/timestamppb"
...@@ -28,15 +29,6 @@ func (p *S3ObjectPresigner) CheckAndPresign(ctx context.Context) { ...@@ -28,15 +29,6 @@ func (p *S3ObjectPresigner) CheckAndPresign(ctx context.Context) {
return return
} }
s3Config := workspaceStorageSetting.GetS3Config()
if s3Config == nil {
return
}
s3Client, err := s3.NewClient(ctx, s3Config)
if err != nil {
return
}
s3StorageType := storepb.ResourceStorageType_S3 s3StorageType := storepb.ResourceStorageType_S3
resources, err := p.Store.ListResources(ctx, &store.FindResource{ resources, err := p.Store.ListResources(ctx, &store.FindResource{
GetBlob: false, GetBlob: false,
...@@ -59,10 +51,27 @@ func (p *S3ObjectPresigner) CheckAndPresign(ctx context.Context) { ...@@ -59,10 +51,27 @@ func (p *S3ObjectPresigner) CheckAndPresign(ctx context.Context) {
continue continue
} }
} }
s3Config := workspaceStorageSetting.GetS3Config()
if s3ObjectPayload.S3Config != nil {
s3Config = s3ObjectPayload.S3Config
}
if s3Config == nil {
slog.Error("S3 config is not found")
continue
}
s3Client, err := s3.NewClient(ctx, s3Config)
if err != nil {
slog.Error("Failed to create S3 client", slog.Any("err", err))
continue
}
presignURL, err := s3Client.PresignGetObject(ctx, s3ObjectPayload.Key) presignURL, err := s3Client.PresignGetObject(ctx, s3ObjectPayload.Key)
if err != nil { if err != nil {
return return
} }
s3ObjectPayload.S3Config = s3Config
s3ObjectPayload.LastPresignedTime = timestamppb.New(time.Now()) s3ObjectPayload.LastPresignedTime = timestamppb.New(time.Now())
if err := p.Store.UpdateResource(ctx, &store.UpdateResource{ if err := p.Store.UpdateResource(ctx, &store.UpdateResource{
Reference: &presignURL, Reference: &presignURL,
......
...@@ -129,10 +129,14 @@ func (s *Store) DeleteResource(ctx context.Context, delete *DeleteResource) erro ...@@ -129,10 +129,14 @@ func (s *Store) DeleteResource(ctx context.Context, delete *DeleteResource) erro
if err != nil { if err != nil {
return errors.Wrap(err, "failed to get workspace storage setting") return errors.Wrap(err, "failed to get workspace storage setting")
} }
s3Config := workspaceStorageSetting.S3Config s3Config := s3ObjectPayload.S3Config
if s3Config == nil { if s3Config == nil {
return errors.Errorf("No actived external storage found") if workspaceStorageSetting.S3Config == nil {
return errors.Errorf("S3 config is not found")
} }
s3Config = workspaceStorageSetting.S3Config
}
s3Client, err := s3.NewClient(ctx, s3Config) s3Client, err := s3.NewClient(ctx, s3Config)
if err != nil { if err != nil {
return errors.Wrap(err, "Failed to create s3 client") return errors.Wrap(err, "Failed to create s3 client")
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment