---
policy: /ce/ca/aws/inspector/lambda-standard-scanning
logic: /ce/ca/aws/inspector/lambda-standard-scanning/prod.logic.yaml
executionTime: 2025-12-27T12:02:04.399627602Z
generationMs: 47
executionMs: 594
rows:
  - id: test1
    match: true
    status:
      expected: INCOMPLIANT
      actual: INCOMPLIANT
    conditionIndex:
      expected: 299
      actual: 299
    conditionText:
      expected: extract('CA10__inspectorStatus__c') == 'Disabled'
      actual: extract('CA10__inspectorStatus__c') == 'Disabled'
    runtimeError: {}
  - id: test2
    match: true
    status:
      expected: INCOMPLIANT
      actual: INCOMPLIANT
    conditionIndex:
      expected: 499
      actual: 499
    conditionText:
      expected: extract('CA10__inspectorLambdaStatus__c') == 'Disabled'
      actual: extract('CA10__inspectorLambdaStatus__c') == 'Disabled'
    runtimeError: {}
  - id: test3
    match: true
    status:
      expected: COMPLIANT
      actual: COMPLIANT
    conditionIndex:
      expected: 599
      actual: 599
    conditionText:
      expected: extract('CA10__inspectorLambdaStatus__c') == 'Enabled'
      actual: extract('CA10__inspectorLambdaStatus__c') == 'Enabled'
    runtimeError: {}
