2017-10-31 18:05:35 +00:00
|
|
|
// @flow
|
|
|
|
import * as db from '../common/database';
|
2018-06-25 17:42:50 +00:00
|
|
|
import type { BaseModel } from './index';
|
2017-10-31 18:05:35 +00:00
|
|
|
|
|
|
|
export const name = 'Client Certificate';
|
|
|
|
export const type = 'ClientCertificate';
|
|
|
|
export const prefix = 'crt';
|
|
|
|
export const canDuplicate = true;
|
2019-04-18 00:50:03 +00:00
|
|
|
export const canSync = false;
|
2017-10-31 18:05:35 +00:00
|
|
|
|
|
|
|
type BaseClientCertificate = {
|
|
|
|
parentId: string,
|
|
|
|
host: string,
|
|
|
|
passphrase: string | null,
|
|
|
|
cert: string | null,
|
|
|
|
key: string | null,
|
|
|
|
pfx: string | null,
|
|
|
|
disabled: boolean,
|
|
|
|
|
|
|
|
// For sync control
|
2018-12-12 17:36:11 +00:00
|
|
|
isPrivate: boolean,
|
2017-10-31 18:05:35 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
export type ClientCertificate = BaseModel & BaseClientCertificate;
|
|
|
|
|
2018-06-25 17:42:50 +00:00
|
|
|
export function init(): BaseClientCertificate {
|
2017-10-31 18:05:35 +00:00
|
|
|
return {
|
|
|
|
parentId: '',
|
|
|
|
host: '',
|
|
|
|
passphrase: null,
|
|
|
|
disabled: false,
|
|
|
|
cert: null,
|
|
|
|
key: null,
|
|
|
|
pfx: null,
|
2018-12-12 17:36:11 +00:00
|
|
|
isPrivate: false,
|
2017-10-31 18:05:35 +00:00
|
|
|
};
|
|
|
|
}
|
|
|
|
|
2018-06-25 17:42:50 +00:00
|
|
|
export async function migrate(doc: ClientCertificate) {
|
2017-10-31 18:05:35 +00:00
|
|
|
return doc;
|
|
|
|
}
|
|
|
|
|
2020-03-18 18:58:57 +00:00
|
|
|
export function create(patch: $Shape<ClientCertificate> = {}): Promise<ClientCertificate> {
|
2017-10-31 18:05:35 +00:00
|
|
|
if (!patch.parentId) {
|
2018-10-17 16:42:33 +00:00
|
|
|
throw new Error('New ClientCertificate missing `parentId`: ' + JSON.stringify(patch));
|
2017-10-31 18:05:35 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
return db.docCreate(type, patch);
|
|
|
|
}
|
|
|
|
|
2020-03-18 18:58:57 +00:00
|
|
|
export function update(
|
|
|
|
cert: ClientCertificate,
|
|
|
|
patch: $Shape<ClientCertificate> = {},
|
|
|
|
): Promise<ClientCertificate> {
|
2017-10-31 18:05:35 +00:00
|
|
|
return db.docUpdate(cert, patch);
|
|
|
|
}
|
|
|
|
|
2018-06-25 17:42:50 +00:00
|
|
|
export function getById(id: string): Promise<ClientCertificate | null> {
|
2017-10-31 18:05:35 +00:00
|
|
|
return db.get(type, id);
|
|
|
|
}
|
|
|
|
|
2018-10-17 16:42:33 +00:00
|
|
|
export function findByParentId(parentId: string): Promise<Array<ClientCertificate>> {
|
2018-06-25 17:42:50 +00:00
|
|
|
return db.find(type, { parentId });
|
2017-10-31 18:05:35 +00:00
|
|
|
}
|
|
|
|
|
2018-06-25 17:42:50 +00:00
|
|
|
export function remove(cert: ClientCertificate): Promise<void> {
|
2017-10-31 18:05:35 +00:00
|
|
|
return db.remove(cert);
|
|
|
|
}
|
|
|
|
|
2018-06-25 17:42:50 +00:00
|
|
|
export function all(): Promise<Array<ClientCertificate>> {
|
2017-10-31 18:05:35 +00:00
|
|
|
return db.all(type);
|
|
|
|
}
|