---
policy: /ce/ca/azure/key-vault/private-endpoints-use
logic: /ce/ca/azure/key-vault/private-endpoints-use/prod.logic.yaml
executionTime: 2025-04-24T23:45:24.866526121Z
rows:
  - id: test1
    match: true
    status:
      expected: DISAPPEARED
      actual: DISAPPEARED
    conditionIndex:
      expected: 99
      actual: 99
    conditionText:
      expected: isDisappeared(CA10__disappearanceTime__c)
      actual: isDisappeared(CA10__disappearanceTime__c)
    runtimeError: {}
  - id: test2
    match: true
    status:
      expected: INCOMPLIANT
      actual: INCOMPLIANT
    conditionIndex:
      expected: 199
      actual: 199
    conditionText:
      expected: CA10Z1__Azure_Private_Endpoint_Connections__r.has(INCOMPLIANT)
      actual: CA10Z1__Azure_Private_Endpoint_Connections__r.has(INCOMPLIANT)
    runtimeError: {}
  - id: test3
    match: true
    status:
      expected: INCOMPLIANT
      actual: INCOMPLIANT
    conditionIndex:
      expected: 199
      actual: 199
    conditionText:
      expected: CA10Z1__Azure_Private_Endpoint_Connections__r.has(INCOMPLIANT)
      actual: CA10Z1__Azure_Private_Endpoint_Connections__r.has(INCOMPLIANT)
    runtimeError: {}
  - id: test4
    match: true
    status:
      expected: INCOMPLIANT
      actual: INCOMPLIANT
    conditionIndex:
      expected: 199
      actual: 199
    conditionText:
      expected: CA10Z1__Azure_Private_Endpoint_Connections__r.has(INCOMPLIANT)
      actual: CA10Z1__Azure_Private_Endpoint_Connections__r.has(INCOMPLIANT)
    runtimeError: {}
  - id: test5
    match: true
    status:
      expected: INCOMPLIANT
      actual: INCOMPLIANT
    conditionIndex:
      expected: 199
      actual: 199
    conditionText:
      expected: CA10Z1__Azure_Private_Endpoint_Connections__r.has(INCOMPLIANT)
      actual: CA10Z1__Azure_Private_Endpoint_Connections__r.has(INCOMPLIANT)
    runtimeError: {}
  - id: test6
    match: true
    status:
      expected: COMPLIANT
      actual: COMPLIANT
    conditionIndex:
      expected: 299
      actual: 299
    conditionText:
      expected: CA10Z1__Azure_Private_Endpoint_Connections__r.has(COMPLIANT)
      actual: CA10Z1__Azure_Private_Endpoint_Connections__r.has(COMPLIANT)
    runtimeError: {}
  - id: test7
    match: true
    status:
      expected: INCOMPLIANT
      actual: INCOMPLIANT
    conditionIndex:
      expected: 400
      actual: 400
    conditionText:
      expected: otherwise
      actual: otherwise
    runtimeError: {}
  - id: test8
    match: true
    status:
      expected: INCOMPLIANT
      actual: INCOMPLIANT
    conditionIndex:
      expected: 400
      actual: 400
    conditionText:
      expected: otherwise
      actual: otherwise
    runtimeError: {}
