更新时间:2024-11-22 GMT+08:00
分享

创建数据脱敏策略

功能介绍

创建动态数据脱敏策略。

调用方法

请参见如何调用API

URI

POST /v1/{project_id}/security/masking/dynamic/policies

表1 路径参数

参数

是否必选

参数类型

描述

project_id

String

项目ID,获取方法请参见项目ID和账号ID

请求参数

表2 请求Header参数

参数

是否必选

参数类型

描述

workspace

String

工作空间ID,获取方法请参见实例ID和工作空间ID

X-Auth-Token

String

IAM Token,通过调用IAM服务获取用户Token接口获取(响应消息头中X-Subject-Token的值)使用Token认证时必选。

表3 请求Body参数

参数

是否必选

参数类型

描述

name

String

策略名称。英文和汉字开头, 支持英文、汉字、数字、下划线, 2-64字符。

datasource_type

String

数据源类型

  • HIVE数据源
  • DWS数据源
  • DLI数据源

cluster_id

String

集群id。请于集群管理页面查看集群ID信息。当数据源类型为DLI时,该参数需要填写为DLI。

cluster_name

String

集群名称。请于集群管理页面查看集群名称信息。当数据源类型为DLI时,该参数需要填写为DLI。

database_name

String

数据库名称。获取方法请参见获取数据源中的表

table_id

String

数据表id,获取方法请参见获取数据源中的表

table_name

String

数据表名称, 获取方法请参见获取数据源中的表

user_groups

String

用户组列表,用户组名称逗号分隔(非必填项,但用户、用户组必须二选其一进行配置)。例如:"userGroup1,userGroup2"。

users

String

用户列表,用户名称逗号分隔(非必填项,但用户、用户组必须二选其一进行配置),例如:"user1,user2"。

conn_name

String

数据连接名称,获取方法请参见查询数据连接列表

conn_id

String

数据连接id,获取方法请参见查询数据连接列表

schema_name

String

DWS数据源的模式名称。

policy_list

Array of DynamicMaskingPolicyCreate objects

动态数据脱敏策略列表。

表4 DynamicMaskingPolicyCreate

参数

是否必选

参数类型

描述

column_name

String

数据表中的字段名称。

column_type

String

数据表中字段的数据类型。

algorithm_type

String

具体动态脱敏规则参数介绍请参见DataArts Studio用户指南手册中“管理动态脱敏策略”章节。

HIVE数据源动态脱敏算法

  • MASK 掩盖英文字符和数字
  • MASK_SHOW_LAST_4 保留后四位
  • MASK_SHOW_FIRST_4 保留前四位
  • MASK_HASH 哈希掩盖
  • MASK_DATE_SHOW_YEAR 掩盖月份和日期
  • MASK_NULL NULL掩盖

DWS数据源动态脱敏算法

  • DWS_ALL_MASK 全掩码
  • DWS_BACK_KEEP 保留后4位,其余脱敏为*
  • DWS_FRONT_KEEP 保留前2位,其余脱敏为*
  • DWS_SELF_CONFIG 需要输入开始位置、结束位置、脱敏字符传入detail结构体中,例如{"start": 1, "end": 2, "string_target": "*"}

DLI数据源动态脱敏算法

  • MASK 掩盖英文字符和数字
  • MASK_SHOW_LAST_4 保留后四位
  • MASK_SHOW_FIRST_4 保留前四位
  • MASK_HASH 哈希掩盖
  • MASK_DATE_SHOW_YEAR 掩盖月份和日期
  • MASK_NULL NULL掩盖

algorithm_detail

String

动态脱敏策略算法详情。

algorithm_detail_dto

AlgorithmDetailDTO object

动态脱敏策略算法详情

表5 AlgorithmDetailDTO

参数

是否必选

参数类型

描述

start

Integer

开始位数,该值需要大于0且小于end值。

end

Integer

结束位数,该值需要大于或等于start值。

int_target

Integer

数值类型。

string_target

String

字符串类型。可输入参数为"*"或者"#"。

响应参数

状态码: 200

表6 响应Body参数

参数

参数类型

描述

id

String

策略id。

name

String

策略名称。英文和汉字开头, 支持英文、汉字、数字、下划线, 2-64字符。

datasource_type

String

数据源类型

  • HIVE数据源
  • DWS数据源
  • DLI数据源

cluster_id

String

集群id。请于集群管理页面查看集群ID信息。当数据源类型为DLI时,该参数需要填写为DLI。

