def create_detector()

in src/org_setup/resources/guardduty.py [0:0]


    def create_detector(self) -> List[str]:
        """
        Update the organization configuration to auto-enroll new accounts in GuardDuty

        Executes in: delegated administrator account in all regions
        """

        detector_ids = []

        paginator = self.client.get_paginator("list_detectors")
        page_iterator = paginator.paginate()
        for page in page_iterator:
            detector_ids.extend(page.get("DetectorIds", []))

        if detector_ids:
            for detector_id in detector_ids:
                self.client.update_detector(
                    DetectorId=detector_id,
                    Enable=True,
                    FindingPublishingFrequency="FIFTEEN_MINUTES",
                    DataSources={"S3Logs": {"Enable": True}},
                )
        else:
            response = self.client.create_detector(
                Enable=True,
                DataSources={"S3Logs": {"Enable": True}},
                FindingPublishingFrequency="FIFTEEN_MINUTES",
            )
            detector_ids.append(response["DetectorId"])

        for detector_id in detector_ids:
            self.client.update_organization_configuration(
                DetectorId=detector_id,
                AutoEnable=True,
                DataSources={"S3Logs": {"AutoEnable": True}},
            )

        logger.info(f"[{self.region}] Updated GuardDuty to auto-enroll new accounts")

        return detector_ids