-
Notifications
You must be signed in to change notification settings - Fork 22
Enforce a style guide #101
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
Changes from all commits
7b36e0e
0e5d9d0
c2eef44
b118bb5
16ae1dc
85002f7
00e1210
c85fdbd
ebdfd9d
bcbbb29
b8d86d8
bc60c3d
2839a09
03b8cfe
b50b78c
2c55981
fe14330
60f8cc3
917f501
e319915
9095f88
60c7d03
0354542
58e7eb6
3185ba8
fc483f9
c770f80
609be0d
ba920f5
9d6d70a
ad5c216
0eccbb3
6a6883b
029f762
65a71e8
75b6ca5
6a6d5d4
60d32b6
c2c8d16
d1d0065
c45b95e
3983077
cb8393c
bab1b2c
419a6d0
097403b
3cc9ec0
034ac08
2ce2601
0df254c
d6bd3d5
d26f8c2
6f75463
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
static/js/*.min.js |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
module.exports = { | ||
"env": { | ||
"browser": true, | ||
"es6": false | ||
}, | ||
"extends": [ | ||
"eslint:recommended", | ||
"standard" | ||
], | ||
"globals": { | ||
"$": true, | ||
"Dygraph": true, | ||
"Scout": true, | ||
"ajaxForm": true, | ||
"updateFormStatus": true, | ||
}, | ||
"rules": { | ||
// Override some of standard js rules. | ||
"semi": ["error", "always"], | ||
"comma-dangle": [ | ||
"error", { | ||
"arrays": "only-multiline", | ||
"objects": "only-multiline", | ||
"imports": "never", | ||
"exports": "never", | ||
"functions": "never", | ||
} | ||
], | ||
|
||
// Override some eslint base rules because we're using ES5. | ||
"no-new": "off", | ||
|
||
// Custom rules. | ||
"no-console": ["error", {"allow": ["warn", "error"]}], | ||
} | ||
}; |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
module.exports = { | ||
"env": { | ||
"browser": false, | ||
"es6": true, | ||
"node": true | ||
}, | ||
"extends": [ | ||
"eslint:recommended", | ||
"plugin:node/recommended", | ||
"standard" | ||
], | ||
"plugins": [ | ||
"node" | ||
], | ||
"rules": { | ||
// Override some of standard js rules | ||
"semi": ["error", "always"], | ||
"comma-dangle": ["error", "only-multiline"], | ||
"camelcase": "off", | ||
"no-var": "error", | ||
|
||
// Override some eslint base rules because we're using node. | ||
"no-console": "off", | ||
} | ||
}; |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -141,7 +141,6 @@ hostAPI.post({ | |
// No authentication. | ||
response.statusCode = 403; // Forbidden | ||
response.json({ error: 'Unauthorized' }, null, 2); | ||
return; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Interesting. This |
||
|
||
function createHost () { | ||
getHostProperties(properties => { | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -16,9 +16,8 @@ const sessions = require('./lib/sessions'); | |
const hostname = db.get('hostname', 'localhost'); | ||
|
||
if (!hostname || hostname === 'localhost') { | ||
log('[fail] cannot join cluster as [hostname = ' + hostname + ']: ' + | ||
throw new Error('Cannot join cluster as [hostname = ' + hostname + ']: ' + | ||
'please fix the hostname in ./db.json and try again'); | ||
return; | ||
} | ||
|
||
log('[ok] will try to join cluster as [hostname = ' + hostname + ']'); | ||
|
@@ -256,18 +255,17 @@ function routeRequest (proxyParameters, request, response) { | |
switch (proxy) { | ||
case 'https': | ||
routes.webProxy(request, response, { port, path }); | ||
return; | ||
break; | ||
|
||
case 'none': | ||
const url = 'https://' + hostname + ':' + port + path; | ||
routes.redirect(response, url); | ||
return; | ||
routes.redirect(response, 'https://' + hostname + ':' + port + path); | ||
break; | ||
|
||
default: | ||
log('[fail] unsupported proxy type:', proxy); | ||
response.statusCode = 500; // Internal Server Error | ||
response.end(); | ||
return; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. It's inconsistent that we have |
||
break; | ||
} | ||
} | ||
|
||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,9 +1,9 @@ | ||
// Copyright © 2016 Jan Keromnes. All rights reserved. | ||
// The following code is covered by the AGPL-3.0 license. | ||
|
||
let child_process = require('child_process'); | ||
let forge = require('node-forge'); | ||
let letsencrypt = require('le-acme-core'); | ||
const child_process = require('child_process'); | ||
const forge = require('node-forge'); | ||
const letsencrypt = require('le-acme-core'); | ||
|
||
// ACME protocol client to interact with the Let's Encrypt service. | ||
let client = letsencrypt.ACME.create({ | ||
|
@@ -18,11 +18,9 @@ let letsEncryptChallengePrefix = | |
// ACME protocol challenge tokens proving our identity to Let's Encrypt. | ||
let letsEncryptChallenges = {}; | ||
|
||
|
||
// Verify if a given certificate in PEM format satisfies validity constraints. | ||
|
||
exports.isValid = function (parameters, enableDebug) { | ||
|
||
let debug = () => { | ||
if (enableDebug) { | ||
console.error(...arguments); | ||
|
@@ -101,17 +99,13 @@ exports.isValid = function (parameters, enableDebug) { | |
} | ||
|
||
return true; | ||
|
||
}; | ||
|
||
|
||
// Generate an RSA public and private key pair in forge format (binary). | ||
|
||
exports.generateRSAKeyPair = function (callback) { | ||
|
||
// Generate a new 4096-bit RSA private key (up to 100x faster than forge). | ||
child_process.exec('openssl genrsa 4096', (error, stdout, stderr) => { | ||
|
||
if (error) { | ||
callback(error); | ||
return; | ||
|
@@ -127,18 +121,13 @@ exports.generateRSAKeyPair = function (callback) { | |
privateKey: privateKey, | ||
publicKey: publicKey | ||
}); | ||
|
||
}); | ||
|
||
}; | ||
|
||
|
||
// Generate an SSH public and private key pair in OpenSSH format. | ||
|
||
exports.createSSHKeyPair = function (callback) { | ||
|
||
exports.generateRSAKeyPair((error, keypair) => { | ||
|
||
if (error) { | ||
callback(error); | ||
return; | ||
|
@@ -156,16 +145,12 @@ exports.createSSHKeyPair = function (callback) { | |
}; | ||
|
||
callback(null, sshKeyPair); | ||
|
||
}); | ||
|
||
}; | ||
|
||
|
||
// Create a TLS certificate in PEM format. | ||
|
||
exports.createTLSCertificate = function (parameters, callback) { | ||
|
||
let commonName = parameters.commonName; | ||
let altNames = parameters.altNames || []; | ||
let basicConstraints = parameters.basicConstraints || null; | ||
|
@@ -245,33 +230,26 @@ exports.createTLSCertificate = function (parameters, callback) { | |
certificate.setExtensions(extensions); | ||
|
||
if (key) { | ||
|
||
// A private key was provided, use it to finalize the certificate. | ||
let privateKey = forge.pki.privateKeyFromPem(key); | ||
let publicKey = forge.pki.setRsaPublicKey(privateKey.n, privateKey.e); | ||
signOff({ | ||
privateKey: privateKey, | ||
publicKey: publicKey | ||
}); | ||
return; | ||
|
||
} else { | ||
|
||
// No private key was provided, generate a new one for this certificate. | ||
exports.generateRSAKeyPair((error, keypair) => { | ||
if (error) { | ||
callback(error); | ||
return; | ||
} | ||
signOff(keypair); | ||
return; | ||
}); | ||
|
||
} | ||
|
||
// Use a given TLS key pair to sign and return the certificate. | ||
function signOff (keypair) { | ||
|
||
certificate.publicKey = keypair.publicKey; | ||
|
||
if (caKey) { | ||
|
@@ -289,17 +267,12 @@ exports.createTLSCertificate = function (parameters, callback) { | |
} | ||
|
||
callback(null, crt, key); | ||
return; | ||
|
||
} | ||
|
||
}; | ||
|
||
|
||
// Generate an HTTPS certificate using Let's Encrypt (https://letsencrypt.org/). | ||
|
||
exports.createHTTPSCertificate = function (parameters, callback) { | ||
|
||
let hostname = parameters.hostname; | ||
let accountEmail = parameters.accountEmail; | ||
let accountKey = parameters.accountKey || null; | ||
|
@@ -345,7 +318,6 @@ exports.createHTTPSCertificate = function (parameters, callback) { | |
|
||
// Wait for all required tasks to finish before proceding. | ||
function done () { | ||
|
||
if (!acmeUrls || !accountKey || !httpsKey) { | ||
// Some tasks are not finished yet. Let's wait. | ||
return; | ||
|
@@ -369,6 +341,7 @@ exports.createHTTPSCertificate = function (parameters, callback) { | |
} | ||
|
||
// All required tasks are now finished, destroy the `done` callback. | ||
// eslint-disable-next-line no-func-assign | ||
done = null; | ||
|
||
// We can now actually request an HTTPS certificate from Let's Encrypt. | ||
|
@@ -384,21 +357,16 @@ exports.createHTTPSCertificate = function (parameters, callback) { | |
} | ||
callback(null, certificate, accountKey); | ||
}); | ||
|
||
} | ||
|
||
}; | ||
|
||
|
||
// Expose the URL prefix that Let's Encrypt will use to challenge our identity. | ||
|
||
exports.letsEncryptChallengePrefix = letsEncryptChallengePrefix; | ||
|
||
|
||
// Look for an identity token that satisfies the given Let's Encrypt challenge. | ||
|
||
exports.getLetsEncryptChallengeToken = function (url) { | ||
|
||
if (!url || !url.startsWith(letsEncryptChallengePrefix)) { | ||
// Not a Let's Encrypt challenge URL. | ||
return null; | ||
|
@@ -412,14 +380,11 @@ exports.getLetsEncryptChallengeToken = function (url) { | |
} | ||
|
||
return token; | ||
|
||
}; | ||
|
||
|
||
// Register a new Let's Encrypt account. | ||
|
||
function registerLetsEncryptAccount (parameters, callback) { | ||
|
||
let accountEmail = parameters.accountEmail; | ||
let accountKey = parameters.accountKey; | ||
let acmeUrls = parameters.acmeUrls; | ||
|
@@ -437,14 +402,11 @@ function registerLetsEncryptAccount (parameters, callback) { | |
}; | ||
|
||
client.registerNewAccount(options, callback); | ||
|
||
} // Don't export `registerLetsEncryptAccount`. | ||
|
||
|
||
// Request HTTPS certificate issuance by Let's Encrypt via the ACME protocol. | ||
|
||
function requestLetsEncryptCertificate (parameters, callback) { | ||
|
||
let hostname = parameters.hostname; | ||
let acmeUrls = parameters.acmeUrls; | ||
let accountKey = parameters.accountKey; | ||
|
@@ -473,5 +435,4 @@ function requestLetsEncryptCertificate (parameters, callback) { | |
}; | ||
|
||
client.getCertificate(options, callback); | ||
|
||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Huge 👍! I used to do all these changes by hand... You're saving me so much time! There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Same here, just an auto-fix |
||
} // Don't export `requestLetsEncryptCertificate`. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Quite funny that the eslintrc.js files don't actually respect the eslint rules :D
Property names should either have no quotes or single quotes.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I believe it's because you can either use a js file, or plain json? I don't have an opinion on this matter. Also for some reason those configuration files are auto-ignored by eslint.