File

src/registrar/registrar.controller.ts

Prefix

registrar

Description

Controller for managing registrar configuration and creating access certificates. Allows tenants to configure their connection to an external registrar and create access certificates for their keys.

Index

Methods

Methods

Async createAccessCertificate
createAccessCertificate(token: TokenPayload, dto: CreateAccessCertificateDto)
Decorators :
@Post('access-certificate')
@ApiOperation({summary: 'Create an access certificate for a key', description: undefined})
@ApiResponse({status: 201, description: 'Access certificate created successfully', schema: undefined})
@ApiResponse({status: 400, description: 'No relying party found at registrar or failed to create certificate'})
@ApiResponse({status: 404, description: 'No registrar configuration found or key not found'})

Create an access certificate for a specific key. The certificate will be fetched from the registrar and stored in EUDIPLO. Requires a relying party to be already registered at the registrar.

Parameters :
Name Type Optional Description
token TokenPayload No
  • The token payload from the auth context
dto CreateAccessCertificateDto No
  • The key ID to create the certificate for
Returns : Promise<literal type>

The access certificate ID and PEM

Async createConfig
createConfig(token: TokenPayload, dto: CreateRegistrarConfigDto)
Decorators :
@Post('config')
@ApiOperation({summary: 'Create or replace registrar configuration'})
@ApiResponse({status: 201, description: 'Configuration created successfully', type: RegistrarConfigEntity})
@ApiResponse({status: 400, description: 'Invalid credentials'})

Create or replace the registrar configuration for the tenant. Credentials are validated before saving.

Parameters :
Name Type Optional Description
token TokenPayload No
  • The token payload from the auth context
dto CreateRegistrarConfigDto No
  • The configuration data

The saved configuration

Async deleteConfig
deleteConfig(token: TokenPayload)
Decorators :
@Delete('config')
@HttpCode(HttpStatus.NO_CONTENT)
@ApiOperation({summary: 'Delete registrar configuration'})
@ApiResponse({status: 204, description: 'Configuration deleted successfully'})

Delete the registrar configuration for the tenant.

Parameters :
Name Type Optional Description
token TokenPayload No
  • The token payload from the auth context
Returns : Promise<void>
Async getConfig
getConfig(token: TokenPayload)
Decorators :
@Get('config')
@ApiOperation({summary: 'Get registrar configuration'})
@ApiResponse({status: 200, description: 'The registrar configuration', type: RegistrarConfigEntity})
@ApiResponse({status: 404, description: 'No registrar configuration found'})

Get the current registrar configuration for the tenant.

Parameters :
Name Type Optional
token TokenPayload No

The registrar configuration

Async updateConfig
updateConfig(token: TokenPayload, dto: UpdateRegistrarConfigDto)
Decorators :
@Patch('config')
@ApiOperation({summary: 'Update registrar configuration'})
@ApiResponse({status: 200, description: 'Configuration updated successfully', type: RegistrarConfigEntity})
@ApiResponse({status: 400, description: 'Invalid credentials'})
@ApiResponse({status: 404, description: 'No registrar configuration found'})

Update the registrar configuration for the tenant. Credentials are validated if auth-related fields are changed.

Parameters :
Name Type Optional Description
token TokenPayload No
  • The token payload from the auth context
dto UpdateRegistrarConfigDto No
  • The partial configuration data to update

The updated configuration

