diff --git a/request.sh b/request.sh index 3f0f2ad1140538967249a4bf33ddb7f518160360..0cdd903ad433e7458720a4b4cdfeedcbbc31717a 100755 --- a/request.sh +++ b/request.sh @@ -6,7 +6,7 @@ export SGA_BASE_URL="http://localhost:12345" case "$1" in job) - curl -v -H "Content-Type: application/json" -H 'Authorization: USER_TOKEN' -X POST -d '{ + curl -v -H "Content-Type: application/json" -X POST -d '{ "cmd_string": "bash -c \"echo user token: \\$CSBASE_USER_TOKEN \" && sleep 10 && echo bye", "cmd_id": "job_123", "parameters": { @@ -14,6 +14,7 @@ job) "csbase_command_root_path":"/tmp", "csbase_command_output_path":"/tmp", "csbase_command_sandbox_paths.1":"/tmp/job_123", + "csbase_command_user_token":"USER_TOKEN", } }' $SGA_BASE_URL'/v1/sga/'$SGA_NAME'/job' ;; diff --git a/sga/driver/posix.lua b/sga/driver/posix.lua index 975447581a99e92f2e356fbd920d6b3eeb171442..894944f22b02111bee2c75a3ffdd5abfbc15603d 100644 --- a/sga/driver/posix.lua +++ b/sga/driver/posix.lua @@ -27,6 +27,12 @@ function posix.execute_command(self, job, cmd_string) filemonitor.init(job) + local job_cmd = cmd_string + -- Export the user token as an environment variable to the command string + if job.parameters.csbase_command_user_token then + job_cmd = "CSBASE_USER_TOKEN="..job.parameters.csbase_command_user_token.." "..job_cmd + end + for _, sandbox_path in ipairs(job.sandboxes) do local ok, err = lfs.mkdir(sandbox_path) if not ok then @@ -65,7 +71,7 @@ function posix.execute_command(self, job, cmd_string) end local start_time = os.time() - os.execute(cmd_string) + os.execute(job_cmd) local walltime_s = os.difftime(os.time(), start_time) ok, err = util.write_file(done_file(self, job.jid), walltime_s) if not ok then diff --git a/sga/server.lua b/sga/server.lua index 5a9905067a10ad34e81f6bd2dfdfd38e4ee4cd5f..7923bdb0b7c535dc7c88ddceb13f87ed45f5404f 100644 --- a/sga/server.lua +++ b/sga/server.lua @@ -224,10 +224,7 @@ function server.new(config, logger, client, driver) local job = self.joblist:new_job(job_request.cmd_id, job_request.cmd_string, job_request.parameters) - --TODO: Usar o valor do token obtido do header do request - local job_cmd = "CSBASE_USER_TOKEN=MEU_TOKEN "..job_request.cmd_string - - local pok, ok, err = pcall(self.driver.execute_command, self.driver, job, job_cmd) + local pok, ok, err = pcall(self.driver.execute_command, self.driver, job, job_request.cmd_string) self.joblist:accept_job(job, pok and ok) if not pok then fail(ok, 500)