cluster_name

String

集群名称。请于集群管理页面查看集群名称信息。当数据源类型为DLI时,该参数需要填写为DLI。

database_name

String

数据库名称。获取方法请参见获取数据源中的表

table_id

String

数据表id,获取方法请参见获取数据源中的表

table_name

String

数据表名称, 获取方法请参见获取数据源中的表

user_groups

String

用户组列表,用户组名称逗号分隔(非必填项,但用户、用户组必须二选其一进行配置)。例如:"userGroup1,userGroup2"。

users

String

用户列表,用户名称逗号分隔(非必填项,但用户、用户组必须二选其一进行配置),例如:"user1,user2"。

conn_name

String

数据连接名称,获取方法请参见查询数据连接列表

conn_id

String

数据连接id,获取方法请参见查询数据连接列表

sync_status

String

同步状态:

  • UNKNOWN 未知状态
  • NOT_SYNC 未同步
  • SYNCING 同步中
  • SYNC_SUCCESS 同步成功
  • SYNC_FAIL 同步失败
  • SYNC_PARTIAL_FAIL 存在失败
  • DELETE_FAIL 删除失败
  • DELETING 删除中
  • UPDATING 更新中
  • DATA_UPDATED 数据存在更新

sync_msg

String

策略同步信息。

sync_log

String

同步运行日志, 格式为 字段同步信息+换行符。

create_time

Long

策略创建时间。

create_user

String

策略创建者。

update_time

Long

策略更新时间。

update_user

String

策略更新者。

schema_name

String

DWS数据源的模式名称。

policy_list

Array of DynamicMaskingPolicy objects

动态数据脱敏策略列表。

表7 DynamicMaskingPolicy

参数

参数类型

描述

id

String

字段脱敏策略id。

policy_set_id

String

动态脱敏策略id。

column_name

String

数据表中的字段名称。

column_type

String

数据表中字段的数据类型。

algorithm_type

String

动态脱敏规则参数介绍,具体请参考用户指南手册中的“动态脱敏规则介绍”章节。

HIVE数据源动态脱敏算法

  • MASK 掩盖英文字符和数字
  • MASK_SHOW_LAST_4 保留后四位
  • MASK_SHOW_FIRST_4 保留前四位
  • MASK_HASH 哈希掩盖
  • MASK_DATE_SHOW_YEAR 掩盖月份和日期
  • MASK_NULL NULL掩盖

DWS数据源动态脱敏算法

  • DWS_ALL_MASK 全掩码
  • DWS_BACK_KEEP 保留后4位,其余脱敏为*
  • DWS_FRONT_KEEP 保留前2位,其余脱敏为*
  • DWS_SELF_CONFIG 需要输入开始位置、结束位置、脱敏字符传入detail结构体中,例如{"start": 1, "end": 2, "string_target": "*"}

DLI数据源动态脱敏算法

  • MASK 掩盖英文字符和数字
  • MASK_SHOW_LAST_4 保留后四位
  • MASK_SHOW_FIRST_4 保留前四位
  • MASK_HASH 哈希掩盖
  • MASK_DATE_SHOW_YEAR 掩盖月份和日期
  • MASK_NULL NULL掩盖

sync_status

String

同步状态:

  • UNKNOWN 未知状态
  • NOT_SYNC 未同步
  • SYNCING 同步中
  • SYNC_SUCCESS 同步成功
  • SYNC_FAIL 同步失败
  • SYNC_PARTIAL_FAIL 存在失败
  • DELETE_FAIL 删除失败
  • DELETING 删除中
  • UPDATING 更新中
  • DATA_UPDATED 数据存在更新

algorithm_detail

String

动态脱敏策略算法详情。

algorithm_detail_dto

AlgorithmDetailDTO object

动态脱敏策略算法详情

表8 AlgorithmDetailDTO

参数

参数类型

描述

start

Integer

开始位数,该值需要大于0且小于end值。

end

Integer

结束位数,该值需要大于或等于start值。

int_target

Integer

数值类型。

string_target

String

字符串类型。可输入参数为"*"或者"#"。

状态码: 400

表9 响应Body参数

参数

参数类型

描述

error_code

String

错误码。

error_msg

String

错误描述。

