github.com/chnsz/golangsdk@v0.0.0-20240506093406-85a3fbfa605b/openstack/obs/client_bucket.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 "strings" 19 ) 20 21 func (obsClient ObsClient) DeleteBucketCustomDomain(input *DeleteBucketCustomDomainInput, extensions ...extensionOptions) (output *BaseModel, err error) { 22 if input == nil { 23 return nil, errors.New("DeleteBucketCustomDomainInput is nil") 24 } 25 26 output = &BaseModel{} 27 err = obsClient.doActionWithBucket("DeleteBucketCustomDomain", HTTP_DELETE, input.Bucket, newSubResourceSerialV2(SubResourceCustomDomain, input.CustomDomain), output, extensions) 28 if err != nil { 29 output = nil 30 } 31 return 32 } 33 34 func (obsClient ObsClient) SetBucketCustomDomain(input *SetBucketCustomDomainInput, extensions ...extensionOptions) (output *BaseModel, err error) { 35 if input == nil { 36 return nil, errors.New("SetBucketCustomDomainInput is nil") 37 } 38 39 output = &BaseModel{} 40 err = obsClient.doActionWithBucket("SetBucketCustomDomain", HTTP_PUT, input.Bucket, newSubResourceSerialV2(SubResourceCustomDomain, input.CustomDomain), output, extensions) 41 if err != nil { 42 output = nil 43 } 44 return 45 } 46 47 func (obsClient ObsClient) GetBucketCustomDomain(bucketName string, extensions ...extensionOptions) (output *GetBucketCustomDomainOuput, err error) { 48 output = &GetBucketCustomDomainOuput{} 49 err = obsClient.doActionWithBucket("GetBucketCustomDomain", HTTP_GET, bucketName, newSubResourceSerial(SubResourceCustomDomain), output, extensions) 50 if err != nil { 51 output = nil 52 } 53 return 54 } 55 56 func (obsClient ObsClient) SetBucketMirrorBackToSource(input *SetBucketMirrorBackToSourceInput, extensions ...extensionOptions) (output *BaseModel, err error) { 57 58 output = &BaseModel{} 59 err = obsClient.doActionWithBucket("SetBucketMirrorBackToSource", HTTP_PUT, input.Bucket, input, output, extensions) 60 if err != nil { 61 output = nil 62 } 63 return 64 } 65 66 func (obsClient ObsClient) DeleteBucketMirrorBackToSource(bucketName string, extensions ...extensionOptions) (output *BaseModel, err error) { 67 output = &BaseModel{} 68 err = obsClient.doActionWithBucketV2("DeleteBucketMirrorBackToSource", HTTP_DELETE, bucketName, newSubResourceSerial(SubResourceMirrorBackToSource), output, extensions) 69 if err != nil { 70 output = nil 71 } 72 return 73 } 74 75 func (obsClient ObsClient) GetBucketMirrorBackToSource(bucketName string, extensions ...extensionOptions) (output *GetBucketMirrorBackToSourceOuput, err error) { 76 output = &GetBucketMirrorBackToSourceOuput{} 77 err = obsClient.doActionWithBucketV2("GetBucketMirrorBackToSource", HTTP_GET, bucketName, newSubResourceSerial(SubResourceMirrorBackToSource), output, extensions) 78 if err != nil { 79 output = nil 80 } 81 return 82 } 83 84 // ListBuckets lists buckets. 85 // 86 // You can use this API to obtain the bucket list. In the list, bucket names are displayed in lexicographical order. 87 func (obsClient ObsClient) ListBuckets(input *ListBucketsInput, extensions ...extensionOptions) (output *ListBucketsOutput, err error) { 88 if input == nil { 89 input = &ListBucketsInput{} 90 } 91 output = &ListBucketsOutput{} 92 err = obsClient.doActionWithoutBucket("ListBuckets", HTTP_GET, input, output, extensions) 93 if err != nil { 94 output = nil 95 } 96 return 97 } 98 99 // CreateBucket creates a bucket. 100 // 101 // You can use this API to create a bucket and name it as you specify. The created bucket name must be unique in OBS. 102 func (obsClient ObsClient) CreateBucket(input *CreateBucketInput, extensions ...extensionOptions) (output *BaseModel, err error) { 103 if input == nil { 104 return nil, errors.New("CreateBucketInput is nil") 105 } 106 output = &BaseModel{} 107 err = obsClient.doActionWithBucket("CreateBucket", HTTP_PUT, input.Bucket, input, output, extensions) 108 if err != nil { 109 output = nil 110 } 111 return 112 } 113 114 // DeleteBucket deletes a bucket. 115 // 116 // You can use this API to delete a bucket. The bucket to be deleted must be empty 117 // (containing no objects, noncurrent object versions, or part fragments). 118 func (obsClient ObsClient) DeleteBucket(bucketName string, extensions ...extensionOptions) (output *BaseModel, err error) { 119 output = &BaseModel{} 120 err = obsClient.doActionWithBucket("DeleteBucket", HTTP_DELETE, bucketName, defaultSerializable, output, extensions) 121 if err != nil { 122 output = nil 123 } 124 return 125 } 126 127 // SetBucketStoragePolicy sets bucket storage class. 128 // 129 // You can use this API to set storage class for bucket. 130 func (obsClient ObsClient) SetBucketStoragePolicy(input *SetBucketStoragePolicyInput, extensions ...extensionOptions) (output *BaseModel, err error) { 131 if input == nil { 132 return nil, errors.New("SetBucketStoragePolicyInput is nil") 133 } 134 output = &BaseModel{} 135 err = obsClient.doActionWithBucket("SetBucketStoragePolicy", HTTP_PUT, input.Bucket, input, output, extensions) 136 if err != nil { 137 output = nil 138 } 139 return 140 } 141 func (obsClient ObsClient) getBucketStoragePolicyS3(bucketName string, extensions []extensionOptions) (output *GetBucketStoragePolicyOutput, err error) { 142 output = &GetBucketStoragePolicyOutput{} 143 var outputS3 *getBucketStoragePolicyOutputS3 144 outputS3 = &getBucketStoragePolicyOutputS3{} 145 err = obsClient.doActionWithBucket("GetBucketStoragePolicy", HTTP_GET, bucketName, newSubResourceSerial(SubResourceStoragePolicy), outputS3, extensions) 146 if err != nil { 147 output = nil 148 return 149 } 150 output.BaseModel = outputS3.BaseModel 151 output.StorageClass = fmt.Sprintf("%s", outputS3.StorageClass) 152 return 153 } 154 155 func (obsClient ObsClient) getBucketStoragePolicyObs(bucketName string, extensions []extensionOptions) (output *GetBucketStoragePolicyOutput, err error) { 156 output = &GetBucketStoragePolicyOutput{} 157 var outputObs *getBucketStoragePolicyOutputObs 158 outputObs = &getBucketStoragePolicyOutputObs{} 159 err = obsClient.doActionWithBucket("GetBucketStoragePolicy", HTTP_GET, bucketName, newSubResourceSerial(SubResourceStorageClass), outputObs, extensions) 160 if err != nil { 161 output = nil 162 return 163 } 164 output.BaseModel = outputObs.BaseModel 165 output.StorageClass = outputObs.StorageClass 166 return 167 } 168 169 // GetBucketStoragePolicy gets bucket storage class. 170 // 171 // You can use this API to obtain the storage class of a bucket. 172 func (obsClient ObsClient) GetBucketStoragePolicy(bucketName string, extensions ...extensionOptions) (output *GetBucketStoragePolicyOutput, err error) { 173 if obsClient.conf.signature == SignatureObs { 174 return obsClient.getBucketStoragePolicyObs(bucketName, extensions) 175 } 176 return obsClient.getBucketStoragePolicyS3(bucketName, extensions) 177 } 178 179 // SetBucketQuota sets the bucket quota. 180 // 181 // You can use this API to set the bucket quota. A bucket quota must be expressed in bytes and the maximum value is 2^63-1. 182 func (obsClient ObsClient) SetBucketQuota(input *SetBucketQuotaInput, extensions ...extensionOptions) (output *BaseModel, err error) { 183 if input == nil { 184 return nil, errors.New("SetBucketQuotaInput is nil") 185 } 186 output = &BaseModel{} 187 err = obsClient.doActionWithBucket("SetBucketQuota", HTTP_PUT, input.Bucket, input, output, extensions) 188 if err != nil { 189 output = nil 190 } 191 return 192 } 193 194 // GetBucketQuota gets the bucket quota. 195 // 196 // You can use this API to obtain the bucket quota. Value 0 indicates that no upper limit is set for the bucket quota. 197 func (obsClient ObsClient) GetBucketQuota(bucketName string, extensions ...extensionOptions) (output *GetBucketQuotaOutput, err error) { 198 output = &GetBucketQuotaOutput{} 199 err = obsClient.doActionWithBucket("GetBucketQuota", HTTP_GET, bucketName, newSubResourceSerial(SubResourceQuota), output, extensions) 200 if err != nil { 201 output = nil 202 } 203 return 204 } 205 206 // HeadBucket checks whether a bucket exists. 207 // 208 // You can use this API to check whether a bucket exists. 209 func (obsClient ObsClient) HeadBucket(bucketName string, extensions ...extensionOptions) (output *BaseModel, err error) { 210 output = &BaseModel{} 211 err = obsClient.doActionWithBucket("HeadBucket", HTTP_HEAD, bucketName, defaultSerializable, output, extensions) 212 if err != nil { 213 output = nil 214 } 215 return 216 } 217 218 // GetBucketMetadata gets the metadata of a bucket. 219 // 220 // You can use this API to send a HEAD request to a bucket to obtain the bucket 221 // metadata such as the storage class and CORS rules (if set). 222 func (obsClient ObsClient) GetBucketMetadata(input *GetBucketMetadataInput, extensions ...extensionOptions) (output *GetBucketMetadataOutput, err error) { 223 output = &GetBucketMetadataOutput{} 224 err = obsClient.doActionWithBucket("GetBucketMetadata", HTTP_HEAD, input.Bucket, input, output, extensions) 225 if err != nil { 226 output = nil 227 } else { 228 ParseGetBucketMetadataOutput(output) 229 } 230 return 231 } 232 233 func (obsClient ObsClient) GetBucketFSStatus(input *GetBucketFSStatusInput, extensions ...extensionOptions) (output *GetBucketFSStatusOutput, err error) { 234 output = &GetBucketFSStatusOutput{} 235 err = obsClient.doActionWithBucket("GetBucketFSStatus", HTTP_HEAD, input.Bucket, input, output, extensions) 236 if err != nil { 237 output = nil 238 } else { 239 ParseGetBucketFSStatusOutput(output) 240 } 241 return 242 } 243 244 // GetBucketStorageInfo gets storage information about a bucket. 245 // 246 // You can use this API to obtain storage information about a bucket, including the 247 // bucket size and number of objects in the bucket. 248 func (obsClient ObsClient) GetBucketStorageInfo(bucketName string, extensions ...extensionOptions) (output *GetBucketStorageInfoOutput, err error) { 249 output = &GetBucketStorageInfoOutput{} 250 err = obsClient.doActionWithBucket("GetBucketStorageInfo", HTTP_GET, bucketName, newSubResourceSerial(SubResourceStorageInfo), output, extensions) 251 if err != nil { 252 output = nil 253 } 254 return 255 } 256 257 func (obsClient ObsClient) getBucketLocationS3(bucketName string, extensions []extensionOptions) (output *GetBucketLocationOutput, err error) { 258 output = &GetBucketLocationOutput{} 259 var outputS3 *getBucketLocationOutputS3 260 outputS3 = &getBucketLocationOutputS3{} 261 err = obsClient.doActionWithBucket("GetBucketLocation", HTTP_GET, bucketName, newSubResourceSerial(SubResourceLocation), outputS3, extensions) 262 if err != nil { 263 output = nil 264 } else { 265 output.BaseModel = outputS3.BaseModel 266 output.Location = outputS3.Location 267 } 268 return 269 } 270 func (obsClient ObsClient) getBucketLocationObs(bucketName string, extensions []extensionOptions) (output *GetBucketLocationOutput, err error) { 271 output = &GetBucketLocationOutput{} 272 var outputObs *getBucketLocationOutputObs 273 outputObs = &getBucketLocationOutputObs{} 274 err = obsClient.doActionWithBucket("GetBucketLocation", HTTP_GET, bucketName, newSubResourceSerial(SubResourceLocation), outputObs, extensions) 275 if err != nil { 276 output = nil 277 } else { 278 output.BaseModel = outputObs.BaseModel 279 output.Location = outputObs.Location 280 } 281 return 282 } 283 284 // GetBucketLocation gets the location of a bucket. 285 // 286 // You can use this API to obtain the bucket location. 287 func (obsClient ObsClient) GetBucketLocation(bucketName string, extensions ...extensionOptions) (output *GetBucketLocationOutput, err error) { 288 if obsClient.conf.signature == SignatureObs { 289 return obsClient.getBucketLocationObs(bucketName, extensions) 290 } 291 return obsClient.getBucketLocationS3(bucketName, extensions) 292 } 293 294 // SetBucketAcl sets the bucket ACL. 295 // 296 // You can use this API to set the ACL for a bucket. 297 func (obsClient ObsClient) SetBucketAcl(input *SetBucketAclInput, extensions ...extensionOptions) (output *BaseModel, err error) { 298 if input == nil { 299 return nil, errors.New("SetBucketAclInput is nil") 300 } 301 output = &BaseModel{} 302 err = obsClient.doActionWithBucket("SetBucketAcl", HTTP_PUT, input.Bucket, input, output, extensions) 303 if err != nil { 304 output = nil 305 } 306 return 307 } 308 func (obsClient ObsClient) getBucketACLObs(bucketName string, extensions []extensionOptions) (output *GetBucketAclOutput, err error) { 309 output = &GetBucketAclOutput{} 310 var outputObs *getBucketACLOutputObs 311 outputObs = &getBucketACLOutputObs{} 312 err = obsClient.doActionWithBucket("GetBucketAcl", HTTP_GET, bucketName, newSubResourceSerial(SubResourceAcl), outputObs, extensions) 313 if err != nil { 314 output = nil 315 } else { 316 output.BaseModel = outputObs.BaseModel 317 output.Owner = outputObs.Owner 318 output.Grants = make([]Grant, 0, len(outputObs.Grants)) 319 for _, valGrant := range outputObs.Grants { 320 tempOutput := Grant{} 321 tempOutput.Delivered = valGrant.Delivered 322 tempOutput.Permission = valGrant.Permission 323 tempOutput.Grantee.DisplayName = valGrant.Grantee.DisplayName 324 tempOutput.Grantee.ID = valGrant.Grantee.ID 325 tempOutput.Grantee.Type = valGrant.Grantee.Type 326 tempOutput.Grantee.URI = GroupAllUsers 327 328 output.Grants = append(output.Grants, tempOutput) 329 } 330 } 331 return 332 } 333 334 // GetBucketAcl gets the bucket ACL. 335 // 336 // You can use this API to obtain a bucket ACL. 337 func (obsClient ObsClient) GetBucketAcl(bucketName string, extensions ...extensionOptions) (output *GetBucketAclOutput, err error) { 338 output = &GetBucketAclOutput{} 339 if obsClient.conf.signature == SignatureObs { 340 return obsClient.getBucketACLObs(bucketName, extensions) 341 } 342 err = obsClient.doActionWithBucket("GetBucketAcl", HTTP_GET, bucketName, newSubResourceSerial(SubResourceAcl), output, extensions) 343 if err != nil { 344 output = nil 345 } 346 return 347 } 348 349 // SetBucketPolicy sets the bucket policy. 350 // 351 // You can use this API to set a bucket policy. If the bucket already has a policy, the 352 // policy will be overwritten by the one specified in this request. 353 func (obsClient ObsClient) SetBucketPolicy(input *SetBucketPolicyInput, extensions ...extensionOptions) (output *BaseModel, err error) { 354 if input == nil { 355 return nil, errors.New("SetBucketPolicy is nil") 356 } 357 output = &BaseModel{} 358 err = obsClient.doActionWithBucket("SetBucketPolicy", HTTP_PUT, input.Bucket, input, output, extensions) 359 if err != nil { 360 output = nil 361 } 362 return 363 } 364 365 // GetBucketPolicy gets the bucket policy. 366 // 367 // You can use this API to obtain the policy of a bucket. 368 func (obsClient ObsClient) GetBucketPolicy(bucketName string, extensions ...extensionOptions) (output *GetBucketPolicyOutput, err error) { 369 output = &GetBucketPolicyOutput{} 370 err = obsClient.doActionWithBucketV2("GetBucketPolicy", HTTP_GET, bucketName, newSubResourceSerial(SubResourcePolicy), output, extensions) 371 if err != nil { 372 output = nil 373 } 374 return 375 } 376 377 // DeleteBucketPolicy deletes the bucket policy. 378 // 379 // You can use this API to delete the policy of a bucket. 380 func (obsClient ObsClient) DeleteBucketPolicy(bucketName string, extensions ...extensionOptions) (output *BaseModel, err error) { 381 output = &BaseModel{} 382 err = obsClient.doActionWithBucket("DeleteBucketPolicy", HTTP_DELETE, bucketName, newSubResourceSerial(SubResourcePolicy), output, extensions) 383 if err != nil { 384 output = nil 385 } 386 return 387 } 388 389 // SetBucketCors sets CORS rules for a bucket. 390 // 391 // You can use this API to set CORS rules for a bucket to allow client browsers to send cross-origin requests. 392 func (obsClient ObsClient) SetBucketCors(input *SetBucketCorsInput, extensions ...extensionOptions) (output *BaseModel, err error) { 393 if input == nil { 394 return nil, errors.New("SetBucketCorsInput is nil") 395 } 396 output = &BaseModel{} 397 err = obsClient.doActionWithBucket("SetBucketCors", HTTP_PUT, input.Bucket, input, output, extensions) 398 if err != nil { 399 output = nil 400 } 401 return 402 } 403 404 // GetBucketCors gets CORS rules of a bucket. 405 // 406 // You can use this API to obtain the CORS rules of a specified bucket. 407 func (obsClient ObsClient) GetBucketCors(bucketName string, extensions ...extensionOptions) (output *GetBucketCorsOutput, err error) { 408 output = &GetBucketCorsOutput{} 409 err = obsClient.doActionWithBucket("GetBucketCors", HTTP_GET, bucketName, newSubResourceSerial(SubResourceCors), output, extensions) 410 if err != nil { 411 output = nil 412 } 413 return 414 } 415 416 // DeleteBucketCors deletes CORS rules of a bucket. 417 // 418 // You can use this API to delete the CORS rules of a specified bucket. 419 func (obsClient ObsClient) DeleteBucketCors(bucketName string, extensions ...extensionOptions) (output *BaseModel, err error) { 420 output = &BaseModel{} 421 err = obsClient.doActionWithBucket("DeleteBucketCors", HTTP_DELETE, bucketName, newSubResourceSerial(SubResourceCors), output, extensions) 422 if err != nil { 423 output = nil 424 } 425 return 426 } 427 428 // SetBucketVersioning sets the versioning status for a bucket. 429 // 430 // You can use this API to set the versioning status for a bucket. 431 func (obsClient ObsClient) SetBucketVersioning(input *SetBucketVersioningInput, extensions ...extensionOptions) (output *BaseModel, err error) { 432 if input == nil { 433 return nil, errors.New("SetBucketVersioningInput is nil") 434 } 435 output = &BaseModel{} 436 err = obsClient.doActionWithBucket("SetBucketVersioning", HTTP_PUT, input.Bucket, input, output, extensions) 437 if err != nil { 438 output = nil 439 } 440 return 441 } 442 443 // GetBucketVersioning gets the versioning status of a bucket. 444 // 445 // You can use this API to obtain the versioning status of a bucket. 446 func (obsClient ObsClient) GetBucketVersioning(bucketName string, extensions ...extensionOptions) (output *GetBucketVersioningOutput, err error) { 447 output = &GetBucketVersioningOutput{} 448 err = obsClient.doActionWithBucket("GetBucketVersioning", HTTP_GET, bucketName, newSubResourceSerial(SubResourceVersioning), output, extensions) 449 if err != nil { 450 output = nil 451 } 452 return 453 } 454 455 // SetBucketWebsiteConfiguration sets website hosting for a bucket. 456 // 457 // You can use this API to set website hosting for a bucket. 458 func (obsClient ObsClient) SetBucketWebsiteConfiguration(input *SetBucketWebsiteConfigurationInput, extensions ...extensionOptions) (output *BaseModel, err error) { 459 if input == nil { 460 return nil, errors.New("SetBucketWebsiteConfigurationInput is nil") 461 } 462 output = &BaseModel{} 463 err = obsClient.doActionWithBucket("SetBucketWebsiteConfiguration", HTTP_PUT, input.Bucket, input, output, extensions) 464 if err != nil { 465 output = nil 466 } 467 return 468 } 469 470 // GetBucketWebsiteConfiguration gets the website hosting settings of a bucket. 471 // 472 // You can use this API to obtain the website hosting settings of a bucket. 473 func (obsClient ObsClient) GetBucketWebsiteConfiguration(bucketName string, extensions ...extensionOptions) (output *GetBucketWebsiteConfigurationOutput, err error) { 474 output = &GetBucketWebsiteConfigurationOutput{} 475 err = obsClient.doActionWithBucket("GetBucketWebsiteConfiguration", HTTP_GET, bucketName, newSubResourceSerial(SubResourceWebsite), output, extensions) 476 if err != nil { 477 output = nil 478 } 479 return 480 } 481 482 // DeleteBucketWebsiteConfiguration deletes the website hosting settings of a bucket. 483 // 484 // You can use this API to delete the website hosting settings of a bucket. 485 func (obsClient ObsClient) DeleteBucketWebsiteConfiguration(bucketName string, extensions ...extensionOptions) (output *BaseModel, err error) { 486 output = &BaseModel{} 487 err = obsClient.doActionWithBucket("DeleteBucketWebsiteConfiguration", HTTP_DELETE, bucketName, newSubResourceSerial(SubResourceWebsite), output, extensions) 488 if err != nil { 489 output = nil 490 } 491 return 492 } 493 494 // SetBucketLoggingConfiguration sets the bucket logging. 495 // 496 // You can use this API to configure access logging for a bucket. 497 func (obsClient ObsClient) SetBucketLoggingConfiguration(input *SetBucketLoggingConfigurationInput, extensions ...extensionOptions) (output *BaseModel, err error) { 498 if input == nil { 499 return nil, errors.New("SetBucketLoggingConfigurationInput is nil") 500 } 501 output = &BaseModel{} 502 err = obsClient.doActionWithBucket("SetBucketLoggingConfiguration", HTTP_PUT, input.Bucket, input, output, extensions) 503 if err != nil { 504 output = nil 505 } 506 return 507 } 508 509 // GetBucketLoggingConfiguration gets the logging settings of a bucket. 510 // 511 // You can use this API to obtain the access logging settings of a bucket. 512 func (obsClient ObsClient) GetBucketLoggingConfiguration(bucketName string, extensions ...extensionOptions) (output *GetBucketLoggingConfigurationOutput, err error) { 513 output = &GetBucketLoggingConfigurationOutput{} 514 err = obsClient.doActionWithBucket("GetBucketLoggingConfiguration", HTTP_GET, bucketName, newSubResourceSerial(SubResourceLogging), output, extensions) 515 if err != nil { 516 output = nil 517 } 518 return 519 } 520 521 // SetBucketLifecycleConfiguration sets lifecycle rules for a bucket. 522 // 523 // You can use this API to set lifecycle rules for a bucket, to periodically transit 524 // storage classes of objects and delete objects in the bucket. 525 func (obsClient ObsClient) SetBucketLifecycleConfiguration(input *SetBucketLifecycleConfigurationInput, extensions ...extensionOptions) (output *BaseModel, err error) { 526 if input == nil { 527 return nil, errors.New("SetBucketLifecycleConfigurationInput is nil") 528 } 529 output = &BaseModel{} 530 err = obsClient.doActionWithBucket("SetBucketLifecycleConfiguration", HTTP_PUT, input.Bucket, input, output, extensions) 531 if err != nil { 532 output = nil 533 } 534 return 535 } 536 537 // GetBucketLifecycleConfiguration gets lifecycle rules of a bucket. 538 // 539 // You can use this API to obtain the lifecycle rules of a bucket. 540 func (obsClient ObsClient) GetBucketLifecycleConfiguration(bucketName string, extensions ...extensionOptions) (output *GetBucketLifecycleConfigurationOutput, err error) { 541 output = &GetBucketLifecycleConfigurationOutput{} 542 err = obsClient.doActionWithBucket("GetBucketLifecycleConfiguration", HTTP_GET, bucketName, newSubResourceSerial(SubResourceLifecycle), output, extensions) 543 if err != nil { 544 output = nil 545 } 546 return 547 } 548 549 // DeleteBucketLifecycleConfiguration deletes lifecycle rules of a bucket. 550 // 551 // You can use this API to delete all lifecycle rules of a bucket. 552 func (obsClient ObsClient) DeleteBucketLifecycleConfiguration(bucketName string, extensions ...extensionOptions) (output *BaseModel, err error) { 553 output = &BaseModel{} 554 err = obsClient.doActionWithBucket("DeleteBucketLifecycleConfiguration", HTTP_DELETE, bucketName, newSubResourceSerial(SubResourceLifecycle), output, extensions) 555 if err != nil { 556 output = nil 557 } 558 return 559 } 560 561 // SetBucketEncryption sets the default server-side encryption for a bucket. 562 // 563 // You can use this API to create or update the default server-side encryption for a bucket. 564 func (obsClient ObsClient) SetBucketEncryption(input *SetBucketEncryptionInput, extensions ...extensionOptions) (output *BaseModel, err error) { 565 if input == nil { 566 return nil, errors.New("SetBucketEncryptionInput is nil") 567 } 568 output = &BaseModel{} 569 err = obsClient.doActionWithBucket("SetBucketEncryption", HTTP_PUT, input.Bucket, input, output, extensions) 570 if err != nil { 571 output = nil 572 } 573 return 574 } 575 576 // GetBucketEncryption gets the encryption configuration of a bucket. 577 // 578 // You can use this API to obtain obtain the encryption configuration of a bucket. 579 func (obsClient ObsClient) GetBucketEncryption(bucketName string, extensions ...extensionOptions) (output *GetBucketEncryptionOutput, err error) { 580 output = &GetBucketEncryptionOutput{} 581 err = obsClient.doActionWithBucket("GetBucketEncryption", HTTP_GET, bucketName, newSubResourceSerial(SubResourceEncryption), output, extensions) 582 if err != nil { 583 output = nil 584 } 585 return 586 } 587 588 // DeleteBucketEncryption deletes the encryption configuration of a bucket. 589 // 590 // You can use this API to delete the encryption configuration of a bucket. 591 func (obsClient ObsClient) DeleteBucketEncryption(bucketName string, extensions ...extensionOptions) (output *BaseModel, err error) { 592 output = &BaseModel{} 593 err = obsClient.doActionWithBucket("DeleteBucketEncryption", HTTP_DELETE, bucketName, newSubResourceSerial(SubResourceEncryption), output, extensions) 594 if err != nil { 595 output = nil 596 } 597 return 598 } 599 600 // SetBucketReplication sets the cross-region replication for a bucket. 601 // 602 // You can use this API to create or update the cross-region replication for a bucket. 603 func (obsClient ObsClient) SetBucketReplication(input *SetBucketReplicationInput, extensions ...extensionOptions) (output *BaseModel, err error) { 604 if input == nil { 605 return nil, errors.New("SetBucketReplicationInput is nil") 606 } 607 output = &BaseModel{} 608 err = obsClient.doActionWithBucket("SetBucketReplication", HTTP_PUT, input.Bucket, input, output, extensions) 609 if err != nil { 610 output = nil 611 } 612 return 613 } 614 615 // GetBucketReplication gets the cross-region replication configuration of a bucket. 616 // 617 // You can use this API to obtain the cross-region replication configuration of a bucket. 618 func (obsClient ObsClient) GetBucketReplication(bucketName string, extensions ...extensionOptions) (output *GetBucketReplicationOutput, err error) { 619 output = &GetBucketReplicationOutput{} 620 err = obsClient.doActionWithBucket("GetBucketReplication", HTTP_GET, bucketName, newSubResourceSerial(SubResourceReplication), output, extensions) 621 if err != nil { 622 output = nil 623 } 624 return 625 } 626 627 // DeleteBucketReplication deletes the cross-region replication configuration of a bucket. 628 // 629 // You can use this API to delete the cross-region replication configuration of a bucket. 630 func (obsClient ObsClient) DeleteBucketReplication(bucketName string, extensions ...extensionOptions) (output *BaseModel, err error) { 631 output = &BaseModel{} 632 err = obsClient.doActionWithBucket("DeleteBucketReplication", HTTP_DELETE, bucketName, newSubResourceSerial(SubResourceReplication), output, extensions) 633 if err != nil { 634 output = nil 635 } 636 return 637 } 638 639 // SetBucketTagging sets bucket tags. 640 // 641 // You can use this API to set bucket tags. 642 func (obsClient ObsClient) SetBucketTagging(input *SetBucketTaggingInput, extensions ...extensionOptions) (output *BaseModel, err error) { 643 if input == nil { 644 return nil, errors.New("SetBucketTaggingInput is nil") 645 } 646 output = &BaseModel{} 647 err = obsClient.doActionWithBucket("SetBucketTagging", HTTP_PUT, input.Bucket, input, output, extensions) 648 if err != nil { 649 output = nil 650 } 651 return 652 } 653 654 // GetBucketTagging gets bucket tags. 655 // 656 // You can use this API to obtain the tags of a specified bucket. 657 func (obsClient ObsClient) GetBucketTagging(bucketName string, extensions ...extensionOptions) (output *GetBucketTaggingOutput, err error) { 658 output = &GetBucketTaggingOutput{} 659 err = obsClient.doActionWithBucket("GetBucketTagging", HTTP_GET, bucketName, newSubResourceSerial(SubResourceTagging), output, extensions) 660 if err != nil { 661 output = nil 662 } 663 return 664 } 665 666 // DeleteBucketTagging deletes bucket tags. 667 // 668 // You can use this API to delete the tags of a specified bucket. 669 func (obsClient ObsClient) DeleteBucketTagging(bucketName string, extensions ...extensionOptions) (output *BaseModel, err error) { 670 output = &BaseModel{} 671 err = obsClient.doActionWithBucket("DeleteBucketTagging", HTTP_DELETE, bucketName, newSubResourceSerial(SubResourceTagging), output, extensions) 672 if err != nil { 673 output = nil 674 } 675 return 676 } 677 678 // SetBucketNotification sets event notification for a bucket. 679 // 680 // You can use this API to configure event notification for a bucket. You will be notified of all 681 // specified operations performed on the bucket. 682 func (obsClient ObsClient) SetBucketNotification(input *SetBucketNotificationInput, extensions ...extensionOptions) (output *BaseModel, err error) { 683 if input == nil { 684 return nil, errors.New("SetBucketNotificationInput is nil") 685 } 686 output = &BaseModel{} 687 err = obsClient.doActionWithBucket("SetBucketNotification", HTTP_PUT, input.Bucket, input, output, extensions) 688 if err != nil { 689 output = nil 690 } 691 return 692 } 693 694 // GetBucketNotification gets event notification settings of a bucket. 695 // 696 // You can use this API to obtain the event notification configuration of a bucket. 697 func (obsClient ObsClient) GetBucketNotification(bucketName string, extensions ...extensionOptions) (output *GetBucketNotificationOutput, err error) { 698 if obsClient.conf.signature != SignatureObs { 699 return obsClient.getBucketNotificationS3(bucketName, extensions) 700 } 701 output = &GetBucketNotificationOutput{} 702 err = obsClient.doActionWithBucket("GetBucketNotification", HTTP_GET, bucketName, newSubResourceSerial(SubResourceNotification), output, extensions) 703 if err != nil { 704 output = nil 705 } 706 return 707 } 708 709 func (obsClient ObsClient) getBucketNotificationS3(bucketName string, extensions []extensionOptions) (output *GetBucketNotificationOutput, err error) { 710 outputS3 := &getBucketNotificationOutputS3{} 711 err = obsClient.doActionWithBucket("GetBucketNotification", HTTP_GET, bucketName, newSubResourceSerial(SubResourceNotification), outputS3, extensions) 712 if err != nil { 713 return nil, err 714 } 715 716 output = &GetBucketNotificationOutput{} 717 output.BaseModel = outputS3.BaseModel 718 topicConfigurations := make([]TopicConfiguration, 0, len(outputS3.TopicConfigurations)) 719 for _, topicConfigurationS3 := range outputS3.TopicConfigurations { 720 topicConfiguration := TopicConfiguration{} 721 topicConfiguration.ID = topicConfigurationS3.ID 722 topicConfiguration.Topic = topicConfigurationS3.Topic 723 topicConfiguration.FilterRules = topicConfigurationS3.FilterRules 724 725 events := make([]EventType, 0, len(topicConfigurationS3.Events)) 726 for _, event := range topicConfigurationS3.Events { 727 events = append(events, ParseStringToEventType(event)) 728 } 729 topicConfiguration.Events = events 730 topicConfigurations = append(topicConfigurations, topicConfiguration) 731 } 732 output.TopicConfigurations = topicConfigurations 733 return 734 } 735 736 // SetBucketRequestPayment sets requester-pays setting for a bucket. 737 func (obsClient ObsClient) SetBucketRequestPayment(input *SetBucketRequestPaymentInput, extensions ...extensionOptions) (output *BaseModel, err error) { 738 if input == nil { 739 return nil, errors.New("SetBucketRequestPaymentInput is nil") 740 } 741 output = &BaseModel{} 742 err = obsClient.doActionWithBucket("SetBucketRequestPayment", HTTP_PUT, input.Bucket, input, output, extensions) 743 if err != nil { 744 output = nil 745 } 746 return 747 } 748 749 // GetBucketRequestPayment gets requester-pays setting of a bucket. 750 func (obsClient ObsClient) GetBucketRequestPayment(bucketName string, extensions ...extensionOptions) (output *GetBucketRequestPaymentOutput, err error) { 751 output = &GetBucketRequestPaymentOutput{} 752 err = obsClient.doActionWithBucket("GetBucketRequestPayment", HTTP_GET, bucketName, newSubResourceSerial(SubResourceRequestPayment), output, extensions) 753 if err != nil { 754 output = nil 755 } 756 return 757 } 758 759 // SetBucketFetchPolicy sets the bucket fetch policy. 760 // 761 // You can use this API to set a bucket fetch policy. 762 func (obsClient ObsClient) SetBucketFetchPolicy(input *SetBucketFetchPolicyInput, extensions ...extensionOptions) (output *BaseModel, err error) { 763 if input == nil { 764 return nil, errors.New("SetBucketFetchPolicyInput is nil") 765 } 766 if strings.TrimSpace(string(input.Status)) == "" { 767 return nil, errors.New("Fetch policy status is empty") 768 } 769 if strings.TrimSpace(input.Agency) == "" { 770 return nil, errors.New("Fetch policy agency is empty") 771 } 772 output = &BaseModel{} 773 err = obsClient.doActionWithBucketAndKey("SetBucketFetchPolicy", HTTP_PUT, input.Bucket, string(objectKeyExtensionPolicy), input, output, extensions) 774 if err != nil { 775 output = nil 776 } 777 return 778 } 779 780 // GetBucketFetchPolicy gets the bucket fetch policy. 781 // 782 // You can use this API to obtain the fetch policy of a bucket. 783 func (obsClient ObsClient) GetBucketFetchPolicy(input *GetBucketFetchPolicyInput, extensions ...extensionOptions) (output *GetBucketFetchPolicyOutput, err error) { 784 if input == nil { 785 return nil, errors.New("GetBucketFetchPolicyInput is nil") 786 } 787 output = &GetBucketFetchPolicyOutput{} 788 err = obsClient.doActionWithBucketAndKeyV2("GetBucketFetchPolicy", HTTP_GET, input.Bucket, string(objectKeyExtensionPolicy), input, output, extensions) 789 if err != nil { 790 output = nil 791 } 792 return 793 } 794 795 // DeleteBucketFetchPolicy deletes the bucket fetch policy. 796 // 797 // You can use this API to delete the fetch policy of a bucket. 798 func (obsClient ObsClient) DeleteBucketFetchPolicy(input *DeleteBucketFetchPolicyInput, extensions ...extensionOptions) (output *BaseModel, err error) { 799 if input == nil { 800 return nil, errors.New("DeleteBucketFetchPolicyInput is nil") 801 } 802 output = &BaseModel{} 803 err = obsClient.doActionWithBucketAndKey("DeleteBucketFetchPolicy", HTTP_DELETE, input.Bucket, string(objectKeyExtensionPolicy), input, output, extensions) 804 if err != nil { 805 output = nil 806 } 807 return 808 } 809 810 // SetBucketFetchJob sets the bucket fetch job. 811 // 812 // You can use this API to set a bucket fetch job. 813 func (obsClient ObsClient) SetBucketFetchJob(input *SetBucketFetchJobInput, extensions ...extensionOptions) (output *SetBucketFetchJobOutput, err error) { 814 if input == nil { 815 return nil, errors.New("SetBucketFetchJobInput is nil") 816 } 817 if strings.TrimSpace(input.URL) == "" { 818 return nil, errors.New("URL is empty") 819 } 820 output = &SetBucketFetchJobOutput{} 821 err = obsClient.doActionWithBucketAndKeyV2("SetBucketFetchJob", HTTP_POST, input.Bucket, string(objectKeyAsyncFetchJob), input, output, extensions) 822 if err != nil { 823 output = nil 824 } 825 return 826 } 827 828 // GetBucketFetchJob gets the bucket fetch job. 829 // 830 // You can use this API to obtain the fetch job of a bucket. 831 func (obsClient ObsClient) GetBucketFetchJob(input *GetBucketFetchJobInput, extensions ...extensionOptions) (output *GetBucketFetchJobOutput, err error) { 832 if input == nil { 833 return nil, errors.New("GetBucketFetchJobInput is nil") 834 } 835 if strings.TrimSpace(input.JobID) == "" { 836 return nil, errors.New("JobID is empty") 837 } 838 output = &GetBucketFetchJobOutput{} 839 err = obsClient.doActionWithBucketAndKeyV2("GetBucketFetchJob", HTTP_GET, input.Bucket, string(objectKeyAsyncFetchJob)+"/"+input.JobID, input, output, extensions) 840 if err != nil { 841 output = nil 842 } 843 return 844 }