---
policy: /ce/ca/google/storage/bucket-logging
logic: /ce/ca/google/storage/bucket-logging/prod.logic.yaml
executionTime: 2025-10-25T12:02:55.602082146Z
generationMs: 73
executionMs: 814
rows:
  - id: '001'
    match: true
    status:
      expected: INAPPLICABLE
      actual: INAPPLICABLE
    conditionIndex:
      expected: 199
      actual: 199
    conditionText:
      expected: CA10__Google_Storage_Buckets__r.has(COMPLIANT)
      actual: CA10__Google_Storage_Buckets__r.has(COMPLIANT)
    runtimeError: {}
  - id: '002'
    match: true
    status:
      expected: INCOMPLIANT
      actual: INCOMPLIANT
    conditionIndex:
      expected: 299
      actual: 299
    conditionText:
      expected: isEmptyLookup('CA10__loggingBucket__r')
      actual: isEmptyLookup('CA10__loggingBucket__r')
    runtimeError: {}
  - id: '003'
    match: true
    status:
      expected: COMPLIANT
      actual: COMPLIANT
    conditionIndex:
      expected: 300
      actual: 300
    conditionText:
      expected: otherwise
      actual: otherwise
    runtimeError: {}
  - id: '004'
    match: true
    status:
      expected: DISAPPEARED
      actual: DISAPPEARED
    conditionIndex:
      expected: 99
      actual: 99
    conditionText:
      expected: isDisappeared(CA10__disappearanceTime__c)
      actual: isDisappeared(CA10__disappearanceTime__c)
    runtimeError: {}
