2017-09-26 12:50:09 +00:00
|
|
|
package biz
|
|
|
|
|
|
|
|
import (
|
|
|
|
"time"
|
|
|
|
|
|
|
|
"github.com/cuigh/auxo/log"
|
|
|
|
"github.com/cuigh/auxo/net/web"
|
|
|
|
"github.com/cuigh/swirl/dao"
|
2017-12-01 08:04:20 +00:00
|
|
|
"github.com/cuigh/swirl/misc"
|
2017-09-26 12:50:09 +00:00
|
|
|
"github.com/cuigh/swirl/model"
|
|
|
|
)
|
|
|
|
|
|
|
|
// Event return a event biz instance.
|
|
|
|
var Event = &eventBiz{}
|
|
|
|
|
|
|
|
type eventBiz struct {
|
|
|
|
}
|
|
|
|
|
|
|
|
func (b *eventBiz) Create(event *model.Event) {
|
2017-12-01 08:04:20 +00:00
|
|
|
event.ID = misc.NewID()
|
2017-09-26 12:50:09 +00:00
|
|
|
event.Time = time.Now()
|
|
|
|
|
|
|
|
do(func(d dao.Interface) {
|
|
|
|
err := d.EventCreate(event)
|
|
|
|
if err != nil {
|
|
|
|
log.Get("event").Errorf("Create event `%+v` failed: %v", event, err)
|
|
|
|
}
|
|
|
|
})
|
|
|
|
}
|
|
|
|
|
|
|
|
func (b *eventBiz) CreateRegistry(action model.EventAction, id, name string, user web.User) {
|
|
|
|
event := &model.Event{
|
|
|
|
Type: model.EventTypeRegistry,
|
|
|
|
Action: action,
|
|
|
|
Code: id,
|
|
|
|
Name: name,
|
|
|
|
UserID: user.ID(),
|
|
|
|
Username: user.Name(),
|
|
|
|
}
|
|
|
|
b.Create(event)
|
|
|
|
}
|
|
|
|
|
|
|
|
func (b *eventBiz) CreateService(action model.EventAction, name string, user web.User) {
|
|
|
|
event := &model.Event{
|
|
|
|
Type: model.EventTypeService,
|
|
|
|
Action: action,
|
|
|
|
Code: name,
|
|
|
|
Name: name,
|
|
|
|
UserID: user.ID(),
|
|
|
|
Username: user.Name(),
|
|
|
|
}
|
|
|
|
b.Create(event)
|
|
|
|
}
|
|
|
|
|
2017-10-09 13:02:41 +00:00
|
|
|
func (b *eventBiz) CreateServiceTemplate(action model.EventAction, id, name string, user web.User) {
|
|
|
|
event := &model.Event{
|
|
|
|
Type: model.EventTypeServiceTemplate,
|
|
|
|
Action: action,
|
|
|
|
Code: id,
|
|
|
|
Name: name,
|
|
|
|
UserID: user.ID(),
|
|
|
|
Username: user.Name(),
|
|
|
|
}
|
|
|
|
b.Create(event)
|
|
|
|
}
|
|
|
|
|
2017-09-26 12:50:09 +00:00
|
|
|
func (b *eventBiz) CreateNetwork(action model.EventAction, id, name string, user web.User) {
|
|
|
|
event := &model.Event{
|
|
|
|
Type: model.EventTypeNetwork,
|
|
|
|
Action: action,
|
|
|
|
Code: id,
|
|
|
|
Name: name,
|
|
|
|
UserID: user.ID(),
|
|
|
|
Username: user.Name(),
|
|
|
|
}
|
|
|
|
b.Create(event)
|
|
|
|
}
|
|
|
|
|
|
|
|
func (b *eventBiz) CreateVolume(action model.EventAction, name string, user web.User) {
|
|
|
|
event := &model.Event{
|
|
|
|
Type: model.EventTypeVolume,
|
|
|
|
Action: action,
|
|
|
|
Code: name,
|
|
|
|
Name: name,
|
|
|
|
UserID: user.ID(),
|
|
|
|
Username: user.Name(),
|
|
|
|
}
|
|
|
|
b.Create(event)
|
|
|
|
}
|
|
|
|
|
2018-04-16 09:21:20 +00:00
|
|
|
func (b *eventBiz) CreateStack(action model.EventAction, name string, user web.User) {
|
2017-09-26 12:50:09 +00:00
|
|
|
event := &model.Event{
|
2018-04-16 09:21:20 +00:00
|
|
|
Type: model.EventTypeStack,
|
2017-09-26 12:50:09 +00:00
|
|
|
Action: action,
|
|
|
|
Code: name,
|
|
|
|
Name: name,
|
|
|
|
UserID: user.ID(),
|
|
|
|
Username: user.Name(),
|
|
|
|
}
|
|
|
|
b.Create(event)
|
|
|
|
}
|
|
|
|
|
|
|
|
func (b *eventBiz) CreateSecret(action model.EventAction, name string, user web.User) {
|
|
|
|
event := &model.Event{
|
|
|
|
Type: model.EventTypeSecret,
|
|
|
|
Action: action,
|
|
|
|
Name: name,
|
|
|
|
UserID: user.ID(),
|
|
|
|
Username: user.Name(),
|
|
|
|
}
|
|
|
|
b.Create(event)
|
|
|
|
}
|
|
|
|
|
|
|
|
func (b *eventBiz) CreateConfig(action model.EventAction, name string, user web.User) {
|
|
|
|
event := &model.Event{
|
|
|
|
Type: model.EventTypeConfig,
|
|
|
|
Action: action,
|
|
|
|
Name: name,
|
|
|
|
UserID: user.ID(),
|
|
|
|
Username: user.Name(),
|
|
|
|
}
|
|
|
|
b.Create(event)
|
|
|
|
}
|
|
|
|
|
|
|
|
func (b *eventBiz) CreateRole(action model.EventAction, id, name string, user web.User) {
|
|
|
|
event := &model.Event{
|
|
|
|
Type: model.EventTypeRole,
|
|
|
|
Action: action,
|
|
|
|
Code: id,
|
|
|
|
Name: name,
|
|
|
|
UserID: user.ID(),
|
|
|
|
Username: user.Name(),
|
|
|
|
}
|
|
|
|
b.Create(event)
|
|
|
|
}
|
|
|
|
|
|
|
|
func (b *eventBiz) CreateUser(action model.EventAction, loginName, name string, user web.User) {
|
|
|
|
event := &model.Event{
|
|
|
|
Type: model.EventTypeUser,
|
|
|
|
Action: action,
|
|
|
|
Code: loginName,
|
|
|
|
Name: name,
|
|
|
|
UserID: user.ID(),
|
|
|
|
Username: user.Name(),
|
|
|
|
}
|
|
|
|
b.Create(event)
|
|
|
|
}
|
|
|
|
|
|
|
|
func (b *eventBiz) CreateSetting(action model.EventAction, user web.User) {
|
|
|
|
event := &model.Event{
|
|
|
|
Type: model.EventTypeSetting,
|
|
|
|
Action: action,
|
|
|
|
Code: "",
|
|
|
|
Name: "Setting",
|
|
|
|
UserID: user.ID(),
|
|
|
|
Username: user.Name(),
|
|
|
|
}
|
|
|
|
b.Create(event)
|
|
|
|
}
|
|
|
|
|
|
|
|
func (b *eventBiz) CreateAuthentication(action model.EventAction, userID, loginName, username string) {
|
|
|
|
event := &model.Event{
|
|
|
|
Type: model.EventTypeAuthentication,
|
|
|
|
Action: action,
|
|
|
|
Code: loginName,
|
|
|
|
Name: username,
|
|
|
|
UserID: userID,
|
|
|
|
Username: username,
|
|
|
|
}
|
|
|
|
b.Create(event)
|
|
|
|
}
|
|
|
|
|
|
|
|
func (b *eventBiz) List(args *model.EventListArgs) (events []*model.Event, count int, err error) {
|
|
|
|
do(func(d dao.Interface) {
|
|
|
|
events, count, err = d.EventList(args)
|
|
|
|
})
|
|
|
|
return
|
|
|
|
}
|