mirror of
https://github.com/certd/certd.git
synced 2026-05-14 20:17:32 +08:00
perf: 授权配置支持加密
原本已经添加的授权配置,再次编辑保存即变成加密配置
This commit is contained in:
@@ -12,13 +12,11 @@ import { PipelineEntity } from '../modules/pipeline/entity/pipeline.js';
|
||||
//import { logger } from '../utils/logger';
|
||||
// load .env file in process.cwd
|
||||
import { mergeConfig } from './loader.js';
|
||||
import { Keys } from './keys.js';
|
||||
|
||||
const env = process.env.NODE_ENV || 'development';
|
||||
|
||||
const keys = Keys.load();
|
||||
const development = {
|
||||
keys: keys.cookieKeys,
|
||||
keys: 'certd',
|
||||
koa: {
|
||||
port: 7001,
|
||||
},
|
||||
@@ -78,7 +76,6 @@ const development = {
|
||||
|
||||
auth: {
|
||||
jwt: {
|
||||
secret: keys.jwtKey,
|
||||
expire: 7 * 24 * 60 * 60, //单位秒
|
||||
},
|
||||
},
|
||||
|
||||
@@ -1,31 +0,0 @@
|
||||
import fs from 'fs';
|
||||
import yaml from 'js-yaml';
|
||||
import * as _ from 'lodash-es';
|
||||
import { nanoid } from 'nanoid';
|
||||
import path from 'path';
|
||||
const KEYS_FILE = './data/keys.yaml';
|
||||
export class Keys {
|
||||
jwtKey: string = nanoid();
|
||||
cookieKeys: string[] = [nanoid()];
|
||||
|
||||
static load(): Keys {
|
||||
const keys = new Keys();
|
||||
if (fs.existsSync(KEYS_FILE)) {
|
||||
const content = fs.readFileSync(KEYS_FILE, 'utf8');
|
||||
const json = yaml.load(content);
|
||||
_.merge(keys, json);
|
||||
}
|
||||
keys.save();
|
||||
return keys;
|
||||
}
|
||||
|
||||
save() {
|
||||
const parent = path.dirname(KEYS_FILE);
|
||||
if (!fs.existsSync(parent)) {
|
||||
fs.mkdirSync(parent, {
|
||||
recursive: true,
|
||||
});
|
||||
}
|
||||
fs.writeFileSync(KEYS_FILE, yaml.dump(this));
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user