Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Automated formatting #583

Open
wants to merge 6 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
34 changes: 17 additions & 17 deletions core/config.service.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ let conf = null;
exports.get_conf = get_conf;

// todo: maybe add a file in config with all the default value, load it and overide it with custom config
function init () {
function init() {
if (!is_init) {
conf = CONFIG;
if (!conf.duration) {
Expand All @@ -27,33 +27,33 @@ function init () {
}
if (!conf.enable_ui) {
conf.enable_ui = {
'messages': true,
'databases': true,
'tps': true,
'websites': true,
'u2f_key': true,
'ip': true,
'newsletters': true,
'log': true
messages: true,
databases: true,
tps: true,
websites: true,
u2f_key: true,
ip: true,
newsletters: true,
log: true
};
}
conf.enable_ui.main_group = CONFIG.general.use_group_in_path;
conf.enable_ui.user_group = !CONFIG.general.disable_user_group;

if (!conf.project) {
conf.project = {
'enable_group': true,
'default_size': 500,
'default_path': '/opt/project',
'default_expire': 360,
'allow_extend': false
enable_group: true,
default_size: 500,
default_path: '/opt/project',
default_expire: 360,
allow_extend: false
};
}

if (!conf.reservation) {
conf.reservation = {
'group_or_project': 'group',
'show_choice_in_ui': false
group_or_project: 'group',
show_choice_in_ui: false
};
}

Expand All @@ -62,7 +62,7 @@ function init () {
}

// todo: should replace all {const CONFIG = require('config');} by a call to this function
function get_conf () {
function get_conf() {
init();
return conf;
}
67 changes: 48 additions & 19 deletions core/db.service.js
Original file line number Diff line number Diff line change
Expand Up @@ -21,11 +21,14 @@ var mongo_tags = null;
var mongo_pending_projects = null;
var mongo_pending_databases = null;

var mongo_connect = async function() {
var mongo_connect = async function () {
let url = CONFIG.mongo.url;
let client = null;
if(!url) {
client = new MongoClient(`mongodb://${CONFIG.mongo.host}:${CONFIG.mongo.port}`, { useNewUrlParser: true, useUnifiedTopology: true });
if (!url) {
client = new MongoClient(`mongodb://${CONFIG.mongo.host}:${CONFIG.mongo.port}`, {
useNewUrlParser: true,
useUnifiedTopology: true
});
} else {
client = new MongoClient(CONFIG.mongo.url, { useNewUrlParser: true, useUnifiedTopology: true });
}
Expand All @@ -46,31 +49,57 @@ var mongo_connect = async function() {
};
// mongo_connect();

exports.init_db = async function() {
exports.init_db = async function () {
logger.info('initialize db connection');
try {
if(mongodb != null) {
if (mongodb != null) {
return null;
}
await mongo_connect();
logger.info('connected');
return null;
} catch(err){
} catch (err) {
logger.debug('Failed to init db', err);
return err;
}
};
exports.mongodb = mongodb;
exports.mongo_users = function() {return mongo_users;};
exports.mongo_groups = function() {return mongo_groups;};
exports.mongo_events = function() {return mongo_events;};
exports.mongo_reservations = function() {return mongo_reservations;};
exports.mongo_databases = function() {return mongo_databases;};
exports.mongo_web = function() {return mongo_web;};
exports.mongo_projects = function() {return mongo_projects;};
exports.mongo_tags = function() {return mongo_tags;};
exports.mongo_pending_projects = function() {return mongo_pending_projects;};
exports.mongo_oldusers = function() {return mongo_oldusers;};
exports.mongo_oldgroups = function() {return mongo_oldgroups;};
exports.mongo_others = function(coll) { return mongodb.collection(coll);};
exports.mongo_pending_databases = function() {return mongo_pending_databases;};
exports.mongo_users = function () {
return mongo_users;
};
exports.mongo_groups = function () {
return mongo_groups;
};
exports.mongo_events = function () {
return mongo_events;
};
exports.mongo_reservations = function () {
return mongo_reservations;
};
exports.mongo_databases = function () {
return mongo_databases;
};
exports.mongo_web = function () {
return mongo_web;
};
exports.mongo_projects = function () {
return mongo_projects;
};
exports.mongo_tags = function () {
return mongo_tags;
};
exports.mongo_pending_projects = function () {
return mongo_pending_projects;
};
exports.mongo_oldusers = function () {
return mongo_oldusers;
};
exports.mongo_oldgroups = function () {
return mongo_oldgroups;
};
exports.mongo_others = function (coll) {
return mongodb.collection(coll);
};
exports.mongo_pending_databases = function () {
return mongo_pending_databases;
};
42 changes: 21 additions & 21 deletions core/file.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,21 +12,16 @@ const templates_dir_default = 'templates/default';

// Todo: Manage mail template with nunjuck

nunjucks.configure(
[templates_dir, templates_dir_default],
{
autoescape: true,
trimBlocks: true,
lstripBlocks: true
}
);

nunjucks.configure([templates_dir, templates_dir_default], {
autoescape: true,
trimBlocks: true,
lstripBlocks: true
});

const tplconf = require('../' + templates_dir + '/templates.json');

function create_file (name, data) {
return new Promise( function (resolve, reject) {

function create_file(name, data) {
return new Promise(function (resolve, reject) {
if (!tplconf[name]) {
logger.warn('Templates file are missing for ' + name);
reject('Templates file are missing for ' + name);
Expand Down Expand Up @@ -71,19 +66,17 @@ function create_file (name, data) {
if (tpl.filename_mode) {
fs.chmodSync(filepath + '/' + filename, tpl.filename_mode);
}
resolve (filepath + '/' + filename);
resolve(filepath + '/' + filename);
return;
});
});
});
});
}


/* Todo: find if we should export create_file or not */
/* Todo: should find a clean way to set name of param from function prototype) */
module.exports = {

/*
set_suffix: function (suffix) {
filename_suffix = suffix;
Expand Down Expand Up @@ -122,7 +115,12 @@ module.exports = {
},

ldap_change_user_groups: function (user, group_add_dn, group_remove_dn, fid) { // will use user.group
return create_file('ldap_change_user_groups', { user: user, group_add_dn: group_add_dn, group_remove_dn: group_remove_dn, fid: fid });
return create_file('ldap_change_user_groups', {
user: user,
group_add_dn: group_add_dn,
group_remove_dn: group_remove_dn,
fid: fid
});
},

/* method for users.js */
Expand All @@ -144,7 +142,12 @@ module.exports = {
},

user_change_group: function (user, group_add, group_remove, fid) {
return create_file('user_change_group', { user: user, group_add: group_add, group_remove: group_remove, fid: fid });
return create_file('user_change_group', {
user: user,
group_add: group_add,
group_remove: group_remove,
fid: fid
});
},

user_delete_user: function (user, fid) {
Expand Down Expand Up @@ -172,7 +175,6 @@ module.exports = {
return create_file('user_add_ssh_key', { user: user, fid: fid });
},


/* method for ssh.js */
ssh_keygen: function (user, fid) {
return create_file('ssh_keygen', { user: user, fid: fid });
Expand Down Expand Up @@ -202,7 +204,5 @@ module.exports = {

project_add_group_to_project: function (project, group, fid) {
return create_file('project_add_group_to_project', { project: project, group: group, fid: fid });
},


}
};
Loading