2022-02-10 14:47:44 +00:00
|
|
|
import { encrypt } from '$lib/crypto';
|
2022-02-11 20:14:47 +00:00
|
|
|
import { prisma } from './common';
|
2022-02-10 14:47:44 +00:00
|
|
|
|
2022-02-19 13:54:47 +00:00
|
|
|
export async function listSecrets(applicationId: string) {
|
2022-02-10 14:47:44 +00:00
|
|
|
return await prisma.secret.findMany({
|
|
|
|
|
where: { applicationId },
|
2022-02-19 13:54:47 +00:00
|
|
|
orderBy: { createdAt: 'desc' }
|
2022-02-10 14:47:44 +00:00
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
|
2022-02-19 13:54:47 +00:00
|
|
|
export async function createSecret({ id, name, value, isBuildSecret, isPRMRSecret }) {
|
2022-02-10 14:47:44 +00:00
|
|
|
value = encrypt(value);
|
|
|
|
|
return await prisma.secret.create({
|
2022-02-19 13:54:47 +00:00
|
|
|
data: { name, value, isBuildSecret, isPRMRSecret, application: { connect: { id } } }
|
2022-02-10 14:47:44 +00:00
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
|
2022-02-19 13:54:47 +00:00
|
|
|
export async function updateSecret({ id, name, value, isBuildSecret, isPRMRSecret }) {
|
|
|
|
|
value = encrypt(value);
|
|
|
|
|
const found = await prisma.secret.findFirst({ where: { applicationId: id, name, isPRMRSecret } });
|
|
|
|
|
if (found) {
|
|
|
|
|
return await prisma.secret.updateMany({
|
|
|
|
|
where: { applicationId: id, name, isPRMRSecret },
|
|
|
|
|
data: { value, isBuildSecret, isPRMRSecret }
|
|
|
|
|
});
|
|
|
|
|
} else {
|
|
|
|
|
return await prisma.secret.create({
|
|
|
|
|
data: { name, value, isBuildSecret, isPRMRSecret, application: { connect: { id } } }
|
|
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2022-02-10 14:47:44 +00:00
|
|
|
export async function removeSecret({ id, name }) {
|
|
|
|
|
return await prisma.secret.deleteMany({ where: { applicationId: id, name } });
|
|
|
|
|
}
|