文档首页/ 云审计服务 CTS/ API参考/ API V3(推荐使用)/ 其它接口/ 检查已经配置OBS桶是否可以成功转储
更新时间:2024-11-08 GMT+08:00

检查已经配置OBS桶是否可以成功转储

功能介绍

检查已经配置OBS桶是否可以成功转储。

调用方法

请参见如何调用API

URI

POST /v3/{domain_id}/checkbucket

表1 路径参数

参数

是否必选

参数类型

描述

domain_id

String

账户id,参见获取账号ID和项目ID章节。

请求参数

表2 请求Body参数

参数

是否必选

参数类型

描述

buckets

Array of CheckBucketRequest objects

请求检查的OBS桶列表。

表3 CheckBucketRequest

参数

是否必选

参数类型

描述

bucket_name

String

标识OBS桶名称。由数字或字母开头,支持小写字母、数字、“-”、“.”,长度为3~63个字符。

bucket_location

String

标识OBS桶位置。

kms_id

String

事件文件转储加密所采用的密钥id,is_support_trace_files_encryption"参数值为“是”时,此参数为必选项。

is_support_trace_files_encryption

Boolean

事件文件转储加密功能开关。 该参数必须与kms_id参数同时使用。

响应参数

状态码: 200

表4 响应Body参数

参数

参数类型

描述

buckets

Array of Bucket objects

检查OBS桶状态响应体。

表5 Bucket

参数

参数类型

描述

bucket_name

String

标识OBS桶名称。由数字或字母开头,支持小写字母、数字、“-”、“.”,长度为3~63个字符。

bucket_location

String

标识桶位置。

kms_id

String

事件文件转储加密所采用的密钥id。 如果is_support_trace_files_encryption"参数值为“是”时,此参数为必选项。

is_support_trace_files_encryption

Boolean

事件文件转储加密功能开关。 该参数必须与kms_id参数同时使用。

check_bucket_response

CheckBucketResponse object

转储OBS桶的检查结果。

表6 CheckBucketResponse

参数

参数类型

描述

error_code

String

错误码。

error_message

String

错误信息。

response_code

Integer

返回的http状态码。

success

Boolean

是否成功转储。

状态码: 400

表7 响应Body参数

参数

参数类型

描述

error_code

String

错误码标识,CTS.XXX。

error_msg

String

错误描述。

状态码: 401

表8 响应Body参数

参数

参数类型

描述

error_code

String

错误码标识,CTS.XXX。

error_msg

String

错误描述。

状态码: 403

表9 响应Body参数

参数

参数类型

描述

error_code

String

错误码标识,CTS.XXX。

error_msg

String

错误描述。

状态码: 404

表10 响应Body参数

参数

参数类型

描述

error_code

String

错误码标识,CTS.XXX。

error_msg

String

错误描述。

状态码: 500

表11 响应Body参数

参数

参数类型

描述

error_code

String

错误码标识,CTS.XXX。

error_msg

String

错误描述。

状态码: 503

表12 响应Body参数

参数

参数类型

描述

error_code

String

错误码标识,CTS.XXX。

error_msg

String

错误描述。

请求示例

检查obs桶状态请求体示例

POST https://{endpoint}/v3/{domain_id}/checkbucket

{
  "buckets" : [ {
    "bucket_location" : "cn-north-1",
    "bucket_name" : "bucket1",
    "is_support_trace_files_encryption" : false,
    "kms_id" : "1f26f8d8-65d4-436b-bea2-bd0ac1984f71"
  }, {
    "bucket_location" : "cn-north-2",
    "bucket_name" : "bucket2",
    "is_support_trace_files_encryption" : false,
    "kms_id" : "0c1b7d87-5186-411a-86ce-ed3b2ec848c9"
  } ]
}

响应示例

状态码: 200

请求成功。

