---
policy: /ce/ca/aws/dynamodb/table-point-in-time-recovery
logic: /ce/ca/aws/dynamodb/table-point-in-time-recovery/prod.logic.yaml
executionTime: 2025-07-25T15:25:53.137831512Z
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: extract('CA10__pointInTimeRecoveryStatus__c') == 'DISABLED'
      actual: extract('CA10__pointInTimeRecoveryStatus__c') == 'DISABLED'
    runtimeError: {}
  - id: test3
    match: true
    status:
      expected: COMPLIANT
      actual: COMPLIANT
    conditionIndex:
      expected: 299
      actual: 299
    conditionText:
      expected: extract('CA10__pointInTimeRecoveryStatus__c') == 'ENABLED'
      actual: extract('CA10__pointInTimeRecoveryStatus__c') == 'ENABLED'
    runtimeError: {}
usedFiles:
  - path: /ce/ca/aws/dynamodb/table-point-in-time-recovery/policy.yaml
    md5Hash: 37EE543E11AF93BF0BD9570D3E3215CC
    content: "---\nnames:\n  full: AWS DynamoDB Table Point In Time Recovery is not\
      \ enabled\n  contextual: Table Point In Time Recovery is not enabled\ndescription:\
      \ >\n  Ensure that Point-in-Time Recovery (PITR) is enabled for your Amazon\
      \ DynamoDB \n  tables to protect against accidental writes or deletes. PITR\
      \ provides continuous \n  backups, allowing you to restore your table to any\
      \ point in time during \n  the last 35 days.\ntype: COMPLIANCE_POLICY\ncategories:\n\
      \  - SECURITY\nframeworkMappings:\n  - \"/frameworks/cloudaware/resource-security/data-protection-and-recovery\"\
      \n  - \"/frameworks/aws-fsbp-v1.0.0/dynamodb/02\"\nsimilarPolicies:\n  awsSecurityHub:\n\
      \    - name: \"[DynamoDB.2] DynamoDB tables should have point-in-time recovery\
      \ enabled\"\n      url: \"https://docs.aws.amazon.com/securityhub/latest/userguide/dynamodb-controls.html#dynamodb-2\"\
      \n  internal:\n    - \"dec-x-a822159a\""
  - path: /ce/ca/aws/dynamodb/table-point-in-time-recovery/prod.logic.yaml
    md5Hash: CA15A4AB11B9A5D93ED06C106CFDCAB8
    content: |-
      inputType: "CA10__CaAwsDynamoDbTable__c"
      testData:
        - file: "test-data.json"
      importExtracts:
        - file: /types/CA10__CaAwsDynamoDbTable__c/object.extracts.yaml
      conditions:
        - status: "INCOMPLIANT"
          currentStateMessage: "Point-in-Time Recovery is not enabled for this DynamoDB table."
          remediationMessage: "Consider enabling Point-in-Time Recovery for the DynamoDB table to allow for granular data restoration."
          check:
            IS_EQUAL:
              left:
                EXTRACT: "CA10__pointInTimeRecoveryStatus__c"
              right:
                TEXT: "DISABLED"
        - status: "COMPLIANT"
          currentStateMessage: "Point-in-Time Recovery is enabled for this DynamoDB table."
          check:
            IS_EQUAL:
              left:
                EXTRACT: "CA10__pointInTimeRecoveryStatus__c"
              right:
                TEXT: "ENABLED"
      otherwise:
        status: "UNDETERMINED"
        currentStateMessage: "Unexpected values in the field."
  - path: /types/CA10__CaAwsDynamoDbTable__c/object.extracts.yaml
    md5Hash: EB356A351A5AB0BB2575E0F65DA30F2E
    content: "---\nextracts:\n# Nullable, null is equal to PROVISIONED\n  - name:\
      \ \"CA10__billingMode__c\"\n    value:\n      FIELD:\n        path: CA10__billingMode__c\n\
      \        # undeterminedIf:\n        #   noAccessDelegate:\n        #     path:\
      \ \"CA10__billingMode__c\"\n        #     currentStateMessage: \"Unable to determine\
      \ Table Billing Mode. Possible permission issue with dynamodb:DescribeTable.\"\
      \n# Values: ENABLED | DISABLED. Not nullable. \n  - name: \"CA10__pointInTimeRecoveryStatus__c\"\
      \n    value:\n      FIELD:\n        path: CA10__pointInTimeRecoveryStatus__c\n\
      \        # undeterminedIf:\n        #   noAccessDelegate:\n        #     path:\
      \ \"CA10__pointInTimeRecoveryStatus__c\"\n        #     currentStateMessage:\
      \ \"Unable to determine Point In Time Recovery Status. Possible permission issue\
      \ with dynamodb:DescribeTable.\"\n"
  - path: /ce/ca/aws/dynamodb/table-point-in-time-recovery/test-data.json
    md5Hash: 230AD4833CEA3B1F5827C80B90EE809D
    content: |-
      [
          {
              "expectedResult": {
                  "status": "DISAPPEARED",
                  "conditionIndex": "99",
                  "conditionText": "isDisappeared(CA10__disappearanceTime__c)",
                  "runtimeError": null
              },
              "context": {
                  "snapshotTime": "2025-07-21T14:37:53Z"
              },
              "Id": "test1",
              "CA10__disappearanceTime__c": "2025-07-14T20:30:40Z",
              "CA10__pointInTimeRecoveryStatus__c": "ENABLED"
          },
          {
              "expectedResult": {
                  "status": "INCOMPLIANT",
                  "conditionIndex": "199",
                  "conditionText": "extract('CA10__pointInTimeRecoveryStatus__c') == 'DISABLED'",
                  "runtimeError": null
              },
              "context": {
                  "snapshotTime": "2025-07-21T14:37:53Z"
              },
              "Id": "test2",
              "CA10__disappearanceTime__c": null,
              "CA10__pointInTimeRecoveryStatus__c": "DISABLED"
          },
          {
              "expectedResult": {
                  "status": "COMPLIANT",
                  "conditionIndex": "299",
                  "conditionText": "extract('CA10__pointInTimeRecoveryStatus__c') == 'ENABLED'",
                  "runtimeError": null
              },
              "context": {
                  "snapshotTime": "2025-07-21T14:37:53Z"
              },
              "Id": "test3",
              "CA10__disappearanceTime__c": null,
              "CA10__pointInTimeRecoveryStatus__c": "ENABLED"
          }
      ]
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" : "extract('CA10__pointInTimeRecoveryStatus__c') == 'DISABLED'",
      "runtimeError" : null
    }
  }, {
    "Id" : "test3",
    "expectedResult" : {
      "status" : "COMPLIANT",
      "conditionIndex" : "299",
      "conditionText" : "extract('CA10__pointInTimeRecoveryStatus__c') == 'ENABLED'",
      "runtimeError" : null
    }
  } ];
  """;

  CREATE TEMP FUNCTION mock_CA10__CaAwsDynamoDbTable__c()
  RETURNS ARRAY<STRUCT<
      Id STRING,
      CA10__disappearanceTime__c TIMESTAMP,
      CA10__pointInTimeRecoveryStatus__c STRING,
      context STRUCT<
          snapshotTime TIMESTAMP
      >
  >>
  DETERMINISTIC
  LANGUAGE js
  AS r"""
    return [ {
    "context" : {
      "snapshotTime" : new Date("2025-07-21T14:37:53Z")
    },
    "Id" : "test1",
    "CA10__disappearanceTime__c" : new Date("2025-07-14T20:30:40Z"),
    "CA10__pointInTimeRecoveryStatus__c" : "ENABLED"
  }, {
    "context" : {
      "snapshotTime" : new Date("2025-07-21T14:37:53Z")
    },
    "Id" : "test2",
    "CA10__pointInTimeRecoveryStatus__c" : "DISABLED"
  }, {
    "context" : {
      "snapshotTime" : new Date("2025-07-21T14:37:53Z")
    },
    "Id" : "test3",
    "CA10__pointInTimeRecoveryStatus__c" : "ENABLED"
  } ];
  """;

  CREATE TEMP FUNCTION process_CA10__CaAwsDynamoDbTable__c(
      obj STRUCT<
          Id STRING,
          CA10__disappearanceTime__c TIMESTAMP,
          CA10__pointInTimeRecoveryStatus__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__pointInTimeRecoveryStatus__c; } return this.out; };
      references1.push('Point In Time Recovery Status [obj.CA10__pointInTimeRecoveryStatus__c]: ' + obj.CA10__pointInTimeRecoveryStatus__c);
      if (TextLib.equal(extract3.call(extract3), 'DISABLED')) {
          return {status: 'INCOMPLIANT', conditionIndex: 199, conditionText: "extract('CA10__pointInTimeRecoveryStatus__c') == 'DISABLED'", currentStateMessage: "Point-in-Time Recovery is not enabled for this DynamoDB table.", currentStateReferences: references1.join('\n'), remediation: "Consider enabling Point-in-Time Recovery for the DynamoDB table to allow for granular data restoration.", runtimeError: null};
      }
      // condition[2], conditionIndex:[200..299]
      function extract6() { if (!this.out) { this.out = obj.CA10__pointInTimeRecoveryStatus__c; } return this.out; };
      if (TextLib.equal(extract6.call(extract6), 'ENABLED')) {
          return {status: 'COMPLIANT', conditionIndex: 299, conditionText: "extract('CA10__pointInTimeRecoveryStatus__c') == 'ENABLED'", currentStateMessage: "Point-in-Time Recovery is enabled for this DynamoDB table.", currentStateReferences: references1.join('\n'), remediation: null, runtimeError: null};
      }
      return {status: 'UNDETERMINED', conditionIndex: 300, 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__pointInTimeRecoveryStatus__c AS CA10__pointInTimeRecoveryStatus__c,
          process_CA10__CaAwsDynamoDbTable__c(
              STRUCT(
                  sObject.Id AS Id,
                  sObject.CA10__disappearanceTime__c AS CA10__disappearanceTime__c,
                  sObject.CA10__pointInTimeRecoveryStatus__c AS CA10__pointInTimeRecoveryStatus__c
              ),
              sObject.context.snapshotTime
          ) as result
      FROM UNNEST(mock_CA10__CaAwsDynamoDbTable__c()) AS sObject
  ) sObject ON sObject.Id = expectedResult.Id;
