---
policy: /ce/ca/azure/key-vault/non-rbac-key-vault-keys-expiration-date
logic: /ce/ca/azure/key-vault/non-rbac-key-vault-keys-expiration-date/prod.logic.yaml
executionTime: 2025-04-24T23:45:23.296101988Z
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: INAPPLICABLE
      actual: INAPPLICABLE
    conditionIndex:
      expected: 199
      actual: 199
    conditionText:
      expected: extract('CA10__rbacAuthorization__c') == 'Enabled'
      actual: extract('CA10__rbacAuthorization__c') == 'Enabled'
    runtimeError: {}
  - id: test3
    match: true
    status:
      expected: INCOMPLIANT
      actual: INCOMPLIANT
    conditionIndex:
      expected: 299
      actual: 299
    conditionText:
      expected: CA10__Azure_Key_Vault_Keys__r.has(INCOMPLIANT)
      actual: CA10__Azure_Key_Vault_Keys__r.has(INCOMPLIANT)
    runtimeError: {}
  - id: test4
    match: true
    status:
      expected: COMPLIANT
      actual: COMPLIANT
    conditionIndex:
      expected: 399
      actual: 399
    conditionText:
      expected: CA10__Azure_Key_Vault_Keys__r.has(COMPLIANT)
      actual: CA10__Azure_Key_Vault_Keys__r.has(COMPLIANT)
    runtimeError: {}
  - id: test5
    match: true
    status:
      expected: INAPPLICABLE
      actual: INAPPLICABLE
    conditionIndex:
      expected: 499
      actual: 499
    conditionText:
      expected: CA10__Azure_Key_Vault_Keys__r.has(INAPPLICABLE)
      actual: CA10__Azure_Key_Vault_Keys__r.has(INAPPLICABLE)
    runtimeError: {}
  - id: test6
    match: true
    status:
      expected: UNDETERMINED
      actual: UNDETERMINED
    conditionIndex:
      expected: 500
      actual: 500
    conditionText:
      expected: otherwise
      actual: otherwise
    runtimeError: {}