{
  "buckets" : [ {
    "bucket_location" : "cn-north-1",
    "bucket_name" : "bucket1",
    "check_bucket_response" : {
      "response_code" : 200,
      "success" : true
    },
    "is_support_trace_files_encryption" : false,
    "kms_id" : "1f26f8d8-65d4-436b-bea2-bd0ac1984f71"
  }, {
    "bucket_location" : "cn-north-2",
    "bucket_name" : "bucket2",
    "check_bucket_response" : {
      "error_code" : "OBS.NoSuchBucket",
      "error_message" : "Error message:Request Error.OBS service Error Message.",
      "response_code" : 404,
      "success" : false
    },
    "is_support_trace_files_encryption" : false,
    "kms_id" : "0c1b7d87-5186-411a-86ce-ed3b2ec848c9"
  } ]
}

SDK代码示例

SDK代码示例如下。

检查obs桶状态请求体示例

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
package com.huaweicloud.sdk.test;

import com.huaweicloud.sdk.core.auth.ICredential;
import com.huaweicloud.sdk.core.auth.BasicCredentials;
import com.huaweicloud.sdk.core.exception.ConnectionException;
import com.huaweicloud.sdk.core.exception.RequestTimeoutException;
import com.huaweicloud.sdk.core.exception.ServiceResponseException;
import com.huaweicloud.sdk.cts.v3.region.CtsRegion;
import com.huaweicloud.sdk.cts.v3.*;
import com.huaweicloud.sdk.cts.v3.model.*;

import java.util.List;
import java.util.ArrayList;

public class CheckObsBucketsSolution {

    public static void main(String[] args) {
        // The AK and SK used for authentication are hard-coded or stored in plaintext, which has great security risks. It is recommended that the AK and SK be stored in ciphertext in configuration files or environment variables and decrypted during use to ensure security.
        // In this example, AK and SK are stored in environment variables for authentication. Before running this example, set environment variables CLOUD_SDK_AK and CLOUD_SDK_SK in the local environment
        String ak = System.getenv("CLOUD_SDK_AK");
        String sk = System.getenv("CLOUD_SDK_SK");

        ICredential auth = new BasicCredentials()
                .withAk(ak)
                .withSk(sk);

        CtsClient client = CtsClient.newBuilder()
                .withCredential(auth)
                .withRegion(CtsRegion.valueOf("<YOUR REGION>"))
                .build();
        CheckObsBucketsRequest request = new CheckObsBucketsRequest();
        CheckObsBucketsRequestBody body = new CheckObsBucketsRequestBody();
        List<CheckBucketRequest> listbodyBuckets = new ArrayList<>();
        listbodyBuckets.add(
            new CheckBucketRequest()
                .withBucketName("bucket1")
                .withBucketLocation("cn-north-1")
                .withKmsId("1f26f8d8-65d4-436b-bea2-bd0ac1984f71")
                .withIsSupportTraceFilesEncryption(false)
        );
        listbodyBuckets.add(
            new CheckBucketRequest()
                .withBucketName("bucket2")
                .withBucketLocation("cn-north-2")
                .withKmsId("0c1b7d87-5186-411a-86ce-ed3b2ec848c9")
                .withIsSupportTraceFilesEncryption(false)
        );
        body.withBuckets(listbodyBuckets);
        request.withBody(body);
        try {
            CheckObsBucketsResponse response = client.checkObsBuckets(request);
            System.out.println(response.toString());
        } catch (ConnectionException e) {
            e.printStackTrace();
        } catch (RequestTimeoutException e) {
            e.printStackTrace();
        } catch (ServiceResponseException e) {
            e.printStackTrace();
            System.out.println(e.getHttpStatusCode());
            System.out.println(e.getRequestId());
            System.out.println(e.getErrorCode());
            System.out.println(e.getErrorMsg());
        }
    }
}

检查obs桶状态请求体示例

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
# coding: utf-8

import os
from huaweicloudsdkcore.auth.credentials import BasicCredentials
from huaweicloudsdkcts.v3.region.cts_region import CtsRegion
from huaweicloudsdkcore.exceptions import exceptions
from huaweicloudsdkcts.v3 import *

