From ea7e505269b748f2dbb757b6450e79f0a41a1721 Mon Sep 17 00:00:00 2001 From: printlin <32053356+printlin@users.noreply.github.com> Date: Mon, 15 Jul 2024 11:10:04 +0800 Subject: [PATCH] feature: support for Kodo (#2363) * support for Kodo * fix mod bug --- config/openim-rpc-third.yml | 8 ++++++++ go.mod | 19 +++++++++++++++++++ internal/rpc/third/third.go | 3 +++ pkg/common/config/config.go | 33 ++++++++++++++++++++++++--------- 4 files changed, 54 insertions(+), 9 deletions(-) diff --git a/config/openim-rpc-third.yml b/config/openim-rpc-third.yml index bde38ccc4..6fb60f47f 100644 --- a/config/openim-rpc-third.yml +++ b/config/openim-rpc-third.yml @@ -29,4 +29,12 @@ object: accessKeyID: '' accessKeySecret: '' sessionToken: '' + publicRead: false + kodo: + endpoint: "http://s3.cn-south-1.qiniucs.com" + bucket: "kodo-bucket-test" + bucketURL: "http://kodo-bucket-test-oetobfb.qiniudns.com" + accessKeyID: '' + accessKeySecret: '' + sessionToken: '' publicRead: false \ No newline at end of file diff --git a/go.mod b/go.mod index 2111208f2..79af68dbc 100644 --- a/go.mod +++ b/go.mod @@ -53,6 +53,24 @@ require ( cloud.google.com/go/longrunning v0.5.4 // indirect cloud.google.com/go/storage v1.36.0 // indirect github.com/aliyun/aliyun-oss-go-sdk v3.0.2+incompatible // indirect + github.com/aws/aws-sdk-go-v2 v1.23.1 // indirect + github.com/aws/aws-sdk-go-v2/aws/protocol/eventstream v1.5.1 // indirect + github.com/aws/aws-sdk-go-v2/config v1.25.4 // indirect + github.com/aws/aws-sdk-go-v2/credentials v1.16.3 // indirect + github.com/aws/aws-sdk-go-v2/feature/ec2/imds v1.14.5 // indirect + github.com/aws/aws-sdk-go-v2/internal/configsources v1.2.4 // indirect + github.com/aws/aws-sdk-go-v2/internal/endpoints/v2 v2.5.4 // indirect + github.com/aws/aws-sdk-go-v2/internal/ini v1.7.1 // indirect + github.com/aws/aws-sdk-go-v2/internal/v4a v1.2.4 // indirect + github.com/aws/aws-sdk-go-v2/service/internal/accept-encoding v1.10.1 // indirect + github.com/aws/aws-sdk-go-v2/service/internal/checksum v1.2.4 // indirect + github.com/aws/aws-sdk-go-v2/service/internal/presigned-url v1.10.4 // indirect + github.com/aws/aws-sdk-go-v2/service/internal/s3shared v1.16.4 // indirect + github.com/aws/aws-sdk-go-v2/service/s3 v1.43.1 // indirect + github.com/aws/aws-sdk-go-v2/service/sso v1.17.3 // indirect + github.com/aws/aws-sdk-go-v2/service/ssooidc v1.20.1 // indirect + github.com/aws/aws-sdk-go-v2/service/sts v1.25.4 // indirect + github.com/aws/smithy-go v1.17.0 // indirect github.com/beorn7/perks v1.0.1 // indirect github.com/bytedance/sonic v1.9.1 // indirect github.com/cespare/xxhash/v2 v2.2.0 // indirect @@ -118,6 +136,7 @@ require ( github.com/prometheus/client_model v0.5.0 // indirect github.com/prometheus/common v0.45.0 // indirect github.com/prometheus/procfs v0.12.0 // indirect + github.com/qiniu/go-sdk/v7 v7.18.2 // indirect github.com/rcrowley/go-metrics v0.0.0-20201227073835-cf1acfcdf475 // indirect github.com/rs/xid v1.5.0 // indirect github.com/sagikazarmark/locafero v0.4.0 // indirect diff --git a/internal/rpc/third/third.go b/internal/rpc/third/third.go index 7560486a0..b371f5e4e 100644 --- a/internal/rpc/third/third.go +++ b/internal/rpc/third/third.go @@ -33,6 +33,7 @@ import ( "github.com/openimsdk/tools/s3/cos" "github.com/openimsdk/tools/s3/minio" "github.com/openimsdk/tools/s3/oss" + "github.com/openimsdk/tools/s3/kodo" "google.golang.org/grpc" ) @@ -81,6 +82,8 @@ func Start(ctx context.Context, config *Config, client discovery.SvcDiscoveryReg o, err = cos.NewCos(*config.RpcConfig.Object.Cos.Build()) case "oss": o, err = oss.NewOSS(*config.RpcConfig.Object.Oss.Build()) + case "kodo": + o, err = kodo.NewKodo(*config.RpcConfig.Object.Kodo.Build()) default: err = fmt.Errorf("invalid object enable: %s", enable) } diff --git a/pkg/common/config/config.go b/pkg/common/config/config.go index 536e4d547..d8916ad04 100644 --- a/pkg/common/config/config.go +++ b/pkg/common/config/config.go @@ -21,6 +21,7 @@ import ( "github.com/openimsdk/tools/s3/cos" "github.com/openimsdk/tools/s3/minio" "github.com/openimsdk/tools/s3/oss" + "github.com/openimsdk/tools/s3/kodo" "strings" "time" ) @@ -281,15 +282,7 @@ type Third struct { Enable string `mapstructure:"enable"` Cos Cos `mapstructure:"cos"` Oss Oss `mapstructure:"oss"` - Kodo struct { - Endpoint string `mapstructure:"endpoint"` - Bucket string `mapstructure:"bucket"` - BucketURL string `mapstructure:"bucketURL"` - AccessKeyID string `mapstructure:"accessKeyID"` - AccessKeySecret string `mapstructure:"accessKeySecret"` - SessionToken string `mapstructure:"sessionToken"` - PublicRead bool `mapstructure:"publicRead"` - } `mapstructure:"kodo"` + Kodo Kodo `mapstructure:"kodo"` Aws struct { Endpoint string `mapstructure:"endpoint"` Region string `mapstructure:"region"` @@ -317,6 +310,16 @@ type Oss struct { PublicRead bool `mapstructure:"publicRead"` } +type Kodo struct { + Endpoint string `mapstructure:"endpoint"` + Bucket string `mapstructure:"bucket"` + BucketURL string `mapstructure:"bucketURL"` + AccessKeyID string `mapstructure:"accessKeyID"` + AccessKeySecret string `mapstructure:"accessKeySecret"` + SessionToken string `mapstructure:"sessionToken"` + PublicRead bool `mapstructure:"publicRead"` +} + type User struct { RPC struct { RegisterIP string `mapstructure:"registerIP"` @@ -528,6 +531,18 @@ func (o *Oss) Build() *oss.Config { } } +func (o *Kodo) Build() *kodo.Config { + return &kodo.Config{ + Endpoint: o.Endpoint, + Bucket: o.Bucket, + BucketURL: o.BucketURL, + AccessKeyID: o.AccessKeyID, + AccessKeySecret: o.AccessKeySecret, + SessionToken: o.SessionToken, + PublicRead: o.PublicRead, + } +} + func (l *CacheConfig) Failed() time.Duration { return time.Second * time.Duration(l.FailedExpire) }