You can not select more than 25 topics Topics must start with a chinese character,a letter or number, can include dashes ('-') and can be up to 35 characters long.

temporary.go 34 kB

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