File

src/crypto/key/cert/cert.controller.ts

Prefix

certs

Description

Controller for managing certificates.

Index

Methods

Methods

addCertificate
addCertificate(token: TokenPayload, body: CertImportDto)
Decorators :
@Post()

Add a new certificate to a key. If no certificate is provided, a self-signed certificate will be generated.

Parameters :
Name Type Optional Description
token TokenPayload No
  • Authentication token
body CertImportDto No
  • Certificate data including keyId

The created certificate ID

Async deleteCertificate
deleteCertificate(token: TokenPayload, certId: string)
Decorators :
@Delete(':certId')

Delete a certificate.

Parameters :
Name Type Optional Description
token TokenPayload No
  • Authentication token
certId string No
  • The certificate ID to delete
Returns : Promise<void>
exportConfig
exportConfig(token: TokenPayload, certId: string)
Decorators :
@Get(':certId/config')

Export the configuration of a certificate for import/export purposes.

Parameters :
Name Type Optional Description
token TokenPayload No
  • Authentication token
certId string No
  • The certificate ID

The certificate

getCertificate
getCertificate(token: TokenPayload, certId: string)
Decorators :
@Get(':certId')

Get a specific certificate by ID.

Parameters :
Name Type Optional Description
token TokenPayload No
  • Authentication token
certId string No
  • The certificate ID

The certificate

getCertificates
getCertificates(token: TokenPayload, keyId?: string)
Decorators :
@Get()
@ApiQuery({name: 'keyId', required: false, type: String})

Get all certificates for the authenticated tenant. Can be filtered by keyId using query parameter.

Parameters :
Name Type Optional Description
token TokenPayload No
  • Authentication token
keyId string Yes
  • Optional key ID to filter certificates

Array of certificates

Async updateCertificate
updateCertificate(token: TokenPayload, certId: string, body: CertUpdateDto)
Decorators :
@Patch(':certId')

Update certificate metadata (description and usage types).

Parameters :
Name Type Optional Description
token TokenPayload No
  • Authentication token
certId string No
  • The certificate ID to update
body CertUpdateDto No
  • Updated certificate metadata
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);
    }
}

results matching ""

    No results matching ""