github.com/chnsz/golangsdk@v0.0.0-20240506093406-85a3fbfa605b/openstack/obs/temporary_createSignedUrl.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 ) 19 20 // CreateSignedUrl creates signed url with the specified CreateSignedUrlInput, and returns the CreateSignedUrlOutput and error 21 func (obsClient ObsClient) CreateSignedUrl(input *CreateSignedUrlInput, extensions ...extensionOptions) (output *CreateSignedUrlOutput, err error) { 22 if input == nil { 23 return nil, errors.New("CreateSignedUrlInput is nil") 24 } 25 26 params := make(map[string]string, len(input.QueryParams)) 27 for key, value := range input.QueryParams { 28 params[key] = value 29 } 30 31 if input.SubResource != "" { 32 params[string(input.SubResource)] = "" 33 } 34 35 headers := make(map[string][]string, len(input.Headers)) 36 for key, value := range input.Headers { 37 headers[key] = []string{value} 38 } 39 40 for _, extension := range extensions { 41 if extensionHeader, ok := extension.(extensionHeaders); ok { 42 _err := extensionHeader(headers, obsClient.conf.signature == SignatureObs) 43 if _err != nil { 44 doLog(LEVEL_INFO, fmt.Sprintf("set header with error: %v", _err)) 45 } 46 } else { 47 doLog(LEVEL_INFO, "Unsupported extensionOptions") 48 } 49 } 50 51 if input.Expires <= 0 { 52 input.Expires = 300 53 } 54 55 requestURL, err := obsClient.doAuthTemporary(string(input.Method), input.Bucket, input.Key, input.Policy, params, headers, int64(input.Expires)) 56 if err != nil { 57 return nil, err 58 } 59 60 output = &CreateSignedUrlOutput{ 61 SignedUrl: requestURL, 62 ActualSignedRequestHeaders: headers, 63 } 64 return 65 }