Skip to content

Commit

Permalink
[hadrian.siregar|bimo.horizon] Inject user email to execution argumen…
Browse files Browse the repository at this point in the history
…t in execution post handler
  • Loading branch information
hadrianbs committed Oct 11, 2019
1 parent 27ef13f commit d12c05b
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 6 deletions.
10 changes: 6 additions & 4 deletions internal/app/service/execution/handler/http.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ import (
"proctor/internal/app/service/infra/config"
"proctor/internal/app/service/infra/logger"
serviceNotification "proctor/internal/app/service/notification/service"
"proctor/internal/pkg/constant"
"proctor/internal/pkg/model/execution"
"proctor/pkg/notification/event"
)
Expand Down Expand Up @@ -155,10 +156,10 @@ func (httpHandler *executionHTTPHandler) GetStatus() http.HandlerFunc {

response.WriteHeader(http.StatusOK)

responseJson, err := json.Marshal(responseBody)
responseJSON, err := json.Marshal(responseBody)
logger.LogErrors(err, "marshal json from: ", responseBody)

_, _ = response.Write(responseJson)
_, _ = response.Write(responseJSON)

}
}
Expand All @@ -179,6 +180,7 @@ func (httpHandler *executionHTTPHandler) Post() http.HandlerFunc {
_, _ = response.Write([]byte(status.MalformedRequest))
return
}
job.Args[constant.AuthorEmailKey] = userEmail

context, executionName, err := httpHandler.service.Execute(job.Name, userEmail, job.Args)

Expand All @@ -205,10 +207,10 @@ func (httpHandler *executionHTTPHandler) Post() http.HandlerFunc {

response.WriteHeader(http.StatusCreated)

responseJson, err := json.Marshal(responseBody)
responseJSON, err := json.Marshal(responseBody)
logger.LogErrors(err, "marshal json from: ", responseBody)

_, _ = response.Write(responseJson)
_, _ = response.Write(responseJSON)
return
}
}
10 changes: 8 additions & 2 deletions internal/app/service/execution/handler/http_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -261,7 +261,10 @@ func (suite *ExecutionHTTPHandlerTestSuite) TestSuccessfulJobExecutionPostHTTPHa
userEmail := "[email protected]"
job := parameter.Job{
Name: "sample-job-name",
Args: map[string]string{"argOne": "sample-arg"},
Args: map[string]string{
"argOne": "sample-arg",
"AUTHOR": userEmail,
},
}
context := &model.ExecutionContext{
UserEmail: userEmail,
Expand Down Expand Up @@ -321,7 +324,10 @@ func (suite *ExecutionHTTPHandlerTestSuite) TestGenericErrorJobExecutionPostHTTP
userEmail := "[email protected]"
job := parameter.Job{
Name: "sample-job-name",
Args: map[string]string{"argOne": "sample-arg"},
Args: map[string]string{
"argOne": "sample-arg",
"AUTHOR": userEmail,
},
}
context := &model.ExecutionContext{
UserEmail: userEmail,
Expand Down
1 change: 1 addition & 0 deletions internal/pkg/constant/constant.go
Original file line number Diff line number Diff line change
Expand Up @@ -49,3 +49,4 @@ const AccessTokenHeaderKey = "Access-Token"
const ClientVersionHeaderKey = "Client-Version"

const WorkerEmail = "worker@proctor"
const AuthorEmailKey = "AUTHOR"

0 comments on commit d12c05b

Please sign in to comment.