if __name__ == "__main__":
    # The AK and SK used for authentication are hard-coded or stored in plaintext, which has great security risks. It is recommended that the AK and SK be stored in ciphertext in configuration files or environment variables and decrypted during use to ensure security.
    # In this example, AK and SK are stored in environment variables for authentication. Before running this example, set environment variables CLOUD_SDK_AK and CLOUD_SDK_SK in the local environment
    ak = os.environ["CLOUD_SDK_AK"]
    sk = os.environ["CLOUD_SDK_SK"]

    credentials = BasicCredentials(ak, sk)

    client = CtsClient.new_builder() \
        .with_credentials(credentials) \
        .with_region(CtsRegion.value_of("<YOUR REGION>")) \
        .build()

    try:
        request = CheckObsBucketsRequest()
        listBucketsbody = [
            CheckBucketRequest(
                bucket_name="bucket1",
                bucket_location="cn-north-1",
                kms_id="1f26f8d8-65d4-436b-bea2-bd0ac1984f71",
                is_support_trace_files_encryption=False
            ),
            CheckBucketRequest(
                bucket_name="bucket2",
                bucket_location="cn-north-2",
                kms_id="0c1b7d87-5186-411a-86ce-ed3b2ec848c9",
                is_support_trace_files_encryption=False
            )
        ]
        request.body = CheckObsBucketsRequestBody(
            buckets=listBucketsbody
        )
        response = client.check_obs_buckets(request)
        print(response)
    except exceptions.ClientRequestException as e:
        print(e.status_code)
        print(e.request_id)
        print(e.error_code)
        print(e.error_msg)

检查obs桶状态请求体示例

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
package main

import (
	"fmt"
	"github.com/huaweicloud/huaweicloud-sdk-go-v3/core/auth/basic"
    cts "github.com/huaweicloud/huaweicloud-sdk-go-v3/services/cts/v3"
	"github.com/huaweicloud/huaweicloud-sdk-go-v3/services/cts/v3/model"
    region "github.com/huaweicloud/huaweicloud-sdk-go-v3/services/cts/v3/region"
)

func main() {
    // The AK and SK used for authentication are hard-coded or stored in plaintext, which has great security risks. It is recommended that the AK and SK be stored in ciphertext in configuration files or environment variables and decrypted during use to ensure security.
    // In this example, AK and SK are stored in environment variables for authentication. Before running this example, set environment variables CLOUD_SDK_AK and CLOUD_SDK_SK in the local environment
    ak := os.Getenv("CLOUD_SDK_AK")
    sk := os.Getenv("CLOUD_SDK_SK")

    auth := basic.NewCredentialsBuilder().
        WithAk(ak).
        WithSk(sk).
        Build()

    client := cts.NewCtsClient(
        cts.CtsClientBuilder().
            WithRegion(region.ValueOf("<YOUR REGION>")).
            WithCredential(auth).
            Build())

    request := &model.CheckObsBucketsRequest{}
	kmsIdBuckets:= "1f26f8d8-65d4-436b-bea2-bd0ac1984f71"
	isSupportTraceFilesEncryptionBuckets:= false
	kmsIdBuckets1:= "0c1b7d87-5186-411a-86ce-ed3b2ec848c9"
	isSupportTraceFilesEncryptionBuckets1:= false
	var listBucketsbody = []model.CheckBucketRequest{
        {
            BucketName: "bucket1",
            BucketLocation: "cn-north-1",
            KmsId: &kmsIdBuckets,
            IsSupportTraceFilesEncryption: &isSupportTraceFilesEncryptionBuckets,
        },
        {
            BucketName: "bucket2",
            BucketLocation: "cn-north-2",
            KmsId: &kmsIdBuckets1,
            IsSupportTraceFilesEncryption: &isSupportTraceFilesEncryptionBuckets1,
        },
    }
	request.Body = &model.CheckObsBucketsRequestBody{
		Buckets: &listBucketsbody,
	}
	response, err := client.CheckObsBuckets(request)
	if err == nil {
        fmt.Printf("%+v\n", response)
    } else {
        fmt.Println(err)
    }
}

更多编程语言的SDK代码示例,请参见API Explorer的代码示例页签,可生成自动对应的SDK代码示例。

状态码

状态码

描述

200

请求成功。

400

服务器未能处理请求。

401

请求鉴权校验失败,访问被拒绝。

403

请求权限校验失败,访问被禁止。

404

请求资源不存在,请求未完成。

500

服务内部异常,请求未完成。

503

被请求的服务无效。建议直接修改该请求,不要重试该请求。

错误码

请参见错误码