Speed improvements, some parallel dataplane calls e.g. account page Fix registration Change cluster -> server wording for now on frontend Frontend dixes re overflowing server linedevelop
parent
fd2989a435
commit
bf3c71b7df
12 changed files with 258 additions and 82 deletions
@ -0,0 +1,100 @@ |
||||
'use strict'; |
||||
|
||||
const fs = require('fs').promises; |
||||
const acme = require('acme-client'); |
||||
|
||||
/** |
||||
* Function used to satisfy an ACME challenge |
||||
* |
||||
* @param {object} authz Authorization object |
||||
* @param {object} challenge Selected challenge |
||||
* @param {string} keyAuthorization Authorization key |
||||
* @returns {Promise} |
||||
*/ |
||||
|
||||
async function challengeCreateFn(authz, challenge, keyAuthorization) { |
||||
console.log('Triggered challengeCreateFn()'); |
||||
|
||||
/* http-01 */ |
||||
if (challenge.type === 'http-01') { |
||||
const filePath = `/tmp/acme-tests/.well-known/acme-challenge/${challenge.token}`; |
||||
const fileContents = keyAuthorization; |
||||
console.log(`Creating challenge response for ${authz.identifier.value} at path: ${filePath}`); |
||||
await fs.writeFile(filePath, fileContents); |
||||
} |
||||
|
||||
/* dns-01 */ |
||||
else if (challenge.type === 'dns-01') { |
||||
const dnsRecord = `_acme-challenge.${authz.identifier.value}`; |
||||
const recordValue = keyAuthorization; |
||||
console.log(`Creating TXT record for ${authz.identifier.value}: ${dnsRecord}`); |
||||
/* Replace this */ |
||||
console.log(`Would create TXT record "${dnsRecord}" with value "${recordValue}"`); |
||||
// await dnsProvider.createRecord(dnsRecord, 'TXT', recordValue);
|
||||
} |
||||
} |
||||
|
||||
|
||||
/** |
||||
* Function used to remove an ACME challenge response |
||||
* |
||||
* @param {object} authz Authorization object |
||||
* @param {object} challenge Selected challenge |
||||
* @param {string} keyAuthorization Authorization key |
||||
* @returns {Promise} |
||||
*/ |
||||
|
||||
async function challengeRemoveFn(authz, challenge, keyAuthorization) { |
||||
console.log('Triggered challengeRemoveFn()'); |
||||
|
||||
/* http-01 */ |
||||
if (challenge.type === 'http-01') { |
||||
const filePath = `/tmp/acme-tests/.well-known/acme-challenge/${challenge.token}`; |
||||
console.log(`Removing challenge response for ${authz.identifier.value} at path: ${filePath}`); |
||||
await fs.unlink(filePath); |
||||
} |
||||
|
||||
/* dns-01 */ |
||||
else if (challenge.type === 'dns-01') { |
||||
const dnsRecord = `_acme-challenge.${authz.identifier.value}`; |
||||
const recordValue = keyAuthorization; |
||||
console.log(`Removing TXT record for ${authz.identifier.value}: ${dnsRecord}`); |
||||
/* Replace this */ |
||||
console.log(`Would remove TXT record "${dnsRecord}" with value "${recordValue}"`); |
||||
// await dnsProvider.removeRecord(dnsRecord, 'TXT');
|
||||
} |
||||
} |
||||
|
||||
|
||||
|
||||
module.exports = { |
||||
|
||||
client: null, |
||||
|
||||
init: async function() { |
||||
/* Init client */ |
||||
module.exports.client = new acme.Client({ |
||||
directoryUrl: acme.directory.letsencrypt.staging, |
||||
accountKey: await acme.crypto.createPrivateKey() |
||||
}); |
||||
}, |
||||
|
||||
generate: async function(domain, email='tom@69420.me') { |
||||
/* Create CSR */ |
||||
const [key, csr] = await acme.crypto.createCsr({ |
||||
commonName: domain |
||||
}); |
||||
/* Certificate */ |
||||
const cert = await module.exports.client.auto({ |
||||
csr, |
||||
email, |
||||
termsOfServiceAgreed: true, |
||||
challengeCreateFn, |
||||
challengeRemoveFn |
||||
}); |
||||
/* Done */ |
||||
const haproxyCert = `${cert.toString()}\n${key.toString()}`; |
||||
return { key, csr, cet, haproxyCert, date: new Date() }; |
||||
}, |
||||
|
||||
}; |
@ -1,15 +0,0 @@ |
||||
import { createContext, useReducer } from 'react'; |
||||
import reducer from './GlobalReducer.js'; |
||||
|
||||
export const GlobalContext = createContext(); |
||||
|
||||
const initialState = {}; |
||||
|
||||
export default function GlobalProvider(props) { |
||||
const [state, dispatch] = useReducer(reducer, initialState); |
||||
return ( |
||||
<GlobalContext.Provider value={[state, dispatch]}> |
||||
{props.children} |
||||
</GlobalContext.Provider> |
||||
); |
||||
} |
@ -1,14 +0,0 @@ |
||||
// reducer.js
|
||||
export default function reducer(state, action) { |
||||
//could do somethig na bit more smart than this
|
||||
switch (action.type) { |
||||
case 'error': |
||||
// Add error, keep existing state
|
||||
return { error: action.payload, ...state }; |
||||
case 'state': |
||||
// Keep state, overwrite or add new values from payload, and null error
|
||||
return { ...state, ...action.payload, error: null }; |
||||
default: |
||||
throw new Error(); |
||||
} |
||||
} |
Loading…
Reference in new issue