github.com/huaweicloud/golangsdk@v0.0.0-20210831081626-d823fe11ceba/openstack/obs/temporary.go (about)

     1  // Copyright 2019 Huawei Technologies Co.,Ltd.
     2  // Licensed under the Apache License, Version 2.0 (the "License"); you may not use
     3  // this file except in compliance with the License.  You may obtain a copy of the
     4  // License at
     5  //
     6  // http://www.apache.org/licenses/LICENSE-2.0
     7  //
     8  // Unless required by applicable law or agreed to in writing, software distributed
     9  // under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR
    10  // CONDITIONS OF ANY KIND, either express or implied.  See the License for the
    11  // specific language governing permissions and limitations under the License.
    12  
    13  package obs
    14  
    15  import (
    16  	"errors"
    17  	"fmt"
    18  	"io"
    19  	"net/http"
    20  	"os"
    21  	"strings"
    22  	"time"
    23  )
    24  
    25  // CreateSignedUrl creates signed url with the specified CreateSignedUrlInput, and returns the CreateSignedUrlOutput and error
    26  func (obsClient ObsClient) CreateSignedUrl(input *CreateSignedUrlInput) (output *CreateSignedUrlOutput, err error) {
    27  	if input == nil {
    28  		return nil, errors.New("CreateSignedUrlInput is nil")
    29  	}
    30  
    31  	params := make(map[string]string, len(input.QueryParams))
    32  	for key, value := range input.QueryParams {
    33  		params[key] = value
    34  	}
    35  
    36  	if input.SubResource != "" {
    37  		params[string(input.SubResource)] = ""
    38  	}
    39  
    40  	headers := make(map[string][]string, len(input.Headers))
    41  	for key, value := range input.Headers {
    42  		headers[key] = []string{value}
    43  	}
    44  
    45  	if input.Expires <= 0 {
    46  		input.Expires = 300
    47  	}
    48  
    49  	requestURL, err := obsClient.doAuthTemporary(string(input.Method), input.Bucket, input.Key, params, headers, int64(input.Expires))
    50  	if err != nil {
    51  		return nil, err
    52  	}
    53  
    54  	output = &CreateSignedUrlOutput{
    55  		SignedUrl:                  requestURL,
    56  		ActualSignedRequestHeaders: headers,
    57  	}
    58  	return
    59  }
    60  
    61  func (obsClient ObsClient) isSecurityToken(params map[string]string, sh securityHolder) {
    62  	if sh.securityToken != "" {
    63  		if obsClient.conf.signature == SignatureObs {
    64  			params[HEADER_STS_TOKEN_OBS] = sh.securityToken
    65  		} else {
    66  			params[HEADER_STS_TOKEN_AMZ] = sh.securityToken
    67  		}
    68  	}
    69  }
    70  
    71  // CreateBrowserBasedSignature gets the browser based signature with the specified CreateBrowserBasedSignatureInput,
    72  // and returns the CreateBrowserBasedSignatureOutput and error
    73  func (obsClient ObsClient) CreateBrowserBasedSignature(input *CreateBrowserBasedSignatureInput) (output *CreateBrowserBasedSignatureOutput, err error) {
    74  	if input == nil {
    75  		return nil, errors.New("CreateBrowserBasedSignatureInput is nil")
    76  	}
    77  
    78  	params := make(map[string]string, len(input.FormParams))
    79  	for key, value := range input.FormParams {
    80  		params[key] = value
    81  	}
    82  
    83  	date := time.Now().UTC()
    84  	shortDate := date.Format(SHORT_DATE_FORMAT)
    85  	longDate := date.Format(LONG_DATE_FORMAT)
    86  	sh := obsClient.getSecurity()
    87  
    88  	credential, _ := getCredential(sh.ak, obsClient.conf.region, shortDate)
    89  
    90  	if input.Expires <= 0 {
    91  		input.Expires = 300
    92  	}
    93  
    94  	expiration := date.Add(time.Second * time.Duration(input.Expires)).Format(ISO8601_DATE_FORMAT)
    95  	if obsClient.conf.signature == SignatureV4 {
    96  		params[PARAM_ALGORITHM_AMZ_CAMEL] = V4_HASH_PREFIX
    97  		params[PARAM_CREDENTIAL_AMZ_CAMEL] = credential
    98  		params[PARAM_DATE_AMZ_CAMEL] = longDate
    99  	}
   100  
   101  	obsClient.isSecurityToken(params, sh)
   102  
   103  	matchAnyBucket := true
   104  	matchAnyKey := true
   105  	count := 5
   106  	if bucket := strings.TrimSpace(input.Bucket); bucket != "" {
   107  		params["bucket"] = bucket
   108  		matchAnyBucket = false
   109  		count--
   110  	}
   111  
   112  	if key := strings.TrimSpace(input.Key); key != "" {
   113  		params["key"] = key
   114  		matchAnyKey = false
   115  		count--
   116  	}
   117  
   118  	originPolicySlice := make([]string, 0, len(params)+count)
   119  	originPolicySlice = append(originPolicySlice, fmt.Sprintf("{\"expiration\":\"%s\",", expiration))
   120  	originPolicySlice = append(originPolicySlice, "\"conditions\":[")
   121  	for key, value := range params {
   122  		if _key := strings.TrimSpace(strings.ToLower(key)); _key != "" {
   123  			originPolicySlice = append(originPolicySlice, fmt.Sprintf("{\"%s\":\"%s\"},", _key, value))
   124  		}
   125  	}
   126  
   127  	if matchAnyBucket {
   128  		originPolicySlice = append(originPolicySlice, "[\"starts-with\", \"$bucket\", \"\"],")
   129  	}
   130  
   131  	if matchAnyKey {
   132  		originPolicySlice = append(originPolicySlice, "[\"starts-with\", \"$key\", \"\"],")
   133  	}
   134  
   135  	originPolicySlice = append(originPolicySlice, "]}")
   136  
   137  	originPolicy := strings.Join(originPolicySlice, "")
   138  	policy := Base64Encode([]byte(originPolicy))
   139  	var signature string
   140  	if obsClient.conf.signature == SignatureV4 {
   141  		signature = getSignature(policy, sh.sk, obsClient.conf.region, shortDate)
   142  	} else {
   143  		signature = Base64Encode(HmacSha1([]byte(sh.sk), []byte(policy)))
   144  	}
   145  
   146  	output = &CreateBrowserBasedSignatureOutput{
   147  		OriginPolicy: originPolicy,
   148  		Policy:       policy,
   149  		Algorithm:    params[PARAM_ALGORITHM_AMZ_CAMEL],
   150  		Credential:   params[PARAM_CREDENTIAL_AMZ_CAMEL],
   151  		Date:         params[PARAM_DATE_AMZ_CAMEL],
   152  		Signature:    signature,
   153  	}
   154  	return
   155  }
   156  
   157  // ListBucketsWithSignedUrl lists buckets with the specified signed url and signed request headers
   158  func (obsClient ObsClient) ListBucketsWithSignedUrl(signedUrl string, actualSignedRequestHeaders http.Header) (output *ListBucketsOutput, err error) {
   159  	output = &ListBucketsOutput{}
   160  	err = obsClient.doHTTPWithSignedURL("ListBuckets", HTTP_GET, signedUrl, actualSignedRequestHeaders, nil, output, true)
   161  	if err != nil {
   162  		output = nil
   163  	}
   164  	return
   165  }
   166  
   167  // CreateBucketWithSignedUrl creates bucket with the specified signed url and signed request headers and data
   168  func (obsClient ObsClient) CreateBucketWithSignedUrl(signedUrl string, actualSignedRequestHeaders http.Header, data io.Reader) (output *BaseModel, err error) {
   169  	output = &BaseModel{}
   170  	err = obsClient.doHTTPWithSignedURL("CreateBucket", HTTP_PUT, signedUrl, actualSignedRequestHeaders, data, output, true)
   171  	if err != nil {
   172  		output = nil
   173  	}
   174  	return
   175  }
   176  
   177  // DeleteBucketWithSignedUrl deletes bucket with the specified signed url and signed request headers
   178  func (obsClient ObsClient) DeleteBucketWithSignedUrl(signedUrl string, actualSignedRequestHeaders http.Header) (output *BaseModel, err error) {
   179  	output = &BaseModel{}
   180  	err = obsClient.doHTTPWithSignedURL("DeleteBucket", HTTP_DELETE, signedUrl, actualSignedRequestHeaders, nil, output, true)
   181  	if err != nil {
   182  		output = nil
   183  	}
   184  	return
   185  }
   186  
   187  // SetBucketStoragePolicyWithSignedUrl sets bucket storage class with the specified signed url and signed request headers and data
   188  func (obsClient ObsClient) SetBucketStoragePolicyWithSignedUrl(signedUrl string, actualSignedRequestHeaders http.Header, data io.Reader) (output *BaseModel, err error) {
   189  	output = &BaseModel{}
   190  	err = obsClient.doHTTPWithSignedURL("SetBucketStoragePolicy", HTTP_PUT, signedUrl, actualSignedRequestHeaders, data, output, true)
   191  	if err != nil {
   192  		output = nil
   193  	}
   194  	return
   195  }
   196  
   197  // GetBucketStoragePolicyWithSignedUrl gets bucket storage class with the specified signed url and signed request headers
   198  func (obsClient ObsClient) GetBucketStoragePolicyWithSignedUrl(signedUrl string, actualSignedRequestHeaders http.Header) (output *GetBucketStoragePolicyOutput, err error) {
   199  	output = &GetBucketStoragePolicyOutput{}
   200  	err = obsClient.doHTTPWithSignedURL("GetBucketStoragePolicy", HTTP_GET, signedUrl, actualSignedRequestHeaders, nil, output, true)
   201  	if err != nil {
   202  		output = nil
   203  	}
   204  	return
   205  }
   206  
   207  // ListObjectsWithSignedUrl lists objects in a bucket with the specified signed url and signed request headers
   208  func (obsClient ObsClient) ListObjectsWithSignedUrl(signedUrl string, actualSignedRequestHeaders http.Header) (output *ListObjectsOutput, err error) {
   209  	output = &ListObjectsOutput{}
   210  	err = obsClient.doHTTPWithSignedURL("ListObjects", HTTP_GET, signedUrl, actualSignedRequestHeaders, nil, output, true)
   211  	if err != nil {
   212  		output = nil
   213  	} else {
   214  		if location, ok := output.ResponseHeaders[HEADER_BUCKET_REGION]; ok {
   215  			output.Location = location[0]
   216  		}
   217  		if output.EncodingType == "url" {
   218  			err = decodeListObjectsOutput(output)
   219  			if err != nil {
   220  				doLog(LEVEL_ERROR, "Failed to get ListObjectsOutput with error: %v.", err)
   221  				output = nil
   222  			}
   223  		}
   224  	}
   225  	return
   226  }
   227  
   228  // ListVersionsWithSignedUrl lists versioning objects in a bucket with the specified signed url and signed request headers
   229  func (obsClient ObsClient) ListVersionsWithSignedUrl(signedUrl string, actualSignedRequestHeaders http.Header) (output *ListVersionsOutput, err error) {
   230  	output = &ListVersionsOutput{}
   231  	err = obsClient.doHTTPWithSignedURL("ListVersions", HTTP_GET, signedUrl, actualSignedRequestHeaders, nil, output, true)
   232  	if err != nil {
   233  		output = nil
   234  	} else {
   235  		if location, ok := output.ResponseHeaders[HEADER_BUCKET_REGION]; ok {
   236  			output.Location = location[0]
   237  		}
   238  		if output.EncodingType == "url" {
   239  			err = decodeListVersionsOutput(output)
   240  			if err != nil {
   241  				doLog(LEVEL_ERROR, "Failed to get ListVersionsOutput with error: %v.", err)
   242  				output = nil
   243  			}
   244  		}
   245  	}
   246  	return
   247  }
   248  
   249  // ListMultipartUploadsWithSignedUrl lists the multipart uploads that are initialized but not combined or aborted in a
   250  // specified bucket with the specified signed url and signed request headers
   251  func (obsClient ObsClient) ListMultipartUploadsWithSignedUrl(signedUrl string, actualSignedRequestHeaders http.Header) (output *ListMultipartUploadsOutput, err error) {
   252  	output = &ListMultipartUploadsOutput{}
   253  	err = obsClient.doHTTPWithSignedURL("ListMultipartUploads", HTTP_GET, signedUrl, actualSignedRequestHeaders, nil, output, true)
   254  	if err != nil {
   255  		output = nil
   256  	} else if output.EncodingType == "url" {
   257  		err = decodeListMultipartUploadsOutput(output)
   258  		if err != nil {
   259  			doLog(LEVEL_ERROR, "Failed to get ListMultipartUploadsOutput with error: %v.", err)
   260  			output = nil
   261  		}
   262  	}
   263  	return
   264  }
   265  
   266  // SetBucketQuotaWithSignedUrl sets the bucket quota with the specified signed url and signed request headers and data
   267  func (obsClient ObsClient) SetBucketQuotaWithSignedUrl(signedUrl string, actualSignedRequestHeaders http.Header, data io.Reader) (output *BaseModel, err error) {
   268  	output = &BaseModel{}
   269  	err = obsClient.doHTTPWithSignedURL("SetBucketQuota", HTTP_PUT, signedUrl, actualSignedRequestHeaders, data, output, true)
   270  	if err != nil {
   271  		output = nil
   272  	}
   273  	return
   274  }
   275  
   276  // GetBucketQuotaWithSignedUrl gets the bucket quota with the specified signed url and signed request headers
   277  func (obsClient ObsClient) GetBucketQuotaWithSignedUrl(signedUrl string, actualSignedRequestHeaders http.Header) (output *GetBucketQuotaOutput, err error) {
   278  	output = &GetBucketQuotaOutput{}
   279  	err = obsClient.doHTTPWithSignedURL("GetBucketQuota", HTTP_GET, signedUrl, actualSignedRequestHeaders, nil, output, true)
   280  	if err != nil {
   281  		output = nil
   282  	}
   283  	return
   284  }
   285  
   286  // HeadBucketWithSignedUrl checks whether a bucket exists with the specified signed url and signed request headers
   287  func (obsClient ObsClient) HeadBucketWithSignedUrl(signedUrl string, actualSignedRequestHeaders http.Header) (output *BaseModel, err error) {
   288  	output = &BaseModel{}
   289  	err = obsClient.doHTTPWithSignedURL("HeadBucket", HTTP_HEAD, signedUrl, actualSignedRequestHeaders, nil, output, true)
   290  	if err != nil {
   291  		output = nil
   292  	}
   293  	return
   294  }
   295  
   296  // HeadObjectWithSignedUrl checks whether an object exists with the specified signed url and signed request headers
   297  func (obsClient ObsClient) HeadObjectWithSignedUrl(signedUrl string, actualSignedRequestHeaders http.Header) (output *BaseModel, err error) {
   298  	output = &BaseModel{}
   299  	err = obsClient.doHTTPWithSignedURL("HeadObject", HTTP_HEAD, signedUrl, actualSignedRequestHeaders, nil, output, true)
   300  	if err != nil {
   301  		output = nil
   302  	}
   303  	return
   304  }
   305  
   306  // GetBucketMetadataWithSignedUrl gets the metadata of a bucket with the specified signed url and signed request headers
   307  func (obsClient ObsClient) GetBucketMetadataWithSignedUrl(signedUrl string, actualSignedRequestHeaders http.Header) (output *GetBucketMetadataOutput, err error) {
   308  	output = &GetBucketMetadataOutput{}
   309  	err = obsClient.doHTTPWithSignedURL("GetBucketMetadata", HTTP_HEAD, signedUrl, actualSignedRequestHeaders, nil, output, true)
   310  	if err != nil {
   311  		output = nil
   312  	} else {
   313  		ParseGetBucketMetadataOutput(output)
   314  	}
   315  	return
   316  }
   317  
   318  // GetBucketStorageInfoWithSignedUrl gets storage information about a bucket with the specified signed url and signed request headers
   319  func (obsClient ObsClient) GetBucketStorageInfoWithSignedUrl(signedUrl string, actualSignedRequestHeaders http.Header) (output *GetBucketStorageInfoOutput, err error) {
   320  	output = &GetBucketStorageInfoOutput{}
   321  	err = obsClient.doHTTPWithSignedURL("GetBucketStorageInfo", HTTP_GET, signedUrl, actualSignedRequestHeaders, nil, output, true)
   322  	if err != nil {
   323  		output = nil
   324  	}
   325  	return
   326  }
   327  
   328  // GetBucketLocationWithSignedUrl gets the location of a bucket with the specified signed url and signed request headers
   329  func (obsClient ObsClient) GetBucketLocationWithSignedUrl(signedUrl string, actualSignedRequestHeaders http.Header) (output *GetBucketLocationOutput, err error) {
   330  	output = &GetBucketLocationOutput{}
   331  	err = obsClient.doHTTPWithSignedURL("GetBucketLocation", HTTP_GET, signedUrl, actualSignedRequestHeaders, nil, output, true)
   332  	if err != nil {
   333  		output = nil
   334  	}
   335  	return
   336  }
   337  
   338  // SetBucketAclWithSignedUrl sets the bucket ACL with the specified signed url and signed request headers and data
   339  func (obsClient ObsClient) SetBucketAclWithSignedUrl(signedUrl string, actualSignedRequestHeaders http.Header, data io.Reader) (output *BaseModel, err error) {
   340  	output = &BaseModel{}
   341  	err = obsClient.doHTTPWithSignedURL("SetBucketAcl", HTTP_PUT, signedUrl, actualSignedRequestHeaders, data, output, true)
   342  	if err != nil {
   343  		output = nil
   344  	}
   345  	return
   346  }
   347  
   348  // GetBucketAclWithSignedUrl gets the bucket ACL with the specified signed url and signed request headers
   349  func (obsClient ObsClient) GetBucketAclWithSignedUrl(signedUrl string, actualSignedRequestHeaders http.Header) (output *GetBucketAclOutput, err error) {
   350  	output = &GetBucketAclOutput{}
   351  	err = obsClient.doHTTPWithSignedURL("GetBucketAcl", HTTP_GET, signedUrl, actualSignedRequestHeaders, nil, output, true)
   352  	if err != nil {
   353  		output = nil
   354  	}
   355  	return
   356  }
   357  
   358  // SetBucketPolicyWithSignedUrl sets the bucket policy with the specified signed url and signed request headers and data
   359  func (obsClient ObsClient) SetBucketPolicyWithSignedUrl(signedUrl string, actualSignedRequestHeaders http.Header, data io.Reader) (output *BaseModel, err error) {
   360  	output = &BaseModel{}
   361  	err = obsClient.doHTTPWithSignedURL("SetBucketPolicy", HTTP_PUT, signedUrl, actualSignedRequestHeaders, data, output, true)
   362  	if err != nil {
   363  		output = nil
   364  	}
   365  	return
   366  }
   367  
   368  // GetBucketPolicyWithSignedUrl gets the bucket policy with the specified signed url and signed request headers
   369  func (obsClient ObsClient) GetBucketPolicyWithSignedUrl(signedUrl string, actualSignedRequestHeaders http.Header) (output *GetBucketPolicyOutput, err error) {
   370  	output = &GetBucketPolicyOutput{}
   371  	err = obsClient.doHTTPWithSignedURL("GetBucketPolicy", HTTP_GET, signedUrl, actualSignedRequestHeaders, nil, output, false)
   372  	if err != nil {
   373  		output = nil
   374  	}
   375  	return
   376  }
   377  
   378  // DeleteBucketPolicyWithSignedUrl deletes the bucket policy with the specified signed url and signed request headers
   379  func (obsClient ObsClient) DeleteBucketPolicyWithSignedUrl(signedUrl string, actualSignedRequestHeaders http.Header) (output *BaseModel, err error) {
   380  	output = &BaseModel{}
   381  	err = obsClient.doHTTPWithSignedURL("DeleteBucketPolicy", HTTP_DELETE, signedUrl, actualSignedRequestHeaders, nil, output, true)
   382  	if err != nil {
   383  		output = nil
   384  	}
   385  	return
   386  }
   387  
   388  // SetBucketCorsWithSignedUrl sets CORS rules for a bucket with the specified signed url and signed request headers and data
   389  func (obsClient ObsClient) SetBucketCorsWithSignedUrl(signedUrl string, actualSignedRequestHeaders http.Header, data io.Reader) (output *BaseModel, err error) {
   390  	output = &BaseModel{}
   391  	err = obsClient.doHTTPWithSignedURL("SetBucketCors", HTTP_PUT, signedUrl, actualSignedRequestHeaders, data, output, true)
   392  	if err != nil {
   393  		output = nil
   394  	}
   395  	return
   396  }
   397  
   398  // GetBucketCorsWithSignedUrl gets CORS rules of a bucket with the specified signed url and signed request headers
   399  func (obsClient ObsClient) GetBucketCorsWithSignedUrl(signedUrl string, actualSignedRequestHeaders http.Header) (output *GetBucketCorsOutput, err error) {
   400  	output = &GetBucketCorsOutput{}
   401  	err = obsClient.doHTTPWithSignedURL("GetBucketCors", HTTP_GET, signedUrl, actualSignedRequestHeaders, nil, output, true)
   402  	if err != nil {
   403  		output = nil
   404  	}
   405  	return
   406  }
   407  
   408  // DeleteBucketCorsWithSignedUrl deletes CORS rules of a bucket with the specified signed url and signed request headers
   409  func (obsClient ObsClient) DeleteBucketCorsWithSignedUrl(signedUrl string, actualSignedRequestHeaders http.Header) (output *BaseModel, err error) {
   410  	output = &BaseModel{}
   411  	err = obsClient.doHTTPWithSignedURL("DeleteBucketCors", HTTP_DELETE, signedUrl, actualSignedRequestHeaders, nil, output, true)
   412  	if err != nil {
   413  		output = nil
   414  	}
   415  	return
   416  }
   417  
   418  // SetBucketVersioningWithSignedUrl sets the versioning status for a bucket with the specified signed url and signed request headers and data
   419  func (obsClient ObsClient) SetBucketVersioningWithSignedUrl(signedUrl string, actualSignedRequestHeaders http.Header, data io.Reader) (output *BaseModel, err error) {
   420  	output = &BaseModel{}
   421  	err = obsClient.doHTTPWithSignedURL("SetBucketVersioning", HTTP_PUT, signedUrl, actualSignedRequestHeaders, data, output, true)
   422  	if err != nil {
   423  		output = nil
   424  	}
   425  	return
   426  }
   427  
   428  // GetBucketVersioningWithSignedUrl gets the versioning status of a bucket with the specified signed url and signed request headers
   429  func (obsClient ObsClient) GetBucketVersioningWithSignedUrl(signedUrl string, actualSignedRequestHeaders http.Header) (output *GetBucketVersioningOutput, err error) {
   430  	output = &GetBucketVersioningOutput{}
   431  	err = obsClient.doHTTPWithSignedURL("GetBucketVersioning", HTTP_GET, signedUrl, actualSignedRequestHeaders, nil, output, true)
   432  	if err != nil {
   433  		output = nil
   434  	}
   435  	return
   436  }
   437  
   438  // SetBucketWebsiteConfigurationWithSignedUrl sets website hosting for a bucket with the specified signed url and signed request headers and data
   439  func (obsClient ObsClient) SetBucketWebsiteConfigurationWithSignedUrl(signedUrl string, actualSignedRequestHeaders http.Header, data io.Reader) (output *BaseModel, err error) {
   440  	output = &BaseModel{}
   441  	err = obsClient.doHTTPWithSignedURL("SetBucketWebsiteConfiguration", HTTP_PUT, signedUrl, actualSignedRequestHeaders, data, output, true)
   442  	if err != nil {
   443  		output = nil
   444  	}
   445  	return
   446  }
   447  
   448  // GetBucketWebsiteConfigurationWithSignedUrl gets the website hosting settings of a bucket with the specified signed url and signed request headers
   449  func (obsClient ObsClient) GetBucketWebsiteConfigurationWithSignedUrl(signedUrl string, actualSignedRequestHeaders http.Header) (output *GetBucketWebsiteConfigurationOutput, err error) {
   450  	output = &GetBucketWebsiteConfigurationOutput{}
   451  	err = obsClient.doHTTPWithSignedURL("GetBucketWebsiteConfiguration", HTTP_GET, signedUrl, actualSignedRequestHeaders, nil, output, true)
   452  	if err != nil {
   453  		output = nil
   454  	}
   455  	return
   456  }
   457  
   458  // DeleteBucketWebsiteConfigurationWithSignedUrl deletes the website hosting settings of a bucket with the specified signed url and signed request headers
   459  func (obsClient ObsClient) DeleteBucketWebsiteConfigurationWithSignedUrl(signedUrl string, actualSignedRequestHeaders http.Header) (output *BaseModel, err error) {
   460  	output = &BaseModel{}
   461  	err = obsClient.doHTTPWithSignedURL("DeleteBucketWebsiteConfiguration", HTTP_DELETE, signedUrl, actualSignedRequestHeaders, nil, output, true)
   462  	if err != nil {
   463  		output = nil
   464  	}
   465  	return
   466  }
   467  
   468  // SetBucketLoggingConfigurationWithSignedUrl sets the bucket logging with the specified signed url and signed request headers and data
   469  func (obsClient ObsClient) SetBucketLoggingConfigurationWithSignedUrl(signedUrl string, actualSignedRequestHeaders http.Header, data io.Reader) (output *BaseModel, err error) {
   470  	output = &BaseModel{}
   471  	err = obsClient.doHTTPWithSignedURL("SetBucketLoggingConfiguration", HTTP_PUT, signedUrl, actualSignedRequestHeaders, data, output, true)
   472  	if err != nil {
   473  		output = nil
   474  	}
   475  	return
   476  }
   477  
   478  // GetBucketLoggingConfigurationWithSignedUrl gets the logging settings of a bucket with the specified signed url and signed request headers
   479  func (obsClient ObsClient) GetBucketLoggingConfigurationWithSignedUrl(signedUrl string, actualSignedRequestHeaders http.Header) (output *GetBucketLoggingConfigurationOutput, err error) {
   480  	output = &GetBucketLoggingConfigurationOutput{}
   481  	err = obsClient.doHTTPWithSignedURL("GetBucketLoggingConfiguration", HTTP_GET, signedUrl, actualSignedRequestHeaders, nil, output, true)
   482  	if err != nil {
   483  		output = nil
   484  	}
   485  	return
   486  }
   487  
   488  // SetBucketLifecycleConfigurationWithSignedUrl sets lifecycle rules for a bucket with the specified signed url and signed request headers and data
   489  func (obsClient ObsClient) SetBucketLifecycleConfigurationWithSignedUrl(signedUrl string, actualSignedRequestHeaders http.Header, data io.Reader) (output *BaseModel, err error) {
   490  	output = &BaseModel{}
   491  	err = obsClient.doHTTPWithSignedURL("SetBucketLifecycleConfiguration", HTTP_PUT, signedUrl, actualSignedRequestHeaders, data, output, true)
   492  	if err != nil {
   493  		output = nil
   494  	}
   495  	return
   496  }
   497  
   498  // GetBucketLifecycleConfigurationWithSignedUrl gets lifecycle rules of a bucket with the specified signed url and signed request headers
   499  func (obsClient ObsClient) GetBucketLifecycleConfigurationWithSignedUrl(signedUrl string, actualSignedRequestHeaders http.Header) (output *GetBucketLifecycleConfigurationOutput, err error) {
   500  	output = &GetBucketLifecycleConfigurationOutput{}
   501  	err = obsClient.doHTTPWithSignedURL("GetBucketLifecycleConfiguration", HTTP_GET, signedUrl, actualSignedRequestHeaders, nil, output, true)
   502  	if err != nil {
   503  		output = nil
   504  	}
   505  	return
   506  }
   507  
   508  // DeleteBucketLifecycleConfigurationWithSignedUrl deletes lifecycle rules of a bucket with the specified signed url and signed request headers
   509  func (obsClient ObsClient) DeleteBucketLifecycleConfigurationWithSignedUrl(signedUrl string, actualSignedRequestHeaders http.Header) (output *BaseModel, err error) {
   510  	output = &BaseModel{}
   511  	err = obsClient.doHTTPWithSignedURL("DeleteBucketLifecycleConfiguration", HTTP_DELETE, signedUrl, actualSignedRequestHeaders, nil, output, true)
   512  	if err != nil {
   513  		output = nil
   514  	}
   515  	return
   516  }
   517  
   518  // SetBucketTaggingWithSignedUrl sets bucket tags with the specified signed url and signed request headers and data
   519  func (obsClient ObsClient) SetBucketTaggingWithSignedUrl(signedUrl string, actualSignedRequestHeaders http.Header, data io.Reader) (output *BaseModel, err error) {
   520  	output = &BaseModel{}
   521  	err = obsClient.doHTTPWithSignedURL("SetBucketTagging", HTTP_PUT, signedUrl, actualSignedRequestHeaders, data, output, true)
   522  	if err != nil {
   523  		output = nil
   524  	}
   525  	return
   526  }
   527  
   528  // GetBucketTaggingWithSignedUrl gets bucket tags with the specified signed url and signed request headers
   529  func (obsClient ObsClient) GetBucketTaggingWithSignedUrl(signedUrl string, actualSignedRequestHeaders http.Header) (output *GetBucketTaggingOutput, err error) {
   530  	output = &GetBucketTaggingOutput{}
   531  	err = obsClient.doHTTPWithSignedURL("GetBucketTagging", HTTP_GET, signedUrl, actualSignedRequestHeaders, nil, output, true)
   532  	if err != nil {
   533  		output = nil
   534  	}
   535  	return
   536  }
   537  
   538  // DeleteBucketTaggingWithSignedUrl deletes bucket tags with the specified signed url and signed request headers
   539  func (obsClient ObsClient) DeleteBucketTaggingWithSignedUrl(signedUrl string, actualSignedRequestHeaders http.Header) (output *BaseModel, err error) {
   540  	output = &BaseModel{}
   541  	err = obsClient.doHTTPWithSignedURL("DeleteBucketTagging", HTTP_DELETE, signedUrl, actualSignedRequestHeaders, nil, output, true)
   542  	if err != nil {
   543  		output = nil
   544  	}
   545  	return
   546  }
   547  
   548  // SetBucketNotificationWithSignedUrl sets event notification for a bucket with the specified signed url and signed request headers and data
   549  func (obsClient ObsClient) SetBucketNotificationWithSignedUrl(signedUrl string, actualSignedRequestHeaders http.Header, data io.Reader) (output *BaseModel, err error) {
   550  	output = &BaseModel{}
   551  	err = obsClient.doHTTPWithSignedURL("SetBucketNotification", HTTP_PUT, signedUrl, actualSignedRequestHeaders, data, output, true)
   552  	if err != nil {
   553  		output = nil
   554  	}
   555  	return
   556  }
   557  
   558  // GetBucketNotificationWithSignedUrl gets event notification settings of a bucket with the specified signed url and signed request headers
   559  func (obsClient ObsClient) GetBucketNotificationWithSignedUrl(signedUrl string, actualSignedRequestHeaders http.Header) (output *GetBucketNotificationOutput, err error) {
   560  	output = &GetBucketNotificationOutput{}
   561  	err = obsClient.doHTTPWithSignedURL("GetBucketNotification", HTTP_GET, signedUrl, actualSignedRequestHeaders, nil, output, true)
   562  	if err != nil {
   563  		output = nil
   564  	}
   565  	return
   566  }
   567  
   568  // DeleteObjectWithSignedUrl deletes an object with the specified signed url and signed request headers
   569  func (obsClient ObsClient) DeleteObjectWithSignedUrl(signedUrl string, actualSignedRequestHeaders http.Header) (output *DeleteObjectOutput, err error) {
   570  	output = &DeleteObjectOutput{}
   571  	err = obsClient.doHTTPWithSignedURL("DeleteObject", HTTP_DELETE, signedUrl, actualSignedRequestHeaders, nil, output, true)
   572  	if err != nil {
   573  		output = nil
   574  	} else {
   575  		ParseDeleteObjectOutput(output)
   576  	}
   577  	return
   578  }
   579  
   580  // DeleteObjectsWithSignedUrl deletes objects in a batch with the specified signed url and signed request headers and data
   581  func (obsClient ObsClient) DeleteObjectsWithSignedUrl(signedUrl string, actualSignedRequestHeaders http.Header, data io.Reader) (output *DeleteObjectsOutput, err error) {
   582  	output = &DeleteObjectsOutput{}
   583  	err = obsClient.doHTTPWithSignedURL("DeleteObjects", HTTP_POST, signedUrl, actualSignedRequestHeaders, data, output, true)
   584  	if err != nil {
   585  		output = nil
   586  	} else if output.EncodingType == "url" {
   587  		err = decodeDeleteObjectsOutput(output)
   588  		if err != nil {
   589  			doLog(LEVEL_ERROR, "Failed to get DeleteObjectsOutput with error: %v.", err)
   590  			output = nil
   591  		}
   592  	}
   593  	return
   594  }
   595  
   596  // SetObjectAclWithSignedUrl sets ACL for an object with the specified signed url and signed request headers and data
   597  func (obsClient ObsClient) SetObjectAclWithSignedUrl(signedUrl string, actualSignedRequestHeaders http.Header, data io.Reader) (output *BaseModel, err error) {
   598  	output = &BaseModel{}
   599  	err = obsClient.doHTTPWithSignedURL("SetObjectAcl", HTTP_PUT, signedUrl, actualSignedRequestHeaders, data, output, true)
   600  	if err != nil {
   601  		output = nil
   602  	}
   603  	return
   604  }
   605  
   606  // GetObjectAclWithSignedUrl gets the ACL of an object with the specified signed url and signed request headers
   607  func (obsClient ObsClient) GetObjectAclWithSignedUrl(signedUrl string, actualSignedRequestHeaders http.Header) (output *GetObjectAclOutput, err error) {
   608  	output = &GetObjectAclOutput{}
   609  	err = obsClient.doHTTPWithSignedURL("GetObjectAcl", HTTP_GET, signedUrl, actualSignedRequestHeaders, nil, output, true)
   610  	if err != nil {
   611  		output = nil
   612  	} else {
   613  		if versionID, ok := output.ResponseHeaders[HEADER_VERSION_ID]; ok {
   614  			output.VersionId = versionID[0]
   615  		}
   616  	}
   617  	return
   618  }
   619  
   620  // RestoreObjectWithSignedUrl restores an object with the specified signed url and signed request headers and data
   621  func (obsClient ObsClient) RestoreObjectWithSignedUrl(signedUrl string, actualSignedRequestHeaders http.Header, data io.Reader) (output *BaseModel, err error) {
   622  	output = &BaseModel{}
   623  	err = obsClient.doHTTPWithSignedURL("RestoreObject", HTTP_POST, signedUrl, actualSignedRequestHeaders, data, output, true)
   624  	if err != nil {
   625  		output = nil
   626  	}
   627  	return
   628  }
   629  
   630  // GetObjectMetadataWithSignedUrl gets object metadata with the specified signed url and signed request headers
   631  func (obsClient ObsClient) GetObjectMetadataWithSignedUrl(signedUrl string, actualSignedRequestHeaders http.Header) (output *GetObjectMetadataOutput, err error) {
   632  	output = &GetObjectMetadataOutput{}
   633  	err = obsClient.doHTTPWithSignedURL("GetObjectMetadata", HTTP_HEAD, signedUrl, actualSignedRequestHeaders, nil, output, true)
   634  	if err != nil {
   635  		output = nil
   636  	} else {
   637  		ParseGetObjectMetadataOutput(output)
   638  	}
   639  	return
   640  }
   641  
   642  // GetObjectWithSignedUrl downloads object with the specified signed url and signed request headers
   643  func (obsClient ObsClient) GetObjectWithSignedUrl(signedUrl string, actualSignedRequestHeaders http.Header) (output *GetObjectOutput, err error) {
   644  	output = &GetObjectOutput{}
   645  	err = obsClient.doHTTPWithSignedURL("GetObject", HTTP_GET, signedUrl, actualSignedRequestHeaders, nil, output, true)
   646  	if err != nil {
   647  		output = nil
   648  	} else {
   649  		ParseGetObjectOutput(output)
   650  	}
   651  	return
   652  }
   653  
   654  // PutObjectWithSignedUrl uploads an object to the specified bucket with the specified signed url and signed request headers and data
   655  func (obsClient ObsClient) PutObjectWithSignedUrl(signedUrl string, actualSignedRequestHeaders http.Header, data io.Reader) (output *PutObjectOutput, err error) {
   656  	output = &PutObjectOutput{}
   657  	err = obsClient.doHTTPWithSignedURL("PutObject", HTTP_PUT, signedUrl, actualSignedRequestHeaders, data, output, true)
   658  	if err != nil {
   659  		output = nil
   660  	} else {
   661  		ParsePutObjectOutput(output)
   662  	}
   663  	return
   664  }
   665  
   666  // PutFileWithSignedUrl uploads a file to the specified bucket with the specified signed url and signed request headers and sourceFile path
   667  func (obsClient ObsClient) PutFileWithSignedUrl(signedUrl string, actualSignedRequestHeaders http.Header, sourceFile string) (output *PutObjectOutput, err error) {
   668  	var data io.Reader
   669  	sourceFile = strings.TrimSpace(sourceFile)
   670  	if sourceFile != "" {
   671  		fd, _err := os.Open(sourceFile)
   672  		if _err != nil {
   673  			err = _err
   674  			return nil, err
   675  		}
   676  		defer func() {
   677  			errMsg := fd.Close()
   678  			if errMsg != nil {
   679  				doLog(LEVEL_WARN, "Failed to close file with reason: %v", errMsg)
   680  			}
   681  		}()
   682  
   683  		stat, _err := fd.Stat()
   684  		if _err != nil {
   685  			err = _err
   686  			return nil, err
   687  		}
   688  		fileReaderWrapper := &fileReaderWrapper{filePath: sourceFile}
   689  		fileReaderWrapper.reader = fd
   690  
   691  		var contentLength int64
   692  		if value, ok := actualSignedRequestHeaders[HEADER_CONTENT_LENGTH_CAMEL]; ok {
   693  			contentLength = StringToInt64(value[0], -1)
   694  		} else if value, ok := actualSignedRequestHeaders[HEADER_CONTENT_LENGTH]; ok {
   695  			contentLength = StringToInt64(value[0], -1)
   696  		} else {
   697  			contentLength = stat.Size()
   698  		}
   699  		if contentLength > stat.Size() {
   700  			return nil, errors.New("ContentLength is larger than fileSize")
   701  		}
   702  		fileReaderWrapper.totalCount = contentLength
   703  		data = fileReaderWrapper
   704  	}
   705  
   706  	output = &PutObjectOutput{}
   707  	err = obsClient.doHTTPWithSignedURL("PutObject", HTTP_PUT, signedUrl, actualSignedRequestHeaders, data, output, true)
   708  	if err != nil {
   709  		output = nil
   710  	} else {
   711  		ParsePutObjectOutput(output)
   712  	}
   713  	return
   714  }
   715  
   716  // CopyObjectWithSignedUrl creates a copy for an existing object with the specified signed url and signed request headers
   717  func (obsClient ObsClient) CopyObjectWithSignedUrl(signedUrl string, actualSignedRequestHeaders http.Header) (output *CopyObjectOutput, err error) {
   718  	output = &CopyObjectOutput{}
   719  	err = obsClient.doHTTPWithSignedURL("CopyObject", HTTP_PUT, signedUrl, actualSignedRequestHeaders, nil, output, true)
   720  	if err != nil {
   721  		output = nil
   722  	} else {
   723  		ParseCopyObjectOutput(output)
   724  	}
   725  	return
   726  }
   727  
   728  // AbortMultipartUploadWithSignedUrl aborts a multipart upload in a specified bucket by using the multipart upload ID with the specified signed url and signed request headers
   729  func (obsClient ObsClient) AbortMultipartUploadWithSignedUrl(signedUrl string, actualSignedRequestHeaders http.Header) (output *BaseModel, err error) {
   730  	output = &BaseModel{}
   731  	err = obsClient.doHTTPWithSignedURL("AbortMultipartUpload", HTTP_DELETE, signedUrl, actualSignedRequestHeaders, nil, output, true)
   732  	if err != nil {
   733  		output = nil
   734  	}
   735  	return
   736  }
   737  
   738  // InitiateMultipartUploadWithSignedUrl initializes a multipart upload with the specified signed url and signed request headers
   739  func (obsClient ObsClient) InitiateMultipartUploadWithSignedUrl(signedUrl string, actualSignedRequestHeaders http.Header) (output *InitiateMultipartUploadOutput, err error) {
   740  	output = &InitiateMultipartUploadOutput{}
   741  	err = obsClient.doHTTPWithSignedURL("InitiateMultipartUpload", HTTP_POST, signedUrl, actualSignedRequestHeaders, nil, output, true)
   742  	if err != nil {
   743  		output = nil
   744  	} else {
   745  		ParseInitiateMultipartUploadOutput(output)
   746  		if output.EncodingType == "url" {
   747  			err = decodeInitiateMultipartUploadOutput(output)
   748  			if err != nil {
   749  				doLog(LEVEL_ERROR, "Failed to get InitiateMultipartUploadOutput with error: %v.", err)
   750  				output = nil
   751  			}
   752  		}
   753  	}
   754  	return
   755  }
   756  
   757  // UploadPartWithSignedUrl uploads a part to a specified bucket by using a specified multipart upload ID
   758  // with the specified signed url and signed request headers and data
   759  func (obsClient ObsClient) UploadPartWithSignedUrl(signedUrl string, actualSignedRequestHeaders http.Header, data io.Reader) (output *UploadPartOutput, err error) {
   760  	output = &UploadPartOutput{}
   761  	err = obsClient.doHTTPWithSignedURL("UploadPart", HTTP_PUT, signedUrl, actualSignedRequestHeaders, data, output, true)
   762  	if err != nil {
   763  		output = nil
   764  	} else {
   765  		ParseUploadPartOutput(output)
   766  	}
   767  	return
   768  }
   769  
   770  // CompleteMultipartUploadWithSignedUrl combines the uploaded parts in a specified bucket by using the multipart upload ID
   771  // with the specified signed url and signed request headers and data
   772  func (obsClient ObsClient) CompleteMultipartUploadWithSignedUrl(signedUrl string, actualSignedRequestHeaders http.Header, data io.Reader) (output *CompleteMultipartUploadOutput, err error) {
   773  	output = &CompleteMultipartUploadOutput{}
   774  	err = obsClient.doHTTPWithSignedURL("CompleteMultipartUpload", HTTP_POST, signedUrl, actualSignedRequestHeaders, data, output, true)
   775  	if err != nil {
   776  		output = nil
   777  	} else {
   778  		ParseCompleteMultipartUploadOutput(output)
   779  		if output.EncodingType == "url" {
   780  			err = decodeCompleteMultipartUploadOutput(output)
   781  			if err != nil {
   782  				doLog(LEVEL_ERROR, "Failed to get CompleteMultipartUploadOutput with error: %v.", err)
   783  				output = nil
   784  			}
   785  		}
   786  	}
   787  	return
   788  }
   789  
   790  // ListPartsWithSignedUrl lists the uploaded parts in a bucket by using the multipart upload ID with the specified signed url and signed request headers
   791  func (obsClient ObsClient) ListPartsWithSignedUrl(signedUrl string, actualSignedRequestHeaders http.Header) (output *ListPartsOutput, err error) {
   792  	output = &ListPartsOutput{}
   793  	err = obsClient.doHTTPWithSignedURL("ListParts", HTTP_GET, signedUrl, actualSignedRequestHeaders, nil, output, true)
   794  	if err != nil {
   795  		output = nil
   796  	} else if output.EncodingType == "url" {
   797  		err = decodeListPartsOutput(output)
   798  		if err != nil {
   799  			doLog(LEVEL_ERROR, "Failed to get ListPartsOutput with error: %v.", err)
   800  			output = nil
   801  		}
   802  	}
   803  	return
   804  }
   805  
   806  // CopyPartWithSignedUrl copy a part to a specified bucket by using a specified multipart upload ID with the specified signed url and signed request headers
   807  func (obsClient ObsClient) CopyPartWithSignedUrl(signedUrl string, actualSignedRequestHeaders http.Header) (output *CopyPartOutput, err error) {
   808  	output = &CopyPartOutput{}
   809  	err = obsClient.doHTTPWithSignedURL("CopyPart", HTTP_PUT, signedUrl, actualSignedRequestHeaders, nil, output, true)
   810  	if err != nil {
   811  		output = nil
   812  	} else {
   813  		ParseCopyPartOutput(output)
   814  	}
   815  	return
   816  }
   817  
   818  // SetBucketRequestPaymentWithSignedUrl sets requester-pays setting for a bucket with the specified signed url and signed request headers and data
   819  func (obsClient ObsClient) SetBucketRequestPaymentWithSignedUrl(signedUrl string, actualSignedRequestHeaders http.Header, data io.Reader) (output *BaseModel, err error) {
   820  	output = &BaseModel{}
   821  	err = obsClient.doHTTPWithSignedURL("SetBucketRequestPayment", HTTP_PUT, signedUrl, actualSignedRequestHeaders, data, output, true)
   822  	if err != nil {
   823  		output = nil
   824  	}
   825  	return
   826  }
   827  
   828  // GetBucketRequestPaymentWithSignedUrl gets requester-pays setting of a bucket with the specified signed url and signed request headers
   829  func (obsClient ObsClient) GetBucketRequestPaymentWithSignedUrl(signedUrl string, actualSignedRequestHeaders http.Header) (output *GetBucketRequestPaymentOutput, err error) {
   830  	output = &GetBucketRequestPaymentOutput{}
   831  	err = obsClient.doHTTPWithSignedURL("GetBucketRequestPayment", HTTP_GET, signedUrl, actualSignedRequestHeaders, nil, output, true)
   832  	if err != nil {
   833  		output = nil
   834  	}
   835  	return
   836  }