Completed kms
This commit is contained in:
@@ -0,0 +1,46 @@
|
||||
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';
|
||||
|
||||
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: AwsProperties) {
|
||||
|
||||
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,
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user