请求示例

  • 创建HIVE数据源的动态脱敏策略
    /v1/0833a5737480d53b2f25c010dc1a7b88/security/masking/dynamic/policies
    
    {
      "name" : "OpenAPI_Hive_test",
      "datasource_type" : "HIVE",
      "cluster_id" : "dc425074-26b3-479c-9e2f-b103c0cdd90f",
      "cluster_name" : "mrs_3x_xxxx_do_not_del",
      "database_name" : "bigdatatest",
      "table_name" : "aaaa",
      "table_id" : "NativeTable-39dc19fb17034ab39e46ebe0420c6202-bigdatatest-aaaa",
      "user_groups" : "DataArts User",
      "users" : "",
      "conn_name" : "hive_3x_0330",
      "conn_id" : "39dc19fb17034ab39e46ebe0420c6202",
      "policy_list" : [ {
        "column_name" : "aa",
        "column_type" : "string",
        "algorithm_type" : "MASK_SHOW_LAST_4"
      } ]
    }
  • 创建DWS数据源的动态脱敏策略
    /v1/0833a5737480d53b2f25c010dc1a7b88/security/masking/dynamic/policies
    
    {
      "name" : "OpenAPI_DWS_test",
      "datasource_type" : "DWS",
      "cluster_id" : "c94a9133-ef65-47ad-9483-bfa8c5eaa101",
      "cluster_name" : "dws_ssl_4autotest_nomodify",
      "database_name" : "gaussdb",
      "table_name" : "all_column",
      "table_id" : "NativeTable-e2f6c44100654778aee017f8ad9e3ac9-gaussdb-public-all_column",
      "user_groups" : "DataArts_PDP5_NoPrivilleage",
      "users" : "autotest_tics",
      "conn_name" : "dws_0430",
      "conn_id" : "e2f6c44100654778aee017f8ad9e3ac9",
      "policy_list" : [ {
        "column_name" : "avarchar",
        "column_type" : "varchar",
        "algorithm_type" : "DWS_ALL_MASK",
        "algorithm_detail_dto" : null
      } ],
      "schema_name" : "public"
    }
  • 创建DLI数据源的动态脱敏策略
    /v1/0833a5737480d53b2f25c010dc1a7b88/security/masking/dynamic/policies
    
    {
      "name" : "OpenAPI_DLI_test",
      "datasource_type" : "DLI",
      "cluster_id" : "DLI",
      "cluster_name" : "DLI",
      "database_name" : "bigdatatest",
      "table_name" : "dli_string_auto_20231116",
      "table_id" : "NativeTable-619d52a0e6954aa68844f5f010e06ef8-bigdatatest-dli_string_auto_20231116",
      "user_groups" : "",
      "users" : "",
      "conn_name" : "xu_dli_link",
      "conn_id" : "619d52a0e6954aa68844f5f010e06ef8",
      "policy_list" : [ {
        "column_name" : "varchar1",
        "column_type" : "string",
        "algorithm_type" : "MASK_NULL"
      } ]
    }

响应示例

状态码: 200

OK

{
  "cluster_id" : "dc425074-26b3-479c-9e2f-b103c0cdd90f",
  "cluster_name" : "mrs_3x_autotest_do_not_del",
  "conn_id" : "ae55cb5c44be4119b8958a3ba5d9a71f",
  "conn_name" : "hive_xxxx_0520",
  "create_time" : 1716195352790,
  "create_user" : "ei_dayu_xxxx_01",
  "database_name" : "bigdatatest",
  "datasource_type" : "HIVE",
  "id" : "e55577e76cb77f87cec2099b8074a88d",
  "name" : "xxxx_unique_test",
  "policy_list" : [ {
    "algorithm_detail" : null,
    "algorithm_detail_dto" : null,
    "algorithm_type" : "MASK_SHOW_LAST_4",
    "associated_id" : null,
    "associated_policy_name" : null,
    "column_name" : "name",
    "column_type" : "string",
    "id" : "607218bdfdf8452cd0abe9354639c472",
    "policy_set_id" : "e55577e76cb77f87cec2099b8074a88d",
    "sync_msg" : null,
    "sync_status" : "NOT_SYNC",
    "sync_time" : null
  }, {
    "algorithm_detail" : null,
    "algorithm_detail_dto" : null,
    "algorithm_type" : "MASK_SHOW_FIRST_4",
    "associated_id" : null,
    "associated_policy_name" : null,
    "column_name" : "a1",
    "column_type" : "string",
    "id" : "95cefff4b29e1db7fedb9b772739d7a0",
    "policy_set_id" : "e55577e76cb77f87cec2099b8074a88d",
    "sync_msg" : null,
    "sync_status" : "NOT_SYNC",
    "sync_time" : null
  } ],
  "schema_id" : null,
  "schema_name" : null,
  "sync_log" : null,
  "sync_msg" : null,
  "sync_status" : "NOT_SYNC",
  "table_id" : "NativeTable-ae55cb5c44be4119b8958a3ba5d9a71f-bigdatatest-dws_gglllsss",
  "table_name" : "dws_gglllsss",
  "update_time" : 1716195352790,
  "update_user" : "ei_dayu_xxxx_01",
  "user_groups" : "DataArts User",
  "users" : "user1,user2,user3,user4"
}

