Pass context to event publishing.
To allow tracing propagation via events, we need to pass the context to the `Publish` function of reva events. This adds the context everywhere where events are published. If there was no context to pass, we started a new one with `context.Background()`.
This commit is contained in:
@@ -104,7 +104,7 @@ func (g Graph) CreateAppRoleAssignment(w http.ResponseWriter, r *http.Request) {
|
||||
if currentUser, ok := revactx.ContextGetUser(r.Context()); ok {
|
||||
e.Executant = currentUser.GetId()
|
||||
}
|
||||
g.publishEvent(e)
|
||||
g.publishEvent(r.Context(), e)
|
||||
render.Status(r, http.StatusCreated)
|
||||
render.JSON(w, r, g.assignmentToAppRoleAssignment(artur.GetAssignment()))
|
||||
}
|
||||
|
||||
@@ -185,7 +185,7 @@ func (g Graph) PatchEducationClass(w http.ResponseWriter, r *http.Request) {
|
||||
if currentUser, ok := revactx.ContextGetUser(r.Context()); ok {
|
||||
e.Executant = currentUser.GetId()
|
||||
}
|
||||
g.publishEvent(e)
|
||||
g.publishEvent(r.Context(), e)
|
||||
|
||||
}
|
||||
|
||||
|
||||
@@ -146,7 +146,7 @@ func (g Graph) PostEducationUser(w http.ResponseWriter, r *http.Request) {
|
||||
if currentUser, ok := revactx.ContextGetUser(r.Context()); ok {
|
||||
e.Executant = currentUser.GetId()
|
||||
}
|
||||
g.publishEvent(e)
|
||||
g.publishEvent(r.Context(), e)
|
||||
|
||||
render.Status(r, http.StatusOK)
|
||||
render.JSON(w, r, u)
|
||||
@@ -172,7 +172,6 @@ func (g Graph) GetEducationUser(w http.ResponseWriter, r *http.Request) {
|
||||
|
||||
logger.Debug().Str("id", userID).Msg("calling get education user from backend")
|
||||
user, err := g.identityEducationBackend.GetEducationUser(r.Context(), userID)
|
||||
|
||||
if err != nil {
|
||||
logger.Debug().Err(err).Msg("could not get education user: error fetching education user from backend")
|
||||
errorcode.RenderError(w, r, err)
|
||||
@@ -288,7 +287,7 @@ func (g Graph) DeleteEducationUser(w http.ResponseWriter, r *http.Request) {
|
||||
return
|
||||
}
|
||||
|
||||
g.publishEvent(e)
|
||||
g.publishEvent(r.Context(), e)
|
||||
|
||||
render.Status(r, http.StatusNoContent)
|
||||
render.NoContent(w, r)
|
||||
@@ -368,11 +367,10 @@ func (g Graph) PatchEducationUser(w http.ResponseWriter, r *http.Request) {
|
||||
if currentUser, ok := revactx.ContextGetUser(r.Context()); ok {
|
||||
e.Executant = currentUser.GetId()
|
||||
}
|
||||
g.publishEvent(e)
|
||||
g.publishEvent(r.Context(), e)
|
||||
|
||||
render.Status(r, http.StatusOK) // TODO StatusNoContent when prefer=minimal is used
|
||||
render.JSON(w, r, u)
|
||||
|
||||
}
|
||||
|
||||
func sortEducationUsers(req *godata.GoDataRequest, users []*libregraph.EducationUser) ([]*libregraph.EducationUser, error) {
|
||||
|
||||
@@ -89,9 +89,9 @@ func (g Graph) ServeHTTP(w http.ResponseWriter, r *http.Request) {
|
||||
g.mux.ServeHTTP(w, r)
|
||||
}
|
||||
|
||||
func (g Graph) publishEvent(ev interface{}) {
|
||||
func (g Graph) publishEvent(ctx context.Context, ev interface{}) {
|
||||
if g.eventsPublisher != nil {
|
||||
if err := events.Publish(g.eventsPublisher, ev); err != nil {
|
||||
if err := events.Publish(ctx, g.eventsPublisher, ev); err != nil {
|
||||
g.logger.Error().
|
||||
Err(err).
|
||||
Msg("could not publish user created event")
|
||||
|
||||
@@ -95,7 +95,7 @@ func (g Graph) PostGroup(w http.ResponseWriter, r *http.Request) {
|
||||
if currentUser, ok := revactx.ContextGetUser(r.Context()); ok {
|
||||
e.Executant = currentUser.GetId()
|
||||
}
|
||||
g.publishEvent(e)
|
||||
g.publishEvent(r.Context(), e)
|
||||
}
|
||||
render.Status(r, http.StatusOK) // FIXME 201 should return 201 created
|
||||
render.JSON(w, r, grp)
|
||||
@@ -256,7 +256,7 @@ func (g Graph) DeleteGroup(w http.ResponseWriter, r *http.Request) {
|
||||
if currentUser, ok := revactx.ContextGetUser(r.Context()); ok {
|
||||
e.Executant = currentUser.GetId()
|
||||
}
|
||||
g.publishEvent(e)
|
||||
g.publishEvent(r.Context(), e)
|
||||
render.Status(r, http.StatusNoContent)
|
||||
render.NoContent(w, r)
|
||||
}
|
||||
@@ -366,7 +366,7 @@ func (g Graph) PostGroupMember(w http.ResponseWriter, r *http.Request) {
|
||||
if currentUser, ok := revactx.ContextGetUser(r.Context()); ok {
|
||||
e.Executant = currentUser.GetId()
|
||||
}
|
||||
g.publishEvent(e)
|
||||
g.publishEvent(r.Context(), e)
|
||||
render.Status(r, http.StatusNoContent)
|
||||
render.NoContent(w, r)
|
||||
}
|
||||
@@ -418,7 +418,7 @@ func (g Graph) DeleteGroupMember(w http.ResponseWriter, r *http.Request) {
|
||||
if currentUser, ok := revactx.ContextGetUser(r.Context()); ok {
|
||||
e.Executant = currentUser.GetId()
|
||||
}
|
||||
g.publishEvent(e)
|
||||
g.publishEvent(r.Context(), e)
|
||||
render.Status(r, http.StatusNoContent)
|
||||
render.NoContent(w, r)
|
||||
}
|
||||
|
||||
@@ -96,6 +96,7 @@ func (g Graph) ChangeOwnPassword(w http.ResponseWriter, r *http.Request) {
|
||||
|
||||
currentUser := revactx.ContextMustGetUser(r.Context())
|
||||
g.publishEvent(
|
||||
ctx,
|
||||
events.UserFeatureChanged{
|
||||
Executant: currentUser.Id,
|
||||
UserID: u.Id.OpaqueId,
|
||||
|
||||
@@ -141,7 +141,7 @@ func (g Graph) GatherPersonalData(usr *user.User, ref *provider.Reference, token
|
||||
errmsg = err.Error()
|
||||
}
|
||||
|
||||
if err := events.Publish(g.eventsPublisher, events.PersonalDataExtracted{
|
||||
if err := events.Publish(ctx, g.eventsPublisher, events.PersonalDataExtracted{
|
||||
Executant: usr.GetId(),
|
||||
Timestamp: utils.TSNow(),
|
||||
ErrorMsg: errmsg,
|
||||
|
||||
@@ -135,7 +135,7 @@ func (g Graph) AssignTags(w http.ResponseWriter, r *http.Request) {
|
||||
SpaceOwner: sres.Info.Owner,
|
||||
Executant: revaCtx.ContextMustGetUser(r.Context()).Id,
|
||||
}
|
||||
if err := events.Publish(g.eventsPublisher, ev); err != nil {
|
||||
if err := events.Publish(r.Context(), g.eventsPublisher, ev); err != nil {
|
||||
g.logger.Error().Err(err).Msg("Failed to publish TagsAdded event")
|
||||
}
|
||||
}
|
||||
@@ -230,7 +230,7 @@ func (g Graph) UnassignTags(w http.ResponseWriter, r *http.Request) {
|
||||
SpaceOwner: sres.Info.Owner,
|
||||
Executant: revaCtx.ContextMustGetUser(r.Context()).Id,
|
||||
}
|
||||
if err := events.Publish(g.eventsPublisher, ev); err != nil {
|
||||
if err := events.Publish(ctx, g.eventsPublisher, ev); err != nil {
|
||||
g.logger.Error().Err(err).Msg("Failed to publish TagsAdded event")
|
||||
}
|
||||
}
|
||||
|
||||
@@ -332,7 +332,7 @@ func (g Graph) PostUser(w http.ResponseWriter, r *http.Request) {
|
||||
if currentUser, ok := revactx.ContextGetUser(r.Context()); ok {
|
||||
e.Executant = currentUser.GetId()
|
||||
}
|
||||
g.publishEvent(e)
|
||||
g.publishEvent(r.Context(), e)
|
||||
|
||||
render.Status(r, http.StatusOK) // FIXME 201 should return 201 created
|
||||
render.JSON(w, r, u)
|
||||
@@ -375,7 +375,6 @@ func (g Graph) GetUser(w http.ResponseWriter, r *http.Request) {
|
||||
|
||||
logger.Debug().Str("id", userID).Msg("calling get user from backend")
|
||||
user, err := g.identityBackend.GetUser(r.Context(), userID, odataReq)
|
||||
|
||||
if err != nil {
|
||||
logger.Debug().Err(err).Msg("could not get user: error fetching user from backend")
|
||||
errorcode.RenderError(w, r, err)
|
||||
@@ -594,7 +593,7 @@ func (g Graph) DeleteUser(w http.ResponseWriter, r *http.Request) {
|
||||
return
|
||||
}
|
||||
|
||||
g.publishEvent(e)
|
||||
g.publishEvent(r.Context(), e)
|
||||
|
||||
render.Status(r, http.StatusNoContent)
|
||||
render.NoContent(w, r)
|
||||
@@ -725,11 +724,10 @@ func (g Graph) PatchUser(w http.ResponseWriter, r *http.Request) {
|
||||
if currentUser, ok := revactx.ContextGetUser(r.Context()); ok {
|
||||
e.Executant = currentUser.GetId()
|
||||
}
|
||||
g.publishEvent(e)
|
||||
g.publishEvent(r.Context(), e)
|
||||
|
||||
render.Status(r, http.StatusOK) // TODO StatusNoContent when prefer=minimal is used
|
||||
render.JSON(w, r, u)
|
||||
|
||||
}
|
||||
|
||||
const (
|
||||
|
||||
Reference in New Issue
Block a user