mirror of
https://github.com/goharbor/harbor.git
synced 2024-12-22 08:38:03 +01:00
Add API for query supported event types and notify types; Return policy name in last trigger info; Remove project_id unique constraint in table notification_policy (#11029)
Signed-off-by: guanxiatao <guanxiatao@corp.netease.com>
This commit is contained in:
parent
8452100148
commit
4ac31c6d46
@ -565,6 +565,23 @@ paths:
|
|||||||
$ref: '#/responses/401'
|
$ref: '#/responses/401'
|
||||||
'500':
|
'500':
|
||||||
$ref: '#/responses/500'
|
$ref: '#/responses/500'
|
||||||
|
/projects/{project_id}/webhook/events:
|
||||||
|
get:
|
||||||
|
summary: Get supported event types and notify types.
|
||||||
|
description: Get supportted event types and notify types.
|
||||||
|
tags:
|
||||||
|
- notification
|
||||||
|
parameters:
|
||||||
|
- $ref: '#/parameters/projectId'
|
||||||
|
responses:
|
||||||
|
'200':
|
||||||
|
description: Success
|
||||||
|
schema:
|
||||||
|
$ref: '#/definitions/SupportedWebhookEventTypes'
|
||||||
|
'401':
|
||||||
|
$ref: '#/responses/401'
|
||||||
|
'403':
|
||||||
|
$ref: '#/responses/403'
|
||||||
parameters:
|
parameters:
|
||||||
query:
|
query:
|
||||||
name: q
|
name: q
|
||||||
@ -585,6 +602,12 @@ parameters:
|
|||||||
description: The name of the project
|
description: The name of the project
|
||||||
required: true
|
required: true
|
||||||
type: string
|
type: string
|
||||||
|
projectId:
|
||||||
|
name: project_id
|
||||||
|
in: path
|
||||||
|
description: The ID of the project
|
||||||
|
required: true
|
||||||
|
type: string
|
||||||
repositoryName:
|
repositoryName:
|
||||||
name: repository_name
|
name: repository_name
|
||||||
in: path
|
in: path
|
||||||
@ -1012,3 +1035,23 @@ definitions:
|
|||||||
op_time:
|
op_time:
|
||||||
type: string
|
type: string
|
||||||
description: The time when this operation is triggered.
|
description: The time when this operation is triggered.
|
||||||
|
SupportedWebhookEventTypes:
|
||||||
|
type: object
|
||||||
|
description: Supportted webhook event types and notify types.
|
||||||
|
properties:
|
||||||
|
event_type:
|
||||||
|
type: array
|
||||||
|
items:
|
||||||
|
$ref: '#/definitions/EventType'
|
||||||
|
notify_type:
|
||||||
|
type: array
|
||||||
|
items:
|
||||||
|
$ref: '#/definitions/NotifyType'
|
||||||
|
EventType:
|
||||||
|
type: string
|
||||||
|
description: Webhook supportted event type.
|
||||||
|
example: 'pullImage'
|
||||||
|
NotifyType:
|
||||||
|
type: string
|
||||||
|
description: Webhook supportted notify type.
|
||||||
|
example: 'http'
|
||||||
|
@ -208,3 +208,9 @@ BEGIN
|
|||||||
END IF;
|
END IF;
|
||||||
END LOOP;
|
END LOOP;
|
||||||
END $$;
|
END $$;
|
||||||
|
|
||||||
|
/*remove the constraint for project_id in table 'notification_policy'*/
|
||||||
|
ALTER TABLE notification_policy DROP CONSTRAINT unique_project_id;
|
||||||
|
|
||||||
|
/*add the unique constraint for name in table 'notification_policy'*/
|
||||||
|
ALTER TABLE notification_policy ADD UNIQUE (name);
|
||||||
|
@ -23,12 +23,18 @@ type NotificationPolicyAPI struct {
|
|||||||
|
|
||||||
// notificationPolicyForUI defines the structure of notification policy info display in UI
|
// notificationPolicyForUI defines the structure of notification policy info display in UI
|
||||||
type notificationPolicyForUI struct {
|
type notificationPolicyForUI struct {
|
||||||
|
PolicyName string `json:"policy_name"`
|
||||||
EventType string `json:"event_type"`
|
EventType string `json:"event_type"`
|
||||||
Enabled bool `json:"enabled"`
|
Enabled bool `json:"enabled"`
|
||||||
CreationTime *time.Time `json:"creation_time"`
|
CreationTime *time.Time `json:"creation_time"`
|
||||||
LastTriggerTime *time.Time `json:"last_trigger_time,omitempty"`
|
LastTriggerTime *time.Time `json:"last_trigger_time,omitempty"`
|
||||||
}
|
}
|
||||||
|
|
||||||
|
type notificationSupportedEventTypes struct {
|
||||||
|
EventType []string `json:"event_type"`
|
||||||
|
NotifyType []string `json:"notify_type"`
|
||||||
|
}
|
||||||
|
|
||||||
// Prepare ...
|
// Prepare ...
|
||||||
func (w *NotificationPolicyAPI) Prepare() {
|
func (w *NotificationPolicyAPI) Prepare() {
|
||||||
w.BaseController.Prepare()
|
w.BaseController.Prepare()
|
||||||
@ -256,6 +262,24 @@ func (w *NotificationPolicyAPI) Delete() {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// GetSupportedEventTypes get supported trigger event types and notify types in module notification
|
||||||
|
func (w *NotificationPolicyAPI) GetSupportedEventTypes() {
|
||||||
|
projectID := w.project.ProjectID
|
||||||
|
if !w.validateRBAC(rbac.ActionList, projectID) {
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
var notificationTypes = notificationSupportedEventTypes{}
|
||||||
|
for key := range notification.SupportedNotifyTypes {
|
||||||
|
notificationTypes.NotifyType = append(notificationTypes.NotifyType, key)
|
||||||
|
}
|
||||||
|
|
||||||
|
for key := range notification.SupportedEventTypes {
|
||||||
|
notificationTypes.EventType = append(notificationTypes.EventType, key)
|
||||||
|
}
|
||||||
|
w.WriteJSONData(notificationTypes)
|
||||||
|
}
|
||||||
|
|
||||||
// Test ...
|
// Test ...
|
||||||
func (w *NotificationPolicyAPI) Test() {
|
func (w *NotificationPolicyAPI) Test() {
|
||||||
projectID := w.project.ProjectID
|
projectID := w.project.ProjectID
|
||||||
@ -353,6 +377,7 @@ func constructPolicyWithTriggerTime(policies []*models.NotificationPolicy) ([]*n
|
|||||||
for _, policy := range policies {
|
for _, policy := range policies {
|
||||||
for _, t := range policy.EventTypes {
|
for _, t := range policy.EventTypes {
|
||||||
ply := ¬ificationPolicyForUI{
|
ply := ¬ificationPolicyForUI{
|
||||||
|
PolicyName: policy.Name,
|
||||||
EventType: t,
|
EventType: t,
|
||||||
Enabled: policy.Enabled,
|
Enabled: policy.Enabled,
|
||||||
CreationTime: &policy.CreationTime,
|
CreationTime: &policy.CreationTime,
|
||||||
|
@ -77,6 +77,7 @@ func registerLegacyRoutes() {
|
|||||||
beego.Router("/api/"+version+"/projects/:pid([0-9]+)/webhook/policies/:id([0-9]+)", &api.NotificationPolicyAPI{})
|
beego.Router("/api/"+version+"/projects/:pid([0-9]+)/webhook/policies/:id([0-9]+)", &api.NotificationPolicyAPI{})
|
||||||
beego.Router("/api/"+version+"/projects/:pid([0-9]+)/webhook/policies/test", &api.NotificationPolicyAPI{}, "post:Test")
|
beego.Router("/api/"+version+"/projects/:pid([0-9]+)/webhook/policies/test", &api.NotificationPolicyAPI{}, "post:Test")
|
||||||
beego.Router("/api/"+version+"/projects/:pid([0-9]+)/webhook/lasttrigger", &api.NotificationPolicyAPI{}, "get:ListGroupByEventType")
|
beego.Router("/api/"+version+"/projects/:pid([0-9]+)/webhook/lasttrigger", &api.NotificationPolicyAPI{}, "get:ListGroupByEventType")
|
||||||
|
beego.Router("/api/"+version+"/projects/:pid([0-9]+)/webhook/events", &api.NotificationPolicyAPI{}, "get:GetSupportedEventTypes")
|
||||||
beego.Router("/api/"+version+"/projects/:pid([0-9]+)/webhook/jobs/", &api.NotificationJobAPI{}, "get:List")
|
beego.Router("/api/"+version+"/projects/:pid([0-9]+)/webhook/jobs/", &api.NotificationJobAPI{}, "get:List")
|
||||||
|
|
||||||
beego.Router("/api/"+version+"/projects/:pid([0-9]+)/immutabletagrules", &api.ImmutableTagRuleAPI{}, "get:List;post:Post")
|
beego.Router("/api/"+version+"/projects/:pid([0-9]+)/immutabletagrules", &api.ImmutableTagRuleAPI{}, "get:List;post:Post")
|
||||||
|
Loading…
Reference in New Issue
Block a user