SDK代码示例

SDK代码示例如下。

  • 创建HIVE数据源的动态脱敏策略
     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
    66
    67
    68
    69
    70
    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.dataartsstudio.v1.region.DataArtsStudioRegion;
    import com.huaweicloud.sdk.dataartsstudio.v1.*;
    import com.huaweicloud.sdk.dataartsstudio.v1.model.*;
    
    import java.util.List;
    import java.util.ArrayList;
    
    public class CreateSecurityDynamicMaskingPolicySolution {
    
        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");
            String projectId = "{project_id}";
    
            ICredential auth = new BasicCredentials()
                    .withProjectId(projectId)
                    .withAk(ak)
                    .withSk(sk);
    
            DataArtsStudioClient client = DataArtsStudioClient.newBuilder()
                    .withCredential(auth)
                    .withRegion(DataArtsStudioRegion.valueOf("<YOUR REGION>"))
                    .build();
            CreateSecurityDynamicMaskingPolicyRequest request = new CreateSecurityDynamicMaskingPolicyRequest();
            DynamicMaskingPolicyCreateDTO body = new DynamicMaskingPolicyCreateDTO();
            List<DynamicMaskingPolicyCreate> listbodyPolicyList = new ArrayList<>();
            listbodyPolicyList.add(
                new DynamicMaskingPolicyCreate()
                    .withColumnName("aa")
                    .withColumnType("string")
                    .withAlgorithmType("MASK_SHOW_LAST_4")
            );
            body.withPolicyList(listbodyPolicyList);
            body.withConnId("39dc19fb17034ab39e46ebe0420c6202");
            body.withConnName("hive_3x_0330");
            body.withUsers("");
            body.withUserGroups("DataArts User");
            body.withTableName("aaaa");
            body.withTableId("NativeTable-39dc19fb17034ab39e46ebe0420c6202-bigdatatest-aaaa");
            body.withDatabaseName("bigdatatest");
            body.withClusterName("mrs_3x_xxxx_do_not_del");
            body.withClusterId("dc425074-26b3-479c-9e2f-b103c0cdd90f");
            body.withDatasourceType(DynamicMaskingPolicyCreateDTO.DatasourceTypeEnum.fromValue("HIVE"));
            body.withName("OpenAPI_Hive_test");
            request.withBody(body);
            try {
                CreateSecurityDynamicMaskingPolicyResponse response = client.createSecurityDynamicMaskingPolicy(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());
            }
        }
    }
    
  • 创建DWS数据源的动态脱敏策略
     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
    66
    67
    68
    69
    70
    71
    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.dataartsstudio.v1.region.DataArtsStudioRegion;
    import com.huaweicloud.sdk.dataartsstudio.v1.*;
    import com.huaweicloud.sdk.dataartsstudio.v1.model.*;
    
    import java.util.List;
    import java.util.ArrayList;
    
    public class CreateSecurityDynamicMaskingPolicySolution {
    
        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");
            String projectId = "{project_id}";
    
            ICredential auth = new BasicCredentials()
                    .withProjectId(projectId)
                    .withAk(ak)
                    .withSk(sk);
    
            DataArtsStudioClient client = DataArtsStudioClient.newBuilder()
                    .withCredential(auth)
                    .withRegion(DataArtsStudioRegion.valueOf("<YOUR REGION>"))
                    .build();
            CreateSecurityDynamicMaskingPolicyRequest request = new CreateSecurityDynamicMaskingPolicyRequest();
            DynamicMaskingPolicyCreateDTO body = new DynamicMaskingPolicyCreateDTO();
            List<DynamicMaskingPolicyCreate> listbodyPolicyList = new ArrayList<>();
            listbodyPolicyList.add(
                new DynamicMaskingPolicyCreate()
                    .withColumnName("avarchar")
                    .withColumnType("varchar")
                    .withAlgorithmType("DWS_ALL_MASK")
            );
            body.withPolicyList(listbodyPolicyList);
            body.withSchemaName("public");
            body.withConnId("e2f6c44100654778aee017f8ad9e3ac9");
            body.withConnName("dws_0430");
            body.withUsers("autotest_tics");
            body.withUserGroups("DataArts_PDP5_NoPrivilleage");
            body.withTableName("all_column");
            body.withTableId("NativeTable-e2f6c44100654778aee017f8ad9e3ac9-gaussdb-public-all_column");
            body.withDatabaseName("gaussdb");
            body.withClusterName("dws_ssl_4autotest_nomodify");
            body.withClusterId("c94a9133-ef65-47ad-9483-bfa8c5eaa101");
            body.withDatasourceType(DynamicMaskingPolicyCreateDTO.DatasourceTypeEnum.fromValue("DWS"));
            body.withName("OpenAPI_DWS_test");
            request.withBody(body);
            try {
                CreateSecurityDynamicMaskingPolicyResponse response = client.createSecurityDynamicMaskingPolicy(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());
            }
        }
    }
    
  • 创建DLI数据源的动态脱敏策略
     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
    66
    67
    68
    69
    70
    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.dataartsstudio.v1.region.DataArtsStudioRegion;
    import com.huaweicloud.sdk.dataartsstudio.v1.*;
    import com.huaweicloud.sdk.dataartsstudio.v1.model.*;
    
    import java.util.List;
    import java.util.ArrayList;
    
    public class CreateSecurityDynamicMaskingPolicySolution {
    
        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");
            String projectId = "{project_id}";
    
            ICredential auth = new BasicCredentials()
                    .withProjectId(projectId)
                    .withAk(ak)
                    .withSk(sk);
    
            DataArtsStudioClient client = DataArtsStudioClient.newBuilder()
                    .withCredential(auth)
                    .withRegion(DataArtsStudioRegion.valueOf("<YOUR REGION>"))
                    .build();
            CreateSecurityDynamicMaskingPolicyRequest request = new CreateSecurityDynamicMaskingPolicyRequest();
            DynamicMaskingPolicyCreateDTO body = new DynamicMaskingPolicyCreateDTO();
            List<DynamicMaskingPolicyCreate> listbodyPolicyList = new ArrayList<>();
            listbodyPolicyList.add(
                new DynamicMaskingPolicyCreate()
                    .withColumnName("varchar1")
                    .withColumnType("string")
                    .withAlgorithmType("MASK_NULL")
            );
            body.withPolicyList(listbodyPolicyList);
            body.withConnId("619d52a0e6954aa68844f5f010e06ef8");
            body.withConnName("xu_dli_link");
            body.withUsers("");
            body.withUserGroups("");
            body.withTableName("dli_string_auto_20231116");
            body.withTableId("NativeTable-619d52a0e6954aa68844f5f010e06ef8-bigdatatest-dli_string_auto_20231116");
            body.withDatabaseName("bigdatatest");
            body.withClusterName("DLI");
            body.withClusterId("DLI");
            body.withDatasourceType(DynamicMaskingPolicyCreateDTO.DatasourceTypeEnum.fromValue("DLI"));
            body.withName("OpenAPI_DLI_test");
            request.withBody(body);
            try {
                CreateSecurityDynamicMaskingPolicyResponse response = client.createSecurityDynamicMaskingPolicy(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());
            }
        }
    }
    
  • 创建HIVE数据源的动态脱敏策略
     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
    # coding: utf-8
    
    import os
    from huaweicloudsdkcore.auth.credentials import BasicCredentials
    from huaweicloudsdkdataartsstudio.v1.region.dataartsstudio_region import DataArtsStudioRegion
    from huaweicloudsdkcore.exceptions import exceptions
    from huaweicloudsdkdataartsstudio.v1 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"]
        projectId = "{project_id}"
    
        credentials = BasicCredentials(ak, sk, projectId)
    
        client = DataArtsStudioClient.new_builder() \
            .with_credentials(credentials) \
            .with_region(DataArtsStudioRegion.value_of("<YOUR REGION>")) \
            .build()
    
        try:
            request = CreateSecurityDynamicMaskingPolicyRequest()
            listPolicyListbody = [
                DynamicMaskingPolicyCreate(
                    column_name="aa",
                    column_type="string",
                    algorithm_type="MASK_SHOW_LAST_4"
                )
            ]
            request.body = DynamicMaskingPolicyCreateDTO(
                policy_list=listPolicyListbody,
                conn_id="39dc19fb17034ab39e46ebe0420c6202",
                conn_name="hive_3x_0330",
                users="",
                user_groups="DataArts User",
                table_name="aaaa",
                table_id="NativeTable-39dc19fb17034ab39e46ebe0420c6202-bigdatatest-aaaa",
                database_name="bigdatatest",
                cluster_name="mrs_3x_xxxx_do_not_del",
                cluster_id="dc425074-26b3-479c-9e2f-b103c0cdd90f",
                datasource_type="HIVE",
                name="OpenAPI_Hive_test"
            )
            response = client.create_security_dynamic_masking_policy(request)
            print(response)
        except exceptions.ClientRequestException as e:
            print(e.status_code)
            print(e.request_id)
            print(e.error_code)
            print(e.error_msg)
    
  • 创建DWS数据源的动态脱敏策略
     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
    # coding: utf-8
    
    import os
    from huaweicloudsdkcore.auth.credentials import BasicCredentials
    from huaweicloudsdkdataartsstudio.v1.region.dataartsstudio_region import DataArtsStudioRegion
    from huaweicloudsdkcore.exceptions import exceptions
    from huaweicloudsdkdataartsstudio.v1 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"]
        projectId = "{project_id}"
    
        credentials = BasicCredentials(ak, sk, projectId)
    
        client = DataArtsStudioClient.new_builder() \
            .with_credentials(credentials) \
            .with_region(DataArtsStudioRegion.value_of("<YOUR REGION>")) \
            .build()
    
        try:
            request = CreateSecurityDynamicMaskingPolicyRequest()
            listPolicyListbody = [
                DynamicMaskingPolicyCreate(
                    column_name="avarchar",
                    column_type="varchar",
                    algorithm_type="DWS_ALL_MASK"
                )
            ]
            request.body = DynamicMaskingPolicyCreateDTO(
                policy_list=listPolicyListbody,
                schema_name="public",
                conn_id="e2f6c44100654778aee017f8ad9e3ac9",
                conn_name="dws_0430",
                users="autotest_tics",
                user_groups="DataArts_PDP5_NoPrivilleage",
                table_name="all_column",
                table_id="NativeTable-e2f6c44100654778aee017f8ad9e3ac9-gaussdb-public-all_column",
                database_name="gaussdb",
                cluster_name="dws_ssl_4autotest_nomodify",
                cluster_id="c94a9133-ef65-47ad-9483-bfa8c5eaa101",
                datasource_type="DWS",
                name="OpenAPI_DWS_test"
            )
            response = client.create_security_dynamic_masking_policy(request)
            print(response)
        except exceptions.ClientRequestException as e:
            print(e.status_code)
            print(e.request_id)
            print(e.error_code)
            print(e.error_msg)
    
  • 创建DLI数据源的动态脱敏策略
     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
    # coding: utf-8
    
    import os
    from huaweicloudsdkcore.auth.credentials import BasicCredentials
    from huaweicloudsdkdataartsstudio.v1.region.dataartsstudio_region import DataArtsStudioRegion
    from huaweicloudsdkcore.exceptions import exceptions
    from huaweicloudsdkdataartsstudio.v1 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"]
        projectId = "{project_id}"
    
        credentials = BasicCredentials(ak, sk, projectId)
    
        client = DataArtsStudioClient.new_builder() \
            .with_credentials(credentials) \
            .with_region(DataArtsStudioRegion.value_of("<YOUR REGION>")) \
            .build()
    
        try:
            request = CreateSecurityDynamicMaskingPolicyRequest()
            listPolicyListbody = [
                DynamicMaskingPolicyCreate(
                    column_name="varchar1",
                    column_type="string",
                    algorithm_type="MASK_NULL"
                )
            ]
            request.body = DynamicMaskingPolicyCreateDTO(
                policy_list=listPolicyListbody,
                conn_id="619d52a0e6954aa68844f5f010e06ef8",
                conn_name="xu_dli_link",
                users="",
                user_groups="",
                table_name="dli_string_auto_20231116",
                table_id="NativeTable-619d52a0e6954aa68844f5f010e06ef8-bigdatatest-dli_string_auto_20231116",
                database_name="bigdatatest",
                cluster_name="DLI",
                cluster_id="DLI",
                datasource_type="DLI",
                name="OpenAPI_DLI_test"
            )
            response = client.create_security_dynamic_masking_policy(request)
            print(response)
        except exceptions.ClientRequestException as e:
            print(e.status_code)
            print(e.request_id)
            print(e.error_code)
            print(e.error_msg)
    
  • 创建HIVE数据源的动态脱敏策略
     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
    package main
    
    import (
    	"fmt"
    	"github.com/huaweicloud/huaweicloud-sdk-go-v3/core/auth/basic"
        dataartsstudio "github.com/huaweicloud/huaweicloud-sdk-go-v3/services/dataartsstudio/v1"
    	"github.com/huaweicloud/huaweicloud-sdk-go-v3/services/dataartsstudio/v1/model"
        region "github.com/huaweicloud/huaweicloud-sdk-go-v3/services/dataartsstudio/v1/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")
        projectId := "{project_id}"
    
        auth := basic.NewCredentialsBuilder().
            WithAk(ak).
            WithSk(sk).
            WithProjectId(projectId).
            Build()
    
        client := dataartsstudio.NewDataArtsStudioClient(
            dataartsstudio.DataArtsStudioClientBuilder().
                WithRegion(region.ValueOf("<YOUR REGION>")).
                WithCredential(auth).
                Build())
    
        request := &model.CreateSecurityDynamicMaskingPolicyRequest{}
    	algorithmTypePolicyList:= "MASK_SHOW_LAST_4"
    	var listPolicyListbody = []model.DynamicMaskingPolicyCreate{
            {
                ColumnName: "aa",
                ColumnType: "string",
                AlgorithmType: &algorithmTypePolicyList,
            },
        }
    	usersDynamicMaskingPolicyCreateDto:= ""
    	userGroupsDynamicMaskingPolicyCreateDto:= "DataArts User"
    	tableIdDynamicMaskingPolicyCreateDto:= "NativeTable-39dc19fb17034ab39e46ebe0420c6202-bigdatatest-aaaa"
    	request.Body = &model.DynamicMaskingPolicyCreateDto{
    		PolicyList: listPolicyListbody,
    		ConnId: "39dc19fb17034ab39e46ebe0420c6202",
    		ConnName: "hive_3x_0330",
    		Users: &usersDynamicMaskingPolicyCreateDto,
    		UserGroups: &userGroupsDynamicMaskingPolicyCreateDto,
    		TableName: "aaaa",
    		TableId: &tableIdDynamicMaskingPolicyCreateDto,
    		DatabaseName: "bigdatatest",
    		ClusterName: "mrs_3x_xxxx_do_not_del",
    		ClusterId: "dc425074-26b3-479c-9e2f-b103c0cdd90f",
    		DatasourceType: model.GetDynamicMaskingPolicyCreateDtoDatasourceTypeEnum().HIVE,
    		Name: "OpenAPI_Hive_test",
    	}
    	response, err := client.CreateSecurityDynamicMaskingPolicy(request)
    	if err == nil {
            fmt.Printf("%+v\n", response)
        } else {
            fmt.Println(err)
        }
    }
    
  • 创建DWS数据源的动态脱敏策略
     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
    package main
    
    import (
    	"fmt"
    	"github.com/huaweicloud/huaweicloud-sdk-go-v3/core/auth/basic"
        dataartsstudio "github.com/huaweicloud/huaweicloud-sdk-go-v3/services/dataartsstudio/v1"
    	"github.com/huaweicloud/huaweicloud-sdk-go-v3/services/dataartsstudio/v1/model"
        region "github.com/huaweicloud/huaweicloud-sdk-go-v3/services/dataartsstudio/v1/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")
        projectId := "{project_id}"
    
        auth := basic.NewCredentialsBuilder().
            WithAk(ak).
            WithSk(sk).
            WithProjectId(projectId).
            Build()
    
        client := dataartsstudio.NewDataArtsStudioClient(
            dataartsstudio.DataArtsStudioClientBuilder().
                WithRegion(region.ValueOf("<YOUR REGION>")).
                WithCredential(auth).
                Build())
    
        request := &model.CreateSecurityDynamicMaskingPolicyRequest{}
    	algorithmTypePolicyList:= "DWS_ALL_MASK"
    	var listPolicyListbody = []model.DynamicMaskingPolicyCreate{
            {
                ColumnName: "avarchar",
                ColumnType: "varchar",
                AlgorithmType: &algorithmTypePolicyList,
            },
        }
    	schemaNameDynamicMaskingPolicyCreateDto:= "public"
    	usersDynamicMaskingPolicyCreateDto:= "autotest_tics"
    	userGroupsDynamicMaskingPolicyCreateDto:= "DataArts_PDP5_NoPrivilleage"
    	tableIdDynamicMaskingPolicyCreateDto:= "NativeTable-e2f6c44100654778aee017f8ad9e3ac9-gaussdb-public-all_column"
    	request.Body = &model.DynamicMaskingPolicyCreateDto{
    		PolicyList: listPolicyListbody,
    		SchemaName: &schemaNameDynamicMaskingPolicyCreateDto,
    		ConnId: "e2f6c44100654778aee017f8ad9e3ac9",
    		ConnName: "dws_0430",
    		Users: &usersDynamicMaskingPolicyCreateDto,
    		UserGroups: &userGroupsDynamicMaskingPolicyCreateDto,
    		TableName: "all_column",
    		TableId: &tableIdDynamicMaskingPolicyCreateDto,
    		DatabaseName: "gaussdb",
    		ClusterName: "dws_ssl_4autotest_nomodify",
    		ClusterId: "c94a9133-ef65-47ad-9483-bfa8c5eaa101",
    		DatasourceType: model.GetDynamicMaskingPolicyCreateDtoDatasourceTypeEnum().DWS,
    		Name: "OpenAPI_DWS_test",
    	}
    	response, err := client.CreateSecurityDynamicMaskingPolicy(request)
    	if err == nil {
            fmt.Printf("%+v\n", response)
        } else {
            fmt.Println(err)
        }
    }
    
  • 创建DLI数据源的动态脱敏策略
     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
    package main
    
    import (
    	"fmt"
    	"github.com/huaweicloud/huaweicloud-sdk-go-v3/core/auth/basic"
        dataartsstudio "github.com/huaweicloud/huaweicloud-sdk-go-v3/services/dataartsstudio/v1"
    	"github.com/huaweicloud/huaweicloud-sdk-go-v3/services/dataartsstudio/v1/model"
        region "github.com/huaweicloud/huaweicloud-sdk-go-v3/services/dataartsstudio/v1/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")
        projectId := "{project_id}"
    
        auth := basic.NewCredentialsBuilder().
            WithAk(ak).
            WithSk(sk).
            WithProjectId(projectId).
            Build()
    
        client := dataartsstudio.NewDataArtsStudioClient(
            dataartsstudio.DataArtsStudioClientBuilder().
                WithRegion(region.ValueOf("<YOUR REGION>")).
                WithCredential(auth).
                Build())
    
        request := &model.CreateSecurityDynamicMaskingPolicyRequest{}
    	algorithmTypePolicyList:= "MASK_NULL"
    	var listPolicyListbody = []model.DynamicMaskingPolicyCreate{
            {
                ColumnName: "varchar1",
                ColumnType: "string",
                AlgorithmType: &algorithmTypePolicyList,
            },
        }
    	usersDynamicMaskingPolicyCreateDto:= ""
    	userGroupsDynamicMaskingPolicyCreateDto:= ""
    	tableIdDynamicMaskingPolicyCreateDto:= "NativeTable-619d52a0e6954aa68844f5f010e06ef8-bigdatatest-dli_string_auto_20231116"
    	request.Body = &model.DynamicMaskingPolicyCreateDto{
    		PolicyList: listPolicyListbody,
    		ConnId: "619d52a0e6954aa68844f5f010e06ef8",
    		ConnName: "xu_dli_link",
    		Users: &usersDynamicMaskingPolicyCreateDto,
    		UserGroups: &userGroupsDynamicMaskingPolicyCreateDto,
    		TableName: "dli_string_auto_20231116",
    		TableId: &tableIdDynamicMaskingPolicyCreateDto,
    		DatabaseName: "bigdatatest",
    		ClusterName: "DLI",
    		ClusterId: "DLI",
    		DatasourceType: model.GetDynamicMaskingPolicyCreateDtoDatasourceTypeEnum().DLI,
    		Name: "OpenAPI_DLI_test",
    	}
    	response, err := client.CreateSecurityDynamicMaskingPolicy(request)
    	if err == nil {
            fmt.Printf("%+v\n", response)
        } else {
            fmt.Println(err)
        }
    }
    

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

状态码

状态码

描述

200

OK

400

Bad Request

相关文档