Remove endpoint to retrieve jobs list

This commit is contained in:
Raul Ochoa 2016-08-30 18:49:01 +02:00
parent 704ba110ba
commit ba0f2f1066
2 changed files with 0 additions and 148 deletions

View File

@ -47,7 +47,6 @@ module.exports.getMaxSizeErrorMessage = getMaxSizeErrorMessage;
JobController.prototype.route = function (app) {
app.post(global.settings.base_url + '/sql/job', bodyPayloadSizeMiddleware, this.createJob.bind(this));
app.get(global.settings.base_url + '/sql/job', this.listJob.bind(this));
app.get(global.settings.base_url + '/sql/job/:job_id', this.getJob.bind(this));
app.delete(global.settings.base_url + '/sql/job/:job_id', this.cancelJob.bind(this));
};
@ -127,82 +126,6 @@ JobController.prototype.cancelJob = function (req, res) {
);
};
JobController.prototype.listJob = function (req, res) {
var self = this;
var body = (req.body) ? req.body : {};
var params = _.extend({}, req.query, body); // clone so don't modify req.params or req.body so oauth is not broken
var cdbUsername = cdbReq.userByReq(req);
if ( req.profiler ) {
req.profiler.start('sqlapi.job');
req.profiler.done('init');
}
step(
function getUserDBInfo() {
var next = this;
var authApi = new AuthApi(req, params);
self.userDatabaseService.getConnectionParams(authApi, cdbUsername, next);
},
function listJob(err, userDatabase) {
assert.ifError(err);
if (!userDatabase.authenticated) {
throw new Error('permission denied');
}
var next = this;
if ( req.profiler ) {
req.profiler.done('setDBAuth');
}
self.jobService.list(cdbUsername, function (err, jobs) {
if (err) {
return next(err);
}
next(null, {
jobs: jobs.map(function (job) {
return job.serialize();
}),
host: userDatabase.host
});
});
},
function handleResponse(err, result) {
if ( err ) {
return handleException(err, res);
}
if (global.settings.api_hostname) {
res.header('X-Served-By-Host', global.settings.api_hostname);
}
if (result.host) {
res.header('X-Served-By-DB-Host', result.host);
}
if ( req.profiler ) {
req.profiler.done('listJob');
req.profiler.end();
req.profiler.sendStats();
res.header('X-SQLAPI-Profiler', req.profiler.toJSONString());
}
if ( err ) {
self.statsdClient.increment('sqlapi.job.error');
} else {
self.statsdClient.increment('sqlapi.job.success');
}
res.send(result.jobs);
}
);
};
JobController.prototype.getJob = function (req, res) {
var self = this;
var job_id = req.params.job_id;

View File

@ -148,25 +148,6 @@ describe('job module', function() {
});
});
it('GET /api/v2/sql/job/ with wrong host header respond with 404 not found', function (done){
assert.response(app, {
url: '/api/v2/sql/job?api_key=1234',
headers: { 'host': 'wrong-host.cartodb.com', 'Content-Type': 'application/x-www-form-urlencoded' },
method: 'GET'
}, {
status: 404
}, function(res) {
var error = JSON.parse(res.body);
assert.deepEqual(error , {
error: [
'Sorry, we can\'t find CartoDB user \'wrong-host\'. ' +
'Please check that you have entered the correct domain.'
]
});
done();
});
});
it('GET /api/v2/sql/job/:jobId with wrong jobId header respond with 400 and an error', function (done){
assert.response(app, {
url: '/api/v2/sql/job/irrelevantJob?api_key=1234',
@ -184,58 +165,6 @@ describe('job module', function() {
});
});
it('GET /api/v2/sql/job/ should respond with 200 and a job\'s list', function (done){
assert.response(app, {
url: '/api/v2/sql/job?api_key=1234',
headers: { 'host': 'vizzuality.cartodb.com', 'Content-Type': 'application/x-www-form-urlencoded' },
method: 'GET'
}, {
status: 200
}, function(res) {
var jobs = JSON.parse(res.body);
assert.deepEqual(res.headers['content-type'], 'application/json; charset=utf-8');
assert.ok(jobs instanceof Array);
assert.ok(jobs.length > 0);
assert.ok(jobs[0].job_id);
assert.ok(jobs[0].status);
assert.ok(jobs[0].query);
done();
});
});
it('GET /api/v2/sql/job/ with wrong api key should respond with 401 permission denied', function (done){
assert.response(app, {
url: '/api/v2/sql/job?api_key=wrong',
headers: { 'host': 'vizzuality.cartodb.com', 'Content-Type': 'application/x-www-form-urlencoded' },
method: 'GET'
}, {
status: 401
}, function(res) {
var error = JSON.parse(res.body);
assert.deepEqual(error, { error: [ 'permission denied' ] });
done();
});
});
it('GET /api/v2/sql/job/ without host header respond with 404 not found', function (done){
assert.response(app, {
url: '/api/v2/sql/job?api_key=1234',
headers: { 'host': 'wrong-host.cartodb.com', 'Content-Type': 'application/x-www-form-urlencoded' },
method: 'GET'
}, {
status: 404
}, function(res) {
var error = JSON.parse(res.body);
assert.deepEqual(error , {
error: [
'Sorry, we can\'t find CartoDB user \'wrong-host\'. ' +
'Please check that you have entered the correct domain.'
]
});
done();
});
});
it('DELETE /api/v2/sql/job/:job_id should respond with 200 and the requested job', function (done){
assert.response(app, {
url: '/api/v2/sql/job/' + job.job_id + '?api_key=1234',