Skip to content

Commit

Permalink
fix: correct the retention webhook payload
Browse files Browse the repository at this point in the history
Fix the incorrect number of total and retained in the retention webhook
payload, and completes the deleted_artifacts field.

Fixes: goharbor#18428

Signed-off-by: chlins <[email protected]>
  • Loading branch information
chlins committed Apr 3, 2023
1 parent 6216a1d commit 823e18f
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 3 deletions.
9 changes: 6 additions & 3 deletions src/controller/event/handler/webhook/artifact/retention.go
Original file line number Diff line number Diff line change
Expand Up @@ -121,8 +121,8 @@ func (r *RetentionHandler) constructRetentionPayload(event *event.RetentionEvent
Operator: execution.Trigger,
EventData: &model.EventData{
Retention: &evtModel.Retention{
Total: task.Total,
Retained: task.Retained,
Total: event.Total,
Retained: event.Retained,
HarborHostname: hostname,
ProjectName: event.Deleted[0].Target.Namespace,
RetentionPolicyID: execution.PolicyID,
Expand All @@ -140,8 +140,11 @@ func (r *RetentionHandler) constructRetentionPayload(event *event.RetentionEvent
}
if len(target.Tags) != 0 {
deletedArtifact.NameAndTag = target.Repository + ":" + target.Tags[0]
} else {
// use digest if no tag
deletedArtifact.NameAndTag = target.Repository + "@" + target.Digest
}
payload.EventData.Retention.DeletedArtifact = []*evtModel.ArtifactInfo{deletedArtifact}
payload.EventData.Retention.DeletedArtifact = append(payload.EventData.Retention.DeletedArtifact, deletedArtifact)
}

for _, v := range md.Rules {
Expand Down
2 changes: 2 additions & 0 deletions src/controller/event/metadata/retention.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,8 @@ func (r *RetentionMetaData) Resolve(evt *event.Event) error {
Status: r.Status,
Deleted: r.Deleted,
TaskID: r.TaskID,
Total: r.Total,
Retained: r.Retained,
}

evt.Topic = event2.TopicTagRetention
Expand Down
2 changes: 2 additions & 0 deletions src/controller/event/topic.go
Original file line number Diff line number Diff line change
Expand Up @@ -371,6 +371,8 @@ type RetentionEvent struct {
OccurAt time.Time
Status string
Deleted []*selector.Result
Total int
Retained int
}

func (r *RetentionEvent) String() string {
Expand Down

0 comments on commit 823e18f

Please sign in to comment.