src/crypto/key/key.controller.ts
key
KeyController is responsible for managing keys in the system.
Methods |
Async addKey | |||||||||
addKey(token: TokenPayload, body: KeyImportDto)
|
|||||||||
Decorators :
@Post()
|
|||||||||
Defined in src/crypto/key/key.controller.ts:48
|
|||||||||
Add a new key to the key service.
Parameters :
Returns :
Promise<literal type>
|
deleteKey | |||||||||
deleteKey(token: TokenPayload, id: string)
|
|||||||||
Decorators :
@Delete(':id')
|
|||||||||
Defined in src/crypto/key/key.controller.ts:63
|
|||||||||
Delete a key from the key service.
Parameters :
Returns :
any
|
getKeys | ||||||
getKeys(token: TokenPayload)
|
||||||
Decorators :
@Get()
|
||||||
Defined in src/crypto/key/key.controller.ts:36
|
||||||
Get all keys for the tenant.
Parameters :
Returns :
Promise<KeyObj[]>
|
import {
Body,
Controller,
Delete,
Get,
Inject,
Param,
Post,
UseGuards,
} from '@nestjs/common';
import { ApiSecurity } from '@nestjs/swagger';
import { JwtAuthGuard } from '../../auth/auth.guard';
import { Token, TokenPayload } from '../../auth/token.decorator';
import { KeyObj, KeyService } from './key.service';
import { KeyImportDto } from './dto/key-import.dto';
import { CryptoService } from '../crypto.service';
/**
* KeyController is responsible for managing keys in the system.
*/
@UseGuards(JwtAuthGuard)
@ApiSecurity('oauth2')
@Controller('key')
export class KeyController {
constructor(
@Inject('KeyService') public readonly keyService: KeyService,
private cryptoService: CryptoService,
) {}
/**
* Get all keys for the tenant.
* @param token
* @returns
*/
@Get()
getKeys(@Token() token: TokenPayload): Promise<KeyObj[]> {
const tenantId = token.sub;
return this.keyService.getKeys(tenantId);
}
/**
* Add a new key to the key service.
* @param token
* @param body
* @returns
*/
@Post()
async addKey(
@Token() token: TokenPayload,
@Body() body: KeyImportDto,
): Promise<{ id: string }> {
const tenantId = token.sub;
const id = await this.cryptoService.importKey(tenantId, body);
return { id };
}
/**
* Delete a key from the key service.
* @param token
* @param id
*/
@Delete(':id')
deleteKey(@Token() token: TokenPayload, @Param('id') id: string) {
return this.cryptoService.deleteKey(token.sub, id);
}
}