mirror of
https://github.com/sourcebot-dev/sourcebot.git
synced 2025-12-12 12:25:22 +00:00
* wip fix repo images * fix config imports * add manifest json * more logos for manifest * add properly padded icon * support old gitlab token case, simplify getImage action, feedback * add changelog entry * fix build error
33 lines
No EOL
1 KiB
TypeScript
33 lines
No EOL
1 KiB
TypeScript
import { PrismaClient } from "@sourcebot/db";
|
|
import { Token } from "@sourcebot/schemas/v3/shared.type";
|
|
import { decrypt } from "./index.js";
|
|
|
|
export const getTokenFromConfig = async (token: Token, orgId: number, db: PrismaClient) => {
|
|
if ('secret' in token) {
|
|
const secretKey = token.secret;
|
|
const secret = await db.secret.findUnique({
|
|
where: {
|
|
orgId_key: {
|
|
key: secretKey,
|
|
orgId
|
|
}
|
|
}
|
|
});
|
|
|
|
if (!secret) {
|
|
throw new Error(`Secret with key ${secretKey} not found for org ${orgId}`);
|
|
}
|
|
|
|
const decryptedToken = decrypt(secret.iv, secret.encryptedValue);
|
|
return decryptedToken;
|
|
} else if ('env' in token) {
|
|
const envToken = process.env[token.env];
|
|
if (!envToken) {
|
|
throw new Error(`Environment variable ${token.env} not found.`);
|
|
}
|
|
|
|
return envToken;
|
|
} else {
|
|
throw new Error('Invalid token configuration');
|
|
}
|
|
};
|