func deployDataToEvent(data *DeployData) error { var evt event.Event evt.UniqueID = data.ID evt.Target = event.Target{Type: event.TargetTypeApp, Value: data.App} evt.Owner = event.Owner{Type: event.OwnerTypeUser, Name: data.User} evt.Kind = event.Kind{Type: event.KindTypePermission, Name: permission.PermAppDeploy.FullName()} evt.StartTime = data.Timestamp evt.EndTime = data.Timestamp.Add(data.Duration) evt.Error = data.Error evt.Log = data.Log evt.RemoveDate = data.RemoveDate a, err := GetByName(data.App) if err == nil { evt.Allowed = event.Allowed(permission.PermAppReadEvents, append(permission.Contexts(permission.CtxTeam, a.Teams), permission.Context(permission.CtxApp, a.Name), permission.Context(permission.CtxPool, a.Pool), )...) } else { evt.Allowed = event.Allowed(permission.PermAppReadEvents) } startOpts := DeployOptions{ Commit: data.Commit, Origin: data.Origin, } var otherData map[string]string if data.Diff != "" { otherData = map[string]string{"diff": data.Diff} } endData := map[string]string{"image": data.Image} err = evt.RawInsert(startOpts, otherData, endData) if mgo.IsDup(err) { return nil } return err }
func (s *S) TestMigrateRCEventsNoApp(c *check.C) { now := time.Unix(time.Now().Unix(), 0) id := bson.NewObjectId() var expected event.Event expected.UniqueID = id expected.Target = event.Target{Type: event.TargetTypeApp, Value: "a1"} expected.Owner = event.Owner{Type: event.OwnerTypeUser, Name: "u1"} expected.Kind = event.Kind{Type: event.KindTypePermission, Name: permission.PermAppDeploy.FullName()} expected.StartTime = now expected.EndTime = now.Add(time.Minute) expected.Error = "err1" expected.Log = "log1" expected.Allowed = event.Allowed(permission.PermAppReadEvents) s.checkEvtMatch(&expected, c) }
func (s *S) TestMigrateRCEventsWithApp(c *check.C) { a := app.App{Name: "a1", Platform: "zend", TeamOwner: s.team.Name} err := app.CreateApp(&a, s.user) c.Assert(err, check.IsNil) now := time.Unix(time.Now().Unix(), 0) id := bson.NewObjectId() var expected event.Event expected.UniqueID = id expected.Target = event.Target{Type: event.TargetTypeApp, Value: "a1"} expected.Owner = event.Owner{Type: event.OwnerTypeUser, Name: "u1"} expected.Kind = event.Kind{Type: event.KindTypePermission, Name: permission.PermAppDeploy.FullName()} expected.StartTime = now expected.EndTime = now.Add(time.Minute) expected.Error = "err1" expected.Log = "log1" expected.Allowed = event.Allowed(permission.PermAppReadEvents, append(permission.Contexts(permission.CtxTeam, a.Teams), permission.Context(permission.CtxApp, a.Name), permission.Context(permission.CtxPool, a.Pool), )..., ) s.checkEvtMatch(&expected, c) }