---
policy: /ce/ca/google/api/cloud-asset-inventory
logic: /ce/ca/google/api/cloud-asset-inventory/prod.logic.yaml
executionTime: 2025-04-24T23:46:45.756622198Z
rows:
  - id: a4p11
    match: true
    status:
      expected: COMPLIANT
      actual: COMPLIANT
    conditionIndex:
      expected: 199
      actual: 199
    conditionText:
      expected: extract('CA10__enabledServices__c').contains('cloudasset.googleapis.com')
      actual: extract('CA10__enabledServices__c').contains('cloudasset.googleapis.com')
    runtimeError: {}
  - id: a4p22
    match: true
    status:
      expected: INCOMPLIANT
      actual: INCOMPLIANT
    conditionIndex:
      expected: 200
      actual: 200
    conditionText:
      expected: otherwise
      actual: otherwise
    runtimeError: {}
usedFiles:
  - path: /ce/ca/google/api/cloud-asset-inventory/policy.yaml
    md5Hash: A717F562FFFA7B9291C9AD859CEBF9B5
    content: "---\nnames: \n  full: \"Google Cloud Asset Inventory API is not enabled\"\
      \n  contextual: \"Asset Inventory API is not enabled\"\ndescription: \"GCP Cloud\
      \ Asset Inventory is services that provides a historical view of GCP resources\
      \ \\\n and IAM policies through a time-series database. The information recorded\
      \ includes metadata on \\\n Google Cloud resources, metadata on policies set\
      \ on Google Cloud projects or resources, and runtime \\\n information gathered\
      \ within a Google Cloud resource. \n Cloud Asset Inventory Service (CAIS) API\
      \ enablement is not required for operation of the service, but \\ \n rather\
      \ enables the mechanism for searching/exporting CAIS asset data directly.\"\n\
      type: COMPLIANCE_POLICY\ncategories:\n  - \"RELIABILITY\"\nframeworkMappings:\n\
      \  - /frameworks/cis-gcp-v3.0.0/02/13\n  - /frameworks/cloudaware/resource-reliability/system-configuration\n\
      similarPolicies:\n  cloudConformity:\n    - url: \"https://www.trendmicro.com/cloudoneconformity-staging/knowledge-base/gcp/CloudAPI/enabled-cloud-asset-inventory.html\"\
      \n      name: \"Enable Cloud Asset Inventory\"\n"
  - path: /ce/ca/google/api/cloud-asset-inventory/prod.logic.yaml
    md5Hash: 1C6DB28C532A9749F082262AB2B92276
    content: |
      ---

      inputType: "CA10__CaGoogleProject__c"
      testData:
        - file: test-data.json
      importExtracts:
        - file: /types/CA10__CaGoogleProject__c/object.extracts.yaml
      conditions:
        - status: "COMPLIANT"
          currentStateMessage: "Cloud Asset Inventory is enabled "
          check:
            CONTAINS:
              arg:
                EXTRACT: "CA10__enabledServices__c"
              substring:
                TEXT: 'cloudasset.googleapis.com'
      otherwise:
        status: "INCOMPLIANT"
        currentStateMessage: "Cloud Asset Inventory is not enabled"
  - path: /types/CA10__CaGoogleProject__c/object.extracts.yaml
    md5Hash: 8EB422663BF4493D44ABA5FEC0FB9AD4
    content: "---\nextracts:\n  - name: \"CA10__projectId__c\"\n    value: \n    \
      \   FIELD:\n         path: \"CA10__projectId__c\"\n         undeterminedIf:\n\
      \          isEmpty: \"Corrupted data. Project ID cannot be empty.\"\n  - name:\
      \ \"CA10__enabledServices__c\"\n    value: \n      FIELD:\n        path: \"\
      CA10__enabledServices__c\""
  - path: /ce/ca/google/api/cloud-asset-inventory/test-data.json
    md5Hash: 92671E999DC0979A8FC2659A012ADEF2
    content: |
      [
        {
          "expectedResult": {
            "status": "COMPLIANT",
            "conditionIndex": "199",
            "conditionText": "extract('CA10__enabledServices__c').contains('cloudasset.googleapis.com')",
            "runtimeError": null
          },
          "context": { "snapshotTime": "2024-09-17T18:22:07Z" },
          "Id": "a4p11",
          "CA10__enabledServices__c": "bigquery.googleapis.com\ncloudasset.googleapis.com\ncloudapis.googleapis.com"
        },
        {
          "expectedResult": {
            "status": "INCOMPLIANT",
            "conditionIndex": "200",
            "conditionText": "otherwise",
            "runtimeError": null
          },
          "context": { "snapshotTime": "2024-09-17T18:22:07Z" },
          "Id": "a4p22",
          "CA10__enabledServices__c": "bigquery.googleapis.com\ncloudapis.googleapis.com"
        }
      ]
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" : "a4p11",
    "expectedResult" : {
      "status" : "COMPLIANT",
      "conditionIndex" : "199",
      "conditionText" : "extract('CA10__enabledServices__c').contains('cloudasset.googleapis.com')",
      "runtimeError" : null
    }
  }, {
    "Id" : "a4p22",
    "expectedResult" : {
      "status" : "INCOMPLIANT",
      "conditionIndex" : "200",
      "conditionText" : "otherwise",
      "runtimeError" : null
    }
  } ];
  """;

  CREATE TEMP FUNCTION mock_CA10__CaGoogleProject__c()
  RETURNS ARRAY<STRUCT<
      Id STRING,
      CA10__enabledServices__c STRING,
      context STRUCT<
          snapshotTime TIMESTAMP
      >
  >>
  DETERMINISTIC
  LANGUAGE js
  AS r"""
    return [ {
    "context" : {
      "snapshotTime" : new Date("2024-09-17T18:22:07Z")
    },
    "Id" : "a4p11",
    "CA10__enabledServices__c" : "bigquery.googleapis.com\ncloudasset.googleapis.com\ncloudapis.googleapis.com"
  }, {
    "context" : {
      "snapshotTime" : new Date("2024-09-17T18:22:07Z")
    },
    "Id" : "a4p22",
    "CA10__enabledServices__c" : "bigquery.googleapis.com\ncloudapis.googleapis.com"
  } ];
  """;

  CREATE TEMP FUNCTION process_CA10__CaGoogleProject__c(
      obj STRUCT<
          Id STRING,
          CA10__enabledServices__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 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__enabledServices__c; } return this.out; };
      references1.push('Enabled Services [obj.CA10__enabledServices__c]: ' + obj.CA10__enabledServices__c);
      if (TextLib.contains(extract3.call(extract3), 'cloudasset.googleapis.com')) {
          return {status: 'COMPLIANT', conditionIndex: 199, conditionText: "extract('CA10__enabledServices__c').contains('cloudasset.googleapis.com')", currentStateMessage: "Cloud Asset Inventory is enabled ", currentStateReferences: references1.join('\n'), remediation: null, runtimeError: null};
      }
      return {status: 'INCOMPLIANT', conditionIndex: 200, conditionText: "otherwise", currentStateMessage: "Cloud Asset Inventory is not enabled", 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__enabledServices__c AS CA10__enabledServices__c,
          process_CA10__CaGoogleProject__c(
              STRUCT(
                  sObject.Id AS Id,
                  sObject.CA10__enabledServices__c AS CA10__enabledServices__c
              ),
              sObject.context.snapshotTime
          ) as result
      FROM UNNEST(mock_CA10__CaGoogleProject__c()) AS sObject
  ) sObject ON sObject.Id = expectedResult.Id;
