Added types for database/secrets
This commit is contained in:
parent
ec3b94cf96
commit
9973197fa5
@ -1,7 +1,8 @@
|
|||||||
import { encrypt, decrypt } from '$lib/crypto';
|
import { encrypt, decrypt } from '$lib/crypto';
|
||||||
import { prisma } from './common';
|
import { prisma } from './common';
|
||||||
|
import type { ServiceSecret, Secret, Prisma } from '@prisma/client';
|
||||||
|
|
||||||
export async function listServiceSecrets(serviceId: string) {
|
export async function listServiceSecrets(serviceId: string): Promise<ServiceSecret[]> {
|
||||||
let secrets = await prisma.serviceSecret.findMany({
|
let secrets = await prisma.serviceSecret.findMany({
|
||||||
where: { serviceId },
|
where: { serviceId },
|
||||||
orderBy: { createdAt: 'desc' }
|
orderBy: { createdAt: 'desc' }
|
||||||
@ -14,7 +15,7 @@ export async function listServiceSecrets(serviceId: string) {
|
|||||||
return secrets;
|
return secrets;
|
||||||
}
|
}
|
||||||
|
|
||||||
export async function listSecrets(applicationId: string) {
|
export async function listSecrets(applicationId: string): Promise<Secret[]> {
|
||||||
let secrets = await prisma.secret.findMany({
|
let secrets = await prisma.secret.findMany({
|
||||||
where: { applicationId },
|
where: { applicationId },
|
||||||
orderBy: { createdAt: 'desc' }
|
orderBy: { createdAt: 'desc' }
|
||||||
@ -27,20 +28,48 @@ export async function listSecrets(applicationId: string) {
|
|||||||
return secrets;
|
return secrets;
|
||||||
}
|
}
|
||||||
|
|
||||||
export async function createServiceSecret({ id, name, value }) {
|
export async function createServiceSecret({
|
||||||
|
id,
|
||||||
|
name,
|
||||||
|
value
|
||||||
|
}: {
|
||||||
|
id: string;
|
||||||
|
name: string;
|
||||||
|
value: string;
|
||||||
|
}): Promise<ServiceSecret> {
|
||||||
value = encrypt(value);
|
value = encrypt(value);
|
||||||
return await prisma.serviceSecret.create({
|
return await prisma.serviceSecret.create({
|
||||||
data: { name, value, service: { connect: { id } } }
|
data: { name, value, service: { connect: { id } } }
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
export async function createSecret({ id, name, value, isBuildSecret, isPRMRSecret }) {
|
export async function createSecret({
|
||||||
|
id,
|
||||||
|
name,
|
||||||
|
value,
|
||||||
|
isBuildSecret,
|
||||||
|
isPRMRSecret
|
||||||
|
}: {
|
||||||
|
id: string;
|
||||||
|
name: string;
|
||||||
|
value: string;
|
||||||
|
isBuildSecret: boolean;
|
||||||
|
isPRMRSecret: boolean;
|
||||||
|
}): Promise<Secret> {
|
||||||
value = encrypt(value);
|
value = encrypt(value);
|
||||||
return await prisma.secret.create({
|
return await prisma.secret.create({
|
||||||
data: { name, value, isBuildSecret, isPRMRSecret, application: { connect: { id } } }
|
data: { name, value, isBuildSecret, isPRMRSecret, application: { connect: { id } } }
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
export async function updateServiceSecret({ id, name, value }) {
|
export async function updateServiceSecret({
|
||||||
|
id,
|
||||||
|
name,
|
||||||
|
value
|
||||||
|
}: {
|
||||||
|
id: string;
|
||||||
|
name: string;
|
||||||
|
value: string;
|
||||||
|
}): Promise<Prisma.BatchPayload | ServiceSecret> {
|
||||||
value = encrypt(value);
|
value = encrypt(value);
|
||||||
const found = await prisma.serviceSecret.findFirst({ where: { serviceId: id, name } });
|
const found = await prisma.serviceSecret.findFirst({ where: { serviceId: id, name } });
|
||||||
|
|
||||||
@ -55,7 +84,19 @@ export async function updateServiceSecret({ id, name, value }) {
|
|||||||
});
|
});
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
export async function updateSecret({ id, name, value, isBuildSecret, isPRMRSecret }) {
|
export async function updateSecret({
|
||||||
|
id,
|
||||||
|
name,
|
||||||
|
value,
|
||||||
|
isBuildSecret,
|
||||||
|
isPRMRSecret
|
||||||
|
}: {
|
||||||
|
id: string;
|
||||||
|
name: string;
|
||||||
|
value: string;
|
||||||
|
isBuildSecret: boolean;
|
||||||
|
isPRMRSecret: boolean;
|
||||||
|
}): Promise<Prisma.BatchPayload | Secret> {
|
||||||
value = encrypt(value);
|
value = encrypt(value);
|
||||||
const found = await prisma.secret.findFirst({ where: { applicationId: id, name, isPRMRSecret } });
|
const found = await prisma.secret.findFirst({ where: { applicationId: id, name, isPRMRSecret } });
|
||||||
|
|
||||||
@ -71,10 +112,22 @@ export async function updateSecret({ id, name, value, isBuildSecret, isPRMRSecre
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
export async function removeServiceSecret({ id, name }) {
|
export async function removeServiceSecret({
|
||||||
|
id,
|
||||||
|
name
|
||||||
|
}: {
|
||||||
|
id: string;
|
||||||
|
name: string;
|
||||||
|
}): Promise<Prisma.BatchPayload> {
|
||||||
return await prisma.serviceSecret.deleteMany({ where: { serviceId: id, name } });
|
return await prisma.serviceSecret.deleteMany({ where: { serviceId: id, name } });
|
||||||
}
|
}
|
||||||
|
|
||||||
export async function removeSecret({ id, name }) {
|
export async function removeSecret({
|
||||||
|
id,
|
||||||
|
name
|
||||||
|
}: {
|
||||||
|
id: string;
|
||||||
|
name: string;
|
||||||
|
}): Promise<Prisma.BatchPayload> {
|
||||||
return await prisma.secret.deleteMany({ where: { applicationId: id, name } });
|
return await prisma.secret.deleteMany({ where: { applicationId: id, name } });
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user