import { Injectable } from '@nestjs/common'; import { AbstractActionHandler, AwsProperties, Format } from '../abstract-action.handler'; import { Action } from '../action.enum'; import * as Joi from 'joi'; import { KmsService } from './kms.service'; import { NotFoundException } from '../aws-shared-entities/aws-exceptions'; type QueryParams = { GrantTokens?: string[]; KeyId: string; } @Injectable() export class DescribeKeyHandler extends AbstractActionHandler { constructor( private readonly kmsService: KmsService, ) { super(); } format = Format.Json; action = Action.KmsDescribeKey; validator = Joi.object({ KeyId: Joi.string().required(), GrantTokens: Joi.array().items(Joi.string()), }); protected async handle({ KeyId }: QueryParams, awsProperties: AwsProperties) { const keyRecord = await this.kmsService.findOneByRef(KeyId, awsProperties); if (!keyRecord) { throw new NotFoundException(); } return { KeyMetadata: keyRecord.metadata, } } }