-
Notifications
You must be signed in to change notification settings - Fork 1.6k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
merge branch master into 'PRWLR-6173-false-positive-in-cloud-front-ch…
…eck'
- Loading branch information
Showing
55 changed files
with
807 additions
and
204 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
64 changes: 64 additions & 0 deletions
64
api/src/backend/api/migrations/0008_daily_scheduled_tasks_update.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,64 @@ | ||
import json | ||
from datetime import datetime, timedelta, timezone | ||
|
||
import django.db.models.deletion | ||
from django.db import migrations, models | ||
from django_celery_beat.models import PeriodicTask | ||
|
||
from api.db_utils import rls_transaction | ||
from api.models import Scan, StateChoices | ||
|
||
|
||
def migrate_daily_scheduled_scan_tasks(apps, schema_editor): | ||
for daily_scheduled_scan_task in PeriodicTask.objects.filter( | ||
task="scan-perform-scheduled" | ||
): | ||
task_kwargs = json.loads(daily_scheduled_scan_task.kwargs) | ||
tenant_id = task_kwargs["tenant_id"] | ||
provider_id = task_kwargs["provider_id"] | ||
|
||
current_time = datetime.now(timezone.utc) | ||
scheduled_time_today = datetime.combine( | ||
current_time.date(), | ||
daily_scheduled_scan_task.start_time.time(), | ||
tzinfo=timezone.utc, | ||
) | ||
|
||
if current_time < scheduled_time_today: | ||
next_scan_date = scheduled_time_today | ||
else: | ||
next_scan_date = scheduled_time_today + timedelta(days=1) | ||
|
||
with rls_transaction(tenant_id): | ||
Scan.objects.create( | ||
tenant_id=tenant_id, | ||
name="Daily scheduled scan", | ||
provider_id=provider_id, | ||
trigger=Scan.TriggerChoices.SCHEDULED, | ||
state=StateChoices.SCHEDULED, | ||
scheduled_at=next_scan_date, | ||
scheduler_task_id=daily_scheduled_scan_task.id, | ||
) | ||
|
||
|
||
class Migration(migrations.Migration): | ||
atomic = False | ||
|
||
dependencies = [ | ||
("api", "0007_scan_and_scan_summaries_indexes"), | ||
("django_celery_beat", "0019_alter_periodictasks_options"), | ||
] | ||
|
||
operations = [ | ||
migrations.AddField( | ||
model_name="scan", | ||
name="scheduler_task", | ||
field=models.ForeignKey( | ||
blank=True, | ||
null=True, | ||
on_delete=django.db.models.deletion.CASCADE, | ||
to="django_celery_beat.periodictask", | ||
), | ||
), | ||
migrations.RunPython(migrate_daily_scheduled_scan_tasks), | ||
] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.