scenario:
  id: 376ad526-529d-4026-81d7-ecc60e8c89a1
  context:
    auth:
      type: bearer
    base_path: null
    host: us-west-2.env.shared.aws.tidbcloud.com
  description: essential_v2 console apikey operation
  name: essential_v2_console_apikey_operation
steps:
  - operation_id: TidbService_CreateTidb
    request_type: http
    request: |-
      {
        "method": "POST",
        "path": "/api/v2025/cloud/v1beta2/tidbs?orgId={orgId}",
        "headers": {},
        "query_params": {},
        "body": {
          "displayName": "sce-essential-v2-api-key-multi1",
          "regionId": "{regionId}",
          "maxRcu": "6000",
          "servicePlan": "Essential_V2",
          "cloudProvider": "{cloud_provider}",
          "highAvailabilityType": "REGIONAL"
        },
        "body_params": {
          "regionId": "region_id",
          "cloud_provider": "cloud_provider"
        },
        "path_params": {
          "orgId": "org_id"
        },
        "auth": {
          "auth_type": "bearer_token"
        }
      }
    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: TidbService_GetTidb
    request_type: http
    request: |-
      {
        "method": "GET",
        "path": "/api/v2025/cloud/v1beta2/tidbs/{tidbId}?orgId={orgId}",
        "headers": {},
        "query_params": {},
        "body": {},
        "auth": {
          "auth_type": "bearer_token"
        },
        "path_params": {
          "tidbId": "cluster_1",
          "orgId": "org_id"
        }
      }
    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_CreateTidb
    request_type: http
    request: |-
      {
        "method": "POST",
        "path": "/api/v2025/cloud/v1beta2/tidbs?orgId={orgId}",
        "headers": {},
        "query_params": {},
        "body": {
          "displayName": "sce-essential-v2-api-key-multi2",
          "regionId": "{regionId}",
          "maxRcu": "6000",
          "servicePlan": "Essential_V2",
          "cloudProvider": "{cloud_provider}",
          "highAvailabilityType": "REGIONAL"
        },
        "body_params": {
          "regionId": "region_id",
          "cloud_provider": "cloud_provider"
        },
        "path_params": {
          "orgId": "org_id"
        },
        "auth": {
          "auth_type": "bearer_token"
        }
      }
    expect: |-
      {
        "status_code": 200,
        "cel": ""
      }
    save: |-
      {
        "placeholder": [
          {
            "key": "cluster_2",
            "eval": "body.tidbId"
          }
        ]
      }
    description: ''
    max_retries: 0
    delay_after: 0
    name: ''
    continue_on_unexpected: false
    stage: ''
    meta: '{}'
    generation_id: ''
    order: 2
  - operation_id: TidbService_GetTidb
    request_type: http
    request: |-
      {
        "method": "GET",
        "path": "/api/v2025/cloud/v1beta2/tidbs/{tidbId}?orgId={orgId}",
        "headers": {},
        "query_params": {},
        "body": {},
        "auth": {
          "auth_type": "bearer_token"
        },
        "path_params": {
          "tidbId": "cluster_2",
          "orgId": "org_id"
        }
      }
    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: 3
  - case_id: c37f522f5754a26096985d8962f63afe
    operation_id: CreateConsoleApiKey
    case_type: typical_positive
    request_type: http
    request: |-
      {
        "auth": {
          "auth_type": "bearer_token"
        },
        "method": "POST",
        "path": "/api/v1/orgs/{orgId}/console-apikey/create",
        "path_params": {
          "orgId": "org_id"
        },
        "query_params": {},
        "headers": {},
        "body": {
          "description": "muti_inst_key",
          "org_role": "org:member",
          "cluster_roles": [
            {
              "scope_type": "tidb",
              "scope_id": "{tidbId_1}",
              "rbac_role": "cluster:admin"
            },
            {
              "scope_type": "tidb",
              "scope_id": "{tidbId_2}",
              "rbac_role": "cluster:admin"
            }
          ]
        },
        "body_params": {
          "projectId": "project_id",
          "tidbId_1": "cluster_1",
          "tidbId_2": "cluster_2"
        }
      }
    expect: |-
      {
        "status_code": 200,
        "cel": ""
      }
    description: Create cluster admin key
    max_retries: 0
    delay_after: 0
    step_type: defined
    name: create_cluster
    save: |-
      {
        "placeholder": [
          {
            "key": "api_key_id_1",
            "eval": "body.id"
          }
        ]
      }
    continue_on_unexpected: false
    stage: execute
    meta: "{}"
    generation_id: 09198df8-3eef-4d82-a5a4-31eb9b0db7de
    order: 4
  - case_id: c37f522f5754a26096985d8962f63afe
    operation_id: ListConsoleApiKeys
    case_type: typical_positive
    request_type: http
    request: |-
      {
        "auth": {
          "auth_type": "bearer_token"
        },
        "method": "GET",
        "path": "/api/v1/orgs/{orgId}/console-apikeys?cluster_id={tidbId}",
        "path_params": {
          "orgId": "org_id",
          "tidbId": "cluster_1"
        },
        "query_params": {},
        "headers": {},
        "body": {},
        "body_params": {}
      }
    expect: |-
      {
        "status_code": 200,
        "cel": "body.items.exists(item, item.org_role.rbac_role == 'org:member' && size(item.cluster_roles) == 2)"
      }
    description: Create cluster admin key
    max_retries: 0
    delay_after: 0
    step_type: defined
    name: create_cluster
    save: null
    continue_on_unexpected: false
    stage: execute
    meta: "{}"
    generation_id: 09198df8-3eef-4d82-a5a4-31eb9b0db7de
    order: 5
  - case_id: c37f522f5754a26096985d8962f63afe
    operation_id: UpdateConsoleApiKey
    case_type: typical_positive
    request_type: http
    request: |-
      {
        "auth": {
          "auth_type": "bearer_token"
        },
        "method": "PUT",
        "path": "/api/v1/orgs/{orgId}/console-apikey/update",
        "path_params": {
          "orgId": "org_id"
        },
        "query_params": {},
        "headers": {},
        "body": {
          "api_key_id": "{apiKeyId}",
          "description": "muti_inst_key",
          "org_role": "org:member",
          "cluster_roles": [
            {
              "scope_type": "tidb",
              "scope_id": "{tidbId_2}",
              "rbac_role": "cluster:viewer"
            }
          ]
        },
        "body_params": {
          "projectId": "project_id",
          "tidbId_2": "cluster_2",
          "apiKeyId": "api_key_id_1"
        }
      }
    expect: |-
      {
        "status_code": 200,
        "cel": ""
      }
    description: Create cluster admin key
    max_retries: 0
    delay_after: 0
    step_type: defined
    name: create_cluster
    save: null
    continue_on_unexpected: false
    stage: execute
    meta: "{}"
    generation_id: 09198df8-3eef-4d82-a5a4-31eb9b0db7de
    order: 6
  - case_id: c37f522f5754a26096985d8962f63afe
    operation_id: ListConsoleApiKeys
    case_type: typical_positive
    request_type: http
    request: |-
      {
        "auth": {
          "auth_type": "bearer_token"
        },
        "method": "GET",
        "path": "/api/v1/orgs/{orgId}/console-apikeys?cluster_id={tidbId}",
        "path_params": {
          "orgId": "org_id",
          "tidbId": "cluster_2"
        },
        "query_params": {},
        "headers": {},
        "body": {},
        "body_params": {}
      }
    expect: |-
      {
        "status_code": 200,
        "cel": "body.items.exists(item, item.org_role.rbac_role == 'org:member' && size(item.cluster_roles) == 1 && item.cluster_roles.exists(cr, cr.rbac_role == 'cluster:viewer'))"
      }
    description: Create cluster admin key
    max_retries: 0
    delay_after: 0
    step_type: defined
    name: create_cluster
    save: null
    continue_on_unexpected: false
    stage: execute
    meta: "{}"
    generation_id: 09198df8-3eef-4d82-a5a4-31eb9b0db7de
    order: 7
  - case_id: c37f522f5754a26096985d8962f63afe
    operation_id: UpdateConsoleApiKey
    case_type: typical_positive
    request_type: http
    request: |-
      {
        "auth": {
          "auth_type": "bearer_token"
        },
        "method": "PUT",
        "path": "/api/v1/orgs/{orgId}/console-apikey/update",
        "path_params": {
          "orgId": "org_id"
        },
        "query_params": {},
        "headers": {},
        "body": {
          "api_key_id": "{apiKeyId}",
          "description": "muti_inst_key",
          "org_role": "org:member",
          "project_roles": [
            {
              "scope_type": "project",
              "scope_id": "{projectId}",
              "rbac_role": "project:ctl_plane_viewer"
            }
          ]
        },
        "body_params": {
          "projectId": "project_id",
          "tidbId": "cluster_1",
          "apiKeyId": "api_key_id_1"
        }
      }
    expect: |-
      {
        "status_code": 200,
        "cel": ""
      }
    description: Create cluster admin key
    max_retries: 0
    delay_after: 0
    step_type: defined
    name: create_cluster
    save: null
    continue_on_unexpected: false
    stage: execute
    meta: "{}"
    generation_id: 09198df8-3eef-4d82-a5a4-31eb9b0db7de
    order: 8
  - case_id: c37f522f5754a26096985d8962f63afe
    operation_id: ListConsoleApiKeys
    case_type: typical_positive
    request_type: http
    request: |-
      {
        "auth": {
          "auth_type": "bearer_token"
        },
        "method": "GET",
        "path": "/api/v1/orgs/{orgId}/console-apikeys?cluster_id={tidbId}",
        "path_params": {
          "orgId": "org_id",
          "tidbId": "cluster_1"
        },
        "query_params": {},
        "headers": {},
        "body": {},
        "body_params": {}
      }
    expect: |-
      {
        "status_code": 200,
        "cel": "body.total == 0"
      }
    description: Create cluster admin key
    max_retries: 0
    delay_after: 0
    step_type: defined
    name: create_cluster
    save: null
    continue_on_unexpected: false
    stage: execute
    meta: "{}"
    generation_id: 09198df8-3eef-4d82-a5a4-31eb9b0db7de
    order: 9
  - case_id: c37f522f5754a26096985d8962f63afe
    operation_id: UpdateConsoleApiKey
    case_type: typical_positive
    request_type: http
    request: |-
      {
        "auth": {
          "auth_type": "bearer_token"
        },
        "method": "PUT",
        "path": "/api/v1/orgs/{orgId}/console-apikey/update",
        "path_params": {
          "orgId": "org_id"
        },
        "query_params": {},
        "headers": {},
        "body": {
          "api_key_id": "{apiKeyId}",
          "description": "muti_inst_key",
          "org_role": "org:member",
          "cluster_roles": [
            {
              "scope_type": "tidb",
              "scope_id": "{tidbId_1}",
              "rbac_role": "cluster:viewer"
            },
            {
              "scope_type": "tidb",
              "scope_id": "{tidbId_2}",
              "rbac_role": "cluster:viewer"
            }
          ]
        },
        "body_params": {
          "projectId": "project_id",
          "tidbId_1": "cluster_1",
          "tidbId_2": "cluster_2",
          "apiKeyId": "api_key_id_1"
        }
      }
    expect: |-
      {
        "status_code": 200,
        "cel": ""
      }
    description: Create cluster admin key
    max_retries: 0
    delay_after: 0
    step_type: defined
    name: create_cluster
    save: null
    continue_on_unexpected: false
    stage: execute
    meta: "{}"
    generation_id: 09198df8-3eef-4d82-a5a4-31eb9b0db7de
    order: 10
  - case_id: c37f522f5754a26096985d8962f63afe
    operation_id: ListConsoleApiKeys
    case_type: typical_positive
    request_type: http
    request: |-
      {
        "auth": {
          "auth_type": "bearer_token"
        },
        "method": "GET",
        "path": "/api/v1/orgs/{orgId}/console-apikeys?cluster_id={tidbId}",
        "path_params": {
          "orgId": "org_id",
          "tidbId": "cluster_1"
        },
        "query_params": {},
        "headers": {},
        "body": {},
        "body_params": {}
      }
    expect: |-
      {
        "status_code": 200,
        "cel": "body.items.exists(item, item.org_role.rbac_role == 'org:member' && size(item.cluster_roles) == 2 && item.cluster_roles.exists(cr, cr.rbac_role == 'cluster:viewer'))"
      }
    description: Create cluster admin key
    max_retries: 0
    delay_after: 0
    step_type: defined
    name: create_cluster
    save: null
    continue_on_unexpected: false
    stage: execute
    meta: "{}"
    generation_id: 09198df8-3eef-4d82-a5a4-31eb9b0db7de
    order: 11
  - case_id: c37f522f5754a26096985d8962f63afe
    operation_id: DeleteConsoleApiKey
    case_type: typical_positive
    request_type: http
    request: |-
      {
        "auth": {
          "auth_type": "bearer_token"
        },
        "method": "DELETE",
        "path": "/api/v1/orgs/{orgId}/api_keys/{apiKeyId}",
        "path_params": {
          "orgId": "org_id",
          "apiKeyId": "api_key_id_1"
        },
        "query_params": {},
        "headers": {},
        "body": {},
        "body_params": {}
      }
    expect: |-
      {
        "status_code": 200,
        "cel": ""
      }
    description: Create cluster admin key
    max_retries: 0
    delay_after: 0
    step_type: defined
    name: create_cluster
    save: null
    continue_on_unexpected: false
    stage: execute
    meta: "{}"
    generation_id: 09198df8-3eef-4d82-a5a4-31eb9b0db7de
    order: 12
  - operation_id: TidbService_DeleteTidb
    request_type: http
    request: |-
      {
        "method": "DELETE",
        "path": "/api/v2025/cloud/v1beta2/tidbs/{tidbId}?orgId={orgId}",
        "headers": {},
        "query_params": {},
        "body": {},
        "auth": {
          "auth_type": "bearer_token"
        },
        "path_params": {
          "tidbId": "cluster_1",
          "orgId": "org_id"
        }
      }
    expect: |-
      {
        "status_code": 200,
        "cel": ""
      }
    save: null
    description: ''
    max_retries: 0
    delay_after: 0
    name: ''
    continue_on_unexpected: false
    stage: ''
    meta: '{}'
    generation_id: ''
    order: 13
  - operation_id: TidbService_DeleteTidb
    request_type: http
    request: |-
      {
        "method": "DELETE",
        "path": "/api/v2025/cloud/v1beta2/tidbs/{tidbId}?orgId={orgId}",
        "headers": {},
        "query_params": {},
        "body": {},
        "auth": {
          "auth_type": "bearer_token"
        },
        "path_params": {
          "tidbId": "cluster_2",
          "orgId": "org_id"
        }
      }
    expect: |-
      {
        "status_code": 200,
        "cel": ""
      }
    save: null
    description: ''
    max_retries: 0
    delay_after: 0
    name: ''
    continue_on_unexpected: false
    stage: ''
    meta: '{}'
    generation_id: ''
    order: 14