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

Add linting through ESLint using AirBnB style guide #7

Open
wants to merge 11 commits into
base: main
Choose a base branch
from
10 changes: 10 additions & 0 deletions .eslintrc.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
env:
node: true
mocha: true
es2021: true
extends: airbnb-base
overrides: []
parserOptions:
ecmaVersion: latest
sourceType: module
rules: {}
36 changes: 36 additions & 0 deletions .github/workflows/ci-jobs.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
name: CI Jobs

on:
push:
pull_request:
branches: [ main ]

env:
NODE_VERSION: 16.x

jobs:
eslint:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
- name: Use Node.js $NODE_VERSION
uses: actions/setup-node@v3
with:
node-version: ${{ env.NODE_VERSION }}
- name: Install Modules
run: npm ci
- name: Run ESLint
run: npm run lint

unit-tests:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
- name: Use Node.js $NODE_VERSION
uses: actions/setup-node@v3
with:
node-version: ${{ env.NODE_VERSION }}
- name: Install Modules
run: npm ci
- name: Run Unit Tests
run: npm run test
26 changes: 0 additions & 26 deletions .github/workflows/unittests.yml

This file was deleted.

22 changes: 11 additions & 11 deletions config.example.yml
Original file line number Diff line number Diff line change
@@ -1,40 +1,40 @@
server:
port: 1389
ip: 0.0.0.0
updateinterval: 600 // intervall in seconds
updateinterval: 600 # interval in seconds
cert: certs/ldap.crt
key: certs/ldap.key
sites:
ccf:
site:
name: sitename
user: username // User needs rights to the api in CT
user: username # user needs API permissions in ChurchTools
password: secret1
url: https://sitename.church.tools/
ldap:
o: Organisation Name
dc: dc=myorg,dc=tld // domain components
dc: dc=myorg,dc=tld # domain components
admincn: admin
password: secret2
attributes: // fields to add to user
attributes: # fields to add to user
- name: key1
default: defaultvalue1
replacements: // add value to user with id
replacements: # add value to user with id
- id: id
value: extra
- name: key2
default: defaultvalue2
adminGroup:
cn: "admin" //
members: // personid s of users to put in admin group
cn: "admin"
members: # person ID of users to put in admin group
- id
selectionGroupIds: // ChurchTools Group Ids - only members of these groups will be served by ldap
selectionGroupIds: # ChurchTools group IDs - only members of these groups will be served by LDAP
- gid
- gid
tranformedGroups: // ChurchTools Group Ids with the group name which will be served by Ldap
tranformedGroups: # ChurchTools group IDs with the group name which will be served by LDAP
- gid: gid
name: Groupname
objectClass: usrObjClass // additionally set objectClass of User to that value if in group
objectClass: usrObjClass # additionally set objectClass of user to that value if in group
- gid: gid
name: Groupname
// further ChurchTools sites to serve - following the same schema above
# further ChurchTools sites to serve - following the same schema as above
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
Loading