src/crypto/key/cert/cert.controller.ts
certs
Controller for managing certificates.
Methods |
| addCertificate | ||||||||||||
addCertificate(token: TokenPayload, body: CertImportDto)
|
||||||||||||
Decorators :
@Post()
|
||||||||||||
|
Defined in src/crypto/key/cert/cert.controller.ts:84
|
||||||||||||
|
Add a new certificate to a key. If no certificate is provided, a self-signed certificate will be generated.
Parameters :
Returns :
Promise<CertResponseDto>
The created certificate ID |
| Async deleteCertificate | ||||||||||||
deleteCertificate(token: TokenPayload, certId: string)
|
||||||||||||
Decorators :
@Delete(':certId')
|
||||||||||||
|
Defined in src/crypto/key/cert/cert.controller.ts:123
|
||||||||||||
|
Delete a certificate.
Parameters :
Returns :
Promise<void>
|
| exportConfig | ||||||||||||
exportConfig(token: TokenPayload, certId: string)
|
||||||||||||
Decorators :
@Get(':certId/config')
|
||||||||||||
|
Defined in src/crypto/key/cert/cert.controller.ts:70
|
||||||||||||
|
Export the configuration of a certificate for import/export purposes.
Parameters :
Returns :
Promise<CertImportDto>
The certificate |
| getCertificate | ||||||||||||
getCertificate(token: TokenPayload, certId: string)
|
||||||||||||
Decorators :
@Get(':certId')
|
||||||||||||
|
Defined in src/crypto/key/cert/cert.controller.ts:56
|
||||||||||||
|
Get a specific certificate by ID.
Parameters :
Returns :
Promise<CertEntity>
The certificate |
| getCertificates | ||||||||||||
getCertificates(token: TokenPayload, keyId?: string)
|
||||||||||||
Decorators :
@Get()
|
||||||||||||
|
Defined in src/crypto/key/cert/cert.controller.ts:39
|
||||||||||||
|
Get all certificates for the authenticated tenant. Can be filtered by keyId using query parameter.
Parameters :
Returns :
Promise<CertEntity[]>
Array of certificates |
| Async updateCertificate | ||||||||||||||||
updateCertificate(token: TokenPayload, certId: string, body: CertUpdateDto)
|
||||||||||||||||
Decorators :
@Patch(':certId')
|
||||||||||||||||
|
Defined in src/crypto/key/cert/cert.controller.ts:105
|
||||||||||||||||
|
Update certificate metadata (description and usage types).
Parameters :
Returns :
Promise<void>
|
import {
Body,
Controller,
Delete,
Get,
Param,
Patch,
Post,
Query,
} from "@nestjs/common";
import { ApiQuery, ApiTags } from "@nestjs/swagger";
import { Role } from "../../../auth/roles/role.enum";
import { Secured } from "../../../auth/secure.decorator";
import { Token, TokenPayload } from "../../../auth/token.decorator";
import { CertImportDto } from "../dto/cert-import.dto";
import { CertResponseDto } from "../dto/cert-response.dto";
import { CertUpdateDto } from "../dto/cert-update.dto";
import { CertEntity } from "../entities/cert.entity";
import { CertService } from "./cert.service";
/**
* Controller for managing certificates.
*/
@ApiTags("Certificate")
@Secured([Role.Issuances, Role.Presentations])
@Controller("certs")
export class CertController {
constructor(private readonly certService: CertService) {}
/**
* Get all certificates for the authenticated tenant.
* Can be filtered by keyId using query parameter.
* @param token - Authentication token
* @param keyId - Optional key ID to filter certificates
* @returns Array of certificates
*/
@Get()
@ApiQuery({ name: "keyId", required: false, type: String })
getCertificates(
@Token() token: TokenPayload,
@Query("keyId") keyId?: string,
): Promise<CertEntity[]> {
if (keyId) {
return this.certService.getCertificates(token.entity!.id, keyId);
}
return this.certService.getAllCertificates(token.entity!.id);
}
/**
* Get a specific certificate by ID.
* @param token - Authentication token
* @param certId - The certificate ID
* @returns The certificate
*/
@Get(":certId")
getCertificate(
@Token() token: TokenPayload,
@Param("certId") certId: string,
): Promise<CertEntity> {
return this.certService.getCertificateById(token.entity!.id, certId);
}
/**
* Export the configuration of a certificate for import/export purposes.
* @param token - Authentication token
* @param certId - The certificate ID
* @returns The certificate
*/
@Get(":certId/config")
exportConfig(
@Token() token: TokenPayload,
@Param("certId") certId: string,
): Promise<CertImportDto> {
return this.certService.getCertificateConfig(token.entity!.id, certId);
}
/**
* Add a new certificate to a key. If no certificate is provided, a self-signed certificate will be generated.
* @param token - Authentication token
* @param body - Certificate data including keyId
* @returns The created certificate ID
*/
@Post()
addCertificate(
@Token() token: TokenPayload,
@Body() body: CertImportDto,
): Promise<CertResponseDto> {
if (!body.crt) {
return this.certService
.addSelfSignedCert(token.entity!, body.keyId, body)
.then((id) => ({ id }));
}
return this.certService
.addCertificate(token.entity!.id, body)
.then((id) => ({ id }));
}
/**
* Update certificate metadata (description and usage types).
* @param token - Authentication token
* @param certId - The certificate ID to update
* @param body - Updated certificate metadata
*/
@Patch(":certId")
async updateCertificate(
@Token() token: TokenPayload,
@Param("certId") certId: string,
@Body() body: CertUpdateDto,
): Promise<void> {
await this.certService.updateCertificate(
token.entity!.id,
certId,
body,
);
}
/**
* Delete a certificate.
* @param token - Authentication token
* @param certId - The certificate ID to delete
*/
@Delete(":certId")
async deleteCertificate(
@Token() token: TokenPayload,
@Param("certId") certId: string,
): Promise<void> {
await this.certService.deleteCertificate(token.entity!.id, certId);
}
}