import {
    Body,
    Controller,
    Delete,
    Get,
    HttpCode,
    HttpStatus,
    Patch,
    Post,
} from "@nestjs/common";
import { ApiOperation, ApiResponse, 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 { CreateAccessCertificateDto } from "./dto/create-access-certificate.dto";
import { CreateRegistrarConfigDto } from "./dto/create-registrar-config.dto";
import { UpdateRegistrarConfigDto } from "./dto/update-registrar-config.dto";
import { RegistrarConfigEntity } from "./entities/registrar-config.entity";
import { RegistrarService } from "./registrar.service";

/**
 * Controller for managing registrar configuration and creating access certificates.
 * Allows tenants to configure their connection to an external registrar
 * and create access certificates for their keys.
 */
@ApiTags("Registrar")
@Secured([Role.Registrar])
@Controller("registrar")
export class RegistrarController {
    constructor(private readonly registrarService: RegistrarService) {}

    /**
     * Get the current registrar configuration for the tenant.
     * @returns The registrar configuration
     */
    @Get("config")
    @ApiOperation({ summary: "Get registrar configuration" })
    @ApiResponse({
        status: 200,
        description: "The registrar configuration",
        type: RegistrarConfigEntity,
    })
    @ApiResponse({
        status: 404,
        description: "No registrar configuration found",
    })
    async getConfig(
        @Token() token: TokenPayload,
    ): Promise<RegistrarConfigEntity | null> {
        return this.registrarService.getConfig(token.entity!.id);
    }

    /**
     * Create or replace the registrar configuration for the tenant.
     * Credentials are validated before saving.
     * @param token - The token payload from the auth context
     * @param dto - The configuration data
     * @returns The saved configuration
     */
    @Post("config")
    @ApiOperation({ summary: "Create or replace registrar configuration" })
    @ApiResponse({
        status: 201,
        description: "Configuration created successfully",
        type: RegistrarConfigEntity,
    })
    @ApiResponse({
        status: 400,
        description: "Invalid credentials",
    })
    async createConfig(
        @Token() token: TokenPayload,
        @Body() dto: CreateRegistrarConfigDto,
    ): Promise<RegistrarConfigEntity> {
        return this.registrarService.saveConfig(token.entity!.id, dto);
    }

    /**
     * Update the registrar configuration for the tenant.
     * Credentials are validated if auth-related fields are changed.
     * @param token - The token payload from the auth context
     * @param dto - The partial configuration data to update
     * @returns The updated configuration
     */
    @Patch("config")
    @ApiOperation({ summary: "Update registrar configuration" })
    @ApiResponse({
        status: 200,
        description: "Configuration updated successfully",
        type: RegistrarConfigEntity,
    })
    @ApiResponse({
        status: 400,
        description: "Invalid credentials",
    })
    @ApiResponse({
        status: 404,
        description: "No registrar configuration found",
    })
    async updateConfig(
        @Token() token: TokenPayload,
        @Body() dto: UpdateRegistrarConfigDto,
    ): Promise<RegistrarConfigEntity> {
        return this.registrarService.updateConfig(token.entity!.id, dto);
    }

    /**
     * Delete the registrar configuration for the tenant.
     * @param token - The token payload from the auth context
     */
    @Delete("config")
    @HttpCode(HttpStatus.NO_CONTENT)
    @ApiOperation({ summary: "Delete registrar configuration" })
    @ApiResponse({
        status: 204,
        description: "Configuration deleted successfully",
    })
    async deleteConfig(@Token() token: TokenPayload): Promise<void> {
        return this.registrarService.deleteConfig(token.entity!.id);
    }

    /**
     * Create an access certificate for a specific key.
     * The certificate will be fetched from the registrar and stored in EUDIPLO.
     * Requires a relying party to be already registered at the registrar.
     * @param token - The token payload from the auth context
     * @param dto - The key ID to create the certificate for
     * @returns The access certificate ID and PEM
     */
    @Post("access-certificate")
    @ApiOperation({
        summary: "Create an access certificate for a key",
        description:
            "Creates an access certificate at the registrar for the specified key. " +
            "Requires a relying party to be already registered at the registrar. " +
            "The certificate is automatically stored in EUDIPLO.",
    })
    @ApiResponse({
        status: 201,
        description: "Access certificate created successfully",
        schema: {
            type: "object",
            properties: {
                id: {
                    type: "string",
                    description: "The certificate ID at the registrar",
                },
                crt: {
                    type: "string",
                    description: "The certificate in PEM format",
                },
            },
        },
    })
    @ApiResponse({
        status: 400,
        description:
            "No relying party found at registrar or failed to create certificate",
    })
    @ApiResponse({
        status: 404,
        description: "No registrar configuration found or key not found",
    })
    async createAccessCertificate(
        @Token() token: TokenPayload,
        @Body() dto: CreateAccessCertificateDto,
    ): Promise<{ id: string; crt: string }> {
        return this.registrarService.createAccessCertificate(
            token.entity!.id,
            dto,
        );
    }
}

results matching ""

    No results matching ""