Skip to content

fix(api): don't try to load cds.scheduler user #5239

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Jun 8, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
28 changes: 18 additions & 10 deletions engine/api/notification/user.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,13 @@ func Init(uiurl string) {
uiURL = uiurl
}

const (
paramsAuthorEmail = "cds.author.email"
paramsAuthorName = "cds.author"
paramsStatus = "cds.status"
paramsBuildURL = "cds.buildURL"
)

// GetUserWorkflowEvents return events to send for the given workflow run
func GetUserWorkflowEvents(ctx context.Context, db gorp.SqlExecutor, store cache.Store, projectID int64, projectKey, workflowName string, notifs []sdk.WorkflowNotification, previousWR *sdk.WorkflowNodeRun, nr sdk.WorkflowNodeRun) []sdk.EventNotif {
events := []sdk.EventNotif{}
Expand All @@ -33,18 +40,18 @@ func GetUserWorkflowEvents(ctx context.Context, db gorp.SqlExecutor, store cache
params[p.Name] = p.Value
}
//Set PipelineBuild UI URL
params["cds.buildURL"] = fmt.Sprintf("%s/project/%s/workflow/%s/run/%d", uiURL, projectKey, workflowName, nr.Number)
params[paramsBuildURL] = fmt.Sprintf("%s/project/%s/workflow/%s/run/%d", uiURL, projectKey, workflowName, nr.Number)
if p, ok := params["cds.triggered_by.email"]; ok {
params["cds.author.email"] = p
params[paramsAuthorEmail] = p
} else if p, ok := params["git.author.email"]; ok {
params["cds.author.email"] = p
params[paramsAuthorEmail] = p
}
if p, ok := params["cds.triggered_by.username"]; ok {
params["cds.author"] = p
params[paramsAuthorName] = p
} else if p, ok := params["git.author"]; ok {
params["cds.author"] = p
params[paramsAuthorName] = p
}
params["cds.status"] = nr.Status
params[paramsStatus] = nr.Status

for _, notif := range notifs {
if ShouldSendUserWorkflowNotification(ctx, notif, nr, previousWR) {
Expand All @@ -68,7 +75,7 @@ func GetUserWorkflowEvents(ctx context.Context, db gorp.SqlExecutor, store cache
}
}
if jn.SendToAuthor == nil || *jn.SendToAuthor {
if author, ok := params["cds.author.email"]; ok {
if author, ok := params[paramsAuthorEmail]; ok {
jn.Recipients = append(jn.Recipients, author)
}
}
Expand Down Expand Up @@ -102,13 +109,14 @@ func GetUserWorkflowEvents(ctx context.Context, db gorp.SqlExecutor, store cache
}
}
if jn.SendToAuthor == nil || *jn.SendToAuthor {
if email, ok := params["cds.author.email"]; ok {
if email, ok := params[paramsAuthorEmail]; ok {
jn.Recipients = append(jn.Recipients, email)
} else if author, okA := params["cds.author"]; okA && author != "" {
} else if author, okA := params[paramsAuthorName]; okA &&
author != "" && author != sdk.SchedulerUsername {
// Load the user
au, err := user.LoadByUsername(ctx, db, author)
if err != nil {
log.Warning(ctx, "notification[Email].GetUserWorkflowEvents> Cannot load author %s: %s", author, err)
log.Error(ctx, "notification[Email].GetUserWorkflowEvents> Cannot load author %s: %s", author, err)
continue
}
jn.Recipients = append(jn.Recipients, au.GetEmail())
Expand Down
4 changes: 2 additions & 2 deletions engine/hooks/scheduled_task.go
Original file line number Diff line number Diff line change
Expand Up @@ -49,8 +49,8 @@ func (s *Service) doScheduledTaskExecution(ctx context.Context, t *sdk.TaskExecu
payloadValues[k] = v.Value
}
}
payloadValues["cds.triggered_by.username"] = "cds.scheduler"
payloadValues["cds.triggered_by.fullname"] = "CDS Scheduler"
payloadValues["cds.triggered_by.username"] = sdk.SchedulerUsername
payloadValues["cds.triggered_by.fullname"] = sdk.SchedulerFullname
h.Payload = payloadValues

return &h, nil
Expand Down
2 changes: 2 additions & 0 deletions sdk/hook.go
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,8 @@ const (
RabbitMQHookModelExchangeType = "exchange_type"
RabbitMQHookModelExchangeName = "exchange_name"
RabbitMQHookModelConsumerTag = "consumer_tag"
SchedulerUsername = "cds.scheduler"
SchedulerFullname = "CDS Scheduler"
)

// Here are the default hooks
Expand Down