CartoDB-SQL-API/batch/user_database_metadata_service.js

45 lines
1.4 KiB
JavaScript
Raw Normal View History

2015-12-10 03:17:45 +08:00
'use strict';
var _ = require('underscore');
2015-12-10 03:17:45 +08:00
function UserDatabaseMetadataService(metadataBackend) {
this.metadataBackend = metadataBackend;
}
UserDatabaseMetadataService.prototype.getUserMetadata = function (username, callback) {
var self = this;
2015-12-10 03:17:45 +08:00
this.metadataBackend.getAllUserDBParams(username, function (err, userDatabaseMetadata) {
if (err) {
return callback(err);
}
2015-12-30 18:51:32 +08:00
callback(null, self.parseMetadataToDatabase(userDatabaseMetadata));
2015-12-10 03:17:45 +08:00
});
};
2015-12-30 18:51:32 +08:00
UserDatabaseMetadataService.prototype.parseMetadataToDatabase = function (userDatabaseMetadata) {
var dbParams = userDatabaseMetadata;
var dbopts = {};
dbopts.pass = dbParams.dbpass || global.settings.db_pubuser_pass;
dbopts.port = dbParams.dbport || global.settings.db_batch_port || global.settings.db_port;
dbopts.host = dbParams.dbhost;
dbopts.dbname = dbParams.dbname;
dbopts.user = (!!dbParams.dbpublicuser) ? dbParams.dbpublicuser : global.settings.db_pubuser;
// batch is secure so it's going to be authenticated by default
dbopts.authenticated = true;
dbopts.user = _.template(global.settings.db_user, { user_id: dbParams.dbuser });
dbopts.pass = _.template(global.settings.db_user_pass, {
user_id: dbParams.dbuser,
user_password: dbParams.dbpass
});
return dbopts;
};
2015-12-10 03:17:45 +08:00
module.exports = UserDatabaseMetadataService;