usedFiles:
  - path: /ce/ca/azure/key-vault/non-rbac-key-vault-keys-expiration-date/policy.yaml
    md5Hash: F1F600D6113EFD2A75ABE2709F2B486D
    content: |
      ---
      names:
        full: Azure Non-RBAC Key Vault stores Keys without expiration date
        contextual: Non-RBAC Key Vault stores Keys without expiration date
      description: Ensure that all Keys in Non Role Based Access Control (RBAC) Azure Key
        Vaults have an expiration date set.
      type: COMPLIANCE_POLICY
      categories:
        - SECURITY
      frameworkMappings:
        - "/frameworks/cis-azure-v2.1.0/08/02"
        - "/frameworks/cis-azure-v3.0.0/03/03/02"
        - "/frameworks/cloudaware/secret-and-certificate-governance/expiration-management"
      frameworkIgnoreMappings:
        - "/frameworks/cis-azure-v1.1.0/08/01"
        - "/frameworks/cis-azure-v1.3.0/08/01"
      similarPolicies:
        internal:
          - dec-x-0feec790
        cloudConformity:
          - url: https://www.trendmicro.com/cloudoneconformity/knowledge-base/azure/KeyVault/key-expiration-check.html
            name: Check for Azure Key Vault Keys Expiration Date
  - path: /ce/ca/azure/key-vault/non-rbac-key-vault-keys-expiration-date/prod.logic.yaml
    md5Hash: EDBCB1D5172B31ED965E7C471D2127AD
    content: |-
      ---
      inputType: "CA10__CaAzureKeyVault__c"
      importExtracts:
        - file: "/types/CA10__CaAzureKeyVault__c/object.extracts.yaml"
      testData:
        - file: "test-data.json"
      conditions:
        - status: "INAPPLICABLE"
          currentStateMessage: "This is an RBAC Key Vault."
          check:
            IS_EQUAL:
              left:
                EXTRACT: "CA10__rbacAuthorization__c"
              right:
                TEXT: "Enabled"
        - status: "INCOMPLIANT"
          currentStateMessage: "The Key Vault has Keys without expiration date."
          remediationMessage: "Consider setting the Keys' expiration date."
          check:
            RELATED_LIST_HAS:
              relationshipName: CA10__Azure_Key_Vault_Keys__r
              status: "INCOMPLIANT"
        - status: "COMPLIANT"
          currentStateMessage: "The Key Vault Keys' expiration date is set for all enabled Keys."
          check:
            RELATED_LIST_HAS:
              relationshipName: CA10__Azure_Key_Vault_Keys__r
              status: "COMPLIANT"
        - status: "INAPPLICABLE"
          currentStateMessage: "The Key Vault only has disabled Keys."
          check:
            RELATED_LIST_HAS:
              relationshipName: CA10__Azure_Key_Vault_Keys__r
              status: "INAPPLICABLE"
      otherwise:
        status: "UNDETERMINED"
        currentStateMessage: "The Key Vault doesn't have Keys or Cloudaware doesn't have access to view Keys."
      relatedLists:
        - relationshipName: CA10__Azure_Key_Vault_Keys__r
          importExtracts:
          - file: "/types/CA10__CaAzureKeyVaultKey__c/object.extracts.yaml"
          conditions:
            - status: "INAPPLICABLE"
              currentStateMessage: "The Key is disabled."
              check:
                NOT_EQUAL:
                  left:
                    EXTRACT: "CA10__enabledStatus__c"
                  right:
                    TEXT: "Enabled"
            - status: "INCOMPLIANT"
              currentStateMessage: "The Key expiration date is not set."
              remediationMessage: "Consider setting the Key expiration date."
              check:
                IS_EMPTY:
                  arg:
                    EXTRACT: "CA10__expirationDate__c"
            - status: "COMPLIANT"
              currentStateMessage: "The Key expiration date is set."
              check:
                NOT_EMPTY:
                  arg:
                    EXTRACT: "CA10__expirationDate__c"
          otherwise:
            status: "UNDETERMINED"
            currentStateMessage: "Unexpected values in the fields."
  - path: /ce/ca/azure/key-vault/non-rbac-key-vault-keys-expiration-date/test-data.json
    md5Hash: 459DA43CD4A02BF66DC846A418580595
    content: |-
      [
          {
              "expectedResult": {
                  "status": "DISAPPEARED",
                  "conditionIndex": "99",
                  "conditionText": "isDisappeared(CA10__disappearanceTime__c)",
                  "runtimeError": null
              },
              "context": {
                  "snapshotTime": "2024-06-27T20:33:04Z"
              },
              "Id": "test1",
              "CA10__disappearanceTime__c": "2024-06-27T20:33:04Z",
              "CA10__rbacAuthorization__c": "Enabled",
              "CA10__Azure_Key_Vault_Keys__r": []
          },
          {
              "expectedResult": {
                  "status": "INAPPLICABLE",
                  "conditionIndex": "199",
                  "conditionText": "extract('CA10__rbacAuthorization__c') == 'Enabled'",
                  "runtimeError": null
              },
              "context": {
                  "snapshotTime": "2024-06-27T20:33:04Z"
              },
              "Id": "test2",
              "CA10__disappearanceTime__c": null,
              "CA10__rbacAuthorization__c": "Enabled",
              "CA10__Azure_Key_Vault_Keys__r": []
          },
          {
              "expectedResult": {
                  "status": "INCOMPLIANT",
                  "conditionIndex": "299",
                  "conditionText": "CA10__Azure_Key_Vault_Keys__r.has(INCOMPLIANT)",
                  "runtimeError": null
              },
              "context": {
                  "snapshotTime": "2024-06-27T20:33:04Z"
              },
              "Id": "test3",
              "CA10__disappearanceTime__c": null,
              "CA10__rbacAuthorization__c": "Disabled",
              "CA10__Azure_Key_Vault_Keys__r": [
                  {
                      "Id": "test3_1",
                      "CA10__disappearanceTime__c": null,
                      "CA10__enabledStatus__c": "Enabled",
                      "CA10__expirationDate__c": null,
                      "CA10__keyVault__c": "test3"
                  }
              ]
          },
          {
              "expectedResult": {
                  "status": "COMPLIANT",
                  "conditionIndex": "399",
                  "conditionText": "CA10__Azure_Key_Vault_Keys__r.has(COMPLIANT)",
                  "runtimeError": null
              },
              "context": {
                  "snapshotTime": "2024-06-27T20:33:04Z"
              },
              "Id": "test4",
              "CA10__disappearanceTime__c": null,
              "CA10__rbacAuthorization__c": "Disabled",
              "CA10__Azure_Key_Vault_Keys__r": [
                  {
                      "Id": "test4_1",
                      "CA10__disappearanceTime__c": null,
                      "CA10__enabledStatus__c": "Enabled",
                      "CA10__expirationDate__c": "2024-06-27T20:33:04Z",
                      "CA10__keyVault__c": "test4"
                  }
              ]
          },
          {
              "expectedResult": {
                  "status": "INAPPLICABLE",
                  "conditionIndex": "499",
                  "conditionText": "CA10__Azure_Key_Vault_Keys__r.has(INAPPLICABLE)",
                  "runtimeError": null
              },
              "context": {
                  "snapshotTime": "2024-06-27T20:33:04Z"
              },
              "Id": "test5",
              "CA10__disappearanceTime__c": null,
              "CA10__rbacAuthorization__c": "Disabled",
              "CA10__Azure_Key_Vault_Keys__r": [
                  {
                      "Id": "test5_1",
                      "CA10__disappearanceTime__c": null,
                      "CA10__enabledStatus__c": "Disabled",
                      "CA10__expirationDate__c": "2024-06-27T20:33:04Z",
                      "CA10__keyVault__c": "test5"
                  }
              ]
          },
          {
              "expectedResult": {
                  "status": "UNDETERMINED",
                  "conditionIndex": "500",
                  "conditionText": "otherwise",
                  "runtimeError": null
              },
              "context": {
                  "snapshotTime": "2024-06-27T20:33:04Z"
              },
              "Id": "test6",
              "CA10__disappearanceTime__c": null,
              "CA10__rbacAuthorization__c": "Disabled",
              "CA10__Azure_Key_Vault_Keys__r": [
                  {
                      "Id": "test6_1",
                      "CA10__disappearanceTime__c": "2024-06-27T20:33:04Z",
                      "CA10__enabledStatus__c": "Enabled",
                      "CA10__expirationDate__c": "2024-06-27T20:33:04Z",
                      "CA10__keyVault__c": "test6"
                  }
              ]
          }
      ]
  - path: /types/CA10__CaAzureKeyVault__c/object.extracts.yaml
    md5Hash: 6C8158AF4E8A90E532020A68611A20C7
    content: "---\nextracts:\n# Values: Enabled, Disabled. Not Nullable. Can't have\
      \ no access, retrieved via Microsoft.KeyVault/vaults\n  - name: \"CA10__rbacAuthorization__c\"\
      \n    value: \n      FIELD:\n        path: \"CA10__rbacAuthorization__c\"\n\
      \        undeterminedIf:\n          isEmpty: \"Corrupted data. Key Vault RBAC\
      \ Authorization cannot be empty.\"\n# Values: Enabled, null. Nullable. Can't\
      \ have no access, retrieved via Microsoft.KeyVault/vaults\n  - name: \"CA10__purgeProtection__c\"\
      \n    value: \n      FIELD:\n        path: \"CA10__purgeProtection__c\"\n# Values:\
      \ Enabled, Disabled. Not Nullable. Can't have no access, retrieved via Microsoft.KeyVault/vaults\n\
      \  - name: \"CA10__softDelete__c\"\n    value: \n      FIELD:\n        path:\
      \ \"CA10__softDelete__c\"\n        undeterminedIf:\n          isEmpty: \"Corrupted\
      \ data. Soft Delete function cannot be empty.\"\n"
  - path: /types/CA10__CaAzureKeyVaultKey__c/object.extracts.yaml
    md5Hash: 06CA2E249D85942230AC96CBEE906A4E
    content: "---\nextracts:\n# Values: Enabled, Disabled. Not Nullable. Can't have\
      \ no access, retrieved via Microsoft.KeyVault/keys\n  - name: \"CA10__enabledStatus__c\"\
      \n    value: \n      FIELD:\n        path: \"CA10__enabledStatus__c\"\n    \
      \    undeterminedIf:\n          isEmpty: \"Corrupted data. Key State cannot\
      \ be empty.\"\n# Nullable. Can't have no access, retrieved via Microsoft.KeyVault/keys\n\
      \  - name: \"CA10__expirationDate__c\"\n    value: \n      FIELD:\n        path:\
      \ \"CA10__expirationDate__c\"\n# Nullable\n  - name: \"CA10__lifetimeActions__c\"\
      \n    value: \n      FIELD:\n        path: \"CA10__lifetimeActions__c\"\n  \
      \      # undeterminedIf:\n        #   noAccessDelegate:\n        #     path:\
      \ \"CA10__lifetimeActions__c\"\n        #     currentStateMessage: \"Unable\
      \ to determine Key Rotation Policy. Possible permission issue with keys/getrotationpolicy\""
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" : "INAPPLICABLE",
      "conditionIndex" : "199",
      "conditionText" : "extract('CA10__rbacAuthorization__c') == 'Enabled'",
      "runtimeError" : null
    }
  }, {
    "Id" : "test3",
    "expectedResult" : {
      "status" : "INCOMPLIANT",
      "conditionIndex" : "299",
      "conditionText" : "CA10__Azure_Key_Vault_Keys__r.has(INCOMPLIANT)",
      "runtimeError" : null
    }
  }, {
    "Id" : "test4",
    "expectedResult" : {
      "status" : "COMPLIANT",
      "conditionIndex" : "399",
      "conditionText" : "CA10__Azure_Key_Vault_Keys__r.has(COMPLIANT)",
      "runtimeError" : null
    }
  }, {
    "Id" : "test5",
    "expectedResult" : {
      "status" : "INAPPLICABLE",
      "conditionIndex" : "499",
      "conditionText" : "CA10__Azure_Key_Vault_Keys__r.has(INAPPLICABLE)",
      "runtimeError" : null
    }
  }, {
    "Id" : "test6",
    "expectedResult" : {
      "status" : "UNDETERMINED",
      "conditionIndex" : "500",
      "conditionText" : "otherwise",
      "runtimeError" : null
    }
  } ];
  """;

  CREATE TEMP FUNCTION mock_CA10__CaAzureKeyVault__c()
  RETURNS ARRAY<STRUCT<
      Id STRING,
      CA10__disappearanceTime__c TIMESTAMP,
      CA10__rbacAuthorization__c STRING,
      context STRUCT<
          snapshotTime TIMESTAMP
      >
  >>
  DETERMINISTIC
  LANGUAGE js
  AS r"""
    return [ {
    "context" : {
      "snapshotTime" : new Date("2024-06-27T20:33:04Z")
    },
    "Id" : "test1",
    "CA10__disappearanceTime__c" : new Date("2024-06-27T20:33:04Z"),
    "CA10__rbacAuthorization__c" : "Enabled"
  }, {
    "context" : {
      "snapshotTime" : new Date("2024-06-27T20:33:04Z")
    },
    "Id" : "test2",
    "CA10__rbacAuthorization__c" : "Enabled"
  }, {
    "context" : {
      "snapshotTime" : new Date("2024-06-27T20:33:04Z")
    },
    "Id" : "test3",
    "CA10__rbacAuthorization__c" : "Disabled"
  }, {
    "context" : {
      "snapshotTime" : new Date("2024-06-27T20:33:04Z")
    },
    "Id" : "test4",
    "CA10__rbacAuthorization__c" : "Disabled"
  }, {
    "context" : {
      "snapshotTime" : new Date("2024-06-27T20:33:04Z")
    },
    "Id" : "test5",
    "CA10__rbacAuthorization__c" : "Disabled"
  }, {
    "context" : {
      "snapshotTime" : new Date("2024-06-27T20:33:04Z")
    },
    "Id" : "test6",
    "CA10__rbacAuthorization__c" : "Disabled"
  } ];
  """;

  CREATE TEMP FUNCTION mock_CA10__CaAzureKeyVaultKey__c()
  RETURNS ARRAY<STRUCT<
      Id STRING,
      CA10__disappearanceTime__c TIMESTAMP,
      CA10__enabledStatus__c STRING,
      CA10__expirationDate__c TIMESTAMP,
      CA10__keyVault__c STRING,
      context STRUCT<
          snapshotTime TIMESTAMP
      >
  >>
  DETERMINISTIC
  LANGUAGE js
  AS r"""
    return [ {
    "context" : {
      "snapshotTime" : new Date("2024-06-27T20:33:04Z")
    },
    "Id" : "test3_1",
    "CA10__enabledStatus__c" : "Enabled",
    "CA10__keyVault__c" : "test3"
  }, {
    "context" : {
      "snapshotTime" : new Date("2024-06-27T20:33:04Z")
    },
    "Id" : "test4_1",
    "CA10__enabledStatus__c" : "Enabled",
    "CA10__expirationDate__c" : new Date("2024-06-27T20:33:04Z"),
    "CA10__keyVault__c" : "test4"
  }, {
    "context" : {
      "snapshotTime" : new Date("2024-06-27T20:33:04Z")
    },
    "Id" : "test5_1",
    "CA10__enabledStatus__c" : "Disabled",
    "CA10__expirationDate__c" : new Date("2024-06-27T20:33:04Z"),
    "CA10__keyVault__c" : "test5"
  }, {
    "context" : {
      "snapshotTime" : new Date("2024-06-27T20:33:04Z")
    },
    "Id" : "test6_1",
    "CA10__disappearanceTime__c" : new Date("2024-06-27T20:33:04Z"),
    "CA10__enabledStatus__c" : "Enabled",
    "CA10__expirationDate__c" : new Date("2024-06-27T20:33:04Z"),
    "CA10__keyVault__c" : "test6"
  } ];
  """;

  CREATE TEMP FUNCTION process_CA10__CaAzureKeyVault__c(
      obj STRUCT<
          Id STRING,
          CA10__disappearanceTime__c TIMESTAMP,
          CA10__rbacAuthorization__c STRING,
          CA10__Azure_Key_Vault_Keys__r ARRAY<STRUCT<
              Id STRING,
              CA10__disappearanceTime__c TIMESTAMP,
              CA10__enabledStatus__c STRING,
              CA10__expirationDate__c TIMESTAMP,
              CA10__keyVault__c STRING,
              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 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 [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};
      }
      // condition[1], conditionIndex:[100..199]
      function fieldChecked4() {
          if (TextLib.isEmpty(obj.CA10__rbacAuthorization__c)) {
              throw new Error("UNDETERMINED condition:101", {cause: {status: 'UNDETERMINED', conditionIndex: 101, conditionText: "CA10__rbacAuthorization__c.isEmpty()", currentStateMessage: "Corrupted data. Key Vault RBAC Authorization cannot be empty.", currentStateReferences: references1.join('\n'), remediation: null, runtimeError: null}});
          }
          return obj.CA10__rbacAuthorization__c;
      }
      function extract3() { if (!this.out) { this.out = fieldChecked4(); } return this.out; };
      references1.push('RBAC Authorization [obj.CA10__rbacAuthorization__c]: ' + obj.CA10__rbacAuthorization__c);
      try {
          if (TextLib.equal(extract3.call(extract3), 'Enabled')) {
              return {status: 'INAPPLICABLE', conditionIndex: 199, conditionText: "extract('CA10__rbacAuthorization__c') == 'Enabled'", currentStateMessage: "This is an RBAC Key Vault.", currentStateReferences: references1.join('\n'), remediation: null, runtimeError: null};
          }
      } catch (err) {
          if (err.cause && err.cause.status) { return err.cause; } else { throw err; }
      }
      var count_CA10__Azure_Key_Vault_Keys__r_INCOMPLIANT5 = 0;
      if (obj.CA10__Azure_Key_Vault_Keys__r != null) {
          for (var i6 = 0; i6 < obj.CA10__Azure_Key_Vault_Keys__r.length; i6++) {
              if (obj.CA10__Azure_Key_Vault_Keys__r[i6].result.status == 'INCOMPLIANT') {
                  count_CA10__Azure_Key_Vault_Keys__r_INCOMPLIANT5 += 1;
              }
          }
      }
      // condition[2], conditionIndex:[200..299]
      references1.push('Related list [CA10__Azure_Key_Vault_Keys__r] ' + (count_CA10__Azure_Key_Vault_Keys__r_INCOMPLIANT5 > 0 ? 'has' : 'does not have') + ' objects in INCOMPLIANT status');
      if (count_CA10__Azure_Key_Vault_Keys__r_INCOMPLIANT5 > 0) {
          return {status: 'INCOMPLIANT', conditionIndex: 299, conditionText: "CA10__Azure_Key_Vault_Keys__r.has(INCOMPLIANT)", currentStateMessage: "The Key Vault has Keys without expiration date.", currentStateReferences: references1.join('\n'), remediation: "Consider setting the Keys' expiration date.", runtimeError: null};
      }
      var count_CA10__Azure_Key_Vault_Keys__r_COMPLIANT7 = 0;
      if (obj.CA10__Azure_Key_Vault_Keys__r != null) {
          for (var i8 = 0; i8 < obj.CA10__Azure_Key_Vault_Keys__r.length; i8++) {
              if (obj.CA10__Azure_Key_Vault_Keys__r[i8].result.status == 'COMPLIANT') {
                  count_CA10__Azure_Key_Vault_Keys__r_COMPLIANT7 += 1;
              }
          }
      }
      // condition[3], conditionIndex:[300..399]
      if (count_CA10__Azure_Key_Vault_Keys__r_COMPLIANT7 > 0) {
          return {status: 'COMPLIANT', conditionIndex: 399, conditionText: "CA10__Azure_Key_Vault_Keys__r.has(COMPLIANT)", currentStateMessage: "The Key Vault Keys' expiration date is set for all enabled Keys.", currentStateReferences: references1.join('\n'), remediation: null, runtimeError: null};
      }
      var count_CA10__Azure_Key_Vault_Keys__r_INAPPLICABLE9 = 0;
      if (obj.CA10__Azure_Key_Vault_Keys__r != null) {
          for (var i10 = 0; i10 < obj.CA10__Azure_Key_Vault_Keys__r.length; i10++) {
              if (obj.CA10__Azure_Key_Vault_Keys__r[i10].result.status == 'INAPPLICABLE') {
                  count_CA10__Azure_Key_Vault_Keys__r_INAPPLICABLE9 += 1;
              }
          }
      }
      // condition[4], conditionIndex:[400..499]
      if (count_CA10__Azure_Key_Vault_Keys__r_INAPPLICABLE9 > 0) {
          return {status: 'INAPPLICABLE', conditionIndex: 499, conditionText: "CA10__Azure_Key_Vault_Keys__r.has(INAPPLICABLE)", currentStateMessage: "The Key Vault only has disabled Keys.", currentStateReferences: references1.join('\n'), remediation: null, runtimeError: null};
      }
      return {status: 'UNDETERMINED', conditionIndex: 500, conditionText: "otherwise", currentStateMessage: "The Key Vault doesn't have Keys or Cloudaware doesn't have access to view Keys.", currentStateReferences: references1.join('\n'), remediation: null, runtimeError: null};
  """;

  CREATE TEMP FUNCTION process_CA10__Azure_Key_Vault_Keys__r(
      obj STRUCT<
          Id STRING,
          CA10__disappearanceTime__c TIMESTAMP,
          CA10__enabledStatus__c STRING,
          CA10__expirationDate__c TIMESTAMP,
          CA10__keyVault__c 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 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 IsEmptyLib = new function () {
          this.simpleIsEmpty = function(arg) {
              return arg == null;
          };
          this.simpleIsNotEmpty = function(arg) {
              return arg != null;
          };
      }();
      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};
      }
      // condition[1], conditionIndex:[100..199]
      function fieldChecked4() {
          if (TextLib.isEmpty(obj.CA10__enabledStatus__c)) {
              throw new Error("UNDETERMINED condition:101", {cause: {status: 'UNDETERMINED', conditionIndex: 101, conditionText: "CA10__enabledStatus__c.isEmpty()", currentStateMessage: "Corrupted data. Key State cannot be empty.", currentStateReferences: references1.join('\n'), remediation: null, runtimeError: null}});
          }
          return obj.CA10__enabledStatus__c;
      }
      function extract3() { if (!this.out) { this.out = fieldChecked4(); } return this.out; };
      references1.push('Enabled Status [obj.CA10__enabledStatus__c]: ' + obj.CA10__enabledStatus__c);
      try {
          if (TextLib.notEqual(extract3.call(extract3), 'Enabled')) {
              return {status: 'INAPPLICABLE', conditionIndex: 199, conditionText: "extract('CA10__enabledStatus__c') != 'Enabled'", currentStateMessage: "The Key is disabled.", currentStateReferences: references1.join('\n'), remediation: null, runtimeError: null};
          }
      } catch (err) {
          if (err.cause && err.cause.status) { return err.cause; } else { throw err; }
      }
      // condition[2], conditionIndex:[200..299]
      function extract6() { if (!this.out) { this.out = obj.CA10__expirationDate__c; } return this.out; };
      references1.push('Expiration Date [obj.CA10__expirationDate__c]: ' + obj.CA10__expirationDate__c);
      if (IsEmptyLib.simpleIsEmpty(extract6.call(extract6))) {
          return {status: 'INCOMPLIANT', conditionIndex: 299, conditionText: "extract('CA10__expirationDate__c').isEmpty()", currentStateMessage: "The Key expiration date is not set.", currentStateReferences: references1.join('\n'), remediation: "Consider setting the Key expiration date.", runtimeError: null};
      }
      // condition[3], conditionIndex:[300..399]
      function extract9() { if (!this.out) { this.out = obj.CA10__expirationDate__c; } return this.out; };
      if (IsEmptyLib.simpleIsNotEmpty(extract9.call(extract9))) {
          return {status: 'COMPLIANT', conditionIndex: 399, conditionText: "extract('CA10__expirationDate__c').isNotEmpty()", currentStateMessage: "The Key expiration date is set.", currentStateReferences: references1.join('\n'), remediation: null, runtimeError: null};
      }
      return {status: 'UNDETERMINED', conditionIndex: 400, conditionText: "otherwise", currentStateMessage: "Unexpected values in the fields.", 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,
          sObject.CA10__rbacAuthorization__c AS CA10__rbacAuthorization__c,
          `CA10__Azure_Key_Vault_Keys__r`.arr AS CA10__Azure_Key_Vault_Keys__r,
          process_CA10__CaAzureKeyVault__c(
              STRUCT(
                  sObject.Id AS Id,
                  sObject.CA10__disappearanceTime__c AS CA10__disappearanceTime__c,
                  sObject.CA10__rbacAuthorization__c AS CA10__rbacAuthorization__c,
                  `CA10__Azure_Key_Vault_Keys__r`.arr AS CA10__Azure_Key_Vault_Keys__r
              ),
              sObject.context.snapshotTime
          ) as result
      FROM UNNEST(mock_CA10__CaAzureKeyVault__c()) AS sObject
      LEFT JOIN (
          SELECT
              sObject.CA10__keyVault__c,
              ARRAY_AGG(
                  STRUCT(
                      sObject.Id AS Id,
                      sObject.CA10__disappearanceTime__c AS CA10__disappearanceTime__c,
                      sObject.CA10__enabledStatus__c AS CA10__enabledStatus__c,
                      sObject.CA10__expirationDate__c AS CA10__expirationDate__c,
                      sObject.CA10__keyVault__c AS CA10__keyVault__c,
                      process_CA10__Azure_Key_Vault_Keys__r(
                          STRUCT(
                              sObject.Id AS Id,
                              sObject.CA10__disappearanceTime__c AS CA10__disappearanceTime__c,
                              sObject.CA10__enabledStatus__c AS CA10__enabledStatus__c,
                              sObject.CA10__expirationDate__c AS CA10__expirationDate__c,
                              sObject.CA10__keyVault__c AS CA10__keyVault__c
                          ),
                          sObject.context.snapshotTime
                      ) as result
                  )
              ) AS arr
          FROM UNNEST(mock_CA10__CaAzureKeyVaultKey__c()) AS sObject
          GROUP BY sObject.CA10__keyVault__c
      ) AS `CA10__Azure_Key_Vault_Keys__r`
          ON sObject.Id = `CA10__Azure_Key_Vault_Keys__r`.CA10__keyVault__c
  ) sObject ON sObject.Id = expectedResult.Id;
