Sts addition, kms updates, context object, improved exception handling
This commit is contained in:
@@ -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;
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user