usedFiles:
  - path: /ce/ca/azure/key-vault/private-endpoints-use/policy.yaml
    md5Hash: 7EEA984013AAD363279B10A26C77650D
    content: |
      ---
      names:
        full: Azure Key Vault Private Endpoints are not used
        contextual: Private Endpoints are not used
      description: Private endpoints will secure network traffic from Azure Key Vault to
        the resources requesting secrets and keys.
      type: COMPLIANCE_POLICY
      categories:
        - SECURITY
      frameworkMappings:
        - "/frameworks/cis-azure-v2.1.0/08/07"
        - "/frameworks/cis-azure-v3.0.0/03/03/07"
        - "/frameworks/cloudaware/resource-security/secure-access"
      similarPolicies:
        internal:
          - dec-x-807a37c9
  - path: /ce/ca/azure/key-vault/private-endpoints-use/prod.logic.yaml
    md5Hash: 9F090F8D96208773A9A858500F45911A
    content: "---\ninputType: \"CA10__CaAzureKeyVault__c\"\ntestData:\n  - file: \"\
      test-data.json\"\nconditions:\n  - status: \"INCOMPLIANT\"\n    currentStateMessage:\
      \ \"A private endpoint is not used by the Key Vault.\"\n    remediationMessage:\
      \ \"Consider creating a private endpoint to limit the\\ \n      \\ network traffic\
      \ to approved sources.\"\n    check:\n      RELATED_LIST_HAS:\n        status:\
      \ \"INCOMPLIANT\"\n        relationshipName: \"CA10Z1__Azure_Private_Endpoint_Connections__r\"\
      \n  - status: \"COMPLIANT\"\n    currentStateMessage: \"the Key Vault uses a\
      \ private endpoint.\"\n    check:\n      RELATED_LIST_HAS:\n        status:\
      \ \"COMPLIANT\"\n        relationshipName: \"CA10Z1__Azure_Private_Endpoint_Connections__r\"\
      \n  - status: \"UNDETERMINED\"\n    currentStateMessage: \"Unable to determine\
      \ the private endpoint status.\"\n    check:\n      RELATED_LIST_HAS:\n    \
      \    status: \"UNDETERMINED\"\n        relationshipName: \"CA10Z1__Azure_Private_Endpoint_Connections__r\"\
      \notherwise:\n  status: \"INCOMPLIANT\"\n  currentStateMessage: \"A private\
      \ endpoint is not used by the Key Vault.\"\n  remediationMessage: \"Consider\
      \ creating a private endpoint to limit the\\ \n    \\ network traffic to approved\
      \ sources.\"\nrelatedLists:\n  - relationshipName: \"CA10Z1__Azure_Private_Endpoint_Connections__r\"\
      \n    recordTypes:\n      - \"privateEndpointConnectionKeyVault\"\n    importExtracts:\n\
      \    - file: \"/types/CA10Z1__CaAzurePrivateEndpointConnection__c/object.extracts.yaml\"\
      \n    conditions:\n      - status: \"INCOMPLIANT\"\n        currentStateMessage:\
      \ \"A private endpoint does not exist.\"\n        remediationMessage: \"Consider\
      \ creating a private endpoint.\"\n        check:\n          IS_EMPTY_LOOKUP:\
      \ \"CA10Z1__privateEndpoint__r\"\n      - status: \"INCOMPLIANT\"\n        currentStateMessage:\
      \ \"The private link service connection is not approved.\"\n        remediationMessage:\
      \ \"Resource owner rejected or removed the connection.\"\n        check:\n \
      \         NOT_EQUAL:\n            left:\n              EXTRACT: \"CA10Z1__serviceConnectionStatus__c\"\
      \n            right:\n              TEXT: \"Approved\"\n      - status: \"COMPLIANT\"\
      \n        currentStateMessage: \"The private link service connection is approved.\"\
      \n        check:\n          IS_EQUAL:\n            left:\n              EXTRACT:\
      \ \"CA10Z1__serviceConnectionStatus__c\"\n            right:\n             \
      \ TEXT: \"Approved\"\n    otherwise:\n      status: \"UNDETERMINED\"\n     \
      \ currentStateMessage: \"Unexpected value in the field.\"\n"
  - path: /ce/ca/azure/key-vault/private-endpoints-use/test-data.json
    md5Hash: B875B682C2F5E1BC880D78283D9E718E
    content: |-
      [
          {
              "expectedResult": {
                  "status": "DISAPPEARED",
                  "conditionIndex": "99",
                  "conditionText": "isDisappeared(CA10__disappearanceTime__c)",
                  "runtimeError": null
              },
              "context": {
                  "snapshotTime": "2024-06-13T04:17:29Z"
              },
              "Id": "test1",
              "CA10__disappearanceTime__c": "2024-06-07T13:58:24Z",
              "CA10Z1__Azure_Private_Endpoint_Connections__r": [
                  {
                      "Id": "test1_1",
                      "RecordTypeId": "RecordTypeId",
                      "CA10Z1__disappearanceTime__c": null,
                      "CA10Z1__privateEndpoint__c": "privateEndpoint1",
                      "CA10Z1__privateEndpointId__c": "privateEndpointId1",
                      "CA10Z1__serviceConnectionStatus__c": "Approved",
                      "CA10Z1__keyVault__c": "test1",
                      "RecordType": {
                          "DeveloperName": "privateEndpointConnectionKeyVault",
                          "Id": "RecordTypeId"
                      }
                      ,
                      "CA10Z1__privateEndpoint__r": {
                          "Id": "privateEndpoint1",
                          "CA10Z1__disappearanceTime__c": null
                      }
                      }
              ]
          },
          {
              "expectedResult": {
                  "status": "INCOMPLIANT",
                  "conditionIndex": "199",
                  "conditionText": "CA10Z1__Azure_Private_Endpoint_Connections__r.has(INCOMPLIANT)",
                  "runtimeError": null
              },
              "context": {
                  "snapshotTime": "2024-06-13T04:17:29Z"
              },
              "Id": "test2",
              "CA10__disappearanceTime__c": null,
              "CA10Z1__Azure_Private_Endpoint_Connections__r": [
                  {
                      "Id": "test2_1",
                      "RecordTypeId": "RecordTypeId",
                      "CA10Z1__disappearanceTime__c": null,
                      "CA10Z1__privateEndpoint__c": "privateEndpoint2",
                      "CA10Z1__privateEndpointId__c": "privateEndpointId2",
                      "CA10Z1__serviceConnectionStatus__c": "Rejected",
                      "CA10Z1__keyVault__c": "test2",
                      "RecordType": {
                          "DeveloperName": "privateEndpointConnectionKeyVault",
                          "Id": "RecordTypeId"
                      }
                      ,
                      "CA10Z1__privateEndpoint__r": {
                          "Id": "privateEndpoint2",
                          "CA10Z1__disappearanceTime__c": null
                      }
                      }
              ]
          },
          {
              "expectedResult": {
                  "status": "INCOMPLIANT",
                  "conditionIndex": "199",
                  "conditionText": "CA10Z1__Azure_Private_Endpoint_Connections__r.has(INCOMPLIANT)",
                  "runtimeError": null
              },
              "context": {
                  "snapshotTime": "2024-06-13T04:17:29Z"
              },
              "Id": "test3",
              "CA10__disappearanceTime__c": null,
              "CA10Z1__Azure_Private_Endpoint_Connections__r": [
                  {
                      "Id": "test3_1",
                      "RecordTypeId": "RecordTypeId",
                      "CA10Z1__disappearanceTime__c": null,
                      "CA10Z1__privateEndpoint__c": "privateEndpoint3",
                      "CA10Z1__privateEndpointId__c": "privateEndpointId3",
                      "CA10Z1__serviceConnectionStatus__c": "Approved",
                      "CA10Z1__keyVault__c": "test3",
                      "RecordType": {
                          "DeveloperName": "privateEndpointConnectionKeyVault",
                          "Id": "RecordTypeId"
                      }
                      ,
                      "CA10Z1__privateEndpoint__r": {
                          "Id": "privateEndpoint3",
                          "CA10Z1__disappearanceTime__c": "2024-06-13T04:17:29Z"
                      }
                      }
              ]
          },
          {
              "expectedResult": {
                  "status": "INCOMPLIANT",
                  "conditionIndex": "199",
                  "conditionText": "CA10Z1__Azure_Private_Endpoint_Connections__r.has(INCOMPLIANT)",
                  "runtimeError": null
              },
              "context": {
                  "snapshotTime": "2024-06-13T04:17:29Z"
              },
              "Id": "test4",
              "CA10__disappearanceTime__c": null,
              "CA10Z1__Azure_Private_Endpoint_Connections__r": [
                  {
                      "Id": "test4_1",
                      "RecordTypeId": "RecordTypeId",
                      "CA10Z1__disappearanceTime__c": null,
                      "CA10Z1__privateEndpoint__c": null,
                      "CA10Z1__privateEndpointId__c": "privateEndpointId4",
                      "CA10Z1__serviceConnectionStatus__c": "Approved",
                      "CA10Z1__keyVault__c": "test4",
                      "RecordType": {
                          "DeveloperName": "privateEndpointConnectionKeyVault",
                          "Id": "RecordTypeId"
                      }
                      ,
                      "CA10Z1__privateEndpoint__r": {
                          "Id": null,
                          "CA10Z1__disappearanceTime__c": null
                      }
                      }
              ]
          },
          {
              "expectedResult": {
                  "status": "INCOMPLIANT",
                  "conditionIndex": "199",
                  "conditionText": "CA10Z1__Azure_Private_Endpoint_Connections__r.has(INCOMPLIANT)",
                  "runtimeError": null
              },
              "context": {
                  "snapshotTime": "2024-06-13T04:17:29Z"
              },
              "Id": "test5",
              "CA10__disappearanceTime__c": null,
              "CA10Z1__Azure_Private_Endpoint_Connections__r": [
                  {
                      "Id": "test5_1",
                      "RecordTypeId": "RecordTypeId",
                      "CA10Z1__disappearanceTime__c": null,
                      "CA10Z1__privateEndpoint__c": null,
                      "CA10Z1__privateEndpointId__c": null,
                      "CA10Z1__serviceConnectionStatus__c": "Approved",
                      "CA10Z1__keyVault__c": "test5",
                      "RecordType": {
                          "DeveloperName": "privateEndpointConnectionKeyVault",
                          "Id": "RecordTypeId"
                      }
                      ,
                      "CA10Z1__privateEndpoint__r": {
                          "Id": null,
                          "CA10Z1__disappearanceTime__c": null
                      }
                      }
              ]
          },
          {
              "expectedResult": {
                  "status": "COMPLIANT",
                  "conditionIndex": "299",
                  "conditionText": "CA10Z1__Azure_Private_Endpoint_Connections__r.has(COMPLIANT)",
                  "runtimeError": null
              },
              "context": {
                  "snapshotTime": "2024-06-13T04:17:29Z"
              },
              "Id": "test6",
              "CA10__disappearanceTime__c": null,
              "CA10Z1__Azure_Private_Endpoint_Connections__r": [
                  {
                      "Id": "test6_1",
                      "RecordTypeId": "RecordTypeId",
                      "CA10Z1__disappearanceTime__c": null,
                      "CA10Z1__privateEndpoint__c": "privateEndpoint6",
                      "CA10Z1__privateEndpointId__c": "privateEndpointId6",
                      "CA10Z1__serviceConnectionStatus__c": "Approved",
                      "CA10Z1__keyVault__c": "test6",
                      "RecordType": {
                          "DeveloperName": "privateEndpointConnectionKeyVault",
                          "Id": "RecordTypeId"
                      }
                      ,
                      "CA10Z1__privateEndpoint__r": {
                          "Id": "privateEndpoint6",
                          "CA10Z1__disappearanceTime__c": null
                      }
                      }
              ]
          },
          {
              "expectedResult": {
                  "status": "INCOMPLIANT",
                  "conditionIndex": "400",
                  "conditionText": "otherwise",
                  "runtimeError": null
              },
              "context": {
                  "snapshotTime": "2024-06-13T04:17:29Z"
              },
              "Id": "test7",
              "CA10__disappearanceTime__c": null,
              "CA10Z1__Azure_Private_Endpoint_Connections__r": [
                  {
                      "Id": "test7_1",
                      "RecordTypeId": "RecordTypeId",
                      "CA10Z1__disappearanceTime__c": "2024-06-13T04:17:29Z",
                      "CA10Z1__privateEndpoint__c": "privateEndpoint7",
                      "CA10Z1__privateEndpointId__c": "privateEndpointId7",
                      "CA10Z1__serviceConnectionStatus__c": "Approved",
                      "CA10Z1__keyVault__c": "test7",
                      "RecordType": {
                          "DeveloperName": "privateEndpointConnectionKeyVault",
                          "Id": "RecordTypeId"
                      }
                      ,
                      "CA10Z1__privateEndpoint__r": {
                          "Id": "privateEndpoint7",
                          "CA10Z1__disappearanceTime__c": null
                      }
                      }
              ]
          },
          {
              "expectedResult": {
                  "status": "INCOMPLIANT",
                  "conditionIndex": "400",
                  "conditionText": "otherwise",
                  "runtimeError": null
              },
              "context": {
                  "snapshotTime": "2024-06-13T04:17:29Z"
              },
              "Id": "test8",
              "CA10__disappearanceTime__c": null,
              "CA10Z1__Azure_Private_Endpoint_Connections__r": []
          }
      ]
  - path: /types/CA10Z1__CaAzurePrivateEndpointConnection__c/object.extracts.yaml
    md5Hash: 5CD7A50D4A2794C12C5D70767988C700
    content: "---\nextracts:\n# Values: Approved, Reject, Disconnected, Pending. Not\
      \ Nullable. Can't have no access, retrieved via Microsoft.DocumentDB/databaseAccounts\n\
      \  - name: \"CA10Z1__serviceConnectionStatus__c\"\n    value: \n      FIELD:\n\
      \        path: \"CA10Z1__serviceConnectionStatus__c\"\n        undeterminedIf:\n\
      \          isEmpty: \"Corrupted data. The Service Connection Status cannot be\
      \ empty.\""
