feat: add target deletion functionality with cascaded removal of associated jobs and tasks

This commit is contained in:
2026-08-22 01:15:05 -07:00
parent af1ee1c9b3
commit 367929e7d0
9 changed files with 501 additions and 21 deletions
+41
View File
@@ -49,3 +49,44 @@ func (db *DB) LoadTargetsFromYAML(filepath string) error {
}
return nil
}
// RemoveTargetFromYAML removes a target from the target configuration YAML file if it exists
func RemoveTargetFromYAML(filepath string, targetURL string) error {
if filepath == "" {
return nil
}
data, err := os.ReadFile(filepath)
if err != nil {
if os.IsNotExist(err) {
return nil
}
return fmt.Errorf("could not read target config: %w", err)
}
var config targetConfig
if err := yaml.Unmarshal(data, &config); err != nil {
return fmt.Errorf("could not parse target config: %w", err)
}
var newTargets []struct {
Name string `yaml:"name"`
TargetURL string `yaml:"target_url"`
Platform string `yaml:"platform"`
IsActive bool `yaml:"is_active"`
}
for _, t := range config.Targets {
if t.TargetURL != targetURL {
newTargets = append(newTargets, t)
}
}
config.Targets = newTargets
outData, err := yaml.Marshal(&config)
if err != nil {
return fmt.Errorf("could not marshal target config: %w", err)
}
return os.WriteFile(filepath, outData, 0644)
}