Commit 80f6aa60 authored by Isabella Almeida da Silva's avatar Isabella Almeida da Silva
Browse files

[SOMA-2553][SOMA-2650] Na sga/server.lua, passar token através do job

- Revertendo alterações no server.lua (não é mais preciso ler nada por
fora do driver, pois o token já vem dentro do objeto job)
- Alterando o driver posix para verificar se o token veio como parâmetro
e, se for o caso, exportar como variável de linha de comando
- Alterado o script request.sh para enviar um token 'fake' para testes
parent a019db92
......@@ -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'
;;
......
......@@ -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
......
......@@ -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)
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment