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

feat: support huaweicloud OBS for Oss #537

Merged
merged 15 commits into from
Mar 13, 2023
Merged
Show file tree
Hide file tree
Changes from 12 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
4 changes: 4 additions & 0 deletions .env
Original file line number Diff line number Diff line change
Expand Up @@ -99,6 +99,10 @@ AWS_ACCESS_SECRET=apitable@com
AWS_ENDPOINT=http://minio:9000
AWS_REGION=us-east-1

HUAWEICLOUD_OBS_ACCESS_KEY=YOUR AK
HUAWEICLOUD_OBS_SECRET_KEY=YOUR SK
HUAWEICLOUD_OBS_ENDPOINT=YOUR ENDPOINT
showlovetommy marked this conversation as resolved.
Show resolved Hide resolved

OSS_BUCKET_NAME=assets
VK_ASSETS_LTD_BUCKET=assets
VK_ASSETS_LTD_URL=assets
Expand Down
2 changes: 1 addition & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -76,4 +76,4 @@ scripts/design_token/__pycache__
/backend-server/**/generated

# eslint results
eslint-results.sarif
eslint-results.sarif
4 changes: 4 additions & 0 deletions backend-server/application/src/main/resources/application.yml
Original file line number Diff line number Diff line change
Expand Up @@ -114,6 +114,10 @@ starter:
callback:
url: ${QINIU_CALLBACK_URL:http://fktcca.natappfree.cc/api/v1/asset/qiniu/uploadCallback}
body-type: ${QINIU_CALLBACK_BODY_TYPE:application/json}
huawei-cloud:
access-key: ${HUAWEICLOUD_OBS_ACCESS_KEY:}
secret-key: ${HUAWEICLOUD_OBS_SECRET_KEY:}
endpoint: ${HUAWEICLOUD_OBS_ENDPOINT:obs.cn-south-1.myhuaweicloud.com}
minio:
endpoint: ${MINIO_ENDPOINT:http://minio:9000}
access-key: ${MINIO_ACCESS_KEY:apitable}
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
package com.apitable.starter.oss;

import com.apitable.starter.oss.autoconfigure.HuaweiCloudOBSAutoConfiguration;
import com.apitable.starter.oss.autoconfigure.OssProperties;
import com.apitable.starter.oss.core.OssClientTemplate;
import com.apitable.starter.oss.core.OssObject;
import com.apitable.starter.oss.core.UrlFetchResponse;
import org.junit.jupiter.api.DisplayName;
import org.junit.jupiter.api.Test;
import org.junit.jupiter.api.TestInstance;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import com.apitable.Application;
import org.springframework.boot.test.context.SpringBootTest;

import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.IOException;
import java.io.InputStream;

@SpringBootTest(classes = com.apitable.Application.class)
@TestInstance(TestInstance.Lifecycle.PER_CLASS)
@DisplayName("HuaweiCloudOBS")
public class HuaweiCloudOssClientTest{

@Autowired
private OssClientTemplate template;
@Test
@DisplayName("CreateHuaweiCloudOssClient")
public void createHuaweiCloudOssClient() throws FileNotFoundException {
String bucketName = "";
String remoteUrl = "";
String path = "";
String path2 = "";
String path3 = "";
FileInputStream fileInputStream1 = new FileInputStream("");
try {
UrlFetchResponse result0 = template.upload(bucketName, remoteUrl, path);
OssObject object = template.getObject(bucketName, result0.getKeyName());
boolean result1 = template.delete(bucketName, result0.getKeyName());
template.upload(bucketName, fileInputStream1, path2);
OssObject object1 = template.getObject(bucketName, path2);
template.upload(bucketName, object1.getInputStream(), path3, object1.getContentType(), object1.getContentDigest());
} catch (IOException e) {
throw new RuntimeException(e);
}
}
}
1 change: 1 addition & 0 deletions backend-server/gradle.properties
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ aliyun_core_version=4.5.10
aliyun_afs_sdk_version=1.0.1
aliyun_oss_sdk_version=3.13.0
qiniu_oss_sdk_version=7.9.5
huaweicloud_obs_sdk_version=3.22.12
qcloud_sms_version=1.0.6
qcloud_ses_version=3.1.444
yunpian_sms_sdk_version=1.2.7
Expand Down
1 change: 1 addition & 0 deletions backend-server/lib.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,7 @@ ext {
'qcloudsms' : "com.github.qcloudsms:qcloudsms:${qcloud_sms_version}",
'qcloudses' : "com.tencentcloudapi:tencentcloud-sdk-java-ses:${qcloud_ses_version}",
'qiniu' : "com.qiniu:qiniu-java-sdk:${qiniu_oss_sdk_version}",
'huaweicloud-obs' : "com.huaweicloud:esdk-obs-java-bundle:${huaweicloud_obs_sdk_version}",
'yunpian-sms' : "com.yunpian.sdk:yunpian-java-sdk:${yunpian_sms_sdk_version}",
'easyexcel' : [
"com.alibaba:easyexcel:${easy_excel_version}",
Expand Down
1 change: 1 addition & 0 deletions backend-server/shared/starters/oss/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ dependencies {
implementation(rootProject.ext.dependencies['aws'])
implementation(rootProject.ext.dependencies['minio'])
implementation(rootProject.ext.dependencies['qiniu'])
implementation(rootProject.ext.dependencies['huaweicloud-obs'])
implementation(rootProject.ext.dependencies['slf4j'])
implementation(rootProject.ext.dependencies['hutool'])
implementation(rootProject.ext.dependencies['gson'])
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
package com.apitable.starter.oss.autoconfigure;

import org.springframework.boot.autoconfigure.condition.ConditionalOnClass;
import org.springframework.boot.autoconfigure.condition.ConditionalOnMissingBean;
import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

import com.apitable.starter.oss.autoconfigure.OssProperties.HuaweiCloud;
import com.apitable.starter.oss.core.OssClientRequestFactory;
import com.apitable.starter.oss.core.obs.HuaweiCloudOssClientRequestFactory;
import com.obs.services.*;

@Configuration(proxyBeanMethods = false)
@ConditionalOnClass(ObsClient.class)
@ConditionalOnProperty(value = "starter.oss.type", havingValue = "huawei-cloud")
public class HuaweiCloudOBSAutoConfiguration extends OssConnectionConfiguration{

public HuaweiCloudOBSAutoConfiguration(OssProperties properties) {
super(properties);
}

@Bean
@ConditionalOnMissingBean(OssClientRequestFactory.class)
OssClientRequestFactory ossClientRequestFactory() {
HuaweiCloud huaweicloud = getProperties().getHuaweiCloud();
return new HuaweiCloudOssClientRequestFactory( huaweicloud.getAccessKey(), huaweicloud.getSecretKey(), huaweicloud.getEndpoint());
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@
@ConditionalOnClass(OssClientTemplate.class)
@Import({ AwsS3AutoConfiguration.class,
QiniuCloudAutoConfiguration.class,
HuaweiCloudOBSAutoConfiguration.class,
MinioAutoConfiguration.class })
public class OssAutoConfiguration {

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,8 @@ public class OssProperties {

private Aliyun aliyun;

private HuaweiCloud huaweiCloud;

private Minio minio;

public boolean isEnabled() {
Expand Down Expand Up @@ -72,6 +74,10 @@ public enum OssType {
* Aliyun Oss
*/
ALIYUN,
/**
* Huawei Cloud
*/
HUAWEICLOUD,

MINIO
}
Expand Down Expand Up @@ -100,6 +106,14 @@ public void setAliyun(Aliyun aliyun) {
this.aliyun = aliyun;
}

public HuaweiCloud getHuaweiCloud() {
return huaweiCloud;
}

public void setHuaweiCloud(HuaweiCloud huaweicloud) {
this.huaweiCloud = huaweicloud;
}

public Minio getMinio() {
return minio;
}
Expand Down Expand Up @@ -257,6 +271,41 @@ public void setBucketName(String bucketName) {
}
}

public static class HuaweiCloud {
private String endpoint;
private String accessKey;
private String secretKey;
private String bucketName;

public String getEndpoint() {
return endpoint;
}
public void setEndpoint(String endpoint) {
this.endpoint = endpoint;
}

public String getAccessKey() {
return accessKey;
}
public void setAccessKey(String accessKey) {
this.accessKey = accessKey;
}

public String getSecretKey() {
return secretKey;
}
public void setSecretKey(String secretKey) {
this.secretKey = secretKey;
}

public String getBucketName() {
return bucketName;
}
public void setBucketName(String bucketName) {
this.bucketName = bucketName;
}
}

public static class Minio {

private String endpoint;
Expand Down
Loading