Skip to content

Commit

Permalink
Apply automatic ESLint fixes for all source files
Browse files Browse the repository at this point in the history
  • Loading branch information
fschrempf committed Nov 13, 2022
1 parent 22fa907 commit 5aacd75
Show file tree
Hide file tree
Showing 20 changed files with 1,062 additions and 1,112 deletions.
60 changes: 28 additions & 32 deletions index.js
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
const fs = require('fs');
const { argv } = require('process');
const pino = require('pino');
const pretty = require('pino-pretty');
const c = require('./src/constants');
const main = require('./src/main');
const ctservice = require('./src/ctservice');
const log = require('./src/logging');
const nc = require('./src/nextcloud');
const fs = require('fs');
const { argv } = require('process');
const pino = require('pino')
const pretty = require('pino-pretty')

function write(name, data) {
try {
Expand All @@ -24,12 +24,12 @@ async function sanpshot() {
write('ldap.json', JSON.stringify(result.ldap));
}

var restart = () => {};
let restart = () => {};

var initialized = false;
let initialized = false;

startedServer = (ip,port) => {
log.info('LDAP listening @ ' + ip + ":"+ port);
startedServer = (ip, port) => {
log.info(`LDAP listening @ ${ip}:${port}`);
initialized = true;
};
process.on('uncaughtException', (err) => {
Expand All @@ -40,51 +40,47 @@ process.on('uncaughtException', (err) => {
}
});

exports.getTestConfig = () => {
return require('./production/config.json');
}
exports.getTestConfig = () => require('./production/config.json');

run = async () => {
if (process.argv.includes('--configsql')) {
var vcount = process.argv.indexOf('--configsql')
if (argv.length < vcount+2) {
log.error("Parameters missing --configsql <s01> <ccf> <nextCloudUser>")
process.exit()
}
var set = process.argv[vcount+1]
var sitename = process.argv[vcount+2]
var objectclass = c.LDAP_OBJCLASS_USER
if (process.argv.length > vcount + 2)
objectclass = process.argv[vcount+3]
const vcount = process.argv.indexOf('--configsql');
if (argv.length < vcount + 2) {
log.error('Parameters missing --configsql <s01> <ccf> <nextCloudUser>');
process.exit();
}
const set = process.argv[vcount + 1];
const sitename = process.argv[vcount + 2];
let objectclass = c.LDAP_OBJCLASS_USER;
if (process.argv.length > vcount + 2) objectclass = process.argv[vcount + 3];
const data = require('./production/ldap.json');
log.logger.level = 'silent';
const testconfig = this.getTestConfig()
const testconfig = this.getTestConfig();
nc.getNextcloudLdapConfig(testconfig, sitename, set, objectclass);
nc.getNextcloudMappingTables(data, testconfig.sites[sitename].ldap.dc);
} else if (process.argv.includes('--testdata')) {
const testconfig = this.getTestConfig()
const testconfig = this.getTestConfig();
const start = await main.start(
testconfig,
async () => require('./production/ctdata.json'),
(site) => async (user, password) => password === 'alex',
startedServer
startedServer,
);
restart = start.restart
restart = start.restart;
} else if (process.argv.includes('--testsnapshot')) {
sanpshot();
} else {
log.logger = pino({ level: 'info', transport: { target: 'pino-pretty' } })
const config = main.getConfig(c.CONFIG_FILE)
if (config.server.loglevel)
log.logger.level = config.server.loglevel
log.logger = pino({ level: 'info', transport: { target: 'pino-pretty' } });
const config = main.getConfig(c.CONFIG_FILE);
if (config.server.loglevel) log.logger.level = config.server.loglevel;
start = await main.start(
config,
ctservice.getChurchToolsData,
ctservice.authWithChurchTools,
startedServer
startedServer,
);
restart = start.restart
setInterval(() => main.update(start.updaters), config.server.updateinterval*1000)
restart = start.restart;
setInterval(() => main.update(start.updaters), config.server.updateinterval * 1000);
}
};

Expand Down
30 changes: 15 additions & 15 deletions src/constants.js
Original file line number Diff line number Diff line change
@@ -1,15 +1,15 @@
exports.CONFIG_FILE = "/ldap/config/config.yml"
exports.API_SLUG = "api"
exports.WHOAMI_AP = "/whoami?only_allow_authenticated=true"
exports.CSRF_AP = "/csrftoken"
exports.LOGIN_AP = "/login"
exports.INFO_AP = "/info"
exports.GROUPMEMBERS_AP = "/groups/members?with_deleted=false"
exports.IDS = "&ids[]="
exports.PERSONS_AP = "/persons"
exports.GROUPS_AP = "/groups"
exports.LDAPID_FIELD = "ncuid"
exports.LDAP_OU_USERS = "users"
exports.LDAP_OU_GROUPS = "groups"
exports.LDAP_OBJCLASS_USER = "CTPerson";
exports.LDAP_OBJCLASS_GROUP = "group";
exports.CONFIG_FILE = '/ldap/config/config.yml';
exports.API_SLUG = 'api';
exports.WHOAMI_AP = '/whoami?only_allow_authenticated=true';
exports.CSRF_AP = '/csrftoken';
exports.LOGIN_AP = '/login';
exports.INFO_AP = '/info';
exports.GROUPMEMBERS_AP = '/groups/members?with_deleted=false';
exports.IDS = '&ids[]=';
exports.PERSONS_AP = '/persons';
exports.GROUPS_AP = '/groups';
exports.LDAPID_FIELD = 'ncuid';
exports.LDAP_OU_USERS = 'users';
exports.LDAP_OU_GROUPS = 'groups';
exports.LDAP_OBJCLASS_USER = 'CTPerson';
exports.LDAP_OBJCLASS_GROUP = 'group';
52 changes: 25 additions & 27 deletions src/ctapi.js
Original file line number Diff line number Diff line change
@@ -1,54 +1,52 @@
const log = require("./logging");
const c = require("./constants");
const axios = require("axios").default;

const log = require('./logging');
const c = require('./constants');
const axios = require('axios').default;

exports.ChurchToolsError = (message) => {
err = new Error(message)
err = new Error(message);
log.error(message);
err.name = "ChurchToolsError"
err.name = 'ChurchToolsError';
return err;
}
};

exports.ChurchToolsFatalError = (message) => {
err = new Error(message)
err = new Error(message);
log.error(message);
err.name = "ChurchToolsFatalError"
err.name = 'ChurchToolsFatalError';
return err;
}

uriTrailingSlash = (uri) => (uri.slice(-1) !== "/" ? uri + "/" : uri);
};

uriTrailingSlash = (uri) => (uri.slice(-1) !== '/' ? `${uri}/` : uri);

exports.result = (result, success, failed) => {
if (result && result.hasOwnProperty("data")) {
if (result && result.hasOwnProperty('data')) {
if (success) success(result);
log.debug(JSON.stringify(result.data));
return result.data
} else if (result && result.hasOwnProperty("status") && result.status === "success") {
return result.data;
} if (result && result.hasOwnProperty('status') && result.status === 'success') {
if (success) success(result);
log.debug(JSON.stringify(result.data));
return result.data
} else if (result && result.hasOwnProperty("message")) {
return result.data;
} if (result && result.hasOwnProperty('message')) {
if (failed) failed();
throw this.ChurchToolsError(result.message);
} else if (result && result.hasOwnProperty("status") &&
[400, 401, 403, 404, 405, 500, 501, 502, 503, 504].includes(result.status)) {
} else if (result && result.hasOwnProperty('status')
&& [400, 401, 403, 404, 405, 500, 501, 502, 503, 504].includes(result.status)) {
if (failed) failed();
throw this.ChurchToolsError("No Session or connection problems");
throw this.ChurchToolsError('No Session or connection problems');
} else {
log.error(JSON.stringify(result));
throw this.ChurchToolsFatalError("Unexpected Error");
throw this.ChurchToolsFatalError('Unexpected Error');
}
}
};

exports.request = async (request, success, failed) => {
log.debug(JSON.stringify(request))
var result = {}
log.debug(JSON.stringify(request));
let result = {};
try {
result = await axios(request)
result = await axios(request);
} catch (err) {
throw this.ChurchToolsError(err.message);
}
return this.result(result, success, failed)
}
return this.result(result, success, failed);
};
Loading

0 comments on commit 5aacd75

Please sign in to comment.