---
policy: /ce/ca/google/project/project-with-default-network
logic: /ce/ca/google/project/project-with-default-network/prod.logic.yaml
executionTime: 2025-04-24T23:47:19.387785383Z
rows:
  - id: a4p77
    match: true
    status:
      expected: INCOMPLIANT
      actual: INCOMPLIANT
    conditionIndex:
      expected: 199
      actual: 199
    conditionText:
      expected: CA10__Google_GCE_Networks__r.has(INCOMPLIANT)
      actual: CA10__Google_GCE_Networks__r.has(INCOMPLIANT)
    runtimeError: {}
  - id: a4p077
    match: true
    status:
      expected: COMPLIANT
      actual: COMPLIANT
    conditionIndex:
      expected: 200
      actual: 200
    conditionText:
      expected: otherwise
      actual: otherwise
    runtimeError: {}
usedFiles:
  - path: /ce/ca/google/project/project-with-default-network/policy.yaml
    md5Hash: 8895F979B9D13500C01BAEB401153C0F
    content: "---\nnames: \n  full: \"Google Project has a default network\"\n  contextual:\
      \ \"Project has a default network\"\ndescription: \"To prevent use of default\
      \ network, a project should not have a default network.\"\ntype: COMPLIANCE_POLICY\n\
      categories:\n  - \"SECURITY\"\nframeworkMappings:\n  - /frameworks/cis-gcp-v3.0.0/03/01\n\
      \  - /frameworks/cloudaware/resource-security/secure-access\nsimilarPolicies:\n\
      \  cloudConformity:\n    - url: \"https://www.trendmicro.com/cloudoneconformity-staging/knowledge-base/gcp/CloudVPC/default-vpc-in-use.html\"\
      \n      name: \"Default VPC Network In Use\"\n"
  - path: /ce/ca/google/project/project-with-default-network/prod.logic.yaml
    md5Hash: E8B363678F50A8BCA6CD8DE194FFC292
    content: "---\n\ninputType: \"CA10__CaGoogleProject__c\"\ntestData:\n  - file:\
      \ test-data.json\nconditions:\n  - status: \"INCOMPLIANT\"\n    currentStateMessage:\
      \ \"This Project has a default network.\"\n    remediationMessage: \"Delete\
      \ the default network.\"\n    check:\n      RELATED_LIST_HAS:\n        status:\
      \ \"INCOMPLIANT\"\n        relationshipName: \"CA10__Google_GCE_Networks__r\"\
      \ \notherwise:\n  status: \"COMPLIANT\"\n  currentStateMessage: \"The Project\
      \ doesn't have a default network.\"\nrelatedLists:\n  - relationshipName: \"\
      CA10__Google_GCE_Networks__r\"\n    importExtracts:\n      - file: /types/CA10__CaGoogleGceNetwork__c/object.extracts.yaml\n\
      \    conditions:\n      - status: \"INCOMPLIANT\"\n        currentStateMessage:\
      \ \"This is a default network.\"\n        check:\n          IS_EQUAL:\n    \
      \        left:\n              EXTRACT: networkName\n            right:\n   \
      \           TEXT: 'default'\n    otherwise:\n      status: \"COMPLIANT\"\n \
      \     currentStateMessage: \"This is not a default network.\""
  - path: /ce/ca/google/project/project-with-default-network/test-data.json
    md5Hash: BA6B12CD1ECB312BD143076243A69506
    content: |
      [
        {
          "expectedResult": {
            "status": "INCOMPLIANT",
            "conditionIndex": "199",
            "conditionText": "CA10__Google_GCE_Networks__r.has(INCOMPLIANT)",
            "runtimeError": null
          },
          "context": { "snapshotTime": "2024-09-05T17:52:17Z" },
          "Id": "a4p77",
          "CA10__Google_GCE_Networks__r": [
            {
              "Id": "a4b7V01",
              "CA10__disappearanceTime__c": null,
              "Name": "default",
              "CA10__project__c": "a4p77"
            }
          ]
        },
        {
          "expectedResult": {
            "status": "COMPLIANT",
            "conditionIndex": "200",
            "conditionText": "otherwise",
            "runtimeError": null
          },
          "context": { "snapshotTime": "2024-09-05T17:52:17Z" },
          "Id": "a4p077",
          "CA10__Google_GCE_Networks__r": [
              {
                  "Id": "a4b7V02",
                  "CA10__disappearanceTime__c": null,
                  "Name": "customNetwork",
                  "CA10__project__c": "a4p077"
                }
          ]
        }
      ]
  - path: /types/CA10__CaGoogleGceNetwork__c/object.extracts.yaml
    md5Hash: 8F9138803D14A08C803D065164BFC0CC
    content: "---\nextracts:\n  - name: \"networkName\"\n    value: \n      FIELD:\n\
      \        path: \"Name\"\n        undeterminedIf:\n          isEmpty:  \"Name\
      \ should not be empty\"\n  - name: \"CA10__autoCreationSubnetworksMode__c\"\n\
      \    value: \n      FIELD:\n        path: \"CA10__autoCreationSubnetworksMode__c\"\
      \n        undeterminedIf:\n          isEmpty:  \"Auto creation subnetworks mode\
      \ should not be empty\""
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" : "a4p77",
    "expectedResult" : {
      "status" : "INCOMPLIANT",
      "conditionIndex" : "199",
      "conditionText" : "CA10__Google_GCE_Networks__r.has(INCOMPLIANT)",
      "runtimeError" : null
    }
  }, {
    "Id" : "a4p077",
    "expectedResult" : {
      "status" : "COMPLIANT",
      "conditionIndex" : "200",
      "conditionText" : "otherwise",
      "runtimeError" : null
    }
  } ];
  """;

  CREATE TEMP FUNCTION mock_CA10__CaGoogleProject__c()
  RETURNS ARRAY<STRUCT<
      Id STRING,
      context STRUCT<
          snapshotTime TIMESTAMP
      >
  >>
  DETERMINISTIC
  LANGUAGE js
  AS r"""
    return [ {
    "context" : {
      "snapshotTime" : new Date("2024-09-05T17:52:17Z")
    },
    "Id" : "a4p77"
  }, {
    "context" : {
      "snapshotTime" : new Date("2024-09-05T17:52:17Z")
    },
    "Id" : "a4p077"
  } ];
  """;

  CREATE TEMP FUNCTION mock_CA10__CaGoogleGceNetwork__c()
  RETURNS ARRAY<STRUCT<
      Id STRING,
      CA10__disappearanceTime__c TIMESTAMP,
      Name STRING,
      CA10__project__c STRING,
      context STRUCT<
          snapshotTime TIMESTAMP
      >
  >>
  DETERMINISTIC
  LANGUAGE js
  AS r"""
    return [ {
    "context" : {
      "snapshotTime" : new Date("2024-09-05T17:52:17Z")
    },
    "Id" : "a4b7V01",
    "Name" : "default",
    "CA10__project__c" : "a4p77"
  }, {
    "context" : {
      "snapshotTime" : new Date("2024-09-05T17:52:17Z")
    },
    "Id" : "a4b7V02",
    "Name" : "customNetwork",
    "CA10__project__c" : "a4p077"
  } ];
  """;

  CREATE TEMP FUNCTION process_CA10__CaGoogleProject__c(
      obj STRUCT<
          Id STRING,
          CA10__Google_GCE_Networks__r ARRAY<STRUCT<
              Id STRING,
              CA10__disappearanceTime__c TIMESTAMP,
              Name STRING,
              CA10__project__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 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};
      }
      var count_CA10__Google_GCE_Networks__r_INCOMPLIANT2 = 0;
      if (obj.CA10__Google_GCE_Networks__r != null) {
          for (var i3 = 0; i3 < obj.CA10__Google_GCE_Networks__r.length; i3++) {
              if (obj.CA10__Google_GCE_Networks__r[i3].result.status == 'INCOMPLIANT') {
                  count_CA10__Google_GCE_Networks__r_INCOMPLIANT2 += 1;
              }
          }
      }
      // condition[1], conditionIndex:[100..199]
      references1.push('Related list [CA10__Google_GCE_Networks__r] ' + (count_CA10__Google_GCE_Networks__r_INCOMPLIANT2 > 0 ? 'has' : 'does not have') + ' objects in INCOMPLIANT status');
      if (count_CA10__Google_GCE_Networks__r_INCOMPLIANT2 > 0) {
          return {status: 'INCOMPLIANT', conditionIndex: 199, conditionText: "CA10__Google_GCE_Networks__r.has(INCOMPLIANT)", currentStateMessage: "This Project has a default network.", currentStateReferences: references1.join('\n'), remediation: "Delete the default network.", runtimeError: null};
      }
      return {status: 'COMPLIANT', conditionIndex: 200, conditionText: "otherwise", currentStateMessage: "The Project doesn't have a default network.", currentStateReferences: references1.join('\n'), remediation: null, runtimeError: null};
  """;

  CREATE TEMP FUNCTION process_CA10__Google_GCE_Networks__r(
      obj STRUCT<
          Id STRING,
          CA10__disappearanceTime__c TIMESTAMP,
          Name STRING,
          CA10__project__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]
      references1.push('Deleted From Google [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.Name)) {
              throw new Error("UNDETERMINED condition:101", {cause: {status: 'UNDETERMINED', conditionIndex: 101, conditionText: "Name.isEmpty()", currentStateMessage: "Name should not be empty", currentStateReferences: references1.join('\n'), remediation: null, runtimeError: null}});
          }
          return obj.Name;
      }
      function extract3() { if (!this.out) { this.out = fieldChecked4(); } return this.out; };
      references1.push('Name [obj.Name]: ' + obj.Name);
      try {
          if (TextLib.equal(extract3.call(extract3), 'default')) {
              return {status: 'INCOMPLIANT', conditionIndex: 199, conditionText: "extract('networkName') == 'default'", currentStateMessage: "This is a default network.", currentStateReferences: references1.join('\n'), remediation: null, runtimeError: null};
          }
      } catch (err) {
          if (err.cause && err.cause.status) { return err.cause; } else { throw err; }
      }
      return {status: 'COMPLIANT', conditionIndex: 200, conditionText: "otherwise", currentStateMessage: "This is not a default network.", 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,
          `CA10__Google_GCE_Networks__r`.arr AS CA10__Google_GCE_Networks__r,
          process_CA10__CaGoogleProject__c(
              STRUCT(
                  sObject.Id AS Id,
                  `CA10__Google_GCE_Networks__r`.arr AS CA10__Google_GCE_Networks__r
              ),
              sObject.context.snapshotTime
          ) as result
      FROM UNNEST(mock_CA10__CaGoogleProject__c()) AS sObject
      LEFT JOIN (
          SELECT
              sObject.CA10__project__c,
              ARRAY_AGG(
                  STRUCT(
                      sObject.Id AS Id,
                      sObject.CA10__disappearanceTime__c AS CA10__disappearanceTime__c,
                      sObject.Name AS Name,
                      sObject.CA10__project__c AS CA10__project__c,
                      process_CA10__Google_GCE_Networks__r(
                          STRUCT(
                              sObject.Id AS Id,
                              sObject.CA10__disappearanceTime__c AS CA10__disappearanceTime__c,
                              sObject.Name AS Name,
                              sObject.CA10__project__c AS CA10__project__c
                          ),
                          sObject.context.snapshotTime
                      ) as result
                  )
              ) AS arr
          FROM UNNEST(mock_CA10__CaGoogleGceNetwork__c()) AS sObject
          GROUP BY sObject.CA10__project__c
      ) AS `CA10__Google_GCE_Networks__r`
          ON sObject.Id = `CA10__Google_GCE_Networks__r`.CA10__project__c
  ) sObject ON sObject.Id = expectedResult.Id;
