Add CODEOCEAN environment variable.

This commit is contained in:
Maximilian Paß
2022-06-09 23:26:36 +02:00
committed by Sebastian Serth
parent 2f066a9fb4
commit 59ca63268b
2 changed files with 10 additions and 5 deletions

View File

@ -84,7 +84,7 @@ func (w *AWSFunctionWorkload) ExecuteInteractively(id string, _ io.ReadWriter, s
if !ok {
return nil, nil, ErrorUnknownExecution
}
w.prepareEnvironmentVariables(request)
hideEnvironmentVariables(request, "AWS")
command, ctx, cancel := prepareExecution(request)
exitInternal := make(chan ExitInfo)
exit := make(chan ExitInfo, 1)
@ -210,11 +210,10 @@ func (w *AWSFunctionWorkload) handleRunnerTimeout(ctx context.Context,
}
}
// prepareEnvironmentVariables sets the CODEOCEAN variable and unsets some AWS variables.
func (w *AWSFunctionWorkload) prepareEnvironmentVariables(request *dto.ExecutionRequest) {
// hideEnvironmentVariables sets the CODEOCEAN variable and unsets all variables starting with the passed prefix.
func hideEnvironmentVariables(request *dto.ExecutionRequest, unsetPrefix string) {
if request.Environment == nil {
request.Environment = make(map[string]string)
}
request.Environment["CODEOCEAN"] = "true"
request.Command = "unset \"${!AWS@}\" && " + request.Command
request.Command = "unset \"${!" + unsetPrefix + "@}\" && " + request.Command
}

View File

@ -25,6 +25,12 @@ type ExecutionRequest struct {
func (er *ExecutionRequest) FullCommand() []string {
command := make([]string, 0)
command = append(command, "env")
if er.Environment == nil {
er.Environment = make(map[string]string)
}
er.Environment["CODEOCEAN"] = "true"
for variable, value := range er.Environment {
command = append(command, fmt.Sprintf("%s=%s", variable, value))
}