scenario:
  id: bee93175-b9d9-4eb6-b3a2-f5f7f145b8cf
  context:
    auth:
      type: digest
    base_path: /v1beta2
    host: null
  description: ng_db_auditlog
  name: ng_db_auditlog
steps:
  - operation_id: TidbService_CreateTidb
    request_type: http
    request: |-
      {
        "method": "POST",
        "path": "/tidbs",
        "headers": {},
        "query_params": {},
        "body": {
          "displayName": "sce-ng-db-auditlog",
          "regionId": "{regionId}",
          "minRcu": "5000",
          "maxRcu": "6000",
          "servicePlan": "Premium",
          "cloudProvider": "{cloud_provider}"
        },
        "body_params": {
          "regionId": "region_id",
          "cloud_provider": "cloud_provider"
        },
        "auth": {
          "auth_type": "digest",
          "content": {
            "private_key": "placeholder",
            "public_key": "placeholder"
          }
        }
      }
    expect: |-
      {
        "status_code": 200,
        "cel": ""
      }
    save: |-
      {
        "placeholder": [
          {
            "key": "cluster_1",
            "eval": "body.tidbId"
          }
        ]
      }
    description: ""
    max_retries: 0
    delay_after: 0
    name: ""
    continue_on_unexpected: false
    stage: ""
    meta: "{}"
    generation_id: ""
    order: 0
  - operation_id: PrivateEndpointConnectionService_GetPrivateLinkService
    request_type: http
    request: |-
      {
        "method": "GET",
        "path": "/tidbs/{tidbId}/privateLinkService",
        "headers": {},
        "query_params": {},
        "body": {},
        "path_params": {
          "tidbId": "cluster_1"
        },
        "auth": {
          "auth_type": "digest",
          "content": {
            "private_key": "placeholder",
            "public_key": "placeholder"
          }
        }
      }
    expect: |-
      {
        "status_code": 200,
        "cel": "body.state == 'ACTIVE'"
      }
    save: |-
      {
        "placeholder": [
          {
            "key": "private_link_service_1",
            "eval": "body.serviceName"
          }
        ]
      }
    description: ''
    max_retries: 120
    delay_after: 30
    name: ''
    continue_on_unexpected: false
    stage: ''
    meta: '{}'
    generation_id: ''
    order: 0.5
  - operation_id: TidbService_GetTidb
    request_type: http
    request: |-
      {
        "method": "GET",
        "path": "/tidbs/{tidbId}",
        "headers": {},
        "query_params": {},
        "body": {},
        "auth": {
          "auth_type": "digest",
          "content": {
            "private_key": "placeholder",
            "public_key": "placeholder"
          }
        },
        "path_params": {
          "tidbId": "cluster_1"
        }
      }
    expect: |-
      {
        "status_code": 200,
        "cel": "body.state == 'ACTIVE'"
      }
    save: null
    description: ""
    max_retries: 120
    delay_after: 30
    name: ""
    continue_on_unexpected: false
    stage: ""
    meta: "{}"
    generation_id: ""
    order: 1
  - operation_id: TidbService_ResetRootPassword
    request_type: http
    request: |-
      {
        "method": "POST",
        "path": "/tidbs/{tidbId}:resetRootPassword",
        "headers": {},
        "query_params": {},
        "body": {
          "rootPassword": "pi31415926"
        },
        "auth": {
          "auth_type": "digest",
          "content": {
            "private_key": "placeholder",
            "public_key": "placeholder"
          }
        },
        "path_params": {
          "tidbId": "cluster_1"
        }
      }
    expect: |-
      {
        "status_code": 200,
        "cel": ""
      }
    save: null
    description: ''
    max_retries: 5
    delay_after: 60
    name: ''
    continue_on_unexpected: false
    stage: ''
    meta: '{}'
    generation_id: ''
    order: 1.5
  - operation_id: PublicConnectionSettingService_GetPublicConnectionSetting
    request_type: http
    request: |-
      {
        "method": "GET",
        "path": "/tidbs/{tidbId}/publicConnectionSetting",
        "headers": {},
        "query_params": {},
        "body": {},
        "auth": {
          "auth_type": "digest",
          "content": {
            "private_key": "placeholder",
            "public_key": "placeholder"
          }
        },
        "path_params": {
          "tidbId": "cluster_1"
        }
      }
    expect: |-
      {
        "status_code": 200,
        "cel": "body.enabled == false"
      }
    save: null
    description: ""
    max_retries: 0
    delay_after: 0
    name: ""
    continue_on_unexpected: false
    stage: ""
    meta: "{}"
    generation_id: ""
    order: 1.6
  - operation_id: PublicConnectionSettingService_UpdatePublicConnectionSetting
    request_type: http
    request: |-
      {
        "method": "PATCH",
        "path": "/tidbs/{tidbId}/publicConnectionSetting",
        "headers": {},
        "query_params": {},
        "body": {
          "enabled": true,
          "ipAccessList": [
            {
              "cidrNotation": "0.0.0.0/0",
              "description": "Allow all IPs"
            }
          ]
        },
        "auth": {
          "auth_type": "digest",
          "content": {
            "private_key": "placeholder",
            "public_key": "placeholder"
          }
        },
        "path_params": {
          "tidbId": "cluster_1"
        }
      }
    expect: |-
      {
        "status_code": 200,
        "cel": ""
      }
    save: null
    description: ""
    max_retries: 0
    delay_after: 0
    name: ""
    continue_on_unexpected: false
    stage: ""
    meta: "{}"
    generation_id: ""
    order: 2
  - operation_id: PublicConnectionSettingService_GetPublicConnectionSetting
    request_type: http
    request: |-
      {
        "method": "GET",
        "path": "/tidbs/{tidbId}/publicConnectionSetting",
        "headers": {},
        "query_params": {},
        "body": {},
        "auth": {
          "auth_type": "digest",
          "content": {
            "private_key": "placeholder",
            "public_key": "placeholder"
          }
        },
        "path_params": {
          "tidbId": "cluster_1"
        }
      }
    expect: |-
      {
        "status_code": 200,
        "cel": "body.enabled == true && body.ipAccessList[0].description == 'Allow all IPs'"
      }
    save: null
    description: ""
    max_retries: 0
    delay_after: 0
    name: ""
    continue_on_unexpected: false
    stage: ""
    meta: "{}"
    generation_id: ""
    order: 2.5
  - operation_id: ClusterService_GetCluster
    generation_id: 09198df8-3eef-4d82-a5a4-31eb9b0db7de
    order: 3
    case_type: supplimental_positive
    request_type: http
    request: |-
      {
        "auth": {
          "auth_type": "digest",
          "content": {"private_key": "placeholder","public_key": "placeholder"}
        },
        "method": "GET",
        "path": "/tidbs/{tidbId}",
        "path_params": {
          "tidbId": "cluster_1"
        },
        "query_params": {},
        "headers": {},
        "body": {}
      }
    expect: |-
      {
        "status_code": 200,
        "cel": "body.state == \"ABC\""
      }
    description: Poll the cluster state until it becomes ACTIVE.
    max_retries: 40
    delay_after: 10
    step_type: defined
    name: force_wait_dns
    save: null
    continue_on_unexpected: true
    stage: prepare
    meta: "{}"
  - operation_id: TidbService_GetTidb
    request_type: http
    request: |-
      {
        "method": "GET",
        "path": "/tidbs/{tidbId}",
        "headers": {},
        "query_params": {},
        "body": {},
        "auth": {
          "auth_type": "digest",
          "content": {
            "private_key": "placeholder",
            "public_key": "placeholder"
          }
        },
        "path_params": {
          "tidbId": "cluster_1"
        }
      }
    expect: |-
      {
        "status_code": 200,
        "cel": "body.state == \"ACTIVE\" && size(body.endpoints.filter(e, e.connectionType == 'PUBLIC')) > 0 && body.endpoints.filter(e, e.connectionType == 'PUBLIC')[0].host != \"\""
      }
    save: |-
      {
        "placeholder": [
          {"key": "public_endpoint", "eval": "body.endpoints.filter(e, e.connectionType == 'PUBLIC')[0].host"},
          {"key": "port", "eval": "body.endpoints.filter(e, e.connectionType == 'PUBLIC')[0].port"}
        ]
      }
    description: ""
    max_retries: 120
    delay_after: 30
    name: ""
    continue_on_unexpected: false
    stage: ""
    meta: "{}"
    generation_id: ""
    order: 4
  - operation_id: Mysqlsh_connection
    generation_id: 09198df8-3eef-4d82-a5a4-31eb9b0db7de
    order: 5
    case_type: typical_positive
    request_type: cmd_mysqlsh
    request: |-
      {
        "name": "mysqlsh",
        "args": [
          "--sql",
          "mysql://root:pi31415926@{public_endpoint}:{port}/mysql",
          "--result-format=json",
          "-e",
          "select count(*) as count from mysql.user",
          "--quiet-start=2"
        ],
        "args_params": {
          "public_endpoint": "public_endpoint",
          "port": "port"
        }
      }
    expect: |-
      {
        "exit_code": 0,
        "cel": "output.count >= 1"
      }
    description: Check the connection status of the cluster.
    max_retries: 0
    delay_after: 0
    step_type: defined
    name: check_password
    continue_on_unexpected: false
    save: null
    stage: execute
    meta: "{}"
  - case_id: create_auditlog_config
    operation_id: DatabaseAuditLogService_UpdateAuditLogSetting
    case_type: typical_positive
    request_type: http
    request: |-
      {
        "auth": {
          "auth_type": "digest",
          "content": {"private_key": "placeholder","public_key": "placeholder"}
        },
        "method": "PATCH",
        "path": "/tidbs/{tidbId}/auditLogSetting",
        "path_params": {
          "tidbId": "cluster_1"
        },
        "query_params": {},
        "headers": {},
        "body": {
          "enabled": true,
          "storageSetting":{
            "bucketUri": "oss://db-auditlog-fang-test/",
            "bucketRegionId": "{regionId}",
            "cloudRoleIdentity": "acs:ram::5841052134823325:role/db-auditlog-fang-test",
            "externalId": "{tidbId}"
          },
          "unredacted": true,
          "format": "TEXT",
          "rotationPolicy": {
            "maxSizeMib": 10,
            "maxAgeSecond": 10
          }
        },
        "body_params": {
          "tidbId": "cluster_1",
          "regionId": "region_id"
        }
      }
    expect: |-
      {
        "status_code": 200,
        "cel": ""
      }
    description: Create audit log config.
    max_retries: 0
    delay_after: 0
    step_type: generated
    name: Create audit log config
    save: null
    continue_on_unexpected: false
    stage: execute
    meta: "{}"
    generation_id: 09198df8-3eef-4d82-a5a4-31eb9b0db7de
    order: 6
  - case_id: get_auditlog_config
    operation_id: DatabaseAuditLogService_GetAuditLogSetting
    case_type: typical_positive
    request_type: http
    request: |-
      {
        "auth": {
          "auth_type": "digest",
          "content": {"private_key": "placeholder","public_key": "placeholder"}
        },
        "method": "GET",
        "path": "/tidbs/{tidbId}/auditLogSetting",
        "path_params": {
          "tidbId": "cluster_1"
        },
        "query_params": {},
        "headers": {},
        "body": {}
      }
    expect: |-
      {
        "status_code": 200,
        "cel": "body.enabled == true && body.storageSetting.bucketUri == \"oss://db-auditlog-fang-test/\""
      }
    description: Get audit log config.
    max_retries: 0
    delay_after: 0
    step_type: generated
    name: Get audit log config
    save: null
    continue_on_unexpected: false
    stage: execute
    meta: "{}"
    generation_id: 09198df8-3eef-4d82-a5a4-31eb9b0db7de
    order: 7
  - case_id: create_auditlog_rule
    operation_id: DatabaseAuditLogService_CreateAuditLogFilterRule
    case_type: typical_positive
    request_type: http
    request: |-
      {
        "auth": {
          "auth_type": "digest",
          "content": {"private_key": "placeholder","public_key": "placeholder"}
        },
        "method": "POST",
        "path": "/tidbs/{tidbId}/auditLogFilterRules",
        "path_params": {
          "tidbId": "cluster_1"
        },
        "query_params": {},
        "headers": {},
        "body": {
          "displayName": "db_auditlog_rule_1",
          "eventTypes": [
            "CONNECTION",
            "CONNECT",
            "DISCONNECT",
            "CHANGE_USER",
            "QUERY",
            "TRANSACTION",
            "EXECUTE",
            "QUERY_DML",
            "INSERT",
            "REPLACE",
            "UPDATE",
            "DELETE",
            "LOAD_DATA",
            "SELECT",
            "QUERY_DDL"
          ],
          "userExpr": "root"
        }
      }
    expect: |-
      {
        "status_code": 200,
        "cel": ""
      }
    description: Create audit log rule.
    max_retries: 0
    delay_after: 0
    step_type: generated
    name: Create audit log rule
    save: |-
      {
        "placeholder": [
          { "key": "auditlog_rule_0", "eval": "body.auditLogFilterRuleId" }
        ]
      }
    continue_on_unexpected: false
    stage: execute
    meta: "{}"
    generation_id: 09198df8-3eef-4d82-a5a4-31eb9b0db7de
    order: 8
  - case_id: get_auditlog_rule
    operation_id: DatabaseAuditLogService_GetAuditLogFilterRule
    case_type: typical_positive
    request_type: http
    request: |-
      {
        "auth": {
          "auth_type": "digest",
          "content": {"private_key": "placeholder","public_key": "placeholder"}
        },
        "method": "GET",
        "path": "/tidbs/{tidbId}/auditLogFilterRules/{auditLogFilterRuleId}",
        "path_params": {
          "tidbId": "cluster_1",
          "auditLogFilterRuleId": "auditlog_rule_0"
        },
        "query_params": {},
        "headers": {},
        "body": {}
      }
    expect: |-
      {
        "status_code": 200,
        "cel": "body.displayName.contains('db_auditlog_rule_1') && body.eventTypes.exists(e, e == \"CONNECTION\")"
      }
    description: Get audit log rule.
    max_retries: 0
    delay_after: 0
    step_type: generated
    name: Get audit log rule
    save: null
    continue_on_unexpected: false
    stage: execute
    meta: "{}"
    generation_id: 09198df8-3eef-4d82-a5a4-31eb9b0db7de
    order: 9
  - operation_id: ClusterService_GetCluster
    generation_id: 09198df8-3eef-4d82-a5a4-31eb9b0db7de
    order: 9.5
    case_type: supplimental_positive
    request_type: http
    request: |-
      {
        "auth": {
          "auth_type": "digest",
          "content": {"private_key": "placeholder","public_key": "placeholder"}
        },
        "method": "GET",
        "path": "/tidbs/{tidbId}",
        "path_params": {
          "tidbId": "cluster_1"
        },
        "query_params": {},
        "headers": {},
        "body": {}
      }
    expect: |-
      {
        "status_code": 200,
        "cel": "body.state == \"ABC\""
      }
    description: Poll the cluster state until it becomes ACTIVE.
    max_retries: 3
    delay_after: 10
    step_type: defined
    name: force_wait
    save: null
    continue_on_unexpected: true
    stage: prepare
    meta: "{}"
  - case_id: update_auditlog_rule
    operation_id: DatabaseAuditLogService_UpdateAuditLogFilterRule
    case_type: typical_positive
    request_type: http
    request: |-
      {
        "auth": {
          "auth_type": "digest",
          "content": {"private_key": "placeholder","public_key": "placeholder"}
        },
        "method": "PATCH",
        "path": "/tidbs/{tidbId}/auditLogFilterRules/{auditLogFilterRuleId}",
        "path_params": {
          "tidbId": "cluster_1",
          "auditLogFilterRuleId": "auditlog_rule_0"
        },
        "query_params": {},
        "headers": {},
        "body": {
          "displayName": "db_auditlog_rule_1_update",
          "eventTypes": [
            "CONNECT",
            "DISCONNECT",
            "CHANGE_USER",
            "QUERY",
            "TRANSACTION",
            "EXECUTE",
            "QUERY_DML",
            "INSERT",
            "REPLACE",
            "UPDATE",
            "DELETE",
            "LOAD_DATA",
            "SELECT",
            "QUERY_DDL"
          ],
          "userExpr": "root"
        }
      }
    expect: |-
      {
        "status_code": 200,
        "cel": "body.displayName.contains('db_auditlog_rule_1_update') && !body.eventTypes.exists(e, e == \"CONNECTION\")"
      }
    description: Update audit log rule.
    max_retries: 3
    delay_after: 10
    step_type: generated
    name: Update audit log rule
    save: null
    continue_on_unexpected: false
    stage: execute
    meta: "{}"
    generation_id: 09198df8-3eef-4d82-a5a4-31eb9b0db7de
    order: 10
  - case_id: get_auditlog_rule
    operation_id: DatabaseAuditLogService_GetAuditLogFilterRule
    case_type: typical_positive
    request_type: http
    request: |-
      {
        "auth": {
          "auth_type": "digest",
          "content": {"private_key": "placeholder","public_key": "placeholder"}
        },
        "method": "GET",
        "path": "/tidbs/{tidbId}/auditLogFilterRules/{auditLogFilterRuleId}",
        "path_params": {
          "tidbId": "cluster_1",
          "auditLogFilterRuleId": "auditlog_rule_0"
        },
        "query_params": {},
        "headers": {},
        "body": {}
      }
    expect: |-
      {
        "status_code": 200,
        "cel": "body.displayName.contains('db_auditlog_rule_1') && !body.eventTypes.exists(e, e == \"CONNECTION\")"
      }
    description: Get audit log rule.
    max_retries: 0
    delay_after: 0
    step_type: generated
    name: Get audit log rule
    save: null
    continue_on_unexpected: false
    stage: execute
    meta: "{}"
    generation_id: 09198df8-3eef-4d82-a5a4-31eb9b0db7de
    order: 11
  - case_id: list_auditlog_rules
    operation_id: DatabaseAuditLogService_ListAuditLogFilterRules
    case_type: typical_positive
    request_type: http
    request: |-
      {
        "auth": {
          "auth_type": "digest",
          "content": {"private_key": "placeholder","public_key": "placeholder"}
        },
        "method": "GET",
        "path": "/tidbs/{tidbId}/auditLogFilterRules",
        "path_params": {
          "tidbId": "cluster_1"
        },
        "query_params": {},
        "headers": {},
        "body": {}
      }
    expect: |-
      {
        "status_code": 200,
        "cel": "body.totalSize == 1"
      }
    description: List audit log rules.
    max_retries: 0
    delay_after: 0
    step_type: generated
    name: List audit log rules
    save: null
    continue_on_unexpected: false
    stage: execute
    meta: "{}"
    generation_id: 09198df8-3eef-4d82-a5a4-31eb9b0db7de
    order: 12
  - case_id: connect_to_create_table
    operation_id: Mysqlsh_connection
    case_type: typical_positive
    request_type: cmd_mysqlsh
    request: |-
      {
        "name": "mysqlsh",
        "args": [
          "--sql",
          "mysql://root:pi31415926@{public_endpoint}:{port}/test",
          "--result-format=json",
          "-e",
          "CREATE TABLE `students` (`id` int(11) NOT NULL AUTO_INCREMENT,`name` varchar(255) DEFAULT NULL,`age` int(11) DEFAULT NULL, PRIMARY KEY (`id`) /*T![clustered_index] CLUSTERED */) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_bin AUTO_INCREMENT=30001;",
          "--quiet-start=2"
        ],
        "args_params": {
          "public_endpoint": "public_endpoint",
          "port": "port"
        }
      }
    expect: |-
      {
        "exit_code": 0,
        "cel": ""
      }
    description: Check the connection status of the cluster.
    max_retries: 0
    delay_after: 0
    step_type: defined
    name: create_table
    save: null
    continue_on_unexpected: false
    stage: execute
    meta: "{}"
    generation_id: 09198df8-3eef-4d82-a5a4-31eb9b0db7de
    order: 13
  - operation_id: ClusterService_GetCluster
    generation_id: 09198df8-3eef-4d82-a5a4-31eb9b0db7de
    order: 13.5
    case_type: supplimental_positive
    request_type: http
    request: |-
      {
        "auth": {
          "auth_type": "digest",
          "content": {"private_key": "placeholder","public_key": "placeholder"}
        },
        "method": "GET",
        "path": "/tidbs/{tidbId}",
        "path_params": {
          "tidbId": "cluster_1"
        },
        "query_params": {},
        "headers": {},
        "body": {}
      }
    expect: |-
      {
        "status_code": 200,
        "cel": "body.state == \"ABC\""
      }
    description: force wait for auditlog generated
    max_retries: 2
    delay_after: 10
    step_type: defined
    name: force_wait
    save: null
    continue_on_unexpected: true
    stage: prepare
    meta: "{}"
  - case_id: check_log_file
    operation_id: Aliyun
    case_type: typical_positive
    request_type: cmd_aliyun
    request: |-
      {
        "name": "aliyun",
        "args": [
          "oss",
          "ls",
          "oss://db-auditlog-fang-test/{tidbId}/",
          "-s",
          "-d",
          "--region",
          "ap-southeast-1"
        ],
        "args_params": {
          "tidbId": "cluster_1"
        }
      }
    expect: |-
      {
        "exit_code": 0,
        "cel": "output.contains('Object and Directory Number is: 2')"
      }
    description: Check the connection status of the cluster.
    max_retries: 0
    delay_after: 0
    step_type: defined
    name: check_log_file
    save: null
    continue_on_unexpected: false
    stage: execute
    meta: "{}"
    generation_id: 09198df8-3eef-4d82-a5a4-31eb9b0db7de
    order: 14
  - case_id: delete_auditlog_rule
    operation_id: DatabaseAuditLogService_DeleteAuditLogFilterRule
    case_type: typical_positive
    request_type: http
    request: |-
      {
        "auth": {
          "auth_type": "digest",
          "content": {"private_key": "placeholder","public_key": "placeholder"}
        },
        "method": "DELETE",
        "path": "/tidbs/{tidbId}/auditLogFilterRules/{auditLogFilterRuleId}",
        "path_params": {
          "tidbId": "cluster_1",
          "auditLogFilterRuleId": "auditlog_rule_0"
        },
        "query_params": {},
        "headers": {},
        "body": {}
      }
    expect: |-
      {
        "status_code": 200,
        "cel": ""
      }
    description: Delete audit log rule.
    max_retries: 0
    delay_after: 0
    step_type: generated
    name: Delete audit log rule
    save: null
    continue_on_unexpected: false
    stage: execute
    meta: "{}"
    generation_id: 09198df8-3eef-4d82-a5a4-31eb9b0db7de
    order: 15
  - case_id: list_auditlog_rules
    operation_id: DatabaseAuditLogService_ListAuditLogFilterRules
    case_type: typical_positive
    request_type: http
    request: |-
      {
        "auth": {
          "auth_type": "digest",
          "content": {"private_key": "placeholder","public_key": "placeholder"}
        },
        "method": "GET",
        "path": "/tidbs/{tidbId}/auditLogFilterRules",
        "path_params": {
          "tidbId": "cluster_1"
        },
        "query_params": {},
        "headers": {},
        "body": {}
      }
    expect: |-
      {
        "status_code": 200,
        "cel": "body.totalSize == 0"
      }
    description: List audit log rules.
    max_retries: 0
    delay_after: 0
    step_type: generated
    name: List audit log rules
    save: null
    continue_on_unexpected: false
    stage: execute
    meta: "{}"
    generation_id: 09198df8-3eef-4d82-a5a4-31eb9b0db7de
    order: 16
  - operation_id: TidbService_DeleteTidb
    request_type: http
    request: |-
      {
        "method": "DELETE",
        "path": "/tidbs/{tidbId}",
        "headers": {},
        "query_params": {},
        "body": {},
        "auth": {
          "auth_type": "digest",
          "content": {
            "private_key": "placeholder",
            "public_key": "placeholder"
          }
        },
        "path_params": {
          "tidbId": "cluster_1"
        }
      }
    expect: |-
      {
        "status_code": 200,
        "cel": ""
      }
    save: null
    description: ''
    max_retries: 0
    delay_after: 0
    name: ''
    continue_on_unexpected: false
    stage: ''
    meta: '{}'
    generation_id: ''
    order: 17
