diff --git a/Makefile b/Makefile index b2c773f0..a7601016 100644 --- a/Makefile +++ b/Makefile @@ -11,7 +11,7 @@ check: jshint: @echo "***jshint***" - @./node_modules/.bin/jshint app/ batch/ test/ app.js + @./node_modules/.bin/jshint lib/ test/ app.js TEST_SUITE := $(shell find test/{unit,integration,acceptance} -name "*.js") TEST_SUITE_UNIT := $(shell find test/unit -name "*.js") diff --git a/app.js b/app.js index 1b51e930..fe839904 100755 --- a/app.js +++ b/app.js @@ -69,15 +69,10 @@ if (global.settings.log_filename) { global.log4js.configure(log4jsConfig); global.logger = global.log4js.getLogger(); - -// kick off controller -if ( ! global.settings.base_url ) { - global.settings.base_url = '/api/*'; -} - const version = require("./package").version; -const StatsClient = require('./app/stats/client'); +const StatsClient = require('./lib/stats/client'); + if (global.settings.statsd) { // Perform keyword substitution in statsd if (global.settings.statsd.prefix) { @@ -86,9 +81,9 @@ if (global.settings.statsd) { } const statsClient = StatsClient.getInstance(global.settings.statsd); -const serverFactory = require('./app/server'); +const createServer = require('./lib/server'); -const server = serverFactory(statsClient); +const server = createServer(statsClient); const listener = server.listen(global.settings.node_port, global.settings.node_host); listener.on('listening', function() { console.info("Using Node.js %s", process.version); diff --git a/app/controllers/api-router.js b/app/controllers/api-router.js deleted file mode 100644 index d38fc645..00000000 --- a/app/controllers/api-router.js +++ /dev/null @@ -1,84 +0,0 @@ -'use strict'; - -const { Router: router } = require('express'); - -const UserDatabaseService = require('../services/user_database_service'); -const UserLimitsService = require('../services/user_limits'); - -const BatchLogger = require('../../batch/batch-logger'); - -const JobPublisher = require('../../batch/pubsub/job-publisher'); -const JobQueue = require('../../batch/job_queue'); -const JobBackend = require('../../batch/job_backend'); -const JobCanceller = require('../../batch/job_canceller'); -const JobService = require('../../batch/job_service'); - -const QueryController = require('./query_controller'); -const CopyController = require('./copy_controller'); -const JobController = require('./job_controller'); - -const socketTimeout = require('../middlewares/socket-timeout'); -const logger = require('../middlewares/logger'); -const profiler = require('../middlewares/profiler'); -const cors = require('../middlewares/cors'); -const servedByHostHeader = require('../middlewares/served-by-host-header'); - -module.exports = class ApiRouter { - constructor ({ redisPool, metadataBackend, statsClient, dataIngestionLogger }) { - this.statsClient = statsClient; - - const userLimitsServiceOptions = { - limits: { - rateLimitsEnabled: global.settings.ratelimits.rateLimitsEnabled - } - }; - - const userDatabaseService = new UserDatabaseService(metadataBackend); - const userLimitsService = new UserLimitsService(metadataBackend, userLimitsServiceOptions); - - this.queryController = new QueryController( - metadataBackend, - userDatabaseService, - statsClient, - userLimitsService - ); - - this.copyController = new CopyController( - metadataBackend, - userDatabaseService, - userLimitsService, - dataIngestionLogger - ); - - const logger = new BatchLogger(global.settings.batch_log_filename, 'batch-queries'); - const jobPublisher = new JobPublisher(redisPool); - const jobQueue = new JobQueue(metadataBackend, jobPublisher, logger); - const jobBackend = new JobBackend(metadataBackend, jobQueue, logger); - const jobCanceller = new JobCanceller(); - const jobService = new JobService(jobBackend, jobCanceller, logger); - - this.jobController = new JobController( - metadataBackend, - userDatabaseService, - jobService, - statsClient, - userLimitsService - ); - } - - route (app) { - const apiRouter = router({ mergeParams: true }); - - apiRouter.use(socketTimeout()); - apiRouter.use(logger()); - apiRouter.use(profiler({ statsClient: this.statsClient })); - apiRouter.use(cors()); - apiRouter.use(servedByHostHeader()); - - this.queryController.route(apiRouter); - this.copyController.route(apiRouter); - this.jobController.route(apiRouter); - - app.use(`${global.settings.base_url}`, apiRouter); - } -}; diff --git a/config/environments/development.js.example b/config/environments/development.js.example index 845f453c..343897e0 100644 --- a/config/environments/development.js.example +++ b/config/environments/development.js.example @@ -1,9 +1,36 @@ // Time in milliseconds to force GC cycle. // Disable by using <=0 value. module.exports.gc_interval = 10000; -// In case the base_url has a :user param the username will be the one specified in the URL, -// otherwise it will fallback to extract the username from the host header. -module.exports.base_url = '(?:/api/:version|/user/:user/api/:version)'; +module.exports.routes = { + // Each entry corresponds with an express' router. + // You must define at least one path. However, middlewares are optional. + api: [{ + // Required: path where other "routers" or "controllers" will be attached to. + paths: [ + // In case the path has a :user param the username will be the one specified in the URL, + // otherwise it will fallback to extract the username from the host header. + '/api/:version', + '/user/:user/api/:version', + ], + // Optional: attach middlewares at the begining of the router + // to perform custom operations. + middlewares: [ + function noop () { + return function noopMiddleware (req, res, next) { + next(); + } + } + ], + sql: [{ + // Required + paths: [ + '/sql' + ], + // Optional + middlewares: [] + }] + }] +}; // If useProfiler is true every response will be served with an // X-SQLAPI-Profile header containing elapsed timing for various // steps taken for producing the response. diff --git a/config/environments/production.js.example b/config/environments/production.js.example index ac663399..6ca0fc8d 100644 --- a/config/environments/production.js.example +++ b/config/environments/production.js.example @@ -1,9 +1,36 @@ // Time in milliseconds to force GC cycle. // Disable by using <=0 value. module.exports.gc_interval = 10000; -// In case the base_url has a :user param the username will be the one specified in the URL, -// otherwise it will fallback to extract the username from the host header. -module.exports.base_url = '(?:/api/:version|/user/:user/api/:version)'; +module.exports.routes = { + // Each entry corresponds with an express' router. + // You must define at least one path. However, middlewares are optional. + api: [{ + // Required: path where other "routers" or "controllers" will be attached to. + paths: [ + // In case the path has a :user param the username will be the one specified in the URL, + // otherwise it will fallback to extract the username from the host header. + '/api/:version', + '/user/:user/api/:version', + ], + // Optional: attach middlewares at the begining of the router + // to perform custom operations. + middlewares: [ + function noop () { + return function noopMiddleware (req, res, next) { + next(); + } + } + ], + sql: [{ + // Required + paths: [ + '/sql' + ], + // Optional + middlewares: [] + }] + }] +}; // If useProfiler is true every response will be served with an // X-SQLAPI-Profile header containing elapsed timing for various // steps taken for producing the response. diff --git a/config/environments/staging.js.example b/config/environments/staging.js.example index 06e91ec5..abbb7e01 100644 --- a/config/environments/staging.js.example +++ b/config/environments/staging.js.example @@ -1,9 +1,36 @@ // Time in milliseconds to force GC cycle. // Disable by using <=0 value. module.exports.gc_interval = 10000; -// In case the base_url has a :user param the username will be the one specified in the URL, -// otherwise it will fallback to extract the username from the host header. -module.exports.base_url = '(?:/api/:version|/user/:user/api/:version)'; +module.exports.routes = { + // Each entry corresponds with an express' router. + // You must define at least one path. However, middlewares are optional. + api: [{ + // Required: path where other "routers" or "controllers" will be attached to. + paths: [ + // In case the path has a :user param the username will be the one specified in the URL, + // otherwise it will fallback to extract the username from the host header. + '/api/:version', + '/user/:user/api/:version', + ], + // Optional: attach middlewares at the begining of the router + // to perform custom operations. + middlewares: [ + function noop () { + return function noopMiddleware (req, res, next) { + next(); + } + } + ], + sql: [{ + // Required + paths: [ + '/sql' + ], + // Optional + middlewares: [] + }] + }] +}; // If useProfiler is true every response will be served with an // X-SQLAPI-Profile header containing elapsed timing for various // steps taken for producing the response. diff --git a/config/environments/test.js.example b/config/environments/test.js.example index 5a123e90..2f8cddf3 100644 --- a/config/environments/test.js.example +++ b/config/environments/test.js.example @@ -1,9 +1,36 @@ // Time in milliseconds to force GC cycle. // Disable by using <=0 value. module.exports.gc_interval = 10000; -// In case the base_url has a :user param the username will be the one specified in the URL, -// otherwise it will fallback to extract the username from the host header. -module.exports.base_url = '(?:/api/:version|/user/:user/api/:version)'; +module.exports.routes = { + // Each entry corresponds with an express' router. + // You must define at least one path. However, middlewares are optional. + api: [{ + // Required: path where other "routers" or "controllers" will be attached to. + paths: [ + // In case the path has a :user param the username will be the one specified in the URL, + // otherwise it will fallback to extract the username from the host header. + '/api/:version', + '/user/:user/api/:version', + ], + // Optional: attach middlewares at the begining of the router + // to perform custom operations. + middlewares: [ + function noop () { + return function noopMiddleware (req, res, next) { + next(); + } + } + ], + sql: [{ + // Required + paths: [ + '/sql' + ], + // Optional + middlewares: [] + }] + }] +}; // If useProfiler is true every response will be served with an // X-SQLAPI-Profile header containing elapsed timing for various // steps taken for producing the response. diff --git a/lib/api/api-router.js b/lib/api/api-router.js new file mode 100644 index 00000000..75501467 --- /dev/null +++ b/lib/api/api-router.js @@ -0,0 +1,64 @@ +'use strict'; + +const { Router: router } = require('express'); + +const SqlRouter = require('./sql/sql-router'); + +const HealthCheckController = require('./health-check-controller'); +const VersionController = require('./version-controller'); +const JobsWipController = require('./jobs-wip-controller'); + +const BatchLogger = require('../batch/batch-logger'); + +const JobPublisher = require('../batch/pubsub/job-publisher'); +const JobQueue = require('../batch/job-queue'); +const JobBackend = require('../batch/job-backend'); +const JobCanceller = require('../batch/job-canceller'); +const JobService = require('../batch/job-service'); + +module.exports = class ApiRouter { + constructor ({ redisPool, metadataBackend, statsClient, dataIngestionLogger }) { + const logger = new BatchLogger(global.settings.batch_log_filename, 'batch-queries'); + const jobPublisher = new JobPublisher(redisPool); + const jobQueue = new JobQueue(metadataBackend, jobPublisher, logger); + const jobBackend = new JobBackend(metadataBackend, jobQueue, logger); + const jobCanceller = new JobCanceller(); + const jobService = new JobService(jobBackend, jobCanceller, logger); + + this.healthCheckController = new HealthCheckController(); + this.versionController = new VersionController(); + this.jobsWipController = new JobsWipController({ jobService }); + + this.sqlRouter = new SqlRouter({ + metadataBackend, + statsClient, + dataIngestionLogger, + jobService + }); + } + + route (app, routes) { + routes.forEach(route => { + const apiRouter = router({ mergeParams: true }); + + const paths = route.paths; + const middlewares = route.middlewares || []; + + middlewares.forEach(middleware => apiRouter.use(middleware())); + + // FIXME: version controller should be atached to the main entry point: "/" + // instead of "/api/:version" or "/user/:user/api/:version" + this.healthCheckController.route(apiRouter); + + // FIXME: version controller should be atached to the main entry point: "/" + // instead of "/api/:version" or "/user/:user/api/:version" + this.versionController.route(apiRouter); + + this.jobsWipController.route(apiRouter); + + this.sqlRouter.route(apiRouter, route.sql); + + paths.forEach(path => app.use(path, apiRouter)); + }); + } +}; diff --git a/app/controllers/health_check_controller.js b/lib/api/health-check-controller.js similarity index 81% rename from app/controllers/health_check_controller.js rename to lib/api/health-check-controller.js index ef19f8a3..4137d087 100644 --- a/app/controllers/health_check_controller.js +++ b/lib/api/health-check-controller.js @@ -1,14 +1,14 @@ 'use strict'; -const HealthCheckBackend = require('../monitoring/health_check'); +const HealthCheckBackend = require('../monitoring/health-check'); module.exports = class HealthCheckController { constructor () { this.healthCheckBackend = new HealthCheckBackend(global.settings.disabled_file); } - route (app) { - app.get(`${global.settings.base_url}/health`, healthCheck({ healthCheckBackend: this.healthCheckBackend })); + route (apiRouter) { + apiRouter.get('/health', healthCheck({ healthCheckBackend: this.healthCheckBackend })); } }; diff --git a/lib/api/jobs-wip-controller.js b/lib/api/jobs-wip-controller.js new file mode 100644 index 00000000..58d3090f --- /dev/null +++ b/lib/api/jobs-wip-controller.js @@ -0,0 +1,39 @@ +'use strict'; + +const bodyParser = require('./middlewares/body-parser'); +const error = require('./middlewares/error'); + +module.exports = class JobsWipController { + constructor ({ jobService }) { + this.jobService = jobService; + } + + route (apiRouter) { + apiRouter.get('/jobs-wip', [ + bodyParser(), + listWorkInProgressJobs(this.jobService), + sendResponse(), + error() + ]); + } +}; + +function listWorkInProgressJobs (jobService) { + return function listWorkInProgressJobsMiddleware (req, res, next) { + jobService.listWorkInProgressJobs((err, list) => { + if (err) { + return next(err); + } + + res.body = list; + + next(); + }); + }; +} + +function sendResponse () { + return function sendResponseMiddleware (req, res) { + res.status(res.statusCode || 200).send(res.body); + }; +} diff --git a/app/middlewares/access-validator.js b/lib/api/middlewares/access-validator.js similarity index 83% rename from app/middlewares/access-validator.js rename to lib/api/middlewares/access-validator.js index f62624e4..70fd33bf 100644 --- a/app/middlewares/access-validator.js +++ b/lib/api/middlewares/access-validator.js @@ -1,6 +1,6 @@ 'use strict'; -const pgEntitiesAccessValidator = require('../services/pg-entities-access-validator'); +const pgEntitiesAccessValidator = require('../../services/pg-entities-access-validator'); module.exports = function accessValidator () { return function accessValidatorMiddleware (req, res, next) { diff --git a/app/middlewares/affected-tables.js b/lib/api/middlewares/affected-tables.js similarity index 100% rename from app/middlewares/affected-tables.js rename to lib/api/middlewares/affected-tables.js diff --git a/app/middlewares/authorization.js b/lib/api/middlewares/authorization.js similarity index 98% rename from app/middlewares/authorization.js rename to lib/api/middlewares/authorization.js index cbed5455..8a97928c 100644 --- a/app/middlewares/authorization.js +++ b/lib/api/middlewares/authorization.js @@ -1,6 +1,6 @@ 'use strict'; -const AuthApi = require('../auth/auth_api'); +const AuthApi = require('../../auth/auth-api'); const basicAuth = require('basic-auth'); module.exports = function authorization (metadataBackend, forceToBeMaster = false) { diff --git a/app/middlewares/body-parser.js b/lib/api/middlewares/body-parser.js similarity index 100% rename from app/middlewares/body-parser.js rename to lib/api/middlewares/body-parser.js diff --git a/app/middlewares/cache-channel.js b/lib/api/middlewares/cache-channel.js similarity index 100% rename from app/middlewares/cache-channel.js rename to lib/api/middlewares/cache-channel.js diff --git a/app/middlewares/cache-control.js b/lib/api/middlewares/cache-control.js similarity index 100% rename from app/middlewares/cache-control.js rename to lib/api/middlewares/cache-control.js diff --git a/app/middlewares/cancel-on-client-abort.js b/lib/api/middlewares/cancel-on-client-abort.js similarity index 100% rename from app/middlewares/cancel-on-client-abort.js rename to lib/api/middlewares/cancel-on-client-abort.js diff --git a/app/middlewares/connection-params.js b/lib/api/middlewares/connection-params.js similarity index 100% rename from app/middlewares/connection-params.js rename to lib/api/middlewares/connection-params.js diff --git a/app/middlewares/content.js b/lib/api/middlewares/content.js similarity index 86% rename from app/middlewares/content.js rename to lib/api/middlewares/content.js index 3064781f..7aeb7375 100644 --- a/app/middlewares/content.js +++ b/lib/api/middlewares/content.js @@ -1,6 +1,6 @@ 'use strict'; -const getContentDisposition = require('../utils/content_disposition'); +const getContentDisposition = require('../../utils/content-disposition'); module.exports = function content () { return function contentMiddleware (req, res, next) { diff --git a/app/middlewares/cors.js b/lib/api/middlewares/cors.js similarity index 100% rename from app/middlewares/cors.js rename to lib/api/middlewares/cors.js diff --git a/app/middlewares/db-quota.js b/lib/api/middlewares/db-quota.js similarity index 100% rename from app/middlewares/db-quota.js rename to lib/api/middlewares/db-quota.js diff --git a/app/middlewares/error.js b/lib/api/middlewares/error.js similarity index 93% rename from app/middlewares/error.js rename to lib/api/middlewares/error.js index 5c9db4a2..c63876b3 100644 --- a/app/middlewares/error.js +++ b/lib/api/middlewares/error.js @@ -1,7 +1,7 @@ 'use strict'; -const errorHandlerFactory = require('../services/error_handler_factory'); -const { stringifyForLogs } = require('../utils/logs'); +const errorHandlerFactory = require('../../services/error-handler-factory'); +const { stringifyForLogs } = require('../../utils/logs'); const MAX_ERROR_STRING_LENGTH = 1024; module.exports = function error() { diff --git a/app/middlewares/formatter.js b/lib/api/middlewares/formatter.js similarity index 85% rename from app/middlewares/formatter.js rename to lib/api/middlewares/formatter.js index 6216e2a8..baee0347 100644 --- a/app/middlewares/formatter.js +++ b/lib/api/middlewares/formatter.js @@ -1,6 +1,6 @@ 'use strict'; -const formats = require('../models/formats'); +const formats = require('../../models/formats'); module.exports = function formatter () { return function formatterMiddleware (req, res, next) { diff --git a/app/middlewares/last-modified.js b/lib/api/middlewares/last-modified.js similarity index 100% rename from app/middlewares/last-modified.js rename to lib/api/middlewares/last-modified.js diff --git a/app/middlewares/log.js b/lib/api/middlewares/log.js similarity index 97% rename from app/middlewares/log.js rename to lib/api/middlewares/log.js index 32815873..e3faf869 100644 --- a/app/middlewares/log.js +++ b/lib/api/middlewares/log.js @@ -1,6 +1,6 @@ 'use strict'; -const { stringifyForLogs } = require('../utils/logs'); +const { stringifyForLogs } = require('../../utils/logs'); const MAX_SQL_LENGTH = (global.settings.logQueries && global.settings.maxQueriesLogLength) || 1024; diff --git a/app/middlewares/logger.js b/lib/api/middlewares/logger.js similarity index 100% rename from app/middlewares/logger.js rename to lib/api/middlewares/logger.js diff --git a/app/middlewares/params.js b/lib/api/middlewares/params.js similarity index 97% rename from app/middlewares/params.js rename to lib/api/middlewares/params.js index e0d6b01d..a241a17c 100644 --- a/app/middlewares/params.js +++ b/lib/api/middlewares/params.js @@ -1,7 +1,7 @@ 'use strict'; -const sanitizeFilename = require('../utils/filename_sanitizer'); -const formats = require('../models/formats'); +const sanitizeFilename = require('../../utils/filename-sanitizer'); +const formats = require('../../models/formats'); module.exports = function params ({ strategy = 'query' } = {}) { const getParams = getParamsFromStrategy(strategy); diff --git a/app/middlewares/profiler.js b/lib/api/middlewares/profiler.js similarity index 78% rename from app/middlewares/profiler.js rename to lib/api/middlewares/profiler.js index aad91099..c932300b 100644 --- a/app/middlewares/profiler.js +++ b/lib/api/middlewares/profiler.js @@ -1,6 +1,6 @@ 'use strict'; -const Profiler = require('../stats/profiler-proxy'); +const Profiler = require('../../stats/profiler-proxy'); module.exports = function profiler ({ statsClient }) { return function profilerMiddleware (req, res, next) { @@ -13,7 +13,7 @@ module.exports = function profiler ({ statsClient }) { }; }; -module.exports.initializeProfilerMiddleware = function initializeProfiler (label) { +module.exports.initializeProfiler = function initializeProfiler (label) { return function initializeProfilerMiddleware (req, res, next) { if (req.profiler) { req.profiler.start(`sqlapi.${label}`); @@ -23,7 +23,7 @@ module.exports.initializeProfilerMiddleware = function initializeProfiler (label }; }; -module.exports.finishProfilerMiddleware = function finishProfiler () { +module.exports.finishProfiler = function finishProfiler () { return function finishProfilerMiddleware (req, res, next) { if (req.profiler) { req.profiler.end(); diff --git a/app/middlewares/query-may-write.js b/lib/api/middlewares/query-may-write.js similarity index 79% rename from app/middlewares/query-may-write.js rename to lib/api/middlewares/query-may-write.js index bc3436ee..607557c4 100644 --- a/app/middlewares/query-may-write.js +++ b/lib/api/middlewares/query-may-write.js @@ -1,6 +1,6 @@ 'use strict'; -const queryMayWrite = require('../utils/query_may_write'); +const queryMayWrite = require('../../utils/query-may-write'); module.exports = function mayWrite () { return function mayWriteMiddleware (req, res, next) { diff --git a/app/middlewares/rate-limit.js b/lib/api/middlewares/rate-limit.js similarity index 100% rename from app/middlewares/rate-limit.js rename to lib/api/middlewares/rate-limit.js diff --git a/app/middlewares/served-by-host-header.js b/lib/api/middlewares/served-by-host-header.js similarity index 100% rename from app/middlewares/served-by-host-header.js rename to lib/api/middlewares/served-by-host-header.js diff --git a/app/middlewares/socket-timeout.js b/lib/api/middlewares/socket-timeout.js similarity index 100% rename from app/middlewares/socket-timeout.js rename to lib/api/middlewares/socket-timeout.js diff --git a/app/middlewares/surrogate-key.js b/lib/api/middlewares/surrogate-key.js similarity index 100% rename from app/middlewares/surrogate-key.js rename to lib/api/middlewares/surrogate-key.js diff --git a/app/middlewares/timeout-limits.js b/lib/api/middlewares/timeout-limits.js similarity index 100% rename from app/middlewares/timeout-limits.js rename to lib/api/middlewares/timeout-limits.js diff --git a/app/middlewares/user.js b/lib/api/middlewares/user.js similarity index 76% rename from app/middlewares/user.js rename to lib/api/middlewares/user.js index 87e71d0b..6685ca8a 100644 --- a/app/middlewares/user.js +++ b/lib/api/middlewares/user.js @@ -1,8 +1,8 @@ 'use strict'; -const CdbRequest = require('../models/cartodb_request'); +const CdbRequest = require('../../models/cartodb-request'); -module.exports = function user(metadataBackend) { +module.exports = function user (metadataBackend) { const cdbRequest = new CdbRequest(); return function userMiddleware (req, res, next) { @@ -23,16 +23,16 @@ module.exports = function user(metadataBackend) { }; }; -function getUserNameFromRequest(req, cdbRequest) { +function getUserNameFromRequest (req, cdbRequest) { return cdbRequest.userByReq(req); } -function checkUserExists(metadataBackend, userName, callback) { +function checkUserExists (metadataBackend, userName, callback) { metadataBackend.getUserId(userName, function(err) { callback(err, !err); }); } -function errorUserNotFoundMessageTemplate(user) { +function errorUserNotFoundMessageTemplate (user) { return `Sorry, we can't find CARTO user '${user}'. Please check that you have entered the correct domain.`; } diff --git a/app/controllers/copy_controller.js b/lib/api/sql/copy-controller.js similarity index 73% rename from app/controllers/copy_controller.js rename to lib/api/sql/copy-controller.js index cf1c9b79..ce5f0dc7 100644 --- a/app/controllers/copy_controller.js +++ b/lib/api/sql/copy-controller.js @@ -1,21 +1,21 @@ 'use strict'; -const userMiddleware = require('../middlewares/user'); -const errorMiddleware = require('../middlewares/error'); -const authorizationMiddleware = require('../middlewares/authorization'); -const connectionParamsMiddleware = require('../middlewares/connection-params'); -const { initializeProfilerMiddleware } = require('../middlewares/profiler'); -const rateLimitsMiddleware = require('../middlewares/rate-limit'); -const dbQuotaMiddleware = require('../middlewares/db-quota'); -const { RATE_LIMIT_ENDPOINTS_GROUPS } = rateLimitsMiddleware; -const errorHandlerFactory = require('../services/error_handler_factory'); -const StreamCopy = require('../services/stream_copy'); -const StreamCopyMetrics = require('../services/stream_copy_metrics'); -const Throttler = require('../services/throttler-stream'); +const user = require('../middlewares/user'); +const error = require('../middlewares/error'); +const authorization = require('../middlewares/authorization'); +const connectionParams = require('../middlewares/connection-params'); +const { initializeProfiler } = require('../middlewares/profiler'); +const dbQuota = require('../middlewares/db-quota'); +const bodyParser = require('../middlewares/body-parser'); +const rateLimits = require('../middlewares/rate-limit'); +const { RATE_LIMIT_ENDPOINTS_GROUPS } = rateLimits; +const errorHandlerFactory = require('../../services/error-handler-factory'); +const StreamCopy = require('../../services/stream-copy'); +const StreamCopyMetrics = require('../../services/stream-copy-metrics'); +const Throttler = require('../../services/throttler-stream'); const zlib = require('zlib'); const { PassThrough } = require('stream'); const params = require('../middlewares/params'); -const bodyParserMiddleware = require('../middlewares/body-parser'); module.exports = class CopyController { constructor (metadataBackend, userDatabaseService, userLimitsService, logger) { @@ -25,40 +25,40 @@ module.exports = class CopyController { this.logger = logger; } - route (apiRouter) { + route (sqlRouter) { const copyFromMiddlewares = endpointGroup => { return [ - initializeProfilerMiddleware('copyfrom'), - userMiddleware(this.metadataBackend), - rateLimitsMiddleware(this.userLimitsService, endpointGroup), - authorizationMiddleware(this.metadataBackend), - connectionParamsMiddleware(this.userDatabaseService), - dbQuotaMiddleware(), + initializeProfiler('copyfrom'), + user(this.metadataBackend), + rateLimits(this.userLimitsService, endpointGroup), + authorization(this.metadataBackend), + connectionParams(this.userDatabaseService), + dbQuota(), params({ strategy: 'copyfrom' }), handleCopyFrom(this.logger), errorHandler(this.logger), - errorMiddleware() + error() ]; }; const copyToMiddlewares = endpointGroup => { return [ - bodyParserMiddleware(), - initializeProfilerMiddleware('copyto'), - userMiddleware(this.metadataBackend), - rateLimitsMiddleware(this.userLimitsService, endpointGroup), - authorizationMiddleware(this.metadataBackend), - connectionParamsMiddleware(this.userDatabaseService), + bodyParser(), + initializeProfiler('copyto'), + user(this.metadataBackend), + rateLimits(this.userLimitsService, endpointGroup), + authorization(this.metadataBackend), + connectionParams(this.userDatabaseService), params({ strategy: 'copyto' }), handleCopyTo(this.logger), errorHandler(this.logger), - errorMiddleware() + error() ]; }; - apiRouter.post('/sql/copyfrom', copyFromMiddlewares(RATE_LIMIT_ENDPOINTS_GROUPS.COPY_FROM)); - apiRouter.get('/sql/copyto', copyToMiddlewares(RATE_LIMIT_ENDPOINTS_GROUPS.COPY_TO)); - apiRouter.post('/sql/copyto', copyToMiddlewares(RATE_LIMIT_ENDPOINTS_GROUPS.COPY_TO)); + sqlRouter.post('/copyfrom', copyFromMiddlewares(RATE_LIMIT_ENDPOINTS_GROUPS.COPY_FROM)); + sqlRouter.get('/copyto', copyToMiddlewares(RATE_LIMIT_ENDPOINTS_GROUPS.COPY_TO)); + sqlRouter.post('/copyto', copyToMiddlewares(RATE_LIMIT_ENDPOINTS_GROUPS.COPY_TO)); } }; diff --git a/app/controllers/job_controller.js b/lib/api/sql/job-controller.js similarity index 74% rename from app/controllers/job_controller.js rename to lib/api/sql/job-controller.js index 8dd9e9b8..fd47338c 100644 --- a/app/controllers/job_controller.js +++ b/lib/api/sql/job-controller.js @@ -2,16 +2,16 @@ const util = require('util'); -const bodyParserMiddleware = require('../middlewares/body-parser'); -const userMiddleware = require('../middlewares/user'); -const { initializeProfilerMiddleware, finishProfilerMiddleware } = require('../middlewares/profiler'); -const authorizationMiddleware = require('../middlewares/authorization'); -const connectionParamsMiddleware = require('../middlewares/connection-params'); -const errorMiddleware = require('../middlewares/error'); -const rateLimitsMiddleware = require('../middlewares/rate-limit'); -const { RATE_LIMIT_ENDPOINTS_GROUPS } = rateLimitsMiddleware; +const bodyParser = require('../middlewares/body-parser'); +const user = require('../middlewares/user'); +const { initializeProfiler, finishProfiler } = require('../middlewares/profiler'); +const authorization = require('../middlewares/authorization'); +const connectionParams = require('../middlewares/connection-params'); +const error = require('../middlewares/error'); +const rateLimits = require('../middlewares/rate-limit'); +const { RATE_LIMIT_ENDPOINTS_GROUPS } = rateLimits; const params = require('../middlewares/params'); -const logMiddleware = require('../middlewares/log'); +const log = require('../middlewares/log'); module.exports = class JobController { constructor (metadataBackend, userDatabaseService, jobService, statsdClient, userLimitsService) { @@ -22,7 +22,7 @@ module.exports = class JobController { this.userLimitsService = userLimitsService; } - route (apiRouter) { + route (sqlRouter) { const jobMiddlewares = composeJobMiddlewares( this.metadataBackend, this.userDatabaseService, @@ -31,55 +31,44 @@ module.exports = class JobController { this.userLimitsService ); - apiRouter.get( - '/jobs-wip', - bodyParserMiddleware(), - listWorkInProgressJobs(this.jobService), - sendResponse(), - errorMiddleware() - ); - - apiRouter.post( - '/sql/job', - bodyParserMiddleware(), + sqlRouter.post('/job', [ + bodyParser(), checkBodyPayloadSize(), params({ strategy: 'job' }), - logMiddleware(logMiddleware.TYPES.JOB), + log(log.TYPES.JOB), jobMiddlewares('create', createJob, RATE_LIMIT_ENDPOINTS_GROUPS.JOB_CREATE) - ); + ]); - apiRouter.get( - '/sql/job/:job_id', - bodyParserMiddleware(), + sqlRouter.get('/job/:job_id', [ + bodyParser(), jobMiddlewares('retrieve', getJob, RATE_LIMIT_ENDPOINTS_GROUPS.JOB_GET) - ); + ]); - apiRouter.delete( - '/sql/job/:job_id', - bodyParserMiddleware(), + sqlRouter.delete('/job/:job_id', [ + bodyParser(), jobMiddlewares('cancel', cancelJob, RATE_LIMIT_ENDPOINTS_GROUPS.JOB_DELETE) - ); + ]); } }; function composeJobMiddlewares (metadataBackend, userDatabaseService, jobService, statsdClient, userLimitsService) { - return function jobMiddlewares (action, jobMiddleware, endpointGroup) { + return function jobMiddlewares (action, job, endpointGroup) { const forceToBeMaster = true; return [ - initializeProfilerMiddleware('job'), - userMiddleware(metadataBackend), - rateLimitsMiddleware(userLimitsService, endpointGroup), - authorizationMiddleware(metadataBackend, forceToBeMaster), - connectionParamsMiddleware(userDatabaseService), - jobMiddleware(jobService), + initializeProfiler('job'), + user(metadataBackend), + rateLimits(userLimitsService, endpointGroup), + authorization(metadataBackend, forceToBeMaster), + connectionParams(userDatabaseService), + job(jobService), setServedByDBHostHeader(), - finishProfilerMiddleware(), + finishProfiler(), logJobResult(action), incrementSuccessMetrics(statsdClient), sendResponse(), incrementErrorMetrics(statsdClient), - errorMiddleware() + error() ]; }; } @@ -155,21 +144,6 @@ function createJob (jobService) { }; } -function listWorkInProgressJobs (jobService) { - return function listWorkInProgressJobsMiddleware (req, res, next) { - jobService.listWorkInProgressJobs((err, list) => { - if (err) { - return next(err); - } - - res.body = list; - - next(); - }); - }; -} - - function checkBodyPayloadSize () { return function checkBodyPayloadSizeMiddleware(req, res, next) { const payload = JSON.stringify(req.body); diff --git a/app/controllers/query_controller.js b/lib/api/sql/query-controller.js similarity index 95% rename from app/controllers/query_controller.js rename to lib/api/sql/query-controller.js index d36dcdc4..4e88a8c3 100644 --- a/app/controllers/query_controller.js +++ b/lib/api/sql/query-controller.js @@ -1,7 +1,7 @@ 'use strict'; const bodyParser = require('../middlewares/body-parser'); -const { initializeProfilerMiddleware: initializeProfiler } = require('../middlewares/profiler'); +const { initializeProfiler } = require('../middlewares/profiler'); const user = require('../middlewares/user'); const rateLimits = require('../middlewares/rate-limit'); const authorization = require('../middlewares/authorization'); @@ -32,7 +32,7 @@ module.exports = class QueryController { this.userLimitsService = userLimitsService; } - route (apiRouter) { + route (sqlRouter) { const forceToBeMaster = false; const queryMiddlewares = () => { @@ -61,8 +61,8 @@ module.exports = class QueryController { ]; }; - apiRouter.all('/sql', queryMiddlewares()); - apiRouter.all('/sql.:f', queryMiddlewares()); + sqlRouter.all('/', queryMiddlewares()); + sqlRouter.all('.:f', queryMiddlewares()); } }; diff --git a/lib/api/sql/sql-router.js b/lib/api/sql/sql-router.js new file mode 100644 index 00000000..b0b4397e --- /dev/null +++ b/lib/api/sql/sql-router.js @@ -0,0 +1,73 @@ +'use strict'; + +const { Router: router } = require('express'); + +const UserDatabaseService = require('../../services/user-database-service'); +const UserLimitsService = require('../../services/user-limits'); + +const socketTimeout = require('../middlewares/socket-timeout'); +const logger = require('../middlewares/logger'); +const profiler = require('../middlewares/profiler'); +const cors = require('../middlewares/cors'); +const servedByHostHeader = require('../middlewares/served-by-host-header'); + +const QueryController = require('./query-controller'); +const CopyController = require('./copy-controller'); +const JobController = require('./job-controller'); + +module.exports = class SqlRouter { + constructor ({ metadataBackend, statsClient, dataIngestionLogger, jobService }) { + const userLimitsServiceOptions = { + limits: { + rateLimitsEnabled: global.settings.ratelimits.rateLimitsEnabled + } + }; + const userDatabaseService = new UserDatabaseService(metadataBackend); + const userLimitsService = new UserLimitsService(metadataBackend, userLimitsServiceOptions); + + this.queryController = new QueryController( + metadataBackend, + userDatabaseService, + statsClient, + userLimitsService + ); + + this.copyController = new CopyController( + metadataBackend, + userDatabaseService, + userLimitsService, + dataIngestionLogger + ); + + this.jobController = new JobController( + metadataBackend, + userDatabaseService, + jobService, + statsClient, + userLimitsService + ); + } + + route (apiRouter, routes) { + routes.forEach(route => { + const sqlRouter = router({ mergeParams: true }); + + const paths = route.paths; + const middlewares = route.middlewares || []; + + middlewares.forEach(middleware => sqlRouter.use(middleware())); + + sqlRouter.use(socketTimeout()); + sqlRouter.use(logger()); + sqlRouter.use(profiler({ statsClient: this.statsClient })); + sqlRouter.use(cors()); + sqlRouter.use(servedByHostHeader()); + + this.queryController.route(sqlRouter); + this.copyController.route(sqlRouter); + this.jobController.route(sqlRouter); + + paths.forEach(path => apiRouter.use(path, sqlRouter)); + }); + } +}; diff --git a/app/controllers/version_controller.js b/lib/api/version-controller.js similarity index 75% rename from app/controllers/version_controller.js rename to lib/api/version-controller.js index 03c99ba9..3ca0e508 100644 --- a/app/controllers/version_controller.js +++ b/lib/api/version-controller.js @@ -5,8 +5,8 @@ const versions = { }; module.exports = class VersionController { - route (app) { - app.get(`${global.settings.base_url}/version`, version()); + route (apiRouter) { + apiRouter.get('/version', version()); } }; diff --git a/app/auth/apikey.js b/lib/auth/apikey.js similarity index 100% rename from app/auth/apikey.js rename to lib/auth/apikey.js diff --git a/app/auth/auth_api.js b/lib/auth/auth-api.js similarity index 100% rename from app/auth/auth_api.js rename to lib/auth/auth-api.js diff --git a/app/auth/oauth.js b/lib/auth/oauth.js similarity index 99% rename from app/auth/oauth.js rename to lib/auth/oauth.js index 298ef3c9..812f5458 100644 --- a/app/auth/oauth.js +++ b/lib/auth/oauth.js @@ -4,7 +4,7 @@ var _ = require('underscore'); var OAuthUtil = require('oauth-client'); var step = require('step'); -var CdbRequest = require('../models/cartodb_request'); +var CdbRequest = require('../models/cartodb-request'); var cdbReq = new CdbRequest(); var oAuth = (function(){ diff --git a/batch/README.md b/lib/batch/README.md similarity index 100% rename from batch/README.md rename to lib/batch/README.md diff --git a/batch/batch-logger.js b/lib/batch/batch-logger.js similarity index 80% rename from batch/batch-logger.js rename to lib/batch/batch-logger.js index 11d1ade8..91b6b35e 100644 --- a/batch/batch-logger.js +++ b/lib/batch/batch-logger.js @@ -1,6 +1,6 @@ 'use strict'; -const Logger = require('../app/services/logger'); +const Logger = require('../services/logger'); class BatchLogger extends Logger { constructor (path, name) { @@ -10,7 +10,6 @@ class BatchLogger extends Logger { log (job) { return job.log(this.logger); } - } module.exports = BatchLogger; diff --git a/batch/batch.js b/lib/batch/batch.js similarity index 100% rename from batch/batch.js rename to lib/batch/batch.js diff --git a/batch/index.js b/lib/batch/index.js similarity index 78% rename from batch/index.js rename to lib/batch/index.js index b224b2f6..9268612c 100644 --- a/batch/index.js +++ b/lib/batch/index.js @@ -1,14 +1,14 @@ 'use strict'; -var JobRunner = require('./job_runner'); -var QueryRunner = require('./query_runner'); -var JobCanceller = require('./job_canceller'); +var JobRunner = require('./job-runner'); +var QueryRunner = require('./query-runner'); +var JobCanceller = require('./job-canceller'); var JobSubscriber = require('./pubsub/job-subscriber'); -var UserDatabaseMetadataService = require('./user_database_metadata_service'); +var UserDatabaseMetadataService = require('./user-database-metadata-service'); var JobPublisher = require('./pubsub/job-publisher'); -var JobQueue = require('./job_queue'); -var JobBackend = require('./job_backend'); -var JobService = require('./job_service'); +var JobQueue = require('./job-queue'); +var JobBackend = require('./job-backend'); +var JobService = require('./job-service'); var BatchLogger = require('./batch-logger'); var Batch = require('./batch'); diff --git a/batch/job_backend.js b/lib/batch/job-backend.js similarity index 99% rename from batch/job_backend.js rename to lib/batch/job-backend.js index 45faf02d..ea079736 100644 --- a/batch/job_backend.js +++ b/lib/batch/job-backend.js @@ -2,7 +2,7 @@ var REDIS_PREFIX = 'batch:jobs:'; var REDIS_DB = 5; -var JobStatus = require('./job_status'); +var JobStatus = require('./job-status'); var queue = require('queue-async'); function JobBackend(metadataBackend, jobQueue, logger) { diff --git a/batch/job_canceller.js b/lib/batch/job-canceller.js similarity index 100% rename from batch/job_canceller.js rename to lib/batch/job-canceller.js diff --git a/batch/job_queue.js b/lib/batch/job-queue.js similarity index 100% rename from batch/job_queue.js rename to lib/batch/job-queue.js diff --git a/batch/job_runner.js b/lib/batch/job-runner.js similarity index 97% rename from batch/job_runner.js rename to lib/batch/job-runner.js index 87762fe4..86610808 100644 --- a/batch/job_runner.js +++ b/lib/batch/job-runner.js @@ -1,7 +1,7 @@ 'use strict'; -var errorCodes = require('../app/postgresql/error_codes').codeToCondition; -var jobStatus = require('./job_status'); +var errorCodes = require('../postgresql/error-codes').codeToCondition; +var jobStatus = require('./job-status'); var Profiler = require('step-profiler'); var _ = require('underscore'); diff --git a/batch/job_service.js b/lib/batch/job-service.js similarity index 97% rename from batch/job_service.js rename to lib/batch/job-service.js index 162a4dd6..c4ad55ae 100644 --- a/batch/job_service.js +++ b/lib/batch/job-service.js @@ -1,7 +1,7 @@ 'use strict'; -var JobFactory = require('./models/job_factory'); -var jobStatus = require('./job_status'); +var JobFactory = require('./models/job-factory'); +var jobStatus = require('./job-status'); function JobService(jobBackend, jobCanceller, logger) { this.jobBackend = jobBackend; diff --git a/batch/job_status.js b/lib/batch/job-status.js similarity index 100% rename from batch/job_status.js rename to lib/batch/job-status.js diff --git a/batch/leader/locker.js b/lib/batch/leader/locker.js similarity index 100% rename from batch/leader/locker.js rename to lib/batch/leader/locker.js diff --git a/batch/leader/provider/redis-distlock.js b/lib/batch/leader/provider/redis-distlock.js similarity index 100% rename from batch/leader/provider/redis-distlock.js rename to lib/batch/leader/provider/redis-distlock.js diff --git a/batch/maintenance/host-user-queue-mover.js b/lib/batch/maintenance/host-user-queue-mover.js similarity index 100% rename from batch/maintenance/host-user-queue-mover.js rename to lib/batch/maintenance/host-user-queue-mover.js diff --git a/batch/maintenance/remove-old-batch-jobs.js b/lib/batch/maintenance/remove-old-batch-jobs.js similarity index 100% rename from batch/maintenance/remove-old-batch-jobs.js rename to lib/batch/maintenance/remove-old-batch-jobs.js diff --git a/batch/models/job_base.js b/lib/batch/models/job-base.js similarity index 96% rename from batch/models/job_base.js rename to lib/batch/models/job-base.js index 9eda131a..0827c586 100644 --- a/batch/models/job_base.js +++ b/lib/batch/models/job-base.js @@ -2,8 +2,8 @@ var util = require('util'); var uuid = require('node-uuid'); -var JobStateMachine = require('./job_state_machine'); -var jobStatus = require('../job_status'); +var JobStateMachine = require('./job-state-machine'); +var jobStatus = require('../job-status'); var mandatoryProperties = [ 'job_id', 'status', diff --git a/batch/models/job_factory.js b/lib/batch/models/job-factory.js similarity index 78% rename from batch/models/job_factory.js rename to lib/batch/models/job-factory.js index 7994314a..e802615f 100644 --- a/batch/models/job_factory.js +++ b/lib/batch/models/job-factory.js @@ -1,8 +1,8 @@ 'use strict'; -var JobSimple = require('./job_simple'); -var JobMultiple = require('./job_multiple'); -var JobFallback = require('./job_fallback'); +var JobSimple = require('./job-simple'); +var JobMultiple = require('./job-multiple'); +var JobFallback = require('./job-fallback'); var Models = [ JobSimple, JobMultiple, JobFallback ]; diff --git a/batch/models/job_fallback.js b/lib/batch/models/job-fallback.js similarity index 96% rename from batch/models/job_fallback.js rename to lib/batch/models/job-fallback.js index 9caa0d1d..83d6ff74 100644 --- a/batch/models/job_fallback.js +++ b/lib/batch/models/job-fallback.js @@ -1,11 +1,11 @@ 'use strict'; var util = require('util'); -var JobBase = require('./job_base'); -var JobStatus = require('../job_status'); -var QueryFallback = require('./query/query_fallback'); -var MainFallback = require('./query/main_fallback'); -var QueryFactory = require('./query/query_factory'); +var JobBase = require('./job-base'); +var JobStatus = require('../job-status'); +var QueryFallback = require('./query/query-fallback'); +var MainFallback = require('./query/main-fallback'); +var QueryFactory = require('./query/query-factory'); function JobFallback(jobDefinition) { JobBase.call(this, jobDefinition); diff --git a/batch/models/job_multiple.js b/lib/batch/models/job-multiple.js similarity index 97% rename from batch/models/job_multiple.js rename to lib/batch/models/job-multiple.js index 85cf1d87..16042d69 100644 --- a/batch/models/job_multiple.js +++ b/lib/batch/models/job-multiple.js @@ -1,8 +1,8 @@ 'use strict'; var util = require('util'); -var JobBase = require('./job_base'); -var jobStatus = require('../job_status'); +var JobBase = require('./job-base'); +var jobStatus = require('../job-status'); function JobMultiple(jobDefinition) { JobBase.call(this, jobDefinition); diff --git a/batch/models/job_simple.js b/lib/batch/models/job-simple.js similarity index 89% rename from batch/models/job_simple.js rename to lib/batch/models/job-simple.js index ad982c36..644ea058 100644 --- a/batch/models/job_simple.js +++ b/lib/batch/models/job-simple.js @@ -1,8 +1,8 @@ 'use strict'; var util = require('util'); -var JobBase = require('./job_base'); -var jobStatus = require('../job_status'); +var JobBase = require('./job-base'); +var jobStatus = require('../job-status'); function JobSimple(jobDefinition) { JobBase.call(this, jobDefinition); diff --git a/batch/models/job_state_machine.js b/lib/batch/models/job-state-machine.js similarity index 96% rename from batch/models/job_state_machine.js rename to lib/batch/models/job-state-machine.js index f476b8a8..08bfd538 100644 --- a/batch/models/job_state_machine.js +++ b/lib/batch/models/job-state-machine.js @@ -1,7 +1,7 @@ 'use strict'; var assert = require('assert'); -var JobStatus = require('../job_status'); +var JobStatus = require('../job-status'); var validStatusTransitions = [ [JobStatus.PENDING, JobStatus.RUNNING], [JobStatus.PENDING, JobStatus.CANCELLED], diff --git a/batch/models/query/fallback.js b/lib/batch/models/query/fallback.js similarity index 96% rename from batch/models/query/fallback.js rename to lib/batch/models/query/fallback.js index 1ce5f22f..373c1020 100644 --- a/batch/models/query/fallback.js +++ b/lib/batch/models/query/fallback.js @@ -1,8 +1,8 @@ 'use strict'; var util = require('util'); -var QueryBase = require('./query_base'); -var jobStatus = require('../../job_status'); +var QueryBase = require('./query-base'); +var jobStatus = require('../../job-status'); function Fallback(index) { QueryBase.call(this, index); diff --git a/batch/models/query/main_fallback.js b/lib/batch/models/query/main-fallback.js similarity index 95% rename from batch/models/query/main_fallback.js rename to lib/batch/models/query/main-fallback.js index 7c52194b..8dd1b172 100644 --- a/batch/models/query/main_fallback.js +++ b/lib/batch/models/query/main-fallback.js @@ -1,8 +1,8 @@ 'use strict'; var util = require('util'); -var QueryBase = require('./query_base'); -var jobStatus = require('../../job_status'); +var QueryBase = require('./query-base'); +var jobStatus = require('../../job-status'); function MainFallback() { QueryBase.call(this); diff --git a/batch/models/query/query_base.js b/lib/batch/models/query/query-base.js similarity index 92% rename from batch/models/query/query_base.js rename to lib/batch/models/query/query-base.js index 737e1bf5..cf36c006 100644 --- a/batch/models/query/query_base.js +++ b/lib/batch/models/query/query-base.js @@ -1,7 +1,7 @@ 'use strict'; var util = require('util'); -var JobStateMachine = require('../job_state_machine'); +var JobStateMachine = require('../job-state-machine'); function QueryBase(index) { JobStateMachine.call(this); diff --git a/batch/models/query/query_factory.js b/lib/batch/models/query/query-factory.js similarity index 86% rename from batch/models/query/query_factory.js rename to lib/batch/models/query/query-factory.js index c33534e0..c60a2ab2 100644 --- a/batch/models/query/query_factory.js +++ b/lib/batch/models/query/query-factory.js @@ -1,6 +1,6 @@ 'use strict'; -var QueryFallback = require('./query_fallback'); +var QueryFallback = require('./query-fallback'); function QueryFactory() { } diff --git a/batch/models/query/query_fallback.js b/lib/batch/models/query/query-fallback.js similarity index 95% rename from batch/models/query/query_fallback.js rename to lib/batch/models/query/query-fallback.js index cb0579a3..4dd48a65 100644 --- a/batch/models/query/query_fallback.js +++ b/lib/batch/models/query/query-fallback.js @@ -1,10 +1,10 @@ 'use strict'; var util = require('util'); -var QueryBase = require('./query_base'); +var QueryBase = require('./query-base'); var Query = require('./query'); var Fallback = require('./fallback'); -var jobStatus = require('../../job_status'); +var jobStatus = require('../../job-status'); function QueryFallback(job, index) { QueryBase.call(this, index); diff --git a/batch/models/query/query.js b/lib/batch/models/query/query.js similarity index 94% rename from batch/models/query/query.js rename to lib/batch/models/query/query.js index 6970ae97..2d11ee7f 100644 --- a/batch/models/query/query.js +++ b/lib/batch/models/query/query.js @@ -1,8 +1,8 @@ 'use strict'; var util = require('util'); -var QueryBase = require('./query_base'); -var jobStatus = require('../../job_status'); +var QueryBase = require('./query-base'); +var jobStatus = require('../../job-status'); function Query(index) { QueryBase.call(this, index); diff --git a/batch/pubsub/channel.js b/lib/batch/pubsub/channel.js similarity index 100% rename from batch/pubsub/channel.js rename to lib/batch/pubsub/channel.js diff --git a/batch/pubsub/job-publisher.js b/lib/batch/pubsub/job-publisher.js similarity index 100% rename from batch/pubsub/job-publisher.js rename to lib/batch/pubsub/job-publisher.js diff --git a/batch/pubsub/job-subscriber.js b/lib/batch/pubsub/job-subscriber.js similarity index 100% rename from batch/pubsub/job-subscriber.js rename to lib/batch/pubsub/job-subscriber.js diff --git a/batch/query_runner.js b/lib/batch/query-runner.js similarity index 100% rename from batch/query_runner.js rename to lib/batch/query-runner.js diff --git a/batch/scheduler/capacity/fixed.js b/lib/batch/scheduler/capacity/fixed.js similarity index 100% rename from batch/scheduler/capacity/fixed.js rename to lib/batch/scheduler/capacity/fixed.js diff --git a/batch/scheduler/capacity/http-load.js b/lib/batch/scheduler/capacity/http-load.js similarity index 100% rename from batch/scheduler/capacity/http-load.js rename to lib/batch/scheduler/capacity/http-load.js diff --git a/batch/scheduler/capacity/http-simple.js b/lib/batch/scheduler/capacity/http-simple.js similarity index 100% rename from batch/scheduler/capacity/http-simple.js rename to lib/batch/scheduler/capacity/http-simple.js diff --git a/batch/scheduler/host-scheduler.js b/lib/batch/scheduler/host-scheduler.js similarity index 100% rename from batch/scheduler/host-scheduler.js rename to lib/batch/scheduler/host-scheduler.js diff --git a/batch/scheduler/scheduler.js b/lib/batch/scheduler/scheduler.js similarity index 100% rename from batch/scheduler/scheduler.js rename to lib/batch/scheduler/scheduler.js diff --git a/batch/user_database_metadata_service.js b/lib/batch/user-database-metadata-service.js similarity index 100% rename from batch/user_database_metadata_service.js rename to lib/batch/user-database-metadata-service.js diff --git a/batch/util/debug.js b/lib/batch/util/debug.js similarity index 100% rename from batch/util/debug.js rename to lib/batch/util/debug.js diff --git a/batch/util/forever.js b/lib/batch/util/forever.js similarity index 100% rename from batch/util/forever.js rename to lib/batch/util/forever.js diff --git a/app/models/bin_encoder.js b/lib/models/bin-encoder.js similarity index 100% rename from app/models/bin_encoder.js rename to lib/models/bin-encoder.js diff --git a/app/models/cartodb_request.js b/lib/models/cartodb-request.js similarity index 100% rename from app/models/cartodb_request.js rename to lib/models/cartodb-request.js diff --git a/app/models/formats/README b/lib/models/formats/README similarity index 100% rename from app/models/formats/README rename to lib/models/formats/README diff --git a/app/models/formats/index.js b/lib/models/formats/index.js similarity index 100% rename from app/models/formats/index.js rename to lib/models/formats/index.js diff --git a/app/models/formats/ogr.js b/lib/models/formats/ogr.js similarity index 100% rename from app/models/formats/ogr.js rename to lib/models/formats/ogr.js diff --git a/app/models/formats/ogr/csv.js b/lib/models/formats/ogr/csv.js similarity index 100% rename from app/models/formats/ogr/csv.js rename to lib/models/formats/ogr/csv.js diff --git a/app/models/formats/ogr/geopackage.js b/lib/models/formats/ogr/geopackage.js similarity index 100% rename from app/models/formats/ogr/geopackage.js rename to lib/models/formats/ogr/geopackage.js diff --git a/app/models/formats/ogr/kml.js b/lib/models/formats/ogr/kml.js similarity index 100% rename from app/models/formats/ogr/kml.js rename to lib/models/formats/ogr/kml.js diff --git a/app/models/formats/ogr/shp.js b/lib/models/formats/ogr/shp.js similarity index 100% rename from app/models/formats/ogr/shp.js rename to lib/models/formats/ogr/shp.js diff --git a/app/models/formats/ogr/spatialite.js b/lib/models/formats/ogr/spatialite.js similarity index 100% rename from app/models/formats/ogr/spatialite.js rename to lib/models/formats/ogr/spatialite.js diff --git a/app/models/formats/pg.js b/lib/models/formats/pg.js similarity index 100% rename from app/models/formats/pg.js rename to lib/models/formats/pg.js diff --git a/app/models/formats/pg/arraybuffer.js b/lib/models/formats/pg/arraybuffer.js similarity index 97% rename from app/models/formats/pg/arraybuffer.js rename to lib/models/formats/pg/arraybuffer.js index d0976599..cbb8a7f6 100644 --- a/app/models/formats/pg/arraybuffer.js +++ b/lib/models/formats/pg/arraybuffer.js @@ -3,7 +3,7 @@ var _ = require('underscore'); var Pg = require('./../pg'); -var ArrayBufferSer = require("../../bin_encoder"); +var ArrayBufferSer = require("../../bin-encoder"); function BinaryFormat() {} diff --git a/app/models/formats/pg/geojson.js b/lib/models/formats/pg/geojson.js similarity index 96% rename from app/models/formats/pg/geojson.js rename to lib/models/formats/pg/geojson.js index a6b49807..30f44600 100644 --- a/app/models/formats/pg/geojson.js +++ b/lib/models/formats/pg/geojson.js @@ -2,8 +2,8 @@ var _ = require('underscore'); -var Pg = require('./../pg'); -const errorHandlerFactory = require('../../../services/error_handler_factory'); +var Pg = require('./../pg'); +const errorHandlerFactory = require('../../../services/error-handler-factory'); function GeoJsonFormat() { this.buffer = ''; diff --git a/app/models/formats/pg/json.js b/lib/models/formats/pg/json.js similarity index 98% rename from app/models/formats/pg/json.js rename to lib/models/formats/pg/json.js index 55f49fc4..26fdda71 100644 --- a/app/models/formats/pg/json.js +++ b/lib/models/formats/pg/json.js @@ -3,7 +3,7 @@ var _ = require('underscore'); var Pg = require('./../pg'); -const errorHandlerFactory = require('../../../services/error_handler_factory'); +const errorHandlerFactory = require('../../../services/error-handler-factory'); function JsonFormat() { this.buffer = ''; diff --git a/app/models/formats/pg/svg.js b/lib/models/formats/pg/svg.js similarity index 100% rename from app/models/formats/pg/svg.js rename to lib/models/formats/pg/svg.js diff --git a/app/models/formats/pg/topojson.js b/lib/models/formats/pg/topojson.js similarity index 98% rename from app/models/formats/pg/topojson.js rename to lib/models/formats/pg/topojson.js index f45f740c..cb58ef1e 100644 --- a/app/models/formats/pg/topojson.js +++ b/lib/models/formats/pg/topojson.js @@ -1,5 +1,7 @@ 'use strict'; +// jshint ignore:start + var Pg = require('./../pg'); var _ = require('underscore'); var geojson = require('./geojson'); @@ -133,6 +135,6 @@ TopoJsonFormat.prototype.cancel = function() { } }; - - module.exports = TopoJsonFormat; + +// jshint ignore:end diff --git a/app/monitoring/health_check.js b/lib/monitoring/health-check.js similarity index 100% rename from app/monitoring/health_check.js rename to lib/monitoring/health-check.js diff --git a/app/postgresql/error_codes.js b/lib/postgresql/error-codes.js similarity index 100% rename from app/postgresql/error_codes.js rename to lib/postgresql/error-codes.js diff --git a/lib/server-options.js b/lib/server-options.js new file mode 100644 index 00000000..448e35de --- /dev/null +++ b/lib/server-options.js @@ -0,0 +1,32 @@ +'use strict'; + +module.exports = function getServerOptions () { + const defaults = { + routes: { + // Each entry corresponds with an express' router. + // You must define at least one path. However, middlewares are optional. + api: [{ + // Required: path where other "routers" or "controllers" will be attached to. + paths: [ + // In case the path has a :user param the username will be the one specified in the URL, + // otherwise it will fallback to extract the username from the host header. + '/api/:version', + '/user/:user/api/:version', + ], + // Optional: attach middlewares at the begining of the router + // to perform custom operations. + middlewares: [], + sql: [{ + // Required + paths: [ + '/sql' + ], + // Optional + middlewares: [] + }] + }] + } + }; + + return Object.assign({}, defaults, global.settings); +}; diff --git a/app/server.js b/lib/server.js similarity index 77% rename from app/server.js rename to lib/server.js index 904d929e..114fde69 100644 --- a/app/server.js +++ b/lib/server.js @@ -6,18 +6,18 @@ const mkdirp = require('mkdirp'); const RedisPool = require('redis-mpool'); const cartodbRedis = require('cartodb-redis'); const Logger = require('./services/logger'); -const ApiRouter = require('./controllers/api-router'); -const HealthCheckController = require('./controllers/health_check_controller'); -const VersionController = require('./controllers/version_controller'); -const batchFactory = require('../batch'); +const ApiRouter = require('./api/api-router'); +const batchFactory = require('./batch'); +const getServerOptions = require('./server-options'); process.env.PGAPPNAME = process.env.PGAPPNAME || 'cartodb_sqlapi'; // override Date.toJSON -require('./utils/date_to_json'); +require('./utils/date-to-json'); // jshint maxcomplexity:9 -module.exports = function serverFactory (statsClient) { +module.exports = function createServer (statsClient) { + const options = getServerOptions(); const app = express(); const redisPool = new RedisPool({ name: 'sql-api', @@ -61,14 +61,13 @@ module.exports = function serverFactory (statsClient) { const dataIngestionLogger = new Logger(global.settings.dataIngestionLogPath, 'data-ingestion'); app.dataIngestionLogger = dataIngestionLogger; - const healthCheckController = new HealthCheckController(); - healthCheckController.route(app); - - const versionController = new VersionController(); - versionController.route(app); - - const apiRouter = new ApiRouter({ redisPool, metadataBackend, statsClient, dataIngestionLogger }); - apiRouter.route(app); + const apiRouter = new ApiRouter({ + redisPool, + metadataBackend, + statsClient, + dataIngestionLogger + }); + apiRouter.route(app, options.routes.api); const isBatchProcess = process.argv.indexOf('--no-batch') === -1; diff --git a/app/services/error_handler_factory.js b/lib/services/error-handler-factory.js similarity index 90% rename from app/services/error_handler_factory.js rename to lib/services/error-handler-factory.js index 5d9429c7..2186ea77 100644 --- a/app/services/error_handler_factory.js +++ b/lib/services/error-handler-factory.js @@ -1,7 +1,7 @@ 'use strict'; -const ErrorHandler = require('./error_handler'); -const { codeToCondition } = require('../postgresql/error_codes'); +const ErrorHandler = require('./error-handler'); +const { codeToCondition } = require('../postgresql/error-codes'); module.exports = function ErrorHandlerFactory (err) { if (isTimeoutError(err)) { diff --git a/app/services/error_handler.js b/lib/services/error-handler.js similarity index 100% rename from app/services/error_handler.js rename to lib/services/error-handler.js diff --git a/app/services/logger.js b/lib/services/logger.js similarity index 100% rename from app/services/logger.js rename to lib/services/logger.js diff --git a/app/services/pg-entities-access-validator.js b/lib/services/pg-entities-access-validator.js similarity index 100% rename from app/services/pg-entities-access-validator.js rename to lib/services/pg-entities-access-validator.js diff --git a/app/services/stream_copy_metrics.js b/lib/services/stream-copy-metrics.js similarity index 96% rename from app/services/stream_copy_metrics.js rename to lib/services/stream-copy-metrics.js index 6ac70b39..13f3f417 100644 --- a/app/services/stream_copy_metrics.js +++ b/lib/services/stream-copy-metrics.js @@ -1,6 +1,6 @@ 'use strict'; -const { getFormatFromCopyQuery } = require('../utils/query_info'); +const { getFormatFromCopyQuery } = require('../utils/query-info'); module.exports = class StreamCopyMetrics { constructor(logger, type, sql, user, isGzip = false) { diff --git a/app/services/stream_copy.js b/lib/services/stream-copy.js similarity index 100% rename from app/services/stream_copy.js rename to lib/services/stream-copy.js diff --git a/app/services/throttler-stream.js b/lib/services/throttler-stream.js similarity index 100% rename from app/services/throttler-stream.js rename to lib/services/throttler-stream.js diff --git a/app/services/user_database_service.js b/lib/services/user-database-service.js similarity index 100% rename from app/services/user_database_service.js rename to lib/services/user-database-service.js diff --git a/app/services/user_limits.js b/lib/services/user-limits.js similarity index 100% rename from app/services/user_limits.js rename to lib/services/user-limits.js diff --git a/app/stats/client.js b/lib/stats/client.js similarity index 100% rename from app/stats/client.js rename to lib/stats/client.js diff --git a/app/stats/profiler-proxy.js b/lib/stats/profiler-proxy.js similarity index 100% rename from app/stats/profiler-proxy.js rename to lib/stats/profiler-proxy.js diff --git a/app/utils/content_disposition.js b/lib/utils/content-disposition.js similarity index 100% rename from app/utils/content_disposition.js rename to lib/utils/content-disposition.js diff --git a/app/utils/date_to_json.js b/lib/utils/date-to-json.js similarity index 100% rename from app/utils/date_to_json.js rename to lib/utils/date-to-json.js diff --git a/app/utils/filename_sanitizer.js b/lib/utils/filename-sanitizer.js similarity index 100% rename from app/utils/filename_sanitizer.js rename to lib/utils/filename-sanitizer.js diff --git a/app/utils/logs.js b/lib/utils/logs.js similarity index 100% rename from app/utils/logs.js rename to lib/utils/logs.js diff --git a/app/utils/md5.js b/lib/utils/md5.js similarity index 100% rename from app/utils/md5.js rename to lib/utils/md5.js diff --git a/app/utils/query_info.js b/lib/utils/query-info.js similarity index 100% rename from app/utils/query_info.js rename to lib/utils/query-info.js diff --git a/app/utils/query_may_write.js b/lib/utils/query-may-write.js similarity index 100% rename from app/utils/query_may_write.js rename to lib/utils/query-may-write.js diff --git a/test/acceptance/app.auth.test.js b/test/acceptance/app-auth-test.js similarity index 98% rename from test/acceptance/app.auth.test.js rename to test/acceptance/app-auth-test.js index 34bdc2f5..2299cf93 100644 --- a/test/acceptance/app.auth.test.js +++ b/test/acceptance/app-auth-test.js @@ -2,7 +2,7 @@ require('../helper'); -var server = require('../../app/server')(); +var server = require('../../lib/server')(); var assert = require('../support/assert'); describe('app.auth', function() { diff --git a/test/acceptance/app-configuration.js b/test/acceptance/app-configuration-test.js similarity index 99% rename from test/acceptance/app-configuration.js rename to test/acceptance/app-configuration-test.js index d42cf5a4..0c48806c 100644 --- a/test/acceptance/app-configuration.js +++ b/test/acceptance/app-configuration-test.js @@ -2,7 +2,7 @@ require('../helper'); -var server = require('../../app/server')(); +var server = require('../../lib/server')(); var assert = require('../support/assert'); const accessControlHeaders = [ diff --git a/test/acceptance/app.test.js b/test/acceptance/app-test.js similarity index 99% rename from test/acceptance/app.test.js rename to test/acceptance/app-test.js index 8e334c80..12bd6301 100644 --- a/test/acceptance/app.test.js +++ b/test/acceptance/app-test.js @@ -16,7 +16,7 @@ */ require('../helper'); -var server = require('../../app/server')(); +var server = require('../../lib/server')(); var assert = require('../support/assert'); var querystring = require('querystring'); var _ = require('underscore'); diff --git a/test/acceptance/auth-api.js b/test/acceptance/auth-api-test.js similarity index 99% rename from test/acceptance/auth-api.js rename to test/acceptance/auth-api-test.js index 82304981..4c9654a8 100644 --- a/test/acceptance/auth-api.js +++ b/test/acceptance/auth-api-test.js @@ -3,7 +3,7 @@ const assert = require('../support/assert'); const TestClient = require('../support/test-client'); const BatchTestClient = require('../support/batch-test-client'); -const JobStatus = require('../../batch/job_status'); +const JobStatus = require('../../lib/batch/job-status'); describe('Auth API', function () { const publicSQL = 'select * from untitle_table_4'; diff --git a/test/acceptance/backend_crash.js b/test/acceptance/backend-crash-test.js similarity index 97% rename from test/acceptance/backend_crash.js rename to test/acceptance/backend-crash-test.js index 897638f9..5e11c27f 100644 --- a/test/acceptance/backend_crash.js +++ b/test/acceptance/backend-crash-test.js @@ -25,7 +25,7 @@ it('does not hang server', function(done){ var db_port_backup = global.settings.db_port; global.settings.db_host = 'localhost'; global.settings.db_port = sql_server_port; - var server = require('../../app/server')(); + var server = require('../../lib/server')(); step( function sendQuery() { assert.response(server, { diff --git a/test/acceptance/batch/batch-drain.test.js b/test/acceptance/batch/batch-drain-test.js similarity index 82% rename from test/acceptance/batch/batch-drain.test.js rename to test/acceptance/batch/batch-drain-test.js index e02593ad..33dbdb7e 100644 --- a/test/acceptance/batch/batch-drain.test.js +++ b/test/acceptance/batch/batch-drain-test.js @@ -2,15 +2,15 @@ require('../../helper'); var assert = require('../../support/assert'); -var redisUtils = require('../../support/redis_utils'); -var batchFactory = require('../../../batch/index'); +var redisUtils = require('../../support/redis-utils'); +var batchFactory = require('../../../lib/batch/index'); -var BatchLogger = require('../../../batch/batch-logger'); -var JobPublisher = require('../../../batch/pubsub/job-publisher'); -var JobQueue = require('../../../batch/job_queue'); -var JobBackend = require('../../../batch/job_backend'); -var JobService = require('../../../batch/job_service'); -var JobCanceller = require('../../../batch/job_canceller'); +var BatchLogger = require('../../../lib/batch/batch-logger'); +var JobPublisher = require('../../../lib/batch/pubsub/job-publisher'); +var JobQueue = require('../../../lib/batch/job-queue'); +var JobBackend = require('../../../lib/batch/job-backend'); +var JobService = require('../../../lib/batch/job-service'); +var JobCanceller = require('../../../lib/batch/job-canceller'); var metadataBackend = require('cartodb-redis')({ pool: redisUtils.getPool() }); describe('batch module', function() { diff --git a/test/acceptance/batch/batch-limits.test.js b/test/acceptance/batch/batch-limits-test.js similarity index 93% rename from test/acceptance/batch/batch-limits.test.js rename to test/acceptance/batch/batch-limits-test.js index fa83d8f4..9b74c7a0 100644 --- a/test/acceptance/batch/batch-limits.test.js +++ b/test/acceptance/batch/batch-limits-test.js @@ -4,8 +4,8 @@ require('../../helper'); var assert = require('../../support/assert'); var BatchTestClient = require('../../support/batch-test-client'); -var JobStatus = require('../../../batch/job_status'); -var redisUtils = require('../../support/redis_utils'); +var JobStatus = require('../../../lib/batch/job-status'); +var redisUtils = require('../../support/redis-utils'); var metadataBackend = require('cartodb-redis')({ pool: redisUtils.getPool() }); const db_utils = require('../../support/db_utils'); diff --git a/test/acceptance/batch/batch.multiquery.test.js b/test/acceptance/batch/batch-multiquery-test.js similarity index 99% rename from test/acceptance/batch/batch.multiquery.test.js rename to test/acceptance/batch/batch-multiquery-test.js index 1214c4a9..3a52e554 100644 --- a/test/acceptance/batch/batch.multiquery.test.js +++ b/test/acceptance/batch/batch-multiquery-test.js @@ -3,7 +3,7 @@ require('../../helper'); var BatchTestClient = require('../../support/batch-test-client'); -var JobStatus = require('../../../batch/job_status'); +var JobStatus = require('../../../lib/batch/job-status'); var assert = require('../../support/assert'); var queue = require('queue-async'); diff --git a/test/acceptance/batch/batch.test.js b/test/acceptance/batch/batch-test.js similarity index 99% rename from test/acceptance/batch/batch.test.js rename to test/acceptance/batch/batch-test.js index 7f3dec72..9da854af 100644 --- a/test/acceptance/batch/batch.test.js +++ b/test/acceptance/batch/batch-test.js @@ -5,7 +5,7 @@ require('../../helper'); var assert = require('../../support/assert'); var queue = require('queue-async'); var BatchTestClient = require('../../support/batch-test-client'); -var JobStatus = require('../../../batch/job_status'); +var JobStatus = require('../../../lib/batch/job-status'); describe('batch happy cases', function() { diff --git a/test/acceptance/batch/batch.wip.test.js b/test/acceptance/batch/batch-wip-test.js similarity index 98% rename from test/acceptance/batch/batch.wip.test.js rename to test/acceptance/batch/batch-wip-test.js index e41e3ab5..63e0303d 100644 --- a/test/acceptance/batch/batch.wip.test.js +++ b/test/acceptance/batch/batch-wip-test.js @@ -4,7 +4,7 @@ require('../../helper'); var assert = require('../../support/assert'); var BatchTestClient = require('../../support/batch-test-client'); -var JobStatus = require('../../../batch/job_status'); +var JobStatus = require('../../../lib/batch/job-status'); describe('batch work in progress endpoint happy cases', function() { diff --git a/test/acceptance/batch/job.callback-template.test.js b/test/acceptance/batch/job-callback-template-test.js similarity index 98% rename from test/acceptance/batch/job.callback-template.test.js rename to test/acceptance/batch/job-callback-template-test.js index 3369c964..94545650 100644 --- a/test/acceptance/batch/job.callback-template.test.js +++ b/test/acceptance/batch/job-callback-template-test.js @@ -4,7 +4,7 @@ require('../../helper'); var assert = require('../../support/assert'); var TestClient = require('../../support/test-client'); -var JobStatus = require('../../../batch/job_status'); +var JobStatus = require('../../../lib/batch/job-status'); var BatchTestClient = require('../../support/batch-test-client'); describe('Batch API callback templates', function () { diff --git a/test/acceptance/batch/job.fallback.test.js b/test/acceptance/batch/job-fallback-test.js similarity index 99% rename from test/acceptance/batch/job.fallback.test.js rename to test/acceptance/batch/job-fallback-test.js index e6b35ce4..a68ec186 100644 --- a/test/acceptance/batch/job.fallback.test.js +++ b/test/acceptance/batch/job-fallback-test.js @@ -3,7 +3,7 @@ require('../../helper'); var assert = require('../../support/assert'); -var JobStatus = require('../../../batch/job_status'); +var JobStatus = require('../../../lib/batch/job-status'); var BatchTestClient = require('../../support/batch-test-client'); describe('Batch API fallback job', function () { diff --git a/test/acceptance/batch/job.query.limit.test.js b/test/acceptance/batch/job-query-limit-test.js similarity index 95% rename from test/acceptance/batch/job.query.limit.test.js rename to test/acceptance/batch/job-query-limit-test.js index b02959f5..ec02c9e0 100644 --- a/test/acceptance/batch/job.query.limit.test.js +++ b/test/acceptance/batch/job-query-limit-test.js @@ -15,9 +15,9 @@ * */ require('../../helper'); -var JobController = require('../../../app/controllers/job_controller'); -var redisUtils = require('../../support/redis_utils'); -var server = require('../../../app/server')(); +var JobController = require('../../../lib/api/sql/job-controller'); +var redisUtils = require('../../support/redis-utils'); +var server = require('../../../lib/server')(); var assert = require('../../support/assert'); var querystring = require('qs'); diff --git a/test/acceptance/batch/job.query.order.test.js b/test/acceptance/batch/job-query-order-test.js similarity index 96% rename from test/acceptance/batch/job.query.order.test.js rename to test/acceptance/batch/job-query-order-test.js index 709692ab..bf280e86 100644 --- a/test/acceptance/batch/job.query.order.test.js +++ b/test/acceptance/batch/job-query-order-test.js @@ -4,7 +4,7 @@ require('../../helper'); var assert = require('../../support/assert'); var BatchTestClient = require('../../support/batch-test-client'); -var JobStatus = require('../../../batch/job_status'); +var JobStatus = require('../../../lib/batch/job-status'); describe('job query order', function() { diff --git a/test/acceptance/batch/job.query.timeout.test.js b/test/acceptance/batch/job-query-timeout-test.js similarity index 98% rename from test/acceptance/batch/job.query.timeout.test.js rename to test/acceptance/batch/job-query-timeout-test.js index e55fe1ce..a449ff5f 100644 --- a/test/acceptance/batch/job.query.timeout.test.js +++ b/test/acceptance/batch/job-query-timeout-test.js @@ -4,7 +4,7 @@ require('../../helper'); var assert = require('../../support/assert'); var BatchTestClient = require('../../support/batch-test-client'); -var JobStatus = require('../../../batch/job_status'); +var JobStatus = require('../../../lib/batch/job-status'); describe('job query timeout', function() { diff --git a/test/acceptance/batch/job.test.js b/test/acceptance/batch/job-test.js similarity index 98% rename from test/acceptance/batch/job.test.js rename to test/acceptance/batch/job-test.js index d8d8288f..fa1d5472 100644 --- a/test/acceptance/batch/job.test.js +++ b/test/acceptance/batch/job-test.js @@ -16,9 +16,9 @@ */ require('../../helper'); -var server = require('../../../app/server')(); +var server = require('../../../lib/server')(); var assert = require('../../support/assert'); -var redisUtils = require('../../support/redis_utils'); +var redisUtils = require('../../support/redis-utils'); var querystring = require('querystring'); describe('job module', function() { diff --git a/test/acceptance/batch/job.timing.test.js b/test/acceptance/batch/job-timing-test.js similarity index 98% rename from test/acceptance/batch/job.timing.test.js rename to test/acceptance/batch/job-timing-test.js index d2482ca4..1391fb14 100644 --- a/test/acceptance/batch/job.timing.test.js +++ b/test/acceptance/batch/job-timing-test.js @@ -3,7 +3,7 @@ require('../../helper'); var BatchTestClient = require('../../support/batch-test-client'); -var JobStatus = require('../../../batch/job_status'); +var JobStatus = require('../../../lib/batch/job-status'); describe('Batch API query timing', function () { before(function() { diff --git a/test/acceptance/batch/leader.job.query.order.test.js b/test/acceptance/batch/leader-job-query-order-test.js similarity index 98% rename from test/acceptance/batch/leader.job.query.order.test.js rename to test/acceptance/batch/leader-job-query-order-test.js index e80b2047..df441c7e 100644 --- a/test/acceptance/batch/leader.job.query.order.test.js +++ b/test/acceptance/batch/leader-job-query-order-test.js @@ -5,7 +5,7 @@ var assert = require('../../support/assert'); var TestClient = require('../../support/test-client'); var BatchTestClient = require('../../support/batch-test-client'); -var JobStatus = require('../../../batch/job_status'); +var JobStatus = require('../../../lib/batch/job-status'); describe('multiple batch clients job query order', function() { diff --git a/test/acceptance/batch/leader-multiple-users-query-order.test.js b/test/acceptance/batch/leader-multiple-users-query-order-test.js similarity index 98% rename from test/acceptance/batch/leader-multiple-users-query-order.test.js rename to test/acceptance/batch/leader-multiple-users-query-order-test.js index 0a5c3609..a7b08108 100644 --- a/test/acceptance/batch/leader-multiple-users-query-order.test.js +++ b/test/acceptance/batch/leader-multiple-users-query-order-test.js @@ -5,7 +5,7 @@ var assert = require('../../support/assert'); var TestClient = require('../../support/test-client'); var BatchTestClient = require('../../support/batch-test-client'); -var JobStatus = require('../../../batch/job_status'); +var JobStatus = require('../../../lib/batch/job-status'); describe('multiple batch clients and users, job query order', function() { diff --git a/test/acceptance/batch/queued-jobs-limit.test.js b/test/acceptance/batch/queued-jobs-limit-test.js similarity index 94% rename from test/acceptance/batch/queued-jobs-limit.test.js rename to test/acceptance/batch/queued-jobs-limit-test.js index 35a0aa5a..f9d52df2 100644 --- a/test/acceptance/batch/queued-jobs-limit.test.js +++ b/test/acceptance/batch/queued-jobs-limit-test.js @@ -3,7 +3,7 @@ require('../../helper'); var assert = require('../../support/assert'); -var redisUtils = require('../../support/redis_utils'); +var redisUtils = require('../../support/redis-utils'); var TestClient = require('../../support/test-client'); describe('max queued jobs', function() { @@ -11,7 +11,7 @@ describe('max queued jobs', function() { before(function(done) { this.batch_max_queued_jobs = global.settings.batch_max_queued_jobs; global.settings.batch_max_queued_jobs = 1; - this.server = require('../../../app/server')(); + this.server = require('../../../lib/server')(); this.testClient = new TestClient(); this.testClient.getResult( 'drop table if exists max_queued_jobs_inserts; create table max_queued_jobs_inserts (status numeric)', diff --git a/test/acceptance/batch/scheduler-basic.test.js b/test/acceptance/batch/scheduler-basic-test.js similarity index 98% rename from test/acceptance/batch/scheduler-basic.test.js rename to test/acceptance/batch/scheduler-basic-test.js index 7cee1e01..46c35d7a 100644 --- a/test/acceptance/batch/scheduler-basic.test.js +++ b/test/acceptance/batch/scheduler-basic-test.js @@ -5,7 +5,7 @@ var assert = require('../../support/assert'); var TestClient = require('../../support/test-client'); var BatchTestClient = require('../../support/batch-test-client'); -var JobStatus = require('../../../batch/job_status'); +var JobStatus = require('../../../lib/batch/job-status'); describe('basic scheduling', function() { diff --git a/test/acceptance/batch/use-cases.test.js b/test/acceptance/batch/use-cases-test.js similarity index 98% rename from test/acceptance/batch/use-cases.test.js rename to test/acceptance/batch/use-cases-test.js index 255d9056..f1fdf3be 100644 --- a/test/acceptance/batch/use-cases.test.js +++ b/test/acceptance/batch/use-cases-test.js @@ -3,7 +3,7 @@ require('../../helper'); var assert = require('../../support/assert'); -var JobStatus = require('../../../batch/job_status'); +var JobStatus = require('../../../lib/batch/job-status'); var BatchTestClient = require('../../support/batch-test-client'); describe('Use cases', function () { diff --git a/test/acceptance/cache-headers.js b/test/acceptance/cache-headers-test.js similarity index 98% rename from test/acceptance/cache-headers.js rename to test/acceptance/cache-headers-test.js index 8d1b6da5..9a179a94 100644 --- a/test/acceptance/cache-headers.js +++ b/test/acceptance/cache-headers-test.js @@ -1,6 +1,6 @@ 'use strict'; -const server = require('../../app/server')(); +const server = require('../../lib/server')(); const assert = require('../support/assert'); const qs = require('querystring'); diff --git a/test/acceptance/copy-abort.js b/test/acceptance/copy-abort-test.js similarity index 98% rename from test/acceptance/copy-abort.js rename to test/acceptance/copy-abort-test.js index c47368bb..5bdcde46 100644 --- a/test/acceptance/copy-abort.js +++ b/test/acceptance/copy-abort-test.js @@ -1,9 +1,9 @@ 'use strict'; const querystring = require('querystring'); -const StatsClient = require('../../app/stats/client'); +const StatsClient = require('../../lib/stats/client'); const statsClient = StatsClient.getInstance(global.settings.statsd); -const server = require('../../app/server')(statsClient); +const server = require('../../lib/server')(statsClient); const request = require('request'); const assert = require('assert'); diff --git a/test/acceptance/copy-endpoints.js b/test/acceptance/copy-endpoints-test.js similarity index 99% rename from test/acceptance/copy-endpoints.js rename to test/acceptance/copy-endpoints-test.js index 5e4ae92d..2afbbd9d 100644 --- a/test/acceptance/copy-endpoints.js +++ b/test/acceptance/copy-endpoints-test.js @@ -9,7 +9,7 @@ const os = require('os'); const { Client } = require('pg'); const request = require('request'); -const StatsClient = require('../../app/stats/client'); +const StatsClient = require('../../lib/stats/client'); if (global.settings.statsd) { // Perform keyword substitution in statsd if (global.settings.statsd.prefix) { @@ -18,7 +18,7 @@ if (global.settings.statsd) { } } const statsClient = StatsClient.getInstance(global.settings.statsd); -const server = require('../../app/server')(statsClient); +const server = require('../../lib/server')(statsClient); // Give it enough time to connect and issue the query diff --git a/test/acceptance/copy-statements.js b/test/acceptance/copy-statements-test.js similarity index 98% rename from test/acceptance/copy-statements.js rename to test/acceptance/copy-statements-test.js index 6fb5c8f3..5055c7a7 100644 --- a/test/acceptance/copy-statements.js +++ b/test/acceptance/copy-statements-test.js @@ -2,7 +2,7 @@ require('../helper'); -var server = require('../../app/server')(); +var server = require('../../lib/server')(); var assert = require('../support/assert'); var querystring = require('querystring'); diff --git a/test/acceptance/copy-throttle.js b/test/acceptance/copy-throttle-test.js similarity index 97% rename from test/acceptance/copy-throttle.js rename to test/acceptance/copy-throttle-test.js index 0be5876e..8ff69fcd 100644 --- a/test/acceptance/copy-throttle.js +++ b/test/acceptance/copy-throttle-test.js @@ -1,9 +1,9 @@ 'use strict'; const querystring = require('querystring'); -const StatsClient = require('../../app/stats/client'); +const StatsClient = require('../../lib/stats/client'); const statsClient = StatsClient.getInstance(global.settings.statsd); -const server = require('../../app/server')(statsClient); +const server = require('../../lib/server')(statsClient); const request = require('request'); const assert = require('assert'); const { Readable } = require('stream'); diff --git a/test/acceptance/custom-middlewares-test.js b/test/acceptance/custom-middlewares-test.js new file mode 100644 index 00000000..7635e366 --- /dev/null +++ b/test/acceptance/custom-middlewares-test.js @@ -0,0 +1,347 @@ +'use strict'; + +require('../helper'); + +const querystring = require('querystring'); +const fs = require('fs'); + +const createServer = require('../../lib/server'); +const assert = require('../support/assert'); + +describe('custom middlewares', function () { + const RESPONSE_OK = { + statusCode: 200 + }; + const RESPONSE_KO_TEAPOT = { + statusCode: 418 + }; + + const customMiddleware = function teapot () { + return function teapotMiddleware (req, res) { + res.status(418).send('I\'m a teapot'); + }; + }; + + describe('wired in /api/v1/', function () { + before(function () { + this.backupRoutes = global.settings.routes; + + global.settings.routes = { + api: [{ + paths: [ + '/api/:version', + '/user/:user/api/:version', + ], + middlewares: [ + customMiddleware + ], + sql: [{ + paths: [ + '/sql' + ] + }] + }] + }; + + this.server = createServer(); + }); + + after(function () { + global.settings.routes = this.backupRoutes; + }); + + it('GET /api/v1/health returns 418: I\'m a teapot', function (done) { + assert.response(this.server, { + url: '/api/v1/health', + method: 'GET' + }, RESPONSE_KO_TEAPOT, function (err, res) { + if (err) { + return done(err); + } + + assert.strictEqual(res.body, 'I\'m a teapot'); + done(); + }); + }); + + it('GET /api/v1/version returns 418: I\'m a teapot', function (done) { + assert.response(this.server, { + url: '/api/v1/version', + method: 'GET' + }, RESPONSE_KO_TEAPOT, function (err, res) { + if (err) { + return done(err); + } + + assert.strictEqual(res.body, 'I\'m a teapot'); + done(); + }); + }); + + it('GET /api/v1/sql returns 418: I\'m a teapot', function (done) { + assert.response(this.server, { + url: '/api/v1/sql?q=SELECT%201', + method: 'GET' + }, RESPONSE_KO_TEAPOT, function (err, res) { + if (err) { + return done(err); + } + + assert.strictEqual(res.body, 'I\'m a teapot'); + done(); + }); + }); + + it('GET /api/v1/sql/job/:id returns 418: I\'m a teapot', function (done) { + assert.response(this.server, { + url: '/api/v1/sql/job/wadus', + method: 'GET' + }, RESPONSE_KO_TEAPOT, function (err, res) { + if (err) { + return done(err); + } + + assert.strictEqual(res.body, 'I\'m a teapot'); + done(); + }); + }); + + it('POST /api/v2/sql/job returns 418: I\'m a teapot', function (done) { + assert.response(this.server, { + url: '/api/v2/sql/job?api_key=1234', + headers: { + host: 'vizzuality.cartodb.com', + 'Content-Type': 'application/x-www-form-urlencoded' + }, + method: 'POST', + data: querystring.stringify({ + query: 'SELECT * FROM untitle_table_4' + }) + }, RESPONSE_KO_TEAPOT, function (err, res) { + if (err) { + return done(err); + } + + assert.strictEqual(res.body, 'I\'m a teapot'); + done(); + }); + }); + + it('DELETE /api/v1/sql/job/:id returns 418: I\'m a teapot', function (done) { + assert.response(this.server, { + url: '/api/v1/sql/job/wadus', + method: 'DELETE' + }, RESPONSE_KO_TEAPOT, function (err, res) { + if (err) { + return done(err); + } + + assert.strictEqual(res.body, 'I\'m a teapot'); + done(); + }); + }); + + it('POST /api/v1/sql/copyfrom returns 418: I\'m a teapot', function (done) { + assert.response(this.server, { + url: `/api/v1/sql/copyfrom?${querystring.stringify({ + q: "COPY copy_endpoints_test (id, name) FROM STDIN WITH (FORMAT CSV, DELIMITER ',', HEADER true)" + })}`, + data: fs.createReadStream(`${__dirname}/../support/csv/copy_test_table.csv`), + headers: { + host: 'vizzuality.cartodb.com' + }, + method: 'POST' + }, RESPONSE_KO_TEAPOT, function (err, res) { + if (err) { + return done(err); + } + + assert.strictEqual(res.body, 'I\'m a teapot'); + done(); + }); + }); + + it('GET /api/v1/sql/copyto returns 418: I\'m a teapot', function (done) { + assert.response(this.server, { + url: `/api/v1/sql/copyto?${querystring.stringify({ + filename: '/tmp/output.dmp' + })}`, + headers: { + host: 'vizzuality.cartodb.com' + }, + method: 'GET' + }, RESPONSE_KO_TEAPOT, function (err, res) { + if (err) { + return done(err); + } + + assert.strictEqual(res.body, 'I\'m a teapot'); + done(); + }); + }); + }); + + describe('wired in /api/v1/sql', function () { + before(function () { + this.backupRoutes = global.settings.routes; + + global.settings.routes = { + api: [{ + paths: [ + '/api/:version', + '/user/:user/api/:version', + ], + sql: [{ + paths: [ + '/sql' + ], + middlewares: [ customMiddleware ] + }] + }] + }; + + this.server = createServer(); + }); + + after(function () { + global.settings.routes = this.backupRoutes; + }); + + it('GET /api/v1/health returns 200', function (done) { + assert.response(this.server, { + url: '/api/v1/health', + method: 'GET' + }, RESPONSE_OK, function (err, res) { + if (err) { + return done(err); + } + + const parsed = JSON.parse(res.body); + + assert.strictEqual(parsed.enabled, true); + assert.strictEqual(parsed.ok, true); + + done(); + }); + }); + + it('GET /api/v1/version returns 200', function (done) { + assert.response(this.server, { + url: '/api/v1/version', + method: 'GET' + }, RESPONSE_OK, function (err, res) { + if (err) { + return done(err); + } + + const parsed = JSON.parse(res.body); + + assert.ok(parsed.hasOwnProperty('cartodb_sql_api')); + + done(); + }); + }); + + it('GET /api/v1/sql returns 418: I\'m a teapot', function (done) { + assert.response(this.server, { + url: '/api/v1/sql?q=SELECT%201', + method: 'GET' + }, RESPONSE_KO_TEAPOT, function (err, res) { + if (err) { + return done(err); + } + + assert.strictEqual(res.body, 'I\'m a teapot'); + done(); + }); + }); + + it('GET /api/v1/sql/job/:id returns 418: I\'m a teapot', function (done) { + assert.response(this.server, { + url: '/api/v1/sql/job/wadus', + method: 'GET' + }, RESPONSE_KO_TEAPOT, function (err, res) { + if (err) { + return done(err); + } + + assert.strictEqual(res.body, 'I\'m a teapot'); + done(); + }); + }); + + it('POST /api/v2/sql/job returns 418: I\'m a teapot', function (done) { + assert.response(this.server, { + url: '/api/v2/sql/job?api_key=1234', + headers: { + host: 'vizzuality.cartodb.com', + 'Content-Type': 'application/x-www-form-urlencoded' + }, + method: 'POST', + data: querystring.stringify({ + query: 'SELECT * FROM untitle_table_4' + }) + }, RESPONSE_KO_TEAPOT, function (err, res) { + if (err) { + return done(err); + } + + assert.strictEqual(res.body, 'I\'m a teapot'); + done(); + }); + }); + + it('DELETE /api/v1/sql/job/:id returns 418: I\'m a teapot', function (done) { + assert.response(this.server, { + url: '/api/v1/sql/job/wadus', + method: 'DELETE' + }, RESPONSE_KO_TEAPOT, function (err, res) { + if (err) { + return done(err); + } + + assert.strictEqual(res.body, 'I\'m a teapot'); + done(); + }); + }); + + it('POST /api/v1/sql/copyfrom returns 418: I\'m a teapot', function (done) { + assert.response(this.server, { + url: `/api/v1/sql/copyfrom?${querystring.stringify({ + q: "COPY copy_endpoints_test (id, name) FROM STDIN WITH (FORMAT CSV, DELIMITER ',', HEADER true)" + })}`, + data: fs.createReadStream(`${__dirname}/../support/csv/copy_test_table.csv`), + headers: { + host: 'vizzuality.cartodb.com' + }, + method: 'POST' + }, RESPONSE_KO_TEAPOT, function (err, res) { + if (err) { + return done(err); + } + + assert.strictEqual(res.body, 'I\'m a teapot'); + done(); + }); + }); + + it('GET /api/v1/sql/copyto returns 418: I\'m a teapot', function (done) { + assert.response(this.server, { + url: `/api/v1/sql/copyto?${querystring.stringify({ + filename: '/tmp/output.dmp' + })}`, + headers: { + host: 'vizzuality.cartodb.com' + }, + method: 'GET' + }, RESPONSE_KO_TEAPOT, function (err, res) { + if (err) { + return done(err); + } + + assert.strictEqual(res.body, 'I\'m a teapot'); + done(); + }); + }); + }); +}); diff --git a/test/acceptance/error-handler.js b/test/acceptance/error-handler-test.js similarity index 95% rename from test/acceptance/error-handler.js rename to test/acceptance/error-handler-test.js index c6d97542..6bc5043e 100644 --- a/test/acceptance/error-handler.js +++ b/test/acceptance/error-handler-test.js @@ -1,6 +1,6 @@ 'use strict'; -var server = require('../../app/server')(); +var server = require('../../lib/server')(); var assert = require('../support/assert'); describe('error handler', function () { diff --git a/test/acceptance/export/arraybuffer.js b/test/acceptance/export/arraybuffer-test.js similarity index 96% rename from test/acceptance/export/arraybuffer.js rename to test/acceptance/export/arraybuffer-test.js index 8e42679d..b891df3f 100644 --- a/test/acceptance/export/arraybuffer.js +++ b/test/acceptance/export/arraybuffer-test.js @@ -4,7 +4,7 @@ require('../../helper'); require('../../support/assert'); -var server = require('../../../app/server')(); +var server = require('../../../lib/server')(); var assert = require('assert'); var querystring = require('querystring'); diff --git a/test/acceptance/export/csv.js b/test/acceptance/export/csv-test.js similarity index 99% rename from test/acceptance/export/csv.js rename to test/acceptance/export/csv-test.js index 7f37b42c..8a4c5671 100644 --- a/test/acceptance/export/csv.js +++ b/test/acceptance/export/csv-test.js @@ -4,7 +4,7 @@ require('../../helper'); require('../../support/assert'); -var server = require('../../../app/server')(); +var server = require('../../../lib/server')(); var assert = require('assert'); var querystring = require('querystring'); diff --git a/test/acceptance/export/folder.js b/test/acceptance/export/folder-test.js similarity index 95% rename from test/acceptance/export/folder.js rename to test/acceptance/export/folder-test.js index 9aebb8c7..59d0e389 100644 --- a/test/acceptance/export/folder.js +++ b/test/acceptance/export/folder-test.js @@ -4,7 +4,7 @@ require('../../helper'); require('../../support/assert'); const fs = require('fs'); -let server = require('../../../app/server'); +let server = require('../../../lib/server'); const assert = require('assert'); const querystring = require('querystring'); diff --git a/test/acceptance/export/geojson.js b/test/acceptance/export/geojson-test.js similarity index 99% rename from test/acceptance/export/geojson.js rename to test/acceptance/export/geojson-test.js index 725d8678..bf19df34 100644 --- a/test/acceptance/export/geojson.js +++ b/test/acceptance/export/geojson-test.js @@ -2,7 +2,7 @@ require('../../helper'); -var server = require('../../../app/server')(); +var server = require('../../../lib/server')(); var assert = require('../../support/assert'); var querystring = require('querystring'); diff --git a/test/acceptance/export/geopackage.js b/test/acceptance/export/geopackage-test.js similarity index 98% rename from test/acceptance/export/geopackage.js rename to test/acceptance/export/geopackage-test.js index 392171c2..9ae9b7ae 100644 --- a/test/acceptance/export/geopackage.js +++ b/test/acceptance/export/geopackage-test.js @@ -2,7 +2,7 @@ require('../../helper'); -var server = require('../../../app/server')(); +var server = require('../../../lib/server')(); var assert = require('../../support/assert'); var sqlite = require('sqlite3'); var fs = require('fs'); diff --git a/test/acceptance/export/kml.js b/test/acceptance/export/kml-test.js similarity index 99% rename from test/acceptance/export/kml.js rename to test/acceptance/export/kml-test.js index 4447363d..d84f7e40 100644 --- a/test/acceptance/export/kml.js +++ b/test/acceptance/export/kml-test.js @@ -2,7 +2,7 @@ require('../../helper'); -var server = require('../../../app/server')(); +var server = require('../../../lib/server')(); var assert = require('../../support/assert'); var querystring = require('querystring'); var libxmljs = require('libxmljs'); diff --git a/test/acceptance/export/shapefile.js b/test/acceptance/export/shapefile-test.js similarity index 99% rename from test/acceptance/export/shapefile.js rename to test/acceptance/export/shapefile-test.js index 7fd8d1e9..33d26951 100644 --- a/test/acceptance/export/shapefile.js +++ b/test/acceptance/export/shapefile-test.js @@ -2,7 +2,7 @@ require('../../helper'); -var server = require('../../../app/server')(); +var server = require('../../../lib/server')(); var assert = require('../../support/assert'); var querystring = require('querystring'); var shapefile = require('shapefile'); diff --git a/test/acceptance/export/spatialite.js b/test/acceptance/export/spatialite-test.js similarity index 97% rename from test/acceptance/export/spatialite.js rename to test/acceptance/export/spatialite-test.js index e8b245cb..dcfa5854 100644 --- a/test/acceptance/export/spatialite.js +++ b/test/acceptance/export/spatialite-test.js @@ -2,7 +2,7 @@ require('../../helper'); -var server = require('../../../app/server')(); +var server = require('../../../lib/server')(); var assert = require('../../support/assert'); var sqlite = require('sqlite3'); diff --git a/test/acceptance/export/svg.js b/test/acceptance/export/svg-test.js similarity index 99% rename from test/acceptance/export/svg.js rename to test/acceptance/export/svg-test.js index 2c452df3..bc266442 100644 --- a/test/acceptance/export/svg.js +++ b/test/acceptance/export/svg-test.js @@ -2,7 +2,7 @@ require('../../helper'); -var server = require('../../../app/server')(); +var server = require('../../../lib/server')(); var assert = require('../../support/assert'); var querystring = require('querystring'); diff --git a/test/acceptance/export/timeout.js b/test/acceptance/export/timeout-test.js similarity index 100% rename from test/acceptance/export/timeout.js rename to test/acceptance/export/timeout-test.js diff --git a/test/acceptance/export/topojson.js b/test/acceptance/export/topojson-test.js similarity index 99% rename from test/acceptance/export/topojson.js rename to test/acceptance/export/topojson-test.js index 61dd6d79..14053a7e 100644 --- a/test/acceptance/export/topojson.js +++ b/test/acceptance/export/topojson-test.js @@ -2,7 +2,7 @@ require('../../helper'); -var server = require('../../../app/server')(); +var server = require('../../../lib/server')(); var assert = require('../../support/assert'); var querystring = require('querystring'); var _ = require('underscore'); diff --git a/test/acceptance/frontend_abort.js b/test/acceptance/frontend_abort-test.js similarity index 97% rename from test/acceptance/frontend_abort.js rename to test/acceptance/frontend_abort-test.js index 7ba7f63a..fe4f73a9 100644 --- a/test/acceptance/frontend_abort.js +++ b/test/acceptance/frontend_abort-test.js @@ -32,7 +32,7 @@ it('aborts request', function(done){ var db_port_backup = global.settings.db_port; global.settings.db_host = 'localhost'; global.settings.db_port = sql_server_port; - var server = require('../../app/server')(); + var server = require('../../lib/server')(); var timeout; step( function sendQuery() { diff --git a/test/acceptance/handle-query.js b/test/acceptance/handle-query-test.js similarity index 97% rename from test/acceptance/handle-query.js rename to test/acceptance/handle-query-test.js index aaf17560..6adc4579 100644 --- a/test/acceptance/handle-query.js +++ b/test/acceptance/handle-query-test.js @@ -2,11 +2,11 @@ require('../helper'); -const server = require('../../app/server')(); +const server = require('../../lib/server')(); const assert = require('../support/assert'); const qs = require('querystring'); const BatchTestClient = require('../support/batch-test-client'); -const JobStatus = require('../../batch/job_status'); +const JobStatus = require('../../lib/batch/job-status'); const QUERY = `SELECT 14 as foo`; const API_KEY = 1234; diff --git a/test/acceptance/health_check.js b/test/acceptance/health-check-test.js similarity index 97% rename from test/acceptance/health_check.js rename to test/acceptance/health-check-test.js index bd29eb1f..be06eca7 100644 --- a/test/acceptance/health_check.js +++ b/test/acceptance/health-check-test.js @@ -4,7 +4,7 @@ require('../helper'); require('../support/assert'); var assert = require('assert'); -var server = require('../../app/server')(); +var server = require('../../lib/server')(); describe('health checks', function() { diff --git a/test/acceptance/last-modified-header.js b/test/acceptance/last-modified-header-test.js similarity index 98% rename from test/acceptance/last-modified-header.js rename to test/acceptance/last-modified-header-test.js index 28799a1b..6c389d66 100644 --- a/test/acceptance/last-modified-header.js +++ b/test/acceptance/last-modified-header-test.js @@ -2,7 +2,7 @@ require('../helper'); -var server = require('../../app/server')(); +var server = require('../../lib/server')(); var assert = require('../support/assert'); var qs = require('querystring'); var MockDate = require('mockdate'); diff --git a/test/acceptance/log.js b/test/acceptance/log-test.js similarity index 98% rename from test/acceptance/log.js rename to test/acceptance/log-test.js index 4d4281de..efea437b 100644 --- a/test/acceptance/log.js +++ b/test/acceptance/log-test.js @@ -2,11 +2,11 @@ require('../helper'); -const server = require('../../app/server')(); +const server = require('../../lib/server')(); const assert = require('../support/assert'); const qs = require('querystring'); const BatchTestClient = require('../support/batch-test-client'); -const { TYPES } = require('../../app/middlewares/log'); +const { TYPES } = require('../../lib/api/middlewares/log'); const QUERY = `SELECT 14 as foo`; const API_KEY = 1234; diff --git a/test/acceptance/pagination.js b/test/acceptance/pagination-test.js similarity index 99% rename from test/acceptance/pagination.js rename to test/acceptance/pagination-test.js index 5aae8747..a7603b18 100644 --- a/test/acceptance/pagination.js +++ b/test/acceptance/pagination-test.js @@ -2,7 +2,7 @@ require('../helper'); -var server = require('../../app/server')(); +var server = require('../../lib/server')(); var assert = require('../support/assert'); var querystring = require('querystring'); var step = require('step'); diff --git a/test/acceptance/pg-entities-access-validator.js b/test/acceptance/pg-entities-access-validator-test.js similarity index 100% rename from test/acceptance/pg-entities-access-validator.js rename to test/acceptance/pg-entities-access-validator-test.js diff --git a/test/acceptance/pg-types.js b/test/acceptance/pg-types-test.js similarity index 99% rename from test/acceptance/pg-types.js rename to test/acceptance/pg-types-test.js index 96ba4f24..34a611e2 100644 --- a/test/acceptance/pg-types.js +++ b/test/acceptance/pg-types-test.js @@ -2,7 +2,7 @@ require('../helper'); -const server = require('../../app/server')(); +const server = require('../../lib/server')(); const assert = require('../support/assert'); const querystring = require('querystring'); diff --git a/test/acceptance/query-float-values.js b/test/acceptance/query-float-values-test.js similarity index 98% rename from test/acceptance/query-float-values.js rename to test/acceptance/query-float-values-test.js index 1b711eed..7aafc9d3 100644 --- a/test/acceptance/query-float-values.js +++ b/test/acceptance/query-float-values-test.js @@ -2,7 +2,7 @@ require('../helper'); -var server = require('../../app/server')(); +var server = require('../../lib/server')(); var assert = require('../support/assert'); var querystring = require('querystring'); var step = require('step'); diff --git a/test/acceptance/query-multipart.js b/test/acceptance/query-multipart-test.js similarity index 94% rename from test/acceptance/query-multipart.js rename to test/acceptance/query-multipart-test.js index a048fae1..90ac65fa 100644 --- a/test/acceptance/query-multipart.js +++ b/test/acceptance/query-multipart-test.js @@ -2,7 +2,7 @@ require('../helper'); -const server = require('../../app/server')(); +const server = require('../../lib/server')(); const assert = require('../support/assert'); describe('query-multipart', function() { diff --git a/test/acceptance/query-returning.js b/test/acceptance/query-returning-test.js similarity index 99% rename from test/acceptance/query-returning.js rename to test/acceptance/query-returning-test.js index cfbf9212..313df9be 100644 --- a/test/acceptance/query-returning.js +++ b/test/acceptance/query-returning-test.js @@ -2,7 +2,7 @@ require('../helper'); -var server = require('../../app/server')(); +var server = require('../../lib/server')(); var assert = require('../support/assert'); var querystring = require('querystring'); var _ = require('underscore'); diff --git a/test/acceptance/rate-limit.js b/test/acceptance/rate-limit-test.js similarity index 96% rename from test/acceptance/rate-limit.js rename to test/acceptance/rate-limit-test.js index afb3cd97..aa708c08 100644 --- a/test/acceptance/rate-limit.js +++ b/test/acceptance/rate-limit-test.js @@ -5,10 +5,10 @@ require('../helper'); const qs = require('querystring'); const assert = require('../support/assert'); const redis = require('redis'); -const rateLimitMiddleware = require('../../app/middlewares/rate-limit'); +const rateLimitMiddleware = require('../../lib/api/middlewares/rate-limit'); const { RATE_LIMIT_ENDPOINTS_GROUPS } = rateLimitMiddleware; -const app = require('../../app/server'); +const app = require('../../lib/server'); let server; let redisClient; diff --git a/test/acceptance/regressions.js b/test/acceptance/regressions-test.js similarity index 98% rename from test/acceptance/regressions.js rename to test/acceptance/regressions-test.js index adb27e66..31b4c43b 100644 --- a/test/acceptance/regressions.js +++ b/test/acceptance/regressions-test.js @@ -2,7 +2,7 @@ require('../helper'); -var server = require('../../app/server')(); +var server = require('../../lib/server')(); var assert = require('../support/assert'); var qs = require('querystring'); diff --git a/test/acceptance/skipfields.js b/test/acceptance/skipfields-test.js similarity index 98% rename from test/acceptance/skipfields.js rename to test/acceptance/skipfields-test.js index 7524f22b..9b3429bd 100644 --- a/test/acceptance/skipfields.js +++ b/test/acceptance/skipfields-test.js @@ -2,7 +2,7 @@ require('../helper'); -var server = require('../../app/server')(); +var server = require('../../lib/server')(); var assert = require('../support/assert'); var querystring = require('querystring'); var _ = require('underscore'); diff --git a/test/acceptance/stream-responses.js b/test/acceptance/stream-responses-test.js similarity index 97% rename from test/acceptance/stream-responses.js rename to test/acceptance/stream-responses-test.js index 126bf997..88b4d068 100644 --- a/test/acceptance/stream-responses.js +++ b/test/acceptance/stream-responses-test.js @@ -2,7 +2,7 @@ require('../helper'); -var server = require('../../app/server')(); +var server = require('../../lib/server')(); var assert = require('../support/assert'); var querystring = require('querystring'); diff --git a/test/acceptance/surrogate-key.js b/test/acceptance/surrogate-key-test.js similarity index 98% rename from test/acceptance/surrogate-key.js rename to test/acceptance/surrogate-key-test.js index 2fd7ed5c..aac7a758 100644 --- a/test/acceptance/surrogate-key.js +++ b/test/acceptance/surrogate-key-test.js @@ -2,7 +2,7 @@ require('../helper'); -var server = require('../../app/server')(); +var server = require('../../lib/server')(); var assert = require('../support/assert'); var querystring = require('querystring'); var QueryTables = require('cartodb-query-tables').queryTables; diff --git a/test/acceptance/system-queries.js b/test/acceptance/system-queries-test.js similarity index 98% rename from test/acceptance/system-queries.js rename to test/acceptance/system-queries-test.js index 8526aade..2c6853e1 100644 --- a/test/acceptance/system-queries.js +++ b/test/acceptance/system-queries-test.js @@ -2,7 +2,7 @@ require('../helper'); -var server = require('../../app/server')(); +var server = require('../../lib/server')(); var assert = require('../support/assert'); var querystring = require('querystring'); diff --git a/test/acceptance/timeout.js b/test/acceptance/timeout-test.js similarity index 96% rename from test/acceptance/timeout.js rename to test/acceptance/timeout-test.js index 99c2d7e5..95270a60 100644 --- a/test/acceptance/timeout.js +++ b/test/acceptance/timeout-test.js @@ -28,7 +28,7 @@ it('after configured milliseconds', function(done){ //console.log("settings:"); console.dir(global.settings); var timeoutBackup = global.settings.node_socket_timeout; global.settings.node_socket_timeout = testTimeout; - var server = require('../../app/server')(); + var server = require('../../lib/server')(); step( function sendLongQuery() { assert.response(server, { diff --git a/test/acceptance/transaction.js b/test/acceptance/transaction-test.js similarity index 97% rename from test/acceptance/transaction.js rename to test/acceptance/transaction-test.js index 0ee54d5a..8fc9d150 100644 --- a/test/acceptance/transaction.js +++ b/test/acceptance/transaction-test.js @@ -12,7 +12,7 @@ describe('transaction', function() { var server; before(function(done) { - server = require('../../app/server')(); + server = require('../../lib/server')(); this.listener = server.listen(SERVER_PORT, '127.0.0.1'); this.listener.on('listening', done); }); diff --git a/test/acceptance/x-cache-channel.js b/test/acceptance/x-cache-channel-test.js similarity index 98% rename from test/acceptance/x-cache-channel.js rename to test/acceptance/x-cache-channel-test.js index dfcc0599..0bf18f16 100644 --- a/test/acceptance/x-cache-channel.js +++ b/test/acceptance/x-cache-channel-test.js @@ -2,7 +2,7 @@ require('../helper'); -var server = require('../../app/server')(); +var server = require('../../lib/server')(); var assert = require('../support/assert'); var querystring = require('querystring'); var _ = require('underscore'); diff --git a/test/integration/batch/job_backend.test.js b/test/integration/batch/job-backend-test.js similarity index 95% rename from test/integration/batch/job_backend.test.js rename to test/integration/batch/job-backend-test.js index fa7534aa..8588a6fa 100644 --- a/test/integration/batch/job_backend.test.js +++ b/test/integration/batch/job-backend-test.js @@ -2,17 +2,17 @@ require('../../helper'); -var BATCH_SOURCE = '../../../batch/'; +var BATCH_SOURCE = '../../../lib/batch/'; var assert = require('../../support/assert'); -var redisUtils = require('../../support/redis_utils'); +var redisUtils = require('../../support/redis-utils'); var BatchLogger = require(BATCH_SOURCE + 'batch-logger'); -var JobQueue = require(BATCH_SOURCE + 'job_queue'); -var JobBackend = require(BATCH_SOURCE + 'job_backend'); +var JobQueue = require(BATCH_SOURCE + 'job-queue'); +var JobBackend = require(BATCH_SOURCE + 'job-backend'); var JobPublisher = require(BATCH_SOURCE + 'pubsub/job-publisher'); -var JobFactory = require(BATCH_SOURCE + 'models/job_factory'); -var jobStatus = require(BATCH_SOURCE + 'job_status'); +var JobFactory = require(BATCH_SOURCE + 'models/job-factory'); +var jobStatus = require(BATCH_SOURCE + 'job-status'); var logger = new BatchLogger(null, 'batch-queries'); var metadataBackend = require('cartodb-redis')({ pool: redisUtils.getPool() }); diff --git a/test/integration/batch/job_canceller.test.js b/test/integration/batch/job-canceller-test.js similarity index 88% rename from test/integration/batch/job_canceller.test.js rename to test/integration/batch/job-canceller-test.js index d71ac91c..b9c3d6c7 100644 --- a/test/integration/batch/job_canceller.test.js +++ b/test/integration/batch/job-canceller-test.js @@ -2,18 +2,18 @@ require('../../helper'); -var BATCH_SOURCE = '../../../batch/'; +var BATCH_SOURCE = '../../../lib/batch/'; var assert = require('../../support/assert'); -var redisUtils = require('../../support/redis_utils'); +var redisUtils = require('../../support/redis-utils'); var BatchLogger = require(BATCH_SOURCE + 'batch-logger'); -var JobQueue = require(BATCH_SOURCE + 'job_queue'); -var JobBackend = require(BATCH_SOURCE + 'job_backend'); +var JobQueue = require(BATCH_SOURCE + 'job-queue'); +var JobBackend = require(BATCH_SOURCE + 'job-backend'); var JobPublisher = require(BATCH_SOURCE + 'pubsub/job-publisher'); -var jobStatus = require(BATCH_SOURCE + 'job_status'); -var JobCanceller = require(BATCH_SOURCE + 'job_canceller'); -var JobFactory = require(BATCH_SOURCE + 'models/job_factory'); +var jobStatus = require(BATCH_SOURCE + 'job-status'); +var JobCanceller = require(BATCH_SOURCE + 'job-canceller'); +var JobFactory = require(BATCH_SOURCE + 'models/job-factory'); var PSQL = require('cartodb-psql'); var logger = new BatchLogger(null, 'batch-queries'); diff --git a/test/integration/batch/job_publisher.test.js b/test/integration/batch/job-publisher-test.js similarity index 90% rename from test/integration/batch/job_publisher.test.js rename to test/integration/batch/job-publisher-test.js index 50c9f5c7..74b252ae 100644 --- a/test/integration/batch/job_publisher.test.js +++ b/test/integration/batch/job-publisher-test.js @@ -2,11 +2,11 @@ require('../../helper'); -var BATCH_SOURCE = '../../../batch/'; +var BATCH_SOURCE = '../../../lib/batch/'; var assert = require('../../support/assert'); -var redisUtils = require('../../support/redis_utils'); +var redisUtils = require('../../support/redis-utils'); var Channel = require(BATCH_SOURCE + 'pubsub/channel'); diff --git a/test/integration/batch/job-queue.test.js b/test/integration/batch/job-queue-test.js similarity index 92% rename from test/integration/batch/job-queue.test.js rename to test/integration/batch/job-queue-test.js index 735e3d3a..34053ef9 100644 --- a/test/integration/batch/job-queue.test.js +++ b/test/integration/batch/job-queue-test.js @@ -2,16 +2,16 @@ require('../../helper'); var assert = require('../../support/assert'); -var redisUtils = require('../../support/redis_utils'); +var redisUtils = require('../../support/redis-utils'); var metadataBackend = require('cartodb-redis')({ pool: redisUtils.getPool() }); -var BatchLogger = require('../../../batch/batch-logger'); -var JobPublisher = require('../../../batch/pubsub/job-publisher'); -var JobQueue = require('../../../batch/job_queue'); +var BatchLogger = require('../../../lib/batch/batch-logger'); +var JobPublisher = require('../../../lib/batch/pubsub/job-publisher'); +var JobQueue = require('../../../lib/batch/job-queue'); -var JobBackend = require('../../../batch/job_backend'); -var JobService = require('../../../batch/job_service'); -var JobCanceller = require('../../../batch/job_canceller'); +var JobBackend = require('../../../lib/batch/job-backend'); +var JobService = require('../../../lib/batch/job-service'); +var JobCanceller = require('../../../lib/batch/job-canceller'); var metadataBackend = require('cartodb-redis')({ pool: redisUtils.getPool() }); describe('job queue', function () { diff --git a/test/integration/batch/job_runner.test.js b/test/integration/batch/job-runner-test.js similarity index 79% rename from test/integration/batch/job_runner.test.js rename to test/integration/batch/job-runner-test.js index cb0eb96d..cfa50a34 100644 --- a/test/integration/batch/job_runner.test.js +++ b/test/integration/batch/job-runner-test.js @@ -2,21 +2,21 @@ require('../../helper'); -var BATCH_SOURCE = '../../../batch/'; +var BATCH_SOURCE = '../../../lib/batch/'; var assert = require('../../support/assert'); -var redisUtils = require('../../support/redis_utils'); +var redisUtils = require('../../support/redis-utils'); var BatchLogger = require(BATCH_SOURCE + 'batch-logger'); -var JobQueue = require(BATCH_SOURCE + 'job_queue'); -var JobBackend = require(BATCH_SOURCE + 'job_backend'); +var JobQueue = require(BATCH_SOURCE + 'job-queue'); +var JobBackend = require(BATCH_SOURCE + 'job-backend'); var JobPublisher = require(BATCH_SOURCE + 'pubsub/job-publisher'); -var jobStatus = require(BATCH_SOURCE + 'job_status'); -var UserDatabaseMetadataService = require(BATCH_SOURCE + 'user_database_metadata_service'); -var JobCanceller = require(BATCH_SOURCE + 'job_canceller'); -var JobService = require(BATCH_SOURCE + 'job_service'); -var JobRunner = require(BATCH_SOURCE + 'job_runner'); -var QueryRunner = require(BATCH_SOURCE + 'query_runner'); +var jobStatus = require(BATCH_SOURCE + 'job-status'); +var UserDatabaseMetadataService = require(BATCH_SOURCE + 'user-database-metadata-service'); +var JobCanceller = require(BATCH_SOURCE + 'job-canceller'); +var JobService = require(BATCH_SOURCE + 'job-service'); +var JobRunner = require(BATCH_SOURCE + 'job-runner'); +var QueryRunner = require(BATCH_SOURCE + 'query-runner'); var metadataBackend = require('cartodb-redis')({ pool: redisUtils.getPool() }); diff --git a/test/integration/batch/job_service.test.js b/test/integration/batch/job-service-test.js similarity index 93% rename from test/integration/batch/job_service.test.js rename to test/integration/batch/job-service-test.js index b8f45797..efadac90 100644 --- a/test/integration/batch/job_service.test.js +++ b/test/integration/batch/job-service-test.js @@ -2,18 +2,18 @@ require('../../helper'); -var BATCH_SOURCE = '../../../batch/'; +var BATCH_SOURCE = '../../../lib/batch/'; var assert = require('../../support/assert'); -var redisUtils = require('../../support/redis_utils'); +var redisUtils = require('../../support/redis-utils'); var BatchLogger = require(BATCH_SOURCE + 'batch-logger'); -var JobQueue = require(BATCH_SOURCE + 'job_queue'); -var JobBackend = require(BATCH_SOURCE + 'job_backend'); +var JobQueue = require(BATCH_SOURCE + 'job-queue'); +var JobBackend = require(BATCH_SOURCE + 'job-backend'); var JobPublisher = require(BATCH_SOURCE + 'pubsub/job-publisher'); -var jobStatus = require(BATCH_SOURCE + 'job_status'); -var JobCanceller = require(BATCH_SOURCE + 'job_canceller'); -var JobService = require(BATCH_SOURCE + 'job_service'); +var jobStatus = require(BATCH_SOURCE + 'job-status'); +var JobCanceller = require(BATCH_SOURCE + 'job-canceller'); +var JobService = require(BATCH_SOURCE + 'job-service'); var PSQL = require('cartodb-psql'); var metadataBackend = require('cartodb-redis')({ pool: redisUtils.getPool() }); diff --git a/test/integration/batch/locker.js b/test/integration/batch/locker-test.js similarity index 93% rename from test/integration/batch/locker.js rename to test/integration/batch/locker-test.js index f1f2116f..f1e5c534 100644 --- a/test/integration/batch/locker.js +++ b/test/integration/batch/locker-test.js @@ -3,8 +3,8 @@ require('../../helper'); var assert = require('../../support/assert'); -var redisUtils = require('../../support/redis_utils'); -var Locker = require('../../../batch/leader/locker'); +var redisUtils = require('../../support/redis-utils'); +var Locker = require('../../../lib/batch/leader/locker'); describe('locker', function() { var host = 'localhost'; diff --git a/test/integration/batch/scheduler.js b/test/integration/batch/scheduler-test.js similarity index 96% rename from test/integration/batch/scheduler.js rename to test/integration/batch/scheduler-test.js index 512ef288..2be1807b 100644 --- a/test/integration/batch/scheduler.js +++ b/test/integration/batch/scheduler-test.js @@ -1,10 +1,10 @@ 'use strict'; require('../../helper'); -var debug = require('../../../batch/util/debug')('scheduler-test'); +var debug = require('../../../lib/batch/util/debug')('scheduler-test'); var assert = require('../../support/assert'); -var Scheduler = require('../../../batch/scheduler/scheduler'); -var FixedCapacity = require('../../../batch/scheduler/capacity/fixed'); +var Scheduler = require('../../../lib/batch/scheduler/scheduler'); +var FixedCapacity = require('../../../lib/batch/scheduler/capacity/fixed'); describe('scheduler', function() { diff --git a/test/integration/stream_copy.test.js b/test/integration/stream-copy-test.js similarity index 90% rename from test/integration/stream_copy.test.js rename to test/integration/stream-copy-test.js index 4ee7c816..f73c740b 100644 --- a/test/integration/stream_copy.test.js +++ b/test/integration/stream-copy-test.js @@ -3,7 +3,7 @@ require('../helper'); const assert = require('assert'); -const StreamCopy = require('../../app/services/stream_copy'); +const StreamCopy = require('../../lib/services/stream-copy'); describe('stream copy', function() { it('uses batch api port', function(done) { diff --git a/test/support/batch-test-client.js b/test/support/batch-test-client.js index 3c43735a..82962354 100644 --- a/test/support/batch-test-client.js +++ b/test/support/batch-test-client.js @@ -2,13 +2,13 @@ require('../helper'); var assert = require('assert'); -var appServer = require('../../app/server'); -var redisUtils = require('./redis_utils'); +var appServer = require('../../lib/server'); +var redisUtils = require('./redis-utils'); var debug = require('debug')('batch-test-client'); -var JobStatus = require('../../batch/job_status'); +var JobStatus = require('../../lib/batch/job-status'); var metadataBackend = require('cartodb-redis')({ pool: redisUtils.getPool() }); -var batchFactory = require('../../batch/index'); +var batchFactory = require('../../lib/batch/index'); function response(code) { return { diff --git a/test/support/redis_utils.js b/test/support/redis-utils.js similarity index 100% rename from test/support/redis_utils.js rename to test/support/redis-utils.js diff --git a/test/support/test-client.js b/test/support/test-client.js index bd1b163f..66bbc3aa 100644 --- a/test/support/test-client.js +++ b/test/support/test-client.js @@ -2,8 +2,8 @@ require('../helper'); var assert = require('assert'); -var appServer = require('../../app/server'); -var redisUtils = require('./redis_utils'); +var appServer = require('../../lib/server'); +var redisUtils = require('./redis-utils'); const step = require('step'); const PSQL = require('cartodb-psql'); const _ = require('underscore'); diff --git a/test/unit/apikeyauth.test.js b/test/unit/apikeyauth-test.js similarity index 98% rename from test/unit/apikeyauth.test.js rename to test/unit/apikeyauth-test.js index 1c47c2fe..1fab72e5 100644 --- a/test/unit/apikeyauth.test.js +++ b/test/unit/apikeyauth-test.js @@ -2,7 +2,7 @@ require('../helper'); -var ApikeyAuth = require('../../app/auth/apikey'); +var ApikeyAuth = require('../../lib/auth/apikey'); var assert = require('assert'); describe.skip('has credentials', function() { diff --git a/test/unit/batch/job_publisher.js b/test/unit/batch/job-publisher-test.js similarity index 89% rename from test/unit/batch/job_publisher.js rename to test/unit/batch/job-publisher-test.js index 82f3bf89..58817213 100644 --- a/test/unit/batch/job_publisher.js +++ b/test/unit/batch/job-publisher-test.js @@ -1,7 +1,7 @@ 'use strict'; -var Channel = require('../../../batch/pubsub/channel'); -var JobPublisher = require('../../../batch/pubsub/job-publisher'); +var Channel = require('../../../lib/batch/pubsub/channel'); +var JobPublisher = require('../../../lib/batch/pubsub/job-publisher'); var assert = require('assert'); describe('batch API job publisher', function () { diff --git a/test/unit/batch/job_queue.js b/test/unit/batch/job-queue-test.js similarity index 96% rename from test/unit/batch/job_queue.js rename to test/unit/batch/job-queue-test.js index 4f7babf2..29b4e43f 100644 --- a/test/unit/batch/job_queue.js +++ b/test/unit/batch/job-queue-test.js @@ -1,6 +1,6 @@ 'use strict'; -var JobQueue = require('../../../batch/job_queue'); +var JobQueue = require('../../../lib/batch/job-queue'); var assert = require('assert'); describe('batch API job queue', function () { diff --git a/test/unit/batch/job_subscriber.js b/test/unit/batch/job-subscriber-test.js similarity index 94% rename from test/unit/batch/job_subscriber.js rename to test/unit/batch/job-subscriber-test.js index 6c63b148..2c3a192a 100644 --- a/test/unit/batch/job_subscriber.js +++ b/test/unit/batch/job-subscriber-test.js @@ -1,7 +1,7 @@ 'use strict'; -var Channel = require('../../../batch/pubsub/channel'); -var JobSubscriber = require('../../../batch/pubsub/job-subscriber'); +var Channel = require('../../../lib/batch/pubsub/channel'); +var JobSubscriber = require('../../../lib/batch/pubsub/job-subscriber'); var assert = require('assert'); describe('batch API job subscriber', function () { diff --git a/test/unit/error_handler_factory.test.js b/test/unit/error-handler-factory-test.js similarity index 91% rename from test/unit/error_handler_factory.test.js rename to test/unit/error-handler-factory-test.js index 97cdfc63..c1d988b5 100644 --- a/test/unit/error_handler_factory.test.js +++ b/test/unit/error-handler-factory-test.js @@ -1,9 +1,9 @@ 'use strict'; const assert = require('assert'); -const errorHandlerFactory = require('../../app/services/error_handler_factory'); -const ErrorHandler = require('../../app/services/error_handler'); -const { codeToCondition } = require('../../app/postgresql/error_codes'); +const errorHandlerFactory = require('../../lib/services/error-handler-factory'); +const ErrorHandler = require('../../lib/services/error-handler'); +const { codeToCondition } = require('../../lib/postgresql/error-codes'); let rateLimitError = new Error( 'You are over platform\'s limits. Please contact us to know more details' diff --git a/test/unit/error_handler.test.js b/test/unit/error-handler-test.js similarity index 97% rename from test/unit/error_handler.test.js rename to test/unit/error-handler-test.js index e3cb5fb3..6f89f95f 100644 --- a/test/unit/error_handler.test.js +++ b/test/unit/error-handler-test.js @@ -1,7 +1,7 @@ 'use strict'; var assert = require('assert'); -var errorMiddleware = require('../../app/middlewares/error'); +var errorMiddleware = require('../../lib/api/middlewares/error'); require('../helper'); const req = { query: { callback: true } }; @@ -75,7 +75,7 @@ describe('error-handler', function() { error.message ); - const res = getRes(); + const res = getRes(); errorMiddleware()(error, req, res, function next () { assert.ok(res.headers['X-SQLAPI-Errors'].length > 0); @@ -105,7 +105,7 @@ describe('error-handler', function() { ); const res = getRes(); - + errorMiddleware()(error, req, res, function () { assert.ok(res.headers['X-SQLAPI-Errors'].length > 0); assert.deepEqual( diff --git a/test/unit/health_check.js b/test/unit/health-check-test.js similarity index 94% rename from test/unit/health_check.js rename to test/unit/health-check-test.js index 1920e977..d776a795 100644 --- a/test/unit/health_check.js +++ b/test/unit/health-check-test.js @@ -3,7 +3,7 @@ require('../helper'); var assert = require('assert'); -var HealthCheck = require('../../app/monitoring/health_check'); +var HealthCheck = require('../../lib/monitoring/health-check'); var metadataBackend = {}; diff --git a/test/unit/model/bin_encoder.js b/test/unit/model/bin-encoder-test.js similarity index 97% rename from test/unit/model/bin_encoder.js rename to test/unit/model/bin-encoder-test.js index a0f7bf4f..a9b4dd8d 100644 --- a/test/unit/model/bin_encoder.js +++ b/test/unit/model/bin-encoder-test.js @@ -3,7 +3,7 @@ require('../../helper'); var assert = require('assert'); -var ArrayBufferSer = require('../../../app/models/bin_encoder'); +var ArrayBufferSer = require('../../../lib/models/bin-encoder'); describe('ArrayBufferSer', function() { diff --git a/test/unit/oauth.test.js b/test/unit/oauth-test.js similarity index 98% rename from test/unit/oauth.test.js rename to test/unit/oauth-test.js index 6b629478..e90b7133 100644 --- a/test/unit/oauth.test.js +++ b/test/unit/oauth-test.js @@ -3,9 +3,9 @@ require('../helper'); var _ = require('underscore'); -var OAuthAuth = require('../../app/auth/oauth'); +var OAuthAuth = require('../../lib/auth/oauth'); var MetadataDB = require('cartodb-redis'); -var oAuth = require('../../app/auth/oauth').backend; +var oAuth = require('../../lib/auth/oauth').backend; var assert = require('assert'); var oauth_data_1 = { oauth_consumer_key: "dpf43f3p2l4k3l03", diff --git a/test/unit/pg-entities-access-validator.test.js b/test/unit/pg-entities-access-validator-test.js similarity index 98% rename from test/unit/pg-entities-access-validator.test.js rename to test/unit/pg-entities-access-validator-test.js index f28a1d67..f859b04b 100644 --- a/test/unit/pg-entities-access-validator.test.js +++ b/test/unit/pg-entities-access-validator-test.js @@ -1,7 +1,7 @@ 'use strict'; const assert = require('assert'); -const pgEntitiesAccessValidator = require('../../app/services/pg-entities-access-validator'); +const pgEntitiesAccessValidator = require('../../lib/services/pg-entities-access-validator'); const fakeAffectedTables = [{ schema_name: 'schema', diff --git a/test/unit/query_info.test.js b/test/unit/query-info-test.js similarity index 97% rename from test/unit/query_info.test.js rename to test/unit/query-info-test.js index 05945b61..d797d8ec 100644 --- a/test/unit/query_info.test.js +++ b/test/unit/query-info-test.js @@ -1,7 +1,7 @@ 'use strict'; const assert = require('assert'); -const queryInfo = require('../../app/utils/query_info'); +const queryInfo = require('../../lib/utils/query-info'); describe('query info', function () { describe('copy format', function () { diff --git a/test/websocket_test/public/run_server.sh b/test/websocket_test/public/run_server.sh index dc1e2ab7..db92673c 100755 --- a/test/websocket_test/public/run_server.sh +++ b/test/websocket_test/public/run_server.sh @@ -1 +1 @@ -python -m SimpleHTTPServer 8000 \ No newline at end of file +python -m SimpleHTTPServer 8000