48 lines
1.3 KiB
TypeScript
48 lines
1.3 KiB
TypeScript
import { Injectable } from '@nestjs/common';
|
|
import * as Joi from 'joi';
|
|
|
|
import { AbstractActionHandler, AwsProperties, Format } from '../abstract-action.handler';
|
|
import { Action } from '../action.enum';
|
|
import { KmsService } from './kms.service';
|
|
import { RequestContext } from '../_context/request.context';
|
|
|
|
type QueryParams = {
|
|
KeyId?: string;
|
|
Limit: number;
|
|
Marker?: string;
|
|
}
|
|
|
|
@Injectable()
|
|
export class ListAliasesHandler extends AbstractActionHandler<QueryParams> {
|
|
|
|
constructor(
|
|
private readonly kmsService: KmsService,
|
|
) {
|
|
super();
|
|
}
|
|
|
|
format = Format.Json;
|
|
action = Action.KmsListAliases;
|
|
validator = Joi.object<QueryParams, true>({
|
|
KeyId: Joi.string(),
|
|
Limit: Joi.number().min(1).max(100).default(50),
|
|
Marker: Joi.string(),
|
|
});
|
|
|
|
protected async handle({ KeyId, Limit, Marker }: QueryParams, { awsProperties} : RequestContext) {
|
|
|
|
const records = await (KeyId
|
|
? this.kmsService.findAndCountAliasesByKeyId(awsProperties.accountId, awsProperties.region, Limit, KeyId, Marker)
|
|
: this.kmsService.findAndCountAliases(awsProperties.accountId, awsProperties.region, Limit, Marker)
|
|
)
|
|
|
|
const nextMarker = records.length > Limit ? records.pop() : null;
|
|
|
|
return {
|
|
Aliases: records.map(r => r.toAws()),
|
|
NextMarker: nextMarker?.name,
|
|
Truncated: !!nextMarker,
|
|
}
|
|
}
|
|
}
|