-
Notifications
You must be signed in to change notification settings - Fork 3
feat: new risk jobs #344
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
feat: new risk jobs #344
Changes from all commits
Commits
Show all changes
17 commits
Select commit
Hold shift + click to select a range
410cbbc
feat: risk notification jobs
gusfcarvalho 656a2ae
fix: copilot issues
gusfcarvalho 2fea429
fix: copilot issues
gusfcarvalho 5209828
fix: copilot issues
gusfcarvalho 86a0ec4
fix: copilot issues
gusfcarvalho 46a9204
Reject zero auto reopen threshold
gusfcarvalho 944b53f
Fix resolveSSP display name fallback
gusfcarvalho 8b65e7d
Limit risk evidence orphan query
gusfcarvalho 9699b54
Clear acceptance justification
gusfcarvalho cc9c5c5
fix: remove uneeded self-heal behavior
gusfcarvalho 04315e2
Merge branch 'main' into codex/plan-bch1183-risk-jobs
gusfcarvalho de99160
Use risk service for overdue reopen
gusfcarvalho 4a321a9
fix: use context on db
gusfcarvalho 93b6051
Update risk scanner batching
gusfcarvalho bae41e2
Apply copilot comments and defaultv2
gusfcarvalho 2365845
Lock risk when reopening review
gusfcarvalho f851351
Address risk worker comments
gusfcarvalho File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or 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 hidden or 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 hidden or 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 hidden or 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 hidden or 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 hidden or 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 hidden or 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 hidden or 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 hidden or 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,118 @@ | ||
| package config | ||
|
|
||
| import ( | ||
| "errors" | ||
| "fmt" | ||
| "os" | ||
| "strings" | ||
|
|
||
| "github.com/robfig/cron/v3" | ||
| "github.com/spf13/viper" | ||
| ) | ||
|
|
||
| // RiskConfig contains configuration for risk-related periodic workers. | ||
| type RiskConfig struct { | ||
| ReviewDeadlineReminderEnabled bool `mapstructure:"review_deadline_reminder_enabled" yaml:"review_deadline_reminder_enabled" json:"reviewDeadlineReminderEnabled"` | ||
| ReviewDeadlineReminderSchedule string `mapstructure:"review_deadline_reminder_schedule" yaml:"review_deadline_reminder_schedule" json:"reviewDeadlineReminderSchedule"` | ||
|
|
||
| ReviewOverdueEscalationEnabled bool `mapstructure:"review_overdue_escalation_enabled" yaml:"review_overdue_escalation_enabled" json:"reviewOverdueEscalationEnabled"` | ||
| ReviewOverdueEscalationSchedule string `mapstructure:"review_overdue_escalation_schedule" yaml:"review_overdue_escalation_schedule" json:"reviewOverdueEscalationSchedule"` | ||
|
|
||
| StaleRiskScannerEnabled bool `mapstructure:"stale_risk_scanner_enabled" yaml:"stale_risk_scanner_enabled" json:"staleRiskScannerEnabled"` | ||
| StaleRiskScannerSchedule string `mapstructure:"stale_risk_scanner_schedule" yaml:"stale_risk_scanner_schedule" json:"staleRiskScannerSchedule"` | ||
|
|
||
| EvidenceReconciliationEnabled bool `mapstructure:"evidence_reconciliation_enabled" yaml:"evidence_reconciliation_enabled" json:"evidenceReconciliationEnabled"` | ||
| EvidenceReconciliationSchedule string `mapstructure:"evidence_reconciliation_schedule" yaml:"evidence_reconciliation_schedule" json:"evidenceReconciliationSchedule"` | ||
|
|
||
| AutoReopenEnabled bool `mapstructure:"auto_reopen_enabled" yaml:"auto_reopen_enabled" json:"autoReopenEnabled"` | ||
| AutoReopenThresholdDays int `mapstructure:"auto_reopen_threshold_days" yaml:"auto_reopen_threshold_days" json:"autoReopenThresholdDays"` | ||
| } | ||
|
|
||
| func DefaultRiskConfig() *RiskConfig { | ||
| return &RiskConfig{ | ||
| ReviewDeadlineReminderEnabled: false, | ||
| ReviewDeadlineReminderSchedule: "0 0 8 * * *", | ||
| ReviewOverdueEscalationEnabled: false, | ||
| ReviewOverdueEscalationSchedule: "0 0 9 * * *", | ||
| StaleRiskScannerEnabled: false, | ||
| StaleRiskScannerSchedule: "0 0 10 * * 1", | ||
| EvidenceReconciliationEnabled: false, | ||
| EvidenceReconciliationSchedule: "0 30 10 * * *", | ||
| AutoReopenEnabled: false, | ||
| AutoReopenThresholdDays: 30, | ||
| } | ||
| } | ||
|
|
||
| func LoadRiskConfig(path string) (*RiskConfig, error) { | ||
| v := viper.NewWithOptions(viper.KeyDelimiter("::")) | ||
|
|
||
| def := DefaultRiskConfig() | ||
| v.SetDefault("review_deadline_reminder_enabled", def.ReviewDeadlineReminderEnabled) | ||
| v.SetDefault("review_deadline_reminder_schedule", def.ReviewDeadlineReminderSchedule) | ||
| v.SetDefault("review_overdue_escalation_enabled", def.ReviewOverdueEscalationEnabled) | ||
| v.SetDefault("review_overdue_escalation_schedule", def.ReviewOverdueEscalationSchedule) | ||
| v.SetDefault("stale_risk_scanner_enabled", def.StaleRiskScannerEnabled) | ||
| v.SetDefault("stale_risk_scanner_schedule", def.StaleRiskScannerSchedule) | ||
| v.SetDefault("evidence_reconciliation_enabled", def.EvidenceReconciliationEnabled) | ||
| v.SetDefault("evidence_reconciliation_schedule", def.EvidenceReconciliationSchedule) | ||
| v.SetDefault("auto_reopen_enabled", def.AutoReopenEnabled) | ||
| v.SetDefault("auto_reopen_threshold_days", def.AutoReopenThresholdDays) | ||
|
|
||
| v.SetEnvPrefix("CCF_RISK") | ||
| v.SetEnvKeyReplacer(strings.NewReplacer("::", "_", ".", "_", "-", "_")) | ||
| v.AutomaticEnv() | ||
|
|
||
| if path != "" { | ||
| v.SetConfigFile(path) | ||
| v.SetConfigType("yaml") | ||
| if err := v.ReadInConfig(); err != nil { | ||
| var notFound viper.ConfigFileNotFoundError | ||
| if !errors.As(err, ¬Found) && !errors.Is(err, os.ErrNotExist) { | ||
| return nil, fmt.Errorf("failed to read risk config file: %w", err) | ||
| } | ||
| } | ||
gusfcarvalho marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| } | ||
|
|
||
| var cfg RiskConfig | ||
| if err := v.Unmarshal(&cfg); err != nil { | ||
| return nil, fmt.Errorf("failed to parse risk config: %w", err) | ||
| } | ||
| if err := cfg.Validate(); err != nil { | ||
| return nil, err | ||
| } | ||
|
|
||
| return &cfg, nil | ||
| } | ||
|
|
||
| func (c *RiskConfig) Validate() error { | ||
| parser := cron.NewParser(cron.Second | cron.Minute | cron.Hour | cron.Dom | cron.Month | cron.Dow | cron.Descriptor) | ||
|
|
||
| if c.ReviewDeadlineReminderEnabled { | ||
| if _, err := parser.Parse(c.ReviewDeadlineReminderSchedule); err != nil { | ||
| return fmt.Errorf("invalid review_deadline_reminder_schedule: %w", err) | ||
| } | ||
| } | ||
| if c.ReviewOverdueEscalationEnabled { | ||
| if _, err := parser.Parse(c.ReviewOverdueEscalationSchedule); err != nil { | ||
| return fmt.Errorf("invalid review_overdue_escalation_schedule: %w", err) | ||
| } | ||
| } | ||
| if c.StaleRiskScannerEnabled { | ||
| if _, err := parser.Parse(c.StaleRiskScannerSchedule); err != nil { | ||
| return fmt.Errorf("invalid stale_risk_scanner_schedule: %w", err) | ||
| } | ||
| } | ||
| if c.EvidenceReconciliationEnabled { | ||
| if _, err := parser.Parse(c.EvidenceReconciliationSchedule); err != nil { | ||
| return fmt.Errorf("invalid evidence_reconciliation_schedule: %w", err) | ||
| } | ||
| } | ||
| if c.AutoReopenThresholdDays < 0 { | ||
| return fmt.Errorf("risk auto reopen threshold days must be non-negative") | ||
| } | ||
gusfcarvalho marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| if c.AutoReopenEnabled && c.AutoReopenThresholdDays <= 0 { | ||
| return fmt.Errorf("risk auto reopen threshold days must be greater than zero when auto reopen is enabled") | ||
| } | ||
|
|
||
| return nil | ||
| } | ||
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.