Sts addition, kms updates, context object, improved exception handling

This commit is contained in:
2024-12-20 01:07:33 -05:00
parent 095ecbd643
commit c34ea76e4e
50 changed files with 3129 additions and 1149 deletions

View File

@@ -1,22 +1,30 @@
import { Injectable } from '@nestjs/common';
import { PrismaService } from '../_prisma/prisma.service';
import { ArnParts } from '../util/breakdown-arn';
import { InjectRepository } from '@nestjs/typeorm';
import { KmsKeyAlias } from './kms-key-alias.entity';
import { Repository } from 'typeorm';
import { KmsKey } from './kms-key.entity';
@Injectable()
export class KmsService {
constructor(
@InjectRepository(KmsKeyAlias)
private readonly aliasRepo: Repository<KmsKeyAlias>,
private readonly prismaService: PrismaService,
) {}
async findKeyIdFromAlias(alias: string, arn: ArnParts): Promise<string> {
const record = await this.aliasRepo.findOne({ where: {
name: alias,
accountId: arn.accountId,
region: arn.region,
}});
return record.targetKeyId;
async findOneById(id: string): Promise<KmsKey | null> {
const pRecord = await this.prismaService.kmsKey.findFirst({
where: { id }
});
return pRecord ? new KmsKey(pRecord) : null;
}
async findKeyIdFromAlias(alias: string, arn: ArnParts): Promise<string | null> {
const record = await this.prismaService.kmsAlias.findFirst({
where: {
name: alias,
accountId: arn.accountId,
region: arn.region,
}
});
return record?.kmsKeyId ?? null;
}
}