feat(center): enforce API key on all APIs except node register
This commit is contained in:
@@ -16,6 +16,8 @@ import {
|
||||
} from '@nestjs/common';
|
||||
import { InjectRepository } from '@nestjs/typeorm';
|
||||
import { Repository } from 'typeorm';
|
||||
import * as bcrypt from 'bcryptjs';
|
||||
import { randomBytes } from 'crypto';
|
||||
import { GuildNode } from '../entities/guild-node.entity';
|
||||
import { AuditService } from '../audit/audit.service';
|
||||
import { RegisterNodeDto } from './dto.register-node.dto';
|
||||
@@ -95,7 +97,10 @@ export class NodesController {
|
||||
name: body.name,
|
||||
endpoint: body.endpoint,
|
||||
status: 'active',
|
||||
apiKeyHash: null,
|
||||
});
|
||||
const rawApiKey = `gk_${randomBytes(24).toString('hex')}`;
|
||||
node.apiKeyHash = await bcrypt.hash(rawApiKey, 10);
|
||||
const saved = await this.nodeRepo.save(node);
|
||||
await this.audit.write({
|
||||
action: 'node.register',
|
||||
@@ -114,6 +119,7 @@ export class NodesController {
|
||||
endpoint: saved.endpoint,
|
||||
status: saved.status,
|
||||
},
|
||||
apiKey: rawApiKey,
|
||||
};
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user