---
policy: /ce/ca/aws/dax/cluster-server-side-encryption
logic: /ce/ca/aws/dax/cluster-server-side-encryption/prod.logic.yaml
executionTime: 2025-07-25T15:25:46.303026594Z
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__nodeType__c').startsWith('dax.r3.')
      actual: extract('CA10__nodeType__c').startsWith('dax.r3.')
    runtimeError: {}
  - id: test3
    match: true
    status:
      expected: INCOMPLIANT
      actual: INCOMPLIANT
    conditionIndex:
      expected: 299
      actual: 299
    conditionText:
      expected: extract('CA10__serverSideEncryptionStatus__c') == 'DISABLED'
      actual: extract('CA10__serverSideEncryptionStatus__c') == 'DISABLED'
    runtimeError: {}
  - id: test4
    match: true
    status:
      expected: COMPLIANT
      actual: COMPLIANT
    conditionIndex:
      expected: 399
      actual: 399
    conditionText:
      expected: extract('CA10__serverSideEncryptionStatus__c') == 'ENABLED'
      actual: extract('CA10__serverSideEncryptionStatus__c') == 'ENABLED'
    runtimeError: {}
usedFiles:
  - path: /ce/ca/aws/dax/cluster-server-side-encryption/policy.yaml
    md5Hash: 9C6801195283BA9CEA2B8DF2B529D459
    content: "---\nnames:\n  full: AWS DAX Cluster Server-Side Encryption is not enabled\n\
      \  contextual: Cluster Server-Side Encryption is not enabled\ndescription: >\n\
      \  Ensure that DynamoDB Accelerator (DAX) clusters are encrypted at rest to\
      \ protect \n  sensitive data from unauthorized access to the underlying storage.\n\
      type: COMPLIANCE_POLICY\ncategories:\n  - SECURITY\nframeworkMappings:\n  -\
      \ \"/frameworks/cloudaware/resource-security/data-encryption\"\n  - \"/frameworks/aws-fsbp-v1.0.0/dynamodb/03\"\
      \nsimilarPolicies:\n  awsSecurityHub:\n    - name: \"[DynamoDB.3] DynamoDB Accelerator\
      \ (DAX) clusters should be encrypted at rest\"\n      url: \"https://docs.aws.amazon.com/securityhub/latest/userguide/dynamodb-controls.html#dynamodb-3\"\
      \n  internal:\n    - \"dec-x-e9e99704\""
  - path: /ce/ca/aws/dax/cluster-server-side-encryption/prod.logic.yaml
    md5Hash: C8AC8BDF75067B542BAB43DBA40063E4
    content: |-
      inputType: "CA10__CaAwsDaxCluster__c"
      testData:
       - file: test-data.json
      importExtracts:
       - file: /types/CA10__CaAwsDaxCluster__c/object.extracts.yaml
      conditions:
        - status: "INAPPLICABLE"
          currentStateMessage: "DAX encryption at rest is not supported for dax.r3.* node types."
          check:
            STARTS_WITH:
              arg:
                EXTRACT: "CA10__nodeType__c"
              search:
                TEXT: "dax.r3."
        - status: "INCOMPLIANT"
          currentStateMessage: "The DAX Cluster is not encrypted at rest."
          remediationMessage: "Consider enabling server-side encryption for the DAX cluster."
          check:
            IS_EQUAL:
              left:
                EXTRACT: "CA10__serverSideEncryptionStatus__c"
              right:
                TEXT: "DISABLED"
        - status: "COMPLIANT"
          currentStateMessage: "The DAX Cluster is encrypted at rest."
          check:
            IS_EQUAL:
              left:
                EXTRACT: "CA10__serverSideEncryptionStatus__c"
              right:
                TEXT: "ENABLED"
      otherwise:
        status: "UNDETERMINED"
        currentStateMessage: "Unexpected values in the field."
  - path: /ce/ca/aws/dax/cluster-server-side-encryption/test-data.json
    md5Hash: 58E483E857062BD0B87C92402E1C28C1
    content: |-
      [
          {
              "expectedResult": {
                  "status": "DISAPPEARED",
                  "conditionIndex": "99",
                  "conditionText": "isDisappeared(CA10__disappearanceTime__c)",
                  "runtimeError": null
              },
              "context": {
                  "snapshotTime": "2025-07-21T14:26:56Z"
              },
              "Id": "test1",
              "CA10__disappearanceTime__c": "2025-07-21T14:26:56Z",
              "CA10__nodeType__c": "dax.r5.large",
              "CA10__serverSideEncryptionStatus__c": "DISABLED"
          },
          {
              "expectedResult": {
                  "status": "INAPPLICABLE",
                  "conditionIndex": "199",
                  "conditionText": "extract('CA10__nodeType__c').startsWith('dax.r3.')",
                  "runtimeError": null
              },
              "context": {
                  "snapshotTime": "2025-07-21T14:26:56Z"
              },
              "Id": "test2",
              "CA10__disappearanceTime__c": null,
              "CA10__nodeType__c": "dax.r3.large",
              "CA10__serverSideEncryptionStatus__c": "DISABLED"
          },
          {
              "expectedResult": {
                  "status": "INCOMPLIANT",
                  "conditionIndex": "299",
                  "conditionText": "extract('CA10__serverSideEncryptionStatus__c') == 'DISABLED'",
                  "runtimeError": null
              },
              "context": {
                  "snapshotTime": "2025-07-21T14:26:56Z"
              },
              "Id": "test3",
              "CA10__disappearanceTime__c": null,
              "CA10__nodeType__c": "dax.r5.large",
              "CA10__serverSideEncryptionStatus__c": "DISABLED"
          },
          {
              "expectedResult": {
                  "status": "COMPLIANT",
                  "conditionIndex": "399",
                  "conditionText": "extract('CA10__serverSideEncryptionStatus__c') == 'ENABLED'",
                  "runtimeError": null
              },
              "context": {
                  "snapshotTime": "2025-07-21T14:26:56Z"
              },
              "Id": "test4",
              "CA10__disappearanceTime__c": null,
              "CA10__nodeType__c": "dax.r5.large",
              "CA10__serverSideEncryptionStatus__c": "ENABLED"
          }
      ]
  - path: /types/CA10__CaAwsDaxCluster__c/object.extracts.yaml
    md5Hash: A1663363B6ECA8EE36DDCBD85AFE8300
    content: |
      ---
      extracts:
      # Not nullable. Can't have no access, retrieved via dax:DescribeClusters
        - name: "CA10__nodeType__c"
          value:
            FIELD:
              path: CA10__nodeType__c
      # Values: ENABLED | DISABLED. Not nullable. Can't have no access, retrieved via dax:DescribeClusters
        - name: "CA10__serverSideEncryptionStatus__c"
          value:
            FIELD:
              path: CA10__serverSideEncryptionStatus__c
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__nodeType__c').startsWith('dax.r3.')",
      "runtimeError" : null
    }
  }, {
    "Id" : "test3",
    "expectedResult" : {
      "status" : "INCOMPLIANT",
      "conditionIndex" : "299",
      "conditionText" : "extract('CA10__serverSideEncryptionStatus__c') == 'DISABLED'",
      "runtimeError" : null
    }
  }, {
    "Id" : "test4",
    "expectedResult" : {
      "status" : "COMPLIANT",
      "conditionIndex" : "399",
      "conditionText" : "extract('CA10__serverSideEncryptionStatus__c') == 'ENABLED'",
      "runtimeError" : null
    }
  } ];
  """;

  CREATE TEMP FUNCTION mock_CA10__CaAwsDaxCluster__c()
  RETURNS ARRAY<STRUCT<
      Id STRING,
      CA10__disappearanceTime__c TIMESTAMP,
      CA10__nodeType__c STRING,
      CA10__serverSideEncryptionStatus__c STRING,
      context STRUCT<
          snapshotTime TIMESTAMP
      >
  >>
  DETERMINISTIC
  LANGUAGE js
  AS r"""
    return [ {
    "context" : {
      "snapshotTime" : new Date("2025-07-21T14:26:56Z")
    },
    "Id" : "test1",
    "CA10__disappearanceTime__c" : new Date("2025-07-21T14:26:56Z"),
    "CA10__nodeType__c" : "dax.r5.large",
    "CA10__serverSideEncryptionStatus__c" : "DISABLED"
  }, {
    "context" : {
      "snapshotTime" : new Date("2025-07-21T14:26:56Z")
    },
    "Id" : "test2",
    "CA10__nodeType__c" : "dax.r3.large",
    "CA10__serverSideEncryptionStatus__c" : "DISABLED"
  }, {
    "context" : {
      "snapshotTime" : new Date("2025-07-21T14:26:56Z")
    },
    "Id" : "test3",
    "CA10__nodeType__c" : "dax.r5.large",
    "CA10__serverSideEncryptionStatus__c" : "DISABLED"
  }, {
    "context" : {
      "snapshotTime" : new Date("2025-07-21T14:26:56Z")
    },
    "Id" : "test4",
    "CA10__nodeType__c" : "dax.r5.large",
    "CA10__serverSideEncryptionStatus__c" : "ENABLED"
  } ];
  """;

  CREATE TEMP FUNCTION process_CA10__CaAwsDaxCluster__c(
      obj STRUCT<
          Id STRING,
          CA10__disappearanceTime__c TIMESTAMP,
          CA10__nodeType__c STRING,
          CA10__serverSideEncryptionStatus__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));
          };
          this.containsAll = function(arg, substrings) {
              if (substrings == null || substrings.length === 0) return false;
              let normalizedArg = this.normalize(arg);
              return substrings.every(sub => normalizedArg.includes(this.normalize(sub)));
          };
          this.containsAny = function(arg, substrings) {
              if (substrings == null || substrings.length === 0) return false;
              let normalizedArg = this.normalize(arg);
              return substrings.some(sub => normalizedArg.includes(this.normalize(sub)));
          };
      }();
      var references1 = [];
      // condition[0], conditionIndex:[0..99]
      references1.push('Deleted From AWS [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 extract3() { if (!this.out) { this.out = obj.CA10__nodeType__c; } return this.out; };
      references1.push('Node Type [obj.CA10__nodeType__c]: ' + obj.CA10__nodeType__c);
      if (TextLib.startsWith(extract3.call(extract3), 'dax.r3.')) {
          return {status: 'INAPPLICABLE', conditionIndex: 199, conditionText: "extract('CA10__nodeType__c').startsWith('dax.r3.')", currentStateMessage: "DAX encryption at rest is not supported for dax.r3.* node types.", currentStateReferences: references1.join('\n'), remediation: null, runtimeError: null};
      }
      // condition[2], conditionIndex:[200..299]
      function extract6() { if (!this.out) { this.out = obj.CA10__serverSideEncryptionStatus__c; } return this.out; };
      references1.push('Server-Side Encryption Status [obj.CA10__serverSideEncryptionStatus__c]: ' + obj.CA10__serverSideEncryptionStatus__c);
      if (TextLib.equal(extract6.call(extract6), 'DISABLED')) {
          return {status: 'INCOMPLIANT', conditionIndex: 299, conditionText: "extract('CA10__serverSideEncryptionStatus__c') == 'DISABLED'", currentStateMessage: "The DAX Cluster is not encrypted at rest.", currentStateReferences: references1.join('\n'), remediation: "Consider enabling server-side encryption for the DAX cluster.", runtimeError: null};
      }
      // condition[3], conditionIndex:[300..399]
      function extract9() { if (!this.out) { this.out = obj.CA10__serverSideEncryptionStatus__c; } return this.out; };
      if (TextLib.equal(extract9.call(extract9), 'ENABLED')) {
          return {status: 'COMPLIANT', conditionIndex: 399, conditionText: "extract('CA10__serverSideEncryptionStatus__c') == 'ENABLED'", currentStateMessage: "The DAX Cluster is encrypted at rest.", currentStateReferences: references1.join('\n'), remediation: null, runtimeError: null};
      }
      return {status: 'UNDETERMINED', conditionIndex: 400, conditionText: "otherwise", currentStateMessage: "Unexpected values 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,
          sObject.CA10__nodeType__c AS CA10__nodeType__c,
          sObject.CA10__serverSideEncryptionStatus__c AS CA10__serverSideEncryptionStatus__c,
          process_CA10__CaAwsDaxCluster__c(
              STRUCT(
                  sObject.Id AS Id,
                  sObject.CA10__disappearanceTime__c AS CA10__disappearanceTime__c,
                  sObject.CA10__nodeType__c AS CA10__nodeType__c,
                  sObject.CA10__serverSideEncryptionStatus__c AS CA10__serverSideEncryptionStatus__c
              ),
              sObject.context.snapshotTime
          ) as result
      FROM UNNEST(mock_CA10__CaAwsDaxCluster__c()) AS sObject
  ) sObject ON sObject.Id = expectedResult.Id;
