Commit d0b03178 authored by Carla Goncalves Ourofino's avatar Carla Goncalves Ourofino
Browse files

Merge branch 'new/soma-2553_token_header' into 'master'

SGA Posix trata token recebido nas chamadas REST

See merge request !37
parents 08de97b4 555cb374
export SGA_NAME="chuva"
export SGA_BASE_URL="http://localhost:12345"
case "$1" in
curl -v -H "Content-Type: application/json" -X POST -d '{
"cmd_string": "./",
"cmd_id": "gobo",
"parameters": {"foo": "bar" }
}' 'http://localhost:12345/v1/sga/chuva/job'
"cmd_string": "bash -c \"echo user token: \\$CSBASE_USER_TOKEN \" && sleep 10 && echo bye",
"cmd_id": "job_123",
"parameters": {
"csbase_command_path": "/tmp",
}' $SGA_BASE_URL'/v1/sga/'$SGA_NAME'/job'
......@@ -16,12 +25,13 @@ status)
curl -v 'http://localhost:12345/v1/sga/chuva/job/'$num'/status'
curl -v $SGA_BASE_URL'/v1/sga/'$SGA_NAME'/job/'$num'/status'
curl -v 'http://localhost:12345/v1/sga/chuva/path?name='$2
curl -v $SGA_BASE_URL'/v1/sga/'$SGA_NAME'/path?name='$2
......@@ -21,12 +21,19 @@ end
-- Execute a new command.
-- @param job The job object: is a writable table for driver data.
-- @param cmd_string The command string
-- @param user_token A string with a token to be exported as an envvar.
-- @return True if succeded or nil and an error message
function posix.execute_command(self, job, cmd_string)
function posix.execute_command(self, job, cmd_string, user_token)
self.active_commands = self.active_commands + 1
local job_cmd = cmd_string
-- Export the user token as an environment variable to the command string
if user_token then
job_cmd = "CSBASE_USER_TOKEN="..user_token.." "..job_cmd
for _, sandbox_path in ipairs(job.sandboxes) do
local ok, err = lfs.mkdir(sandbox_path)
if not ok then
......@@ -65,7 +72,7 @@ function posix.execute_command(self, job, cmd_string)
local start_time = os.time()
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
......@@ -220,10 +220,17 @@ function, logger, client, driver)
if sga_name ~= config.sga_name then
return fail_sga_name(sga_name)
-- FIXME Should we get the token from the request header? We could not get header info from API RestServer.
local user_token_key = "csbase_command_user_token"
local user_token = job_request.parameters[user_token_key]
job_request.parameters[user_token_key] = nil
self.logger:info("Received job: "..job_request.cmd_string.." "..job_request.cmd_id.." "..dkjson.encode(job_request.parameters))
local job = self.joblist:new_job(job_request.cmd_id, job_request.cmd_string, job_request.parameters)
local pok, ok, err = pcall(self.driver.execute_command, self.driver, job, job_request.cmd_string)
local pok, ok, err = pcall(self.driver.execute_command, self.driver, job, job_request.cmd_string, user_token)
self.joblist:accept_job(job, pok and ok)
if not pok then
fail(ok, 500)
......@@ -11,4 +11,4 @@ fi
eval $(luarocks path --bin)
sgad ${confgfile} >> "${logfile}" 2>&1
\ No newline at end of file
sgad ${confgfile} 2>&1 | tee -a "${logfile}"
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