-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
6b283a3
commit 5d3132f
Showing
34 changed files
with
578 additions
and
12 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
import { yearsToDays } from 'date-fns' | ||
import { collections } from '../database/collections' | ||
import { logger } from '../logger' | ||
import pem from 'pem' | ||
import type { CertificateModel } from '../database/models/certificate.model' | ||
|
||
const createCertificate = (options: pem.CertificateCreationOptions) => | ||
new Promise<pem.CertificateCreationResult>((resolve, reject) => { | ||
pem.createCertificate(options, (error, result) => { | ||
if (error) { | ||
reject(error) | ||
} else { | ||
resolve(result) | ||
} | ||
}) | ||
}) | ||
|
||
export async function get(purpose: string): Promise<CertificateModel> { | ||
logger.trace(`certificates.get(purpose=${purpose})`) | ||
const c = await collections.certificates.findOne({ purpose }) | ||
if (c !== null) { | ||
return c | ||
} | ||
|
||
const { clientKey, certificate } = await createCertificate({ | ||
days: yearsToDays(10), | ||
selfSigned: true, | ||
}) | ||
await collections.certificates.insertOne({ purpose, clientKey, certificate }) | ||
logger.info({ purpose }, `certificate created`) | ||
return { purpose, clientKey, certificate } | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
import { get } from './get' | ||
|
||
export const certificates = { | ||
get, | ||
} as const |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,8 +1,10 @@ | ||
import { collections } from '../database/collections' | ||
import type { Configuration } from '../database/models/configuration-entry.model' | ||
import { events } from '../events' | ||
import { get } from './get' | ||
|
||
export async function reset<T extends keyof Configuration>(key: T): Promise<Configuration[T]> { | ||
await collections.configuration.deleteOne({ key }) | ||
events.emit('configuration:updated', { key }) | ||
return await get(key) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.