mirror of
				https://github.com/1Panel-dev/1Panel.git
				synced 2025-10-31 19:26:02 +08:00 
			
		
		
		
	feat: allow tencent cloud cos dual stack domain (#8123)
	
		
			
	
		
	
	
		
	
		
			Some checks failed
		
		
	
	
		
			
				
	
				SonarCloud Scan / SonarCloud (push) Failing after -23s
				
			
		
		
	
	
				
					
				
			
		
			Some checks failed
		
		
	
	SonarCloud Scan / SonarCloud (push) Failing after -23s
				
			Co-authored-by: lm379 <lm379@qq.com>
This commit is contained in:
		
							parent
							
								
									b7e16bd6d5
								
							
						
					
					
						commit
						8f491b2933
					
				
					 1 changed files with 13 additions and 2 deletions
				
			
		|  | @ -6,6 +6,7 @@ import ( | |||
| 	"net/http" | ||||
| 	"net/url" | ||||
| 	"os" | ||||
| 	"regexp" | ||||
| 
 | ||||
| 	cosSDK "github.com/tencentyun/cos-go-sdk-v5" | ||||
| ) | ||||
|  | @ -18,6 +19,7 @@ type cosClient struct { | |||
| 
 | ||||
| func NewCosClient(vars map[string]interface{}) (*cosClient, error) { | ||||
| 	region := loadParamFromVars("region", vars) | ||||
| 	endpoint := loadParamFromVars("endpoint", vars) | ||||
| 	accessKey := loadParamFromVars("accessKey", vars) | ||||
| 	secretKey := loadParamFromVars("secretKey", vars) | ||||
| 	bucket := loadParamFromVars("bucket", vars) | ||||
|  | @ -26,7 +28,16 @@ func NewCosClient(vars map[string]interface{}) (*cosClient, error) { | |||
| 		scType = "Standard" | ||||
| 	} | ||||
| 
 | ||||
| 	u, _ := url.Parse(fmt.Sprintf("https://cos.%s.myqcloud.com", region)) | ||||
| 	// 允许使用对象存储双栈域名 | ||||
| 	endpointType := "cos" | ||||
| 	if len(endpoint) != 0 { | ||||
| 		re := regexp.MustCompile(`.*cos-dualstack\..*`) | ||||
| 		if re.MatchString(endpoint) { | ||||
| 			endpointType = "cos-dualstack" | ||||
| 		} | ||||
| 	} | ||||
| 
 | ||||
| 	u, _ := url.Parse(fmt.Sprintf("https://%s.%s.myqcloud.com", endpointType, region)) | ||||
| 	b := &cosSDK.BaseURL{BucketURL: u} | ||||
| 	client := cosSDK.NewClient(b, &http.Client{ | ||||
| 		Transport: &cosSDK.AuthorizationTransport{ | ||||
|  | @ -36,7 +47,7 @@ func NewCosClient(vars map[string]interface{}) (*cosClient, error) { | |||
| 	}) | ||||
| 
 | ||||
| 	if len(bucket) != 0 { | ||||
| 		u2, _ := url.Parse(fmt.Sprintf("https://%s.cos.%s.myqcloud.com", bucket, region)) | ||||
| 		u2, _ := url.Parse(fmt.Sprintf("https://%s.%s.%s.myqcloud.com", bucket, endpointType, region)) | ||||
| 		b2 := &cosSDK.BaseURL{BucketURL: u2} | ||||
| 		clientWithBucket := cosSDK.NewClient(b2, &http.Client{ | ||||
| 			Transport: &cosSDK.AuthorizationTransport{ | ||||
|  |  | |||
		Loading…
	
	Add table
		
		Reference in a new issue