From d2565e03c80aeec3aca75a8f7c3ef01e02509be0 Mon Sep 17 00:00:00 2001 From: Gucheng Wang Date: Fri, 3 Dec 2021 15:12:16 +0800 Subject: [PATCH] Add tencent_cloud_cos.go --- storage/{aliyun.go => aliyun_oss.go} | 2 +- storage/storage.go | 4 +++- storage/tencent_cloud_cos.go | 32 ++++++++++++++++++++++++++++ web/src/ProviderEditPage.js | 3 ++- web/src/auth/Provider.js | 4 ++++ 5 files changed, 42 insertions(+), 3 deletions(-) rename storage/{aliyun.go => aliyun_oss.go} (85%) create mode 100644 storage/tencent_cloud_cos.go diff --git a/storage/aliyun.go b/storage/aliyun_oss.go similarity index 85% rename from storage/aliyun.go rename to storage/aliyun_oss.go index b5dd78c1..2d59699e 100644 --- a/storage/aliyun.go +++ b/storage/aliyun_oss.go @@ -19,7 +19,7 @@ import ( "github.com/qor/oss/aliyun" ) -func NewAliyunStorageProvider(clientId string, clientSecret string, region string, bucket string, endpoint string) oss.StorageInterface { +func NewAliyunOssStorageProvider(clientId string, clientSecret string, region string, bucket string, endpoint string) oss.StorageInterface { sp := aliyun.New(&aliyun.Config{ AccessID: clientId, AccessKey: clientSecret, diff --git a/storage/storage.go b/storage/storage.go index be022a84..788441ac 100644 --- a/storage/storage.go +++ b/storage/storage.go @@ -23,7 +23,9 @@ func GetStorageProvider(providerType string, clientId string, clientSecret strin case "AWS S3": return NewAwsS3StorageProvider(clientId, clientSecret, region, bucket, endpoint) case "Aliyun OSS": - return NewAliyunStorageProvider(clientId, clientSecret, region, bucket, endpoint) + return NewAliyunOssStorageProvider(clientId, clientSecret, region, bucket, endpoint) + case "Tencent Cloud COS": + return NewTencentCloudCosStorageProvider(clientId, clientSecret, region, bucket, endpoint) } return nil diff --git a/storage/tencent_cloud_cos.go b/storage/tencent_cloud_cos.go new file mode 100644 index 00000000..72362747 --- /dev/null +++ b/storage/tencent_cloud_cos.go @@ -0,0 +1,32 @@ +// Copyright 2021 The casbin Authors. All Rights Reserved. +// +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. + +package storage + +import ( + "github.com/qor/oss" + "github.com/qor/oss/tencent" +) + +func NewTencentCloudCosStorageProvider(clientId string, clientSecret string, region string, bucket string, endpoint string) oss.StorageInterface { + sp := tencent.New(&tencent.Config{ + AccessID: clientId, + AccessKey: clientSecret, + Region: region, + Bucket: bucket, + Endpoint: endpoint, + }) + + return sp +} diff --git a/web/src/ProviderEditPage.js b/web/src/ProviderEditPage.js index 3c6c31b7..b49674b4 100644 --- a/web/src/ProviderEditPage.js +++ b/web/src/ProviderEditPage.js @@ -100,6 +100,7 @@ class ProviderEditPage extends React.Component { {id: 'Local File System', name: 'Local File System'}, {id: 'AWS S3', name: 'AWS S3'}, {id: 'Aliyun OSS', name: 'Aliyun OSS'}, + {id: 'Tencent Cloud COS', name: 'Tencent Cloud COS'}, ] ); } else { @@ -299,7 +300,7 @@ class ProviderEditPage extends React.Component { }} /> - {this.state.provider.type === "AWSS3" ? ( + {this.state.provider.type === "AWS S3" || this.state.provider.type === "Tencent Cloud COS" ? ( {Setting.getLabel(i18next.t("provider:Region ID"), i18next.t("provider:Region ID - Tooltip"))} : diff --git a/web/src/auth/Provider.js b/web/src/auth/Provider.js index fba26dd0..8486cc85 100644 --- a/web/src/auth/Provider.js +++ b/web/src/auth/Provider.js @@ -103,6 +103,10 @@ const otherProviderInfo = { logo: `${StaticBaseUrl}/img/social_aliyun.png`, url: "https://aliyun.com/product/oss", }, + "Tencent Cloud COS": { + logo: `${StaticBaseUrl}/img/social_tencent_cloud.jpg`, + url: "https://cloud.tencent.com/product/cos", + }, }, };