Write `schedules` for scheduled Pipeline execution policies

What does this MR do and why?

This MR adds support for schedules to the WIP policy type pipeline_execution_schedule_policy. It builds on top of !180708 (merged) which introduced the database columns that this MR starts writing and reading.

References

Please include cross links to any resources that are relevant to this MR. This will give reviewers and future readers helpful context to give an efficient review of the changes introduced.

MR acceptance checklist

Please evaluate this MR against the MR acceptance checklist. It helps you analyze changes to reduce risks in quality, performance, reliability, security, and maintainability.

How to set up and validate locally

  1. Enable the feature flag:
echo "Feature.enable(:scheduled_pipeline_execution_policies)" | rails c
  1. Create a group top-level and two contained projects:

    • top-level/spp
    • top-level/test
  2. Commit the following .gitlab/security-policies/policy.yml to top-level/spp:

scan_execution_policy: []
scan_result_policy: []
approval_policy: []
pipeline_execution_policy: []
ci_component_publishing_policy: []
vulnerability_management_policy: []
pipeline_execution_schedule_policy:
- name: "Scheduled PEP"
  enabled: true
  content:
    include:
    - project: top-level/policy-ci-config
      file: policy-ci.yml
  schedules:
  - type: daily
    start_time: "00:00"
    time_window:
      distribution: random
      value: 3600
  - type: weekly
    days: [Tuesday, Wednesday, Friday, Sunday]
    start_time: "00:00"
    time_window:
      distribution: random
      value: 7200
    timezone: "Europe/Berlin"
  - type: monthly
    days_of_month: [1, 2, 3, 27, 28, 29]
    start_time: "12:00"
    timezone: "America/New_York"
    time_window:
      distribution: random
      value: 10800
  1. On the group level of top-level, navigate to Secure > Policies, click the Edit policy project button and assign top-level/spp
  2. Verify the expected rows are in security_pipeline_execution_project_schedules:
SELECT
	security_policy_id, project_id, cron, cron_timezone, time_window_seconds
FROM
	security_pipeline_execution_project_schedules;
security_policy_id project_id cron cron_timezone time_window_seconds
267 438 0 0 * * * UTC 3600
267 439 0 0 * * * UTC 3600
267 438 0 0 * * 2,3,5,0 Europe/Berlin 7200
267 439 0 0 * * 2,3,5,0 Europe/Berlin 7200
267 438 0 12 1,2,3,27,28,29 * * America/New_York 10800
267 439 0 12 1,2,3,27,28,29 * * America/New_York 10800

Related to #504598 (closed)

Edited by Dominic Bauer

Merge request reports

Loading