usedFiles:
  - path: /ce/ca/aws/inspector/lambda-standard-scanning/policy.yaml
    md5Hash: DB42108D8294FA866732C8F9F5D1EDF9
    content: "---\nnames:\n  full: \"AWS Inspector Lambda Standard Scanning is not\
      \ enabled\"\n  contextual: \"Inspector Lambda Standard Scanning is not enabled\"\
      \ndescription: >\n  Amazon Inspector provides standard scanning for AWS Lambda\
      \ functions, which \n  automatically detects software vulnerabilities in your\
      \ function's package dependencies. \n  Enabling this ensures that your serverless\
      \ applications are continuously monitored \n  for known CVEs in their libraries\
      \ and layers.\ntype: \"COMPLIANCE_POLICY\"\ncategories:\n  - \"SECURITY\"\n\
      frameworkMappings:\n  - \"/frameworks/aws-fsbp-v1.0.0/inspector/04\"\n  - \"\
      /frameworks/cloudaware/resource-security/threat-protection\"\nsimilarPolicies:\n\
      \  awsSecurityHub:\n    - name: \"[Inspector.4] Amazon Inspector Lambda standard\
      \ scanning should be enabled\"\n      url: \"https://docs.aws.amazon.com/securityhub/latest/userguide/inspector-controls.html#inspector-4\""
  - path: /ce/ca/aws/inspector/lambda-standard-scanning/prod.logic.yaml
    md5Hash: B439C0E892CED35B7EF5B5B129455E3D
    content: |
      ---
      inputType: "CA10__CaAwsAccount__c"
      importExtracts:
        - file: "/types/CA10__CaAwsAccount__c/object.extracts.yaml"
      testData:
        - file: test-data.json
      conditions:
        - status: "UNDETERMINED"
          currentStateMessage: "Amazon Inspector status is not available."
          check:
            IS_EMPTY:
              arg:
                EXTRACT: "CA10__inspectorStatus__c"
        - status: "INCOMPLIANT"
          currentStateMessage: "Amazon Inspector is not enabled for this account."
          remediationMessage: "Enable Amazon Inspector in the AWS console."
          check:
            IS_EQUAL:
              left:
                EXTRACT: "CA10__inspectorStatus__c"
              right:
                TEXT: "Disabled"
        - status: "UNDETERMINED"
          currentStateMessage: "Amazon Inspector Lambda Standard scanning status is not available."
          check:
            IS_EMPTY:
              arg:
                EXTRACT: "CA10__inspectorLambdaStatus__c"
        - status: "INCOMPLIANT"
          currentStateMessage: "Amazon Inspector Lambda Standard scanning is disabled."
          check:
            IS_EQUAL:
              left:
                EXTRACT: "CA10__inspectorLambdaStatus__c"
              right:
                TEXT: "Disabled"
        - status: "COMPLIANT"
          currentStateMessage: "Amazon Inspector Lambda Standard scanning is enabled."
          check:
            IS_EQUAL:
              left:
                EXTRACT: "CA10__inspectorLambdaStatus__c"
              right:
                TEXT: "Enabled"
      otherwise:
        status: "UNDETERMINED"
        currentStateMessage: "Unexpected values in the fields."
  - path: /ce/ca/aws/inspector/lambda-standard-scanning/test-data.json
    md5Hash: AE5EB38ED21B8D347D77363DA08844A8
    content: |-
      [
          {
              "expectedResult": {
                  "runtimeError": null,
                  "conditionText": "extract('CA10__inspectorStatus__c') == 'Disabled'",
                  "conditionIndex": 299,
                  "status": "INCOMPLIANT"
              },
              "context": {
                  "snapshotTime": "2025-12-24T00:33:47Z"
              },
              "CA10__inspectorLambdaStatus__c": "Disabled",
              "CA10__inspectorStatus__c": "Disabled",
              "Id": "test1"
          },
          {
              "expectedResult": {
                  "runtimeError": null,
                  "conditionText": "extract('CA10__inspectorLambdaStatus__c') == 'Disabled'",
                  "conditionIndex": 499,
                  "status": "INCOMPLIANT"
              },
              "context": {
                  "snapshotTime": "2025-12-24T00:33:47Z"
              },
              "CA10__inspectorLambdaStatus__c": "Disabled",
              "CA10__inspectorStatus__c": "Enabled",
              "Id": "test2"
          },
          {
              "expectedResult": {
                  "runtimeError": null,
                  "conditionText": "extract('CA10__inspectorLambdaStatus__c') == 'Enabled'",
                  "conditionIndex": 599,
                  "status": "COMPLIANT"
              },
              "context": {
                  "snapshotTime": "2025-12-24T00:33:47Z"
              },
              "CA10__inspectorLambdaStatus__c": "Enabled",
              "CA10__inspectorStatus__c": "Enabled",
              "Id": "test3"
          }
      ]
  - path: /types/CA10__CaAwsAccount__c/object.extracts.yaml
    md5Hash: 926999C100E8C1066EC8BD4B82B0F362
    content: "---\nextracts:\n  - name: CA10__accountId__c\n    value: \n      FIELD:\n\
      \        path: CA10__accountId__c\n        undeterminedIf:\n          isEmpty:\
      \ \"Account ID can not be empty. Possibly corrupted data.\"\n# Not nullable\n\
      \  - name: \"CA10__shieldAdvancedState__c\"\n    value: \n      FIELD:\n   \
      \     path: \"CA10__shieldAdvancedState__c\"\n        undeterminedIf:\n    \
      \      noAccessDelegate:\n            path: \"CA10__shieldAdvancedState__c\"\
      \n            currentStateMessage: \"Shield Advanced subscription state cannot\
      \ be empty. Possible permission issue with shield:GetSubscriptionState\"\n#\
      \ Not nullable\n  - name: \"CA10__shieldAdvancedSrtSupportConfigured__c\"\n\
      \    value: \n      FIELD:\n        path: \"CA10__shieldAdvancedSrtSupportConfigured__c\"\
      \n        undeterminedIf:\n          noAccessDelegate:\n            path: \"\
      CA10__shieldAdvancedSrtSupportConfigured__c\"\n            currentStateMessage:\
      \ \"Shield Advanced SRT Access state cannot be empty. Possible permission issue\
      \ with shield:DescribeDRTAccess\"\n# Not nullable\n  - name: \"CA10__status__c\"\
      \n    value: \n      FIELD:\n        path: \"CA10__status__c\"\n  - name: \"\
      CA10__inspectorStatus__c\"\n    value: \n      FIELD:\n        path: \"CA10__inspectorStatus__c\"\
      \n  - name: \"CA10__inspectorEc2Status__c\"\n    value: \n      FIELD:\n   \
      \     path: \"CA10__inspectorEc2Status__c\"\n  - name: \"CA10__inspectorEcrStatus__c\"\
      \n    value: \n      FIELD:\n        path: \"CA10__inspectorEcrStatus__c\"\n\
      \  - name: \"CA10__inspectorLambdaCodeStatus__c\"\n    value: \n      FIELD:\n\
      \        path: \"CA10__inspectorLambdaCodeStatus__c\"\n  - name: \"CA10__inspectorLambdaStatus__c\"\
      \n    value: \n      FIELD:\n        path: \"CA10__inspectorLambdaStatus__c\"\
      \n"
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" : {
      "runtimeError" : null,
      "conditionText" : "extract('CA10__inspectorStatus__c') == 'Disabled'",
      "conditionIndex" : 299,
      "status" : "INCOMPLIANT"
    }
  }, {
    "Id" : "test2",
    "expectedResult" : {
      "runtimeError" : null,
      "conditionText" : "extract('CA10__inspectorLambdaStatus__c') == 'Disabled'",
      "conditionIndex" : 499,
      "status" : "INCOMPLIANT"
    }
  }, {
    "Id" : "test3",
    "expectedResult" : {
      "runtimeError" : null,
      "conditionText" : "extract('CA10__inspectorLambdaStatus__c') == 'Enabled'",
      "conditionIndex" : 599,
      "status" : "COMPLIANT"
    }
  } ];
  """;

  CREATE TEMP FUNCTION mock_CA10__CaAwsAccount__c()
  RETURNS ARRAY<STRUCT<
      CA10__inspectorStatus__c STRING,
      CA10__inspectorLambdaStatus__c STRING,
      Id STRING,
      context STRUCT<
          snapshotTime TIMESTAMP
      >
  >>
  DETERMINISTIC
  LANGUAGE js
  AS r"""
    return [ {
    "context" : {
      "snapshotTime" : new Date("2025-12-24T00:33:47Z")
    },
    "CA10__inspectorStatus__c" : "Disabled",
    "CA10__inspectorLambdaStatus__c" : "Disabled",
    "Id" : "test1"
  }, {
    "context" : {
      "snapshotTime" : new Date("2025-12-24T00:33:47Z")
    },
    "CA10__inspectorStatus__c" : "Enabled",
    "CA10__inspectorLambdaStatus__c" : "Disabled",
    "Id" : "test2"
  }, {
    "context" : {
      "snapshotTime" : new Date("2025-12-24T00:33:47Z")
    },
    "CA10__inspectorStatus__c" : "Enabled",
    "CA10__inspectorLambdaStatus__c" : "Enabled",
    "Id" : "test3"
  } ];
  """;

  CREATE TEMP FUNCTION process_CA10__CaAwsAccount__c(
      obj STRUCT<
          CA10__inspectorStatus__c STRING,
          CA10__inspectorLambdaStatus__c STRING,
          Id 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]
      if (false) {
          return {status: 'DISAPPEARED', conditionIndex: 99, conditionText: "isDisappeared()", 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__inspectorStatus__c; } return this.out; };
      references1.push('Inspector: Status [obj.CA10__inspectorStatus__c]: ' + obj.CA10__inspectorStatus__c);
      if (TextLib.isEmpty(extract3.call(extract3))) {
          return {status: 'UNDETERMINED', conditionIndex: 199, conditionText: "extract('CA10__inspectorStatus__c').isEmpty()", currentStateMessage: "Amazon Inspector status is not available.", currentStateReferences: references1.join('\n'), remediation: null, runtimeError: null};
      }
      // condition[2], conditionIndex:[200..299]
      function extract6() { if (!this.out) { this.out = obj.CA10__inspectorStatus__c; } return this.out; };
      if (TextLib.equal(extract6.call(extract6), 'Disabled')) {
          return {status: 'INCOMPLIANT', conditionIndex: 299, conditionText: "extract('CA10__inspectorStatus__c') == 'Disabled'", currentStateMessage: "Amazon Inspector is not enabled for this account.", currentStateReferences: references1.join('\n'), remediation: "Enable Amazon Inspector in the AWS console.", runtimeError: null};
      }
      // condition[3], conditionIndex:[300..399]
      function extract9() { if (!this.out) { this.out = obj.CA10__inspectorLambdaStatus__c; } return this.out; };
      references1.push('Inspector: Lambda Status [obj.CA10__inspectorLambdaStatus__c]: ' + obj.CA10__inspectorLambdaStatus__c);
      if (TextLib.isEmpty(extract9.call(extract9))) {
          return {status: 'UNDETERMINED', conditionIndex: 399, conditionText: "extract('CA10__inspectorLambdaStatus__c').isEmpty()", currentStateMessage: "Amazon Inspector Lambda Standard scanning status is not available.", currentStateReferences: references1.join('\n'), remediation: null, runtimeError: null};
      }
      // condition[4], conditionIndex:[400..499]
      function extract12() { if (!this.out) { this.out = obj.CA10__inspectorLambdaStatus__c; } return this.out; };
      if (TextLib.equal(extract12.call(extract12), 'Disabled')) {
          return {status: 'INCOMPLIANT', conditionIndex: 499, conditionText: "extract('CA10__inspectorLambdaStatus__c') == 'Disabled'", currentStateMessage: "Amazon Inspector Lambda Standard scanning is disabled.", currentStateReferences: references1.join('\n'), remediation: null, runtimeError: null};
      }
      // condition[5], conditionIndex:[500..599]
      function extract15() { if (!this.out) { this.out = obj.CA10__inspectorLambdaStatus__c; } return this.out; };
      if (TextLib.equal(extract15.call(extract15), 'Enabled')) {
          return {status: 'COMPLIANT', conditionIndex: 599, conditionText: "extract('CA10__inspectorLambdaStatus__c') == 'Enabled'", currentStateMessage: "Amazon Inspector Lambda Standard scanning is enabled.", currentStateReferences: references1.join('\n'), remediation: null, runtimeError: null};
      }
      return {status: 'UNDETERMINED', conditionIndex: 600, 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.CA10__inspectorStatus__c AS CA10__inspectorStatus__c,
          sObject.CA10__inspectorLambdaStatus__c AS CA10__inspectorLambdaStatus__c,
          sObject.Id AS Id,
          process_CA10__CaAwsAccount__c(
              STRUCT(
                  sObject.CA10__inspectorStatus__c AS CA10__inspectorStatus__c,
                  sObject.CA10__inspectorLambdaStatus__c AS CA10__inspectorLambdaStatus__c,
                  sObject.Id AS Id
              ),
              sObject.context.snapshotTime
          ) as result
      FROM UNNEST(mock_CA10__CaAwsAccount__c()) AS sObject
  ) sObject ON sObject.Id = expectedResult.Id;
