swirl/model/event.go

83 lines
2.4 KiB
Go
Raw Normal View History

2017-09-26 12:50:09 +00:00
package model
import (
"fmt"
"time"
)
type EventType string
const (
2017-10-09 13:02:41 +00:00
EventTypeRegistry EventType = "Registry"
EventTypeNode EventType = "Node"
EventTypeNetwork EventType = "Network"
EventTypeService EventType = "Service"
EventTypeServiceTemplate EventType = "Service Template"
2018-04-16 09:21:20 +00:00
EventTypeStack EventType = "Stack"
2017-10-09 13:02:41 +00:00
EventTypeSecret EventType = "Secret"
EventTypeConfig EventType = "Config"
2018-04-16 09:21:20 +00:00
EventTypeVolume EventType = "Volume"
EventTypeAuthentication EventType = "Authentication"
EventTypeRole EventType = "Role"
EventTypeUser EventType = "User"
EventTypeSetting EventType = "Setting"
2017-09-26 12:50:09 +00:00
)
type EventAction string
const (
2017-11-08 10:36:13 +00:00
EventActionLogin EventAction = "Login"
//EventActionLogout EventAction = "Logout"
2017-09-26 12:50:09 +00:00
EventActionCreate EventAction = "Create"
EventActionDelete EventAction = "Delete"
EventActionUpdate EventAction = "Update"
EventActionScale EventAction = "Scale"
2017-10-26 08:16:51 +00:00
EventActionRollback EventAction = "Rollback"
2018-04-10 03:25:55 +00:00
EventActionRestart EventAction = "Restart"
2017-09-26 12:50:09 +00:00
EventActionDisconnect EventAction = "Disconnect"
2018-04-16 09:21:20 +00:00
EventActionDeploy EventAction = "Deploy"
EventActionShutdown EventAction = "Shutdown"
2017-09-26 12:50:09 +00:00
)
type Event struct {
ID string `bson:"_id"`
Type EventType `bson:"type"`
Action EventAction `bson:"action"`
Code string `bson:"code"`
Name string `bson:"name"`
UserID string `bson:"user_id"`
Username string `bson:"username"`
Time time.Time `bson:"time"`
}
func (e *Event) URL(et EventType, code string) string {
switch et {
case EventTypeAuthentication:
return fmt.Sprintf("/system/user/%s/detail", code)
case EventTypeNode:
return fmt.Sprintf("/node/%s/detail", code)
case EventTypeNetwork:
return fmt.Sprintf("/network/%s/detail", code)
case EventTypeService:
return fmt.Sprintf("/service/%s/detail", code)
2018-04-16 09:21:20 +00:00
case EventTypeStack:
return fmt.Sprintf("/stack/%s/detail", code)
2017-09-26 12:50:09 +00:00
case EventTypeVolume:
return fmt.Sprintf("/volume/%s/detail", code)
case EventTypeRole:
return fmt.Sprintf("/system/role/%s/detail", code)
case EventTypeUser:
return fmt.Sprintf("/system/user/%s/detail", code)
case EventTypeSetting:
return "/system/setting/"
}
return ""
}
type EventListArgs struct {
2017-11-08 10:36:13 +00:00
Type string `bind:"type"`
Name string `bind:"name"`
PageIndex int `bind:"page"`
PageSize int `bind:"size"`
2017-09-26 12:50:09 +00:00
}