usedFiles:
  - path: /ce/ca/google/storage/bucket-logging/policy.yaml
    md5Hash: D484949888CB2F4C2B7627292D440320
    content: "---\nnames: \n  full: \"Google Storage Bucket logging is not enabled\"\
      \n  contextual: \"Bucket logging is not enabled\"\ndescription: \"Cloud Storage\
      \ bucket logging provides detailed records of requests\\\n  \\ made to a bucket,\
      \ which is crucial for security auditing and operational insights.\\\n  \\ It\
      \ is recommended to enable logging for all storage buckets to track access\\\
      \n  \\ patterns and identify potential unauthorized activities.\"\ntype: \"\
      COMPLIANCE_POLICY\"\ncategories:\n  - \"SECURITY\"\nframeworkMappings:\n  -\
      \ \"/frameworks/cloudaware/logging-and-monitoring/logging-and-monitoring-configuration\""
  - path: /ce/ca/google/storage/bucket-logging/prod.logic.yaml
    md5Hash: 360D52C61131ABBFCAE85C0E26B37E84
    content: "---\n\ninputType: \"CA10__CaGoogleStorageBucket__c\"\ntestData:\n  -\
      \ file: \"test-data.json\"\nconditions:\n  - status: \"INAPPLICABLE\"\n    currentStateMessage:\
      \ \"This is a log destination bucket.\"\n    check:\n      RELATED_LIST_HAS:\n\
      \        status: \"COMPLIANT\"\n        relationshipName: \"CA10__Google_Storage_Buckets__r\"\
      \n  - status: \"INCOMPLIANT\"\n    currentStateMessage: \"The storage bucket\
      \ logging is not enabled.\"\n    remediationMessage: \"Enable logging for the\
      \ Storage bucket.\"\n    check:\n      IS_EMPTY_LOOKUP: \"CA10__loggingBucket__r\"\
      \notherwise:\n  status: \"COMPLIANT\"\n  currentStateMessage: \"The Storage\
      \ bucket logging is enabled\"\nrelatedLists:\n  - relationshipName: \"CA10__Google_Storage_Buckets__r\"\
      \n    conditions: []\n    otherwise:\n      status: \"COMPLIANT\"\n      currentStateMessage:\
      \ \"This is a log source bucket.\" "
  - path: /ce/ca/google/storage/bucket-logging/test-data.json
    md5Hash: 96451FA1BCABF2B718CB5C49F9E54B45
    content: |-
      [
          {
              "expectedResult": {
                  "status": "INAPPLICABLE",
                  "conditionIndex": "199",
                  "conditionText": "CA10__Google_Storage_Buckets__r.has(COMPLIANT)",
                  "runtimeError": null
              },
              "context": {
                  "snapshotTime": "2025-10-17T08:29:54Z"
              },
              "CA10__disappearanceTime__c": null,
              "CA10__loggingBucket__c": "",
              "CA10__loggingBucketName__c": "",
              "Id": "001",
              "CA10__loggingBucket__r": {
                  "Id": null,
                  "CA10__disappearanceTime__c": null
              },
              "CA10__Google_Storage_Buckets__r": [
                  {
                      "CA10__disappearanceTime__c": null,
                      "CA10__loggingBucket__c": "001",
                      "Id": "001a"
                  },
                  {
                      "CA10__disappearanceTime__c": null,
                      "CA10__loggingBucket__c": "001",
                      "Id": "001b"
                  }
              ]
          },
          {
              "expectedResult": {
                  "status": "INCOMPLIANT",
                  "conditionIndex": "299",
                  "conditionText": "isEmptyLookup('CA10__loggingBucket__r')",
                  "runtimeError": null
              },
              "context": {
                  "snapshotTime": "2025-10-17T08:29:54Z"
              },
              "CA10__disappearanceTime__c": null,
              "CA10__loggingBucket__c": "",
              "CA10__loggingBucketName__c": "",
              "Id": "002",
              "CA10__loggingBucket__r": {
                  "Id": null,
                  "CA10__disappearanceTime__c": null
              },
              "CA10__Google_Storage_Buckets__r": []
          },
          {
              "expectedResult": {
                  "status": "COMPLIANT",
                  "conditionIndex": "300",
                  "conditionText": "otherwise",
                  "runtimeError": null
              },
              "context": {
                  "snapshotTime": "2025-10-17T08:29:54Z"
              },
              "CA10__disappearanceTime__c": null,
              "CA10__loggingBucket__c": "003a",
              "CA10__loggingBucketName__c": "loggingBucketName",
              "Id": "003",
              "CA10__loggingBucket__r": {
                  "Id": "003a",
                  "CA10__disappearanceTime__c": null
              },
              "CA10__Google_Storage_Buckets__r": []
          },
          {
              "expectedResult": {
                  "status": "DISAPPEARED",
                  "conditionIndex": "99",
                  "conditionText": "isDisappeared(CA10__disappearanceTime__c)",
                  "runtimeError": null
              },
              "context": {
                  "snapshotTime": "2025-10-17T08:29:54Z"
              },
              "CA10__disappearanceTime__c": "2025-10-17T08:29:54Z",
              "CA10__loggingBucket__c": "",
              "CA10__loggingBucketName__c": "",
              "Id": "004",
              "CA10__loggingBucket__r": {
                  "Id": null,
                  "CA10__disappearanceTime__c": null
              },
              "CA10__Google_Storage_Buckets__r": []
          }
      ]
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" : "001",
    "expectedResult" : {
      "status" : "INAPPLICABLE",
      "conditionIndex" : "199",
      "conditionText" : "CA10__Google_Storage_Buckets__r.has(COMPLIANT)",
      "runtimeError" : null
    }
  }, {
    "Id" : "002",
    "expectedResult" : {
      "status" : "INCOMPLIANT",
      "conditionIndex" : "299",
      "conditionText" : "isEmptyLookup('CA10__loggingBucket__r')",
      "runtimeError" : null
    }
  }, {
    "Id" : "003",
    "expectedResult" : {
      "status" : "COMPLIANT",
      "conditionIndex" : "300",
      "conditionText" : "otherwise",
      "runtimeError" : null
    }
  }, {
    "Id" : "004",
    "expectedResult" : {
      "status" : "DISAPPEARED",
      "conditionIndex" : "99",
      "conditionText" : "isDisappeared(CA10__disappearanceTime__c)",
      "runtimeError" : null
    }
  } ];
  """;

  CREATE TEMP FUNCTION mock_CA10__CaGoogleStorageBucket__c()
  RETURNS ARRAY<STRUCT<
      CA10__disappearanceTime__c TIMESTAMP,
      CA10__loggingBucket__c STRING,
      CA10__loggingBucketName__c STRING,
      Id STRING,
      context STRUCT<
          snapshotTime TIMESTAMP
      >
  >>
  DETERMINISTIC
  LANGUAGE js
  AS r"""
    return [ {
    "context" : {
      "snapshotTime" : new Date("2025-10-17T08:29:54Z")
    },
    "CA10__loggingBucket__c" : "",
    "CA10__loggingBucketName__c" : "",
    "Id" : "001"
  }, {
    "context" : {
      "snapshotTime" : new Date("2025-10-17T08:29:54Z")
    },
    "Id" : null
  }, {
    "context" : {
      "snapshotTime" : new Date("2025-10-17T08:29:54Z")
    },
    "CA10__loggingBucket__c" : "001",
    "Id" : "001a"
  }, {
    "context" : {
      "snapshotTime" : new Date("2025-10-17T08:29:54Z")
    },
    "CA10__loggingBucket__c" : "001",
    "Id" : "001b"
  }, {
    "context" : {
      "snapshotTime" : new Date("2025-10-17T08:29:54Z")
    },
    "CA10__loggingBucket__c" : "",
    "CA10__loggingBucketName__c" : "",
    "Id" : "002"
  }, {
    "context" : {
      "snapshotTime" : new Date("2025-10-17T08:29:54Z")
    },
    "CA10__loggingBucket__c" : "003a",
    "CA10__loggingBucketName__c" : "loggingBucketName",
    "Id" : "003"
  }, {
    "context" : {
      "snapshotTime" : new Date("2025-10-17T08:29:54Z")
    },
    "Id" : "003a"
  }, {
    "context" : {
      "snapshotTime" : new Date("2025-10-17T08:29:54Z")
    },
    "CA10__disappearanceTime__c" : new Date("2025-10-17T08:29:54Z"),
    "CA10__loggingBucket__c" : "",
    "CA10__loggingBucketName__c" : "",
    "Id" : "004"
  } ];
  """;

  CREATE TEMP FUNCTION process_CA10__CaGoogleStorageBucket__c(
      obj STRUCT<
          CA10__disappearanceTime__c TIMESTAMP,
          CA10__loggingBucket__c STRING,
          CA10__loggingBucketName__c STRING,
          Id STRING,
          CA10__loggingBucket__r STRUCT<
              Id STRING,
              CA10__disappearanceTime__c TIMESTAMP
          >,
          CA10__Google_Storage_Buckets__r ARRAY<STRUCT<
              CA10__disappearanceTime__c TIMESTAMP,
              CA10__loggingBucket__c STRING,
              Id 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 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 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};
      }
      var count_CA10__Google_Storage_Buckets__r_COMPLIANT2 = 0;
      if (obj.CA10__Google_Storage_Buckets__r != null) {
          for (var i3 = 0; i3 < obj.CA10__Google_Storage_Buckets__r.length; i3++) {
              if (typeof(obj.CA10__Google_Storage_Buckets__r[i3].status) !== 'undefined') {
                  if (obj.CA10__Google_Storage_Buckets__r[i3].status == 'COMPLIANT') {
                      count_CA10__Google_Storage_Buckets__r_COMPLIANT2 += obj.CA10__Google_Storage_Buckets__r[i3].count;
                  }
              } else  {
                  if (obj.CA10__Google_Storage_Buckets__r[i3].result.status == 'COMPLIANT') {
                      count_CA10__Google_Storage_Buckets__r_COMPLIANT2 += 1;
                  }
              }
          }
      }
      // condition[1], conditionIndex:[100..199]
      references1.push('Related list [CA10__Google_Storage_Buckets__r] ' + (count_CA10__Google_Storage_Buckets__r_COMPLIANT2 > 0 ? 'has' : 'does not have') + ' objects in COMPLIANT status');
      if (count_CA10__Google_Storage_Buckets__r_COMPLIANT2 > 0) {
          return {status: 'INAPPLICABLE', conditionIndex: 199, conditionText: "CA10__Google_Storage_Buckets__r.has(COMPLIANT)", currentStateMessage: "This is a log destination bucket.", currentStateReferences: references1.join('\n'), remediation: null, runtimeError: null};
      }
      // condition[2], conditionIndex:[200..299]
      if (TextLib.isEmpty(obj.CA10__loggingBucketName__c) || TextLib.isEmpty(obj.CA10__loggingBucket__c) || obj.CA10__loggingBucket__r.CA10__disappearanceTime__c != null) {
          return {status: 'INCOMPLIANT', conditionIndex: 299, conditionText: "isEmptyLookup('CA10__loggingBucket__r')", currentStateMessage: "The storage bucket logging is not enabled.", currentStateReferences: references1.join('\n'), remediation: "Enable logging for the Storage bucket.", runtimeError: null};
      }
      return {status: 'COMPLIANT', conditionIndex: 300, conditionText: "otherwise", currentStateMessage: "The Storage bucket logging is enabled", currentStateReferences: references1.join('\n'), remediation: null, runtimeError: null};
  """;

  CREATE TEMP FUNCTION process_CA10__Google_Storage_Buckets__r(
      obj STRUCT<
          CA10__disappearanceTime__c TIMESTAMP,
          CA10__loggingBucket__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 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};
      }
      return {status: 'COMPLIANT', conditionIndex: 100, conditionText: "otherwise", currentStateMessage: "This is a log source bucket.", 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__disappearanceTime__c AS CA10__disappearanceTime__c,
          sObject.CA10__loggingBucket__c AS CA10__loggingBucket__c,
          sObject.CA10__loggingBucketName__c AS CA10__loggingBucketName__c,
          sObject.Id AS Id,
          STRUCT (
              `CA10__loggingBucket__r`.Id AS Id,
              `CA10__loggingBucket__r`.CA10__disappearanceTime__c AS CA10__disappearanceTime__c
          ) AS CA10__loggingBucket__r,
          `CA10__Google_Storage_Buckets__r`.arr AS CA10__Google_Storage_Buckets__r,
          process_CA10__CaGoogleStorageBucket__c(
              STRUCT(
                  sObject.CA10__disappearanceTime__c AS CA10__disappearanceTime__c,
                  sObject.CA10__loggingBucket__c AS CA10__loggingBucket__c,
                  sObject.CA10__loggingBucketName__c AS CA10__loggingBucketName__c,
                  sObject.Id AS Id,
                  STRUCT (
                      `CA10__loggingBucket__r`.Id AS Id,
                      `CA10__loggingBucket__r`.CA10__disappearanceTime__c AS CA10__disappearanceTime__c
                  ) AS CA10__loggingBucket__r,
                  `CA10__Google_Storage_Buckets__r`.arr AS CA10__Google_Storage_Buckets__r
              ),
              sObject.context.snapshotTime
          ) as result
      FROM UNNEST(mock_CA10__CaGoogleStorageBucket__c()) AS sObject
      LEFT JOIN UNNEST(mock_CA10__CaGoogleStorageBucket__c()) AS `CA10__loggingBucket__r`
          ON sObject.CA10__loggingBucket__c = `CA10__loggingBucket__r`.Id
      LEFT JOIN (
          SELECT
              sObject.CA10__loggingBucket__c,
              ARRAY_AGG(
                  STRUCT(
                      sObject.CA10__disappearanceTime__c AS CA10__disappearanceTime__c,
                      sObject.CA10__loggingBucket__c AS CA10__loggingBucket__c,
                      sObject.Id AS Id,
                      process_CA10__Google_Storage_Buckets__r(
                          STRUCT(
                              sObject.CA10__disappearanceTime__c AS CA10__disappearanceTime__c,
                              sObject.CA10__loggingBucket__c AS CA10__loggingBucket__c,
                              sObject.Id AS Id
                          ),
                          sObject.context.snapshotTime
                      ) as result
                  )
              ) AS arr
          FROM UNNEST(mock_CA10__CaGoogleStorageBucket__c()) AS sObject
          GROUP BY sObject.CA10__loggingBucket__c
      ) AS `CA10__Google_Storage_Buckets__r`
          ON sObject.Id = `CA10__Google_Storage_Buckets__r`.CA10__loggingBucket__c
  ) sObject ON sObject.Id = expectedResult.Id;