script: |-
  CREATE TEMP FUNCTION mock_ExpectedResult()
  RETURNS ARRAY<STRUCT<
          Id STRING,
          expectedResult STRUCT<status STRING, conditionIndex DECIMAL, conditionText STRING, runtimeError STRING>
      >>
  DETERMINISTIC
  LANGUAGE js
  AS r"""
    return [ {
    "Id" : "test1",
    "expectedResult" : {
      "status" : "DISAPPEARED",
      "conditionIndex" : "99",
      "conditionText" : "isDisappeared(CA10__disappearanceTime__c)",
      "runtimeError" : null
    }
  }, {
    "Id" : "test2",
    "expectedResult" : {
      "status" : "INCOMPLIANT",
      "conditionIndex" : "199",
      "conditionText" : "CA10Z1__Azure_Private_Endpoint_Connections__r.has(INCOMPLIANT)",
      "runtimeError" : null
    }
  }, {
    "Id" : "test3",
    "expectedResult" : {
      "status" : "INCOMPLIANT",
      "conditionIndex" : "199",
      "conditionText" : "CA10Z1__Azure_Private_Endpoint_Connections__r.has(INCOMPLIANT)",
      "runtimeError" : null
    }
  }, {
    "Id" : "test4",
    "expectedResult" : {
      "status" : "INCOMPLIANT",
      "conditionIndex" : "199",
      "conditionText" : "CA10Z1__Azure_Private_Endpoint_Connections__r.has(INCOMPLIANT)",
      "runtimeError" : null
    }
  }, {
    "Id" : "test5",
    "expectedResult" : {
      "status" : "INCOMPLIANT",
      "conditionIndex" : "199",
      "conditionText" : "CA10Z1__Azure_Private_Endpoint_Connections__r.has(INCOMPLIANT)",
      "runtimeError" : null
    }
  }, {
    "Id" : "test6",
    "expectedResult" : {
      "status" : "COMPLIANT",
      "conditionIndex" : "299",
      "conditionText" : "CA10Z1__Azure_Private_Endpoint_Connections__r.has(COMPLIANT)",
      "runtimeError" : null
    }
  }, {
    "Id" : "test7",
    "expectedResult" : {
      "status" : "INCOMPLIANT",
      "conditionIndex" : "400",
      "conditionText" : "otherwise",
      "runtimeError" : null
    }
  }, {
    "Id" : "test8",
    "expectedResult" : {
      "status" : "INCOMPLIANT",
      "conditionIndex" : "400",
      "conditionText" : "otherwise",
      "runtimeError" : null
    }
  } ];
  """;

  CREATE TEMP FUNCTION mock_CA10__CaAzureKeyVault__c()
  RETURNS ARRAY<STRUCT<
      Id STRING,
      CA10__disappearanceTime__c TIMESTAMP,
      context STRUCT<
          snapshotTime TIMESTAMP
      >
  >>
  DETERMINISTIC
  LANGUAGE js
  AS r"""
    return [ {
    "context" : {
      "snapshotTime" : new Date("2024-06-13T04:17:29Z")
    },
    "Id" : "test1",
    "CA10__disappearanceTime__c" : new Date("2024-06-07T13:58:24Z")
  }, {
    "context" : {
      "snapshotTime" : new Date("2024-06-13T04:17:29Z")
    },
    "Id" : "test2"
  }, {
    "context" : {
      "snapshotTime" : new Date("2024-06-13T04:17:29Z")
    },
    "Id" : "test3"
  }, {
    "context" : {
      "snapshotTime" : new Date("2024-06-13T04:17:29Z")
    },
    "Id" : "test4"
  }, {
    "context" : {
      "snapshotTime" : new Date("2024-06-13T04:17:29Z")
    },
    "Id" : "test5"
  }, {
    "context" : {
      "snapshotTime" : new Date("2024-06-13T04:17:29Z")
    },
    "Id" : "test6"
  }, {
    "context" : {
      "snapshotTime" : new Date("2024-06-13T04:17:29Z")
    },
    "Id" : "test7"
  }, {
    "context" : {
      "snapshotTime" : new Date("2024-06-13T04:17:29Z")
    },
    "Id" : "test8"
  } ];
  """;

  CREATE TEMP FUNCTION mock_CA10Z1__CaAzurePrivateEndpointConnection__c()
  RETURNS ARRAY<STRUCT<
      Id STRING,
      RecordTypeId STRING,
      CA10Z1__disappearanceTime__c TIMESTAMP,
      CA10Z1__privateEndpoint__c STRING,
      CA10Z1__privateEndpointId__c STRING,
      CA10Z1__serviceConnectionStatus__c STRING,
      CA10Z1__keyVault__c STRING,
      context STRUCT<
          snapshotTime TIMESTAMP
      >
  >>
  DETERMINISTIC
  LANGUAGE js
  AS r"""
    return [ {
    "context" : {
      "snapshotTime" : new Date("2024-06-13T04:17:29Z")
    },
    "Id" : "test1_1",
    "RecordTypeId" : "RecordTypeId",
    "CA10Z1__privateEndpoint__c" : "privateEndpoint1",
    "CA10Z1__privateEndpointId__c" : "privateEndpointId1",
    "CA10Z1__serviceConnectionStatus__c" : "Approved",
    "CA10Z1__keyVault__c" : "test1"
  }, {
    "context" : {
      "snapshotTime" : new Date("2024-06-13T04:17:29Z")
    },
    "Id" : "test2_1",
    "RecordTypeId" : "RecordTypeId",
    "CA10Z1__privateEndpoint__c" : "privateEndpoint2",
    "CA10Z1__privateEndpointId__c" : "privateEndpointId2",
    "CA10Z1__serviceConnectionStatus__c" : "Rejected",
    "CA10Z1__keyVault__c" : "test2"
  }, {
    "context" : {
      "snapshotTime" : new Date("2024-06-13T04:17:29Z")
    },
    "Id" : "test3_1",
    "RecordTypeId" : "RecordTypeId",
    "CA10Z1__privateEndpoint__c" : "privateEndpoint3",
    "CA10Z1__privateEndpointId__c" : "privateEndpointId3",
    "CA10Z1__serviceConnectionStatus__c" : "Approved",
    "CA10Z1__keyVault__c" : "test3"
  }, {
    "context" : {
      "snapshotTime" : new Date("2024-06-13T04:17:29Z")
    },
    "Id" : "test4_1",
    "RecordTypeId" : "RecordTypeId",
    "CA10Z1__privateEndpoint__c" : null,
    "CA10Z1__privateEndpointId__c" : "privateEndpointId4",
    "CA10Z1__serviceConnectionStatus__c" : "Approved",
    "CA10Z1__keyVault__c" : "test4"
  }, {
    "context" : {
      "snapshotTime" : new Date("2024-06-13T04:17:29Z")
    },
    "Id" : "test5_1",
    "RecordTypeId" : "RecordTypeId",
    "CA10Z1__privateEndpoint__c" : null,
    "CA10Z1__privateEndpointId__c" : null,
    "CA10Z1__serviceConnectionStatus__c" : "Approved",
    "CA10Z1__keyVault__c" : "test5"
  }, {
    "context" : {
      "snapshotTime" : new Date("2024-06-13T04:17:29Z")
    },
    "Id" : "test6_1",
    "RecordTypeId" : "RecordTypeId",
    "CA10Z1__privateEndpoint__c" : "privateEndpoint6",
    "CA10Z1__privateEndpointId__c" : "privateEndpointId6",
    "CA10Z1__serviceConnectionStatus__c" : "Approved",
    "CA10Z1__keyVault__c" : "test6"
  }, {
    "context" : {
      "snapshotTime" : new Date("2024-06-13T04:17:29Z")
    },
    "Id" : "test7_1",
    "RecordTypeId" : "RecordTypeId",
    "CA10Z1__disappearanceTime__c" : new Date("2024-06-13T04:17:29Z"),
    "CA10Z1__privateEndpoint__c" : "privateEndpoint7",
    "CA10Z1__privateEndpointId__c" : "privateEndpointId7",
    "CA10Z1__serviceConnectionStatus__c" : "Approved",
    "CA10Z1__keyVault__c" : "test7"
  } ];
  """;

  CREATE TEMP FUNCTION mock_RecordType()
  RETURNS ARRAY<STRUCT<
      DeveloperName STRING,
      Id STRING,
      context STRUCT<
          snapshotTime TIMESTAMP
      >
  >>
  DETERMINISTIC
  LANGUAGE js
  AS r"""
    return [ {
    "context" : {
      "snapshotTime" : new Date("2024-06-13T04:17:29Z")
    },
    "DeveloperName" : "privateEndpointConnectionKeyVault",
    "Id" : "RecordTypeId"
  } ];
  """;

  CREATE TEMP FUNCTION mock_CA10Z1__CaAzurePrivateEndpoint__c()
  RETURNS ARRAY<STRUCT<
      Id STRING,
      CA10Z1__disappearanceTime__c TIMESTAMP,
      context STRUCT<
          snapshotTime TIMESTAMP
      >
  >>
  DETERMINISTIC
  LANGUAGE js
  AS r"""
    return [ {
    "context" : {
      "snapshotTime" : new Date("2024-06-13T04:17:29Z")
    },
    "Id" : "privateEndpoint1"
  }, {
    "context" : {
      "snapshotTime" : new Date("2024-06-13T04:17:29Z")
    },
    "Id" : "privateEndpoint2"
  }, {
    "context" : {
      "snapshotTime" : new Date("2024-06-13T04:17:29Z")
    },
    "Id" : "privateEndpoint3",
    "CA10Z1__disappearanceTime__c" : new Date("2024-06-13T04:17:29Z")
  }, {
    "context" : {
      "snapshotTime" : new Date("2024-06-13T04:17:29Z")
    },
    "Id" : null
  }, {
    "context" : {
      "snapshotTime" : new Date("2024-06-13T04:17:29Z")
    },
    "Id" : "privateEndpoint6"
  }, {
    "context" : {
      "snapshotTime" : new Date("2024-06-13T04:17:29Z")
    },
    "Id" : "privateEndpoint7"
  } ];
  """;

  CREATE TEMP FUNCTION process_CA10__CaAzureKeyVault__c(
      obj STRUCT<
          Id STRING,
          CA10__disappearanceTime__c TIMESTAMP,
          CA10Z1__Azure_Private_Endpoint_Connections__r ARRAY<STRUCT<
              Id STRING,
              RecordTypeId STRING,
              CA10Z1__disappearanceTime__c TIMESTAMP,
              CA10Z1__privateEndpoint__c STRING,
              CA10Z1__privateEndpointId__c STRING,
              CA10Z1__serviceConnectionStatus__c STRING,
              CA10Z1__keyVault__c STRING,
              RecordType STRUCT<
                  DeveloperName STRING,
                  Id STRING
              >,
              CA10Z1__privateEndpoint__r STRUCT<
                  Id STRING,
                  CA10Z1__disappearanceTime__c TIMESTAMP
              >,
              result STRUCT<status STRING, conditionIndex DECIMAL, conditionText STRING, currentStateMessage STRING, currentStateReferences STRING, remediation STRING, runtimeError STRING>
          >>
      >,
      snapshotTime TIMESTAMP
  )
  RETURNS STRUCT<status STRING, conditionIndex DECIMAL, conditionText STRING, currentStateMessage STRING, currentStateReferences STRING, remediation STRING, runtimeError STRING>
  DETERMINISTIC
  LANGUAGE js
  AS r"""
      var references1 = [];
      // condition[0], conditionIndex:[0..99]
      references1.push('Deleted From Azure [CA10__disappearanceTime__c]: ' + obj.CA10__disappearanceTime__c);
      if (obj.CA10__disappearanceTime__c != null) {
          return {status: 'DISAPPEARED', conditionIndex: 99, conditionText: "isDisappeared(CA10__disappearanceTime__c)", currentStateMessage: "Object is deleted in the source", currentStateReferences: references1.join('\n'), remediation: null, runtimeError: null};
      }
      var count_CA10Z1__Azure_Private_Endpoint_Connections__r_INCOMPLIANT2 = 0;
      if (obj.CA10Z1__Azure_Private_Endpoint_Connections__r != null) {
          for (var i3 = 0; i3 < obj.CA10Z1__Azure_Private_Endpoint_Connections__r.length; i3++) {
              if (obj.CA10Z1__Azure_Private_Endpoint_Connections__r[i3].result.status == 'INCOMPLIANT') {
                  count_CA10Z1__Azure_Private_Endpoint_Connections__r_INCOMPLIANT2 += 1;
              }
          }
      }
      // condition[1], conditionIndex:[100..199]
      references1.push('Related list [CA10Z1__Azure_Private_Endpoint_Connections__r] ' + (count_CA10Z1__Azure_Private_Endpoint_Connections__r_INCOMPLIANT2 > 0 ? 'has' : 'does not have') + ' objects in INCOMPLIANT status');
      if (count_CA10Z1__Azure_Private_Endpoint_Connections__r_INCOMPLIANT2 > 0) {
          return {status: 'INCOMPLIANT', conditionIndex: 199, conditionText: "CA10Z1__Azure_Private_Endpoint_Connections__r.has(INCOMPLIANT)", currentStateMessage: "A private endpoint is not used by the Key Vault.", currentStateReferences: references1.join('\n'), remediation: "Consider creating a private endpoint to limit the   network traffic to approved sources.", runtimeError: null};
      }
      var count_CA10Z1__Azure_Private_Endpoint_Connections__r_COMPLIANT4 = 0;
      if (obj.CA10Z1__Azure_Private_Endpoint_Connections__r != null) {
          for (var i5 = 0; i5 < obj.CA10Z1__Azure_Private_Endpoint_Connections__r.length; i5++) {
              if (obj.CA10Z1__Azure_Private_Endpoint_Connections__r[i5].result.status == 'COMPLIANT') {
                  count_CA10Z1__Azure_Private_Endpoint_Connections__r_COMPLIANT4 += 1;
              }
          }
      }
      // condition[2], conditionIndex:[200..299]
      if (count_CA10Z1__Azure_Private_Endpoint_Connections__r_COMPLIANT4 > 0) {
          return {status: 'COMPLIANT', conditionIndex: 299, conditionText: "CA10Z1__Azure_Private_Endpoint_Connections__r.has(COMPLIANT)", currentStateMessage: "the Key Vault uses a private endpoint.", currentStateReferences: references1.join('\n'), remediation: null, runtimeError: null};
      }
      var count_CA10Z1__Azure_Private_Endpoint_Connections__r_UNDETERMINED6 = 0;
      if (obj.CA10Z1__Azure_Private_Endpoint_Connections__r != null) {
          for (var i7 = 0; i7 < obj.CA10Z1__Azure_Private_Endpoint_Connections__r.length; i7++) {
              if (obj.CA10Z1__Azure_Private_Endpoint_Connections__r[i7].result.status == 'UNDETERMINED') {
                  count_CA10Z1__Azure_Private_Endpoint_Connections__r_UNDETERMINED6 += 1;
              }
          }
      }
      // condition[3], conditionIndex:[300..399]
      if (count_CA10Z1__Azure_Private_Endpoint_Connections__r_UNDETERMINED6 > 0) {
          return {status: 'UNDETERMINED', conditionIndex: 399, conditionText: "CA10Z1__Azure_Private_Endpoint_Connections__r.has(UNDETERMINED)", currentStateMessage: "Unable to determine the private endpoint status.", currentStateReferences: references1.join('\n'), remediation: null, runtimeError: null};
      }
      return {status: 'INCOMPLIANT', conditionIndex: 400, conditionText: "otherwise", currentStateMessage: "A private endpoint is not used by the Key Vault.", currentStateReferences: references1.join('\n'), remediation: "Consider creating a private endpoint to limit the   network traffic to approved sources.", runtimeError: null};
  """;

  CREATE TEMP FUNCTION process_CA10Z1__Azure_Private_Endpoint_Connections__r(
      obj STRUCT<
          Id STRING,
          RecordTypeId STRING,
          CA10Z1__disappearanceTime__c TIMESTAMP,
          CA10Z1__privateEndpoint__c STRING,
          CA10Z1__privateEndpointId__c STRING,
          CA10Z1__serviceConnectionStatus__c STRING,
          CA10Z1__keyVault__c STRING,
          RecordType STRUCT<
              DeveloperName STRING,
              Id STRING
          >,
          CA10Z1__privateEndpoint__r STRUCT<
              Id STRING,
              CA10Z1__disappearanceTime__c TIMESTAMP
          >
      >,
      snapshotTime TIMESTAMP
  )
  RETURNS STRUCT<status STRING, conditionIndex DECIMAL, conditionText STRING, currentStateMessage STRING, currentStateReferences STRING, remediation STRING, runtimeError STRING>
  DETERMINISTIC
  LANGUAGE js
  AS r"""
      var CollectionLib = new function () {
          this.parse = function(arg, separator) {
              let out = new Set();
              if (arg == null) {
                  return out;
              }
              arg.split(separator).forEach(el => {if (TextLib.isNotEmpty(el)) {out.add(TextLib.normalize(el))}});
              return out;
          };
          this.fromArray = function(arr) {
              let out = new Set();
              if (arr == null) {
                  return out;
              }
              arr.forEach(el => {if (TextLib.isNotEmpty(el)) {out.add(TextLib.normalize(el))}});
              return out;
          };
          this.equal = function(left, right) {
              left = left == null ? new Set() : left;
              right = right == null ? new Set() : right;
              return left.size === right.size && new Set([...left, ...right]).size === left.size;
          };
          this.notEqual = function(left, right) {
              left = left == null ? new Set() : left;
              right = right == null ? new Set() : right;
              return left.size !== right.size || new Set([...left, ...right]).size !== left.size;
          };
          this.contains = function(collection, search) {
              if (collection == null || TextLib.isEmpty(search)) {
                  return false;
              }
              return collection.has(TextLib.normalize(search));
          };
          this.size = function(collection) {
              return collection == null ? 0 : collection.size;
          };
      }();
      var TextLib = new function () {
          this.normalize = function(arg) {
              return arg == null ? '' : arg.replace(/\s+/g, ' ').trim().toLowerCase();
          };
          this.isEmpty = function(arg) {
              return this.normalize(arg) == '';
          };
          this.isNotEmpty = function(arg) {
              return this.normalize(arg) != '';
          };
          this.equal = function(left, right) {
              return this.normalize(left) == this.normalize(right);
          };
          this.notEqual = function(left, right) {
              return this.normalize(left) != this.normalize(right);
          };
          this.startsWith = function(arg, substring) {
              return this.normalize(arg).startsWith(this.normalize(substring));
          };
          this.endsWith = function(arg, substring) {
              return this.normalize(arg).endsWith(this.normalize(substring));
          };
          this.contains = function(arg, substring) {
              return this.normalize(arg).includes(this.normalize(substring));
          };
      }();
      var references1 = [];
      // condition[0], conditionIndex:[0..99]
      references1.push('Deleted From Azure [CA10Z1__disappearanceTime__c]: ' + obj.CA10Z1__disappearanceTime__c);
      if (obj.CA10Z1__disappearanceTime__c != null) {
          return {status: 'DISAPPEARED', conditionIndex: 99, conditionText: "isDisappeared(CA10Z1__disappearanceTime__c)", currentStateMessage: "Object is deleted in the source", currentStateReferences: references1.join('\n'), remediation: null, runtimeError: null};
      }
      // condition[1], conditionIndex:[100..199]
      references1.push('Record Type Name [obj.RecordType.DeveloperName]: ' + obj.RecordType.DeveloperName);
      if (!CollectionLib.contains(CollectionLib.fromArray(['privateEndpointConnectionKeyVault']), obj.RecordType.DeveloperName)) {
          return {status: 'INAPPLICABLE', conditionIndex: 199, conditionText: "not(['privateEndpointConnectionKeyVault'].contains(RecordType.DeveloperName))", currentStateMessage: "Object record type is not applicable", currentStateReferences: references1.join('\n'), remediation: null, runtimeError: null};
      }
      // condition[2], conditionIndex:[200..299]
      if (TextLib.isEmpty(obj.CA10Z1__privateEndpointId__c) || TextLib.isEmpty(obj.CA10Z1__privateEndpoint__c) || obj.CA10Z1__privateEndpoint__r.CA10Z1__disappearanceTime__c != null) {
          return {status: 'INCOMPLIANT', conditionIndex: 299, conditionText: "isEmptyLookup('CA10Z1__privateEndpoint__r')", currentStateMessage: "A private endpoint does not exist.", currentStateReferences: references1.join('\n'), remediation: "Consider creating a private endpoint.", runtimeError: null};
      }
      // condition[3], conditionIndex:[300..399]
      function fieldChecked5() {
          if (TextLib.isEmpty(obj.CA10Z1__serviceConnectionStatus__c)) {
              throw new Error("UNDETERMINED condition:301", {cause: {status: 'UNDETERMINED', conditionIndex: 301, conditionText: "CA10Z1__serviceConnectionStatus__c.isEmpty()", currentStateMessage: "Corrupted data. The Service Connection Status cannot be empty.", currentStateReferences: references1.join('\n'), remediation: null, runtimeError: null}});
          }
          return obj.CA10Z1__serviceConnectionStatus__c;
      }
      function extract4() { if (!this.out) { this.out = fieldChecked5(); } return this.out; };
      references1.push('Service Connection: Status [obj.CA10Z1__serviceConnectionStatus__c]: ' + obj.CA10Z1__serviceConnectionStatus__c);
      try {
          if (TextLib.notEqual(extract4.call(extract4), 'Approved')) {
              return {status: 'INCOMPLIANT', conditionIndex: 399, conditionText: "extract('CA10Z1__serviceConnectionStatus__c') != 'Approved'", currentStateMessage: "The private link service connection is not approved.", currentStateReferences: references1.join('\n'), remediation: "Resource owner rejected or removed the connection.", runtimeError: null};
          }
      } catch (err) {
          if (err.cause && err.cause.status) { return err.cause; } else { throw err; }
      }
      // condition[4], conditionIndex:[400..499]
      function fieldChecked8() {
          if (TextLib.isEmpty(obj.CA10Z1__serviceConnectionStatus__c)) {
              throw new Error("UNDETERMINED condition:401", {cause: {status: 'UNDETERMINED', conditionIndex: 401, conditionText: "CA10Z1__serviceConnectionStatus__c.isEmpty()", currentStateMessage: "Corrupted data. The Service Connection Status cannot be empty.", currentStateReferences: references1.join('\n'), remediation: null, runtimeError: null}});
          }
          return obj.CA10Z1__serviceConnectionStatus__c;
      }
      function extract7() { if (!this.out) { this.out = fieldChecked8(); } return this.out; };
      try {
          if (TextLib.equal(extract7.call(extract7), 'Approved')) {
              return {status: 'COMPLIANT', conditionIndex: 499, conditionText: "extract('CA10Z1__serviceConnectionStatus__c') == 'Approved'", currentStateMessage: "The private link service connection is approved.", currentStateReferences: references1.join('\n'), remediation: null, runtimeError: null};
          }
      } catch (err) {
          if (err.cause && err.cause.status) { return err.cause; } else { throw err; }
      }
      return {status: 'UNDETERMINED', conditionIndex: 500, conditionText: "otherwise", currentStateMessage: "Unexpected value in the field.", currentStateReferences: references1.join('\n'), remediation: null, runtimeError: null};
  """;


  SELECT
    expectedResult.Id as Id,
    IF (
      IFNULL(expectedResult.expectedResult.status, '') = IFNULL(sObject.result.status, '')
      AND IFNULL(expectedResult.expectedResult.conditionIndex, -1) = IFNULL(sObject.result.conditionIndex, -1)
      AND IFNULL(expectedResult.expectedResult.conditionText, '') = IFNULL(sObject.result.conditionText, '')
      AND IFNULL(expectedResult.expectedResult.runtimeError, '') = IFNULL(sObject.result.runtimeError, ''),
      "MATCH",
      "FAIL"
    ) as match,
    expectedResult.expectedResult.status as expectedStatus, sObject.result.status as actualStatus,
    expectedResult.expectedResult.conditionIndex as expectedConditionIndex, sObject.result.conditionIndex as actualConditionIndex,
    expectedResult.expectedResult.conditionText as expectedConditionText, sObject.result.conditionText as actualConditionText,
    expectedResult.expectedResult.runtimeError as expectedRuntimeError, sObject.result.runtimeError as actualRuntimeError
  FROM UNNEST(mock_ExpectedResult()) expectedResult
  LEFT JOIN (
      SELECT
          sObject.Id AS Id,
          sObject.CA10__disappearanceTime__c AS CA10__disappearanceTime__c,
          `CA10Z1__Azure_Private_Endpoint_Connections__r`.arr AS CA10Z1__Azure_Private_Endpoint_Connections__r,
          process_CA10__CaAzureKeyVault__c(
              STRUCT(
                  sObject.Id AS Id,
                  sObject.CA10__disappearanceTime__c AS CA10__disappearanceTime__c,
                  `CA10Z1__Azure_Private_Endpoint_Connections__r`.arr AS CA10Z1__Azure_Private_Endpoint_Connections__r
              ),
              sObject.context.snapshotTime
          ) as result
      FROM UNNEST(mock_CA10__CaAzureKeyVault__c()) AS sObject
      LEFT JOIN (
          SELECT
              sObject.CA10Z1__keyVault__c,
              ARRAY_AGG(
                  STRUCT(
                      sObject.Id AS Id,
                      sObject.RecordTypeId AS RecordTypeId,
                      sObject.CA10Z1__disappearanceTime__c AS CA10Z1__disappearanceTime__c,
                      sObject.CA10Z1__privateEndpoint__c AS CA10Z1__privateEndpoint__c,
                      sObject.CA10Z1__privateEndpointId__c AS CA10Z1__privateEndpointId__c,
                      sObject.CA10Z1__serviceConnectionStatus__c AS CA10Z1__serviceConnectionStatus__c,
                      sObject.CA10Z1__keyVault__c AS CA10Z1__keyVault__c,
                      STRUCT (
                          `RecordType`.DeveloperName AS DeveloperName,
                          `RecordType`.Id AS Id
                      ) AS RecordType,
                      STRUCT (
                          `CA10Z1__privateEndpoint__r`.Id AS Id,
                          `CA10Z1__privateEndpoint__r`.CA10Z1__disappearanceTime__c AS CA10Z1__disappearanceTime__c
                      ) AS CA10Z1__privateEndpoint__r,
                      process_CA10Z1__Azure_Private_Endpoint_Connections__r(
                          STRUCT(
                              sObject.Id AS Id,
                              sObject.RecordTypeId AS RecordTypeId,
                              sObject.CA10Z1__disappearanceTime__c AS CA10Z1__disappearanceTime__c,
                              sObject.CA10Z1__privateEndpoint__c AS CA10Z1__privateEndpoint__c,
                              sObject.CA10Z1__privateEndpointId__c AS CA10Z1__privateEndpointId__c,
                              sObject.CA10Z1__serviceConnectionStatus__c AS CA10Z1__serviceConnectionStatus__c,
                              sObject.CA10Z1__keyVault__c AS CA10Z1__keyVault__c,
                              STRUCT (
                                  `RecordType`.DeveloperName AS DeveloperName,
                                  `RecordType`.Id AS Id
                              ) AS RecordType,
                              STRUCT (
                                  `CA10Z1__privateEndpoint__r`.Id AS Id,
                                  `CA10Z1__privateEndpoint__r`.CA10Z1__disappearanceTime__c AS CA10Z1__disappearanceTime__c
                              ) AS CA10Z1__privateEndpoint__r
                          ),
                          sObject.context.snapshotTime
                      ) as result
                  )
              ) AS arr
          FROM UNNEST(mock_CA10Z1__CaAzurePrivateEndpointConnection__c()) AS sObject
          LEFT JOIN UNNEST(mock_RecordType()) AS `RecordType`
              ON sObject.RecordTypeId = `RecordType`.Id
          LEFT JOIN UNNEST(mock_CA10Z1__CaAzurePrivateEndpoint__c()) AS `CA10Z1__privateEndpoint__r`
              ON sObject.CA10Z1__privateEndpoint__c = `CA10Z1__privateEndpoint__r`.Id
          GROUP BY sObject.CA10Z1__keyVault__c
      ) AS `CA10Z1__Azure_Private_Endpoint_Connections__r`
          ON sObject.Id = `CA10Z1__Azure_Private_Endpoint_Connections__r`.CA10Z1__keyVault__c
  ) sObject ON sObject.Id = expectedResult.Id;
