2020-03-16 09:56:34 +01:00
|
|
|
package handler
|
|
|
|
|
|
|
|
import (
|
2020-09-30 09:14:00 +02:00
|
|
|
"context"
|
2020-12-14 06:34:35 +01:00
|
|
|
|
2020-03-24 13:45:45 +01:00
|
|
|
"github.com/goharbor/harbor/src/controller/event"
|
|
|
|
"github.com/goharbor/harbor/src/controller/event/handler/auditlog"
|
|
|
|
"github.com/goharbor/harbor/src/controller/event/handler/internal"
|
2020-07-06 13:07:30 +02:00
|
|
|
"github.com/goharbor/harbor/src/controller/event/handler/p2p"
|
2020-03-24 13:45:45 +01:00
|
|
|
"github.com/goharbor/harbor/src/controller/event/handler/replication"
|
|
|
|
"github.com/goharbor/harbor/src/controller/event/handler/webhook/artifact"
|
|
|
|
"github.com/goharbor/harbor/src/controller/event/handler/webhook/chart"
|
|
|
|
"github.com/goharbor/harbor/src/controller/event/handler/webhook/quota"
|
|
|
|
"github.com/goharbor/harbor/src/controller/event/handler/webhook/scan"
|
2020-09-30 09:14:00 +02:00
|
|
|
"github.com/goharbor/harbor/src/controller/event/metadata"
|
|
|
|
"github.com/goharbor/harbor/src/jobservice/job"
|
|
|
|
"github.com/goharbor/harbor/src/pkg/notification"
|
2020-03-16 09:56:34 +01:00
|
|
|
"github.com/goharbor/harbor/src/pkg/notifier"
|
2020-09-30 09:14:00 +02:00
|
|
|
"github.com/goharbor/harbor/src/pkg/task"
|
2020-03-16 09:56:34 +01:00
|
|
|
)
|
|
|
|
|
|
|
|
func init() {
|
|
|
|
// notification
|
|
|
|
notifier.Subscribe(event.TopicPushArtifact, &artifact.Handler{})
|
|
|
|
notifier.Subscribe(event.TopicPullArtifact, &artifact.Handler{})
|
|
|
|
notifier.Subscribe(event.TopicDeleteArtifact, &artifact.Handler{})
|
2021-03-22 10:27:23 +01:00
|
|
|
notifier.Subscribe(event.TopicUploadChart, &chart.Handler{})
|
|
|
|
notifier.Subscribe(event.TopicDeleteChart, &chart.Handler{})
|
|
|
|
notifier.Subscribe(event.TopicDownloadChart, &chart.Handler{})
|
2020-03-16 09:56:34 +01:00
|
|
|
notifier.Subscribe(event.TopicQuotaExceed, "a.Handler{})
|
|
|
|
notifier.Subscribe(event.TopicQuotaWarning, "a.Handler{})
|
|
|
|
notifier.Subscribe(event.TopicScanningFailed, &scan.Handler{})
|
2021-08-15 11:21:39 +02:00
|
|
|
notifier.Subscribe(event.TopicScanningStopped, &scan.Handler{})
|
2020-03-16 09:56:34 +01:00
|
|
|
notifier.Subscribe(event.TopicScanningCompleted, &scan.Handler{})
|
2021-03-22 10:27:23 +01:00
|
|
|
notifier.Subscribe(event.TopicDeleteArtifact, &scan.DelArtHandler{})
|
2020-03-23 11:45:58 +01:00
|
|
|
notifier.Subscribe(event.TopicReplication, &artifact.ReplicationHandler{})
|
2021-01-08 01:09:34 +01:00
|
|
|
notifier.Subscribe(event.TopicTagRetention, &artifact.RetentionHandler{})
|
2020-03-16 09:56:34 +01:00
|
|
|
|
|
|
|
// replication
|
|
|
|
notifier.Subscribe(event.TopicPushArtifact, &replication.Handler{})
|
|
|
|
notifier.Subscribe(event.TopicDeleteArtifact, &replication.Handler{})
|
|
|
|
notifier.Subscribe(event.TopicCreateTag, &replication.Handler{})
|
2020-03-12 09:00:23 +01:00
|
|
|
notifier.Subscribe(event.TopicDeleteTag, &replication.Handler{})
|
2020-03-16 09:56:34 +01:00
|
|
|
|
2020-07-06 13:07:30 +02:00
|
|
|
// p2p preheat
|
2021-03-22 10:27:23 +01:00
|
|
|
notifier.Subscribe(event.TopicPushArtifact, &p2p.Handler{})
|
|
|
|
notifier.Subscribe(event.TopicScanningCompleted, &p2p.Handler{})
|
|
|
|
notifier.Subscribe(event.TopicArtifactLabeled, &p2p.Handler{})
|
2020-07-06 13:07:30 +02:00
|
|
|
|
2020-03-16 09:56:34 +01:00
|
|
|
// audit logs
|
|
|
|
notifier.Subscribe(event.TopicPushArtifact, &auditlog.Handler{})
|
|
|
|
notifier.Subscribe(event.TopicPullArtifact, &auditlog.Handler{})
|
|
|
|
notifier.Subscribe(event.TopicDeleteArtifact, &auditlog.Handler{})
|
|
|
|
notifier.Subscribe(event.TopicCreateProject, &auditlog.Handler{})
|
|
|
|
notifier.Subscribe(event.TopicDeleteProject, &auditlog.Handler{})
|
|
|
|
notifier.Subscribe(event.TopicDeleteRepository, &auditlog.Handler{})
|
|
|
|
notifier.Subscribe(event.TopicCreateTag, &auditlog.Handler{})
|
|
|
|
notifier.Subscribe(event.TopicDeleteTag, &auditlog.Handler{})
|
2020-03-18 11:38:37 +01:00
|
|
|
|
|
|
|
// internal
|
2021-03-22 10:27:23 +01:00
|
|
|
notifier.Subscribe(event.TopicPullArtifact, &internal.Handler{})
|
|
|
|
notifier.Subscribe(event.TopicPushArtifact, &internal.Handler{})
|
2020-09-30 09:14:00 +02:00
|
|
|
|
|
|
|
task.RegisterTaskStatusChangePostFunc(job.Replication, func(ctx context.Context, taskID int64, status string) error {
|
|
|
|
notification.AddEvent(ctx, &metadata.ReplicationMetaData{
|
|
|
|
ReplicationTaskID: taskID,
|
|
|
|
Status: status,
|
|
|
|
})
|
|
|
|
return nil
|
|
|
|
})
|
2020-03-16 09:56:34 +01:00
|
|
|
}
|