mirror of
https://github.com/Dokploy/dokploy
synced 2025-06-26 18:27:59 +00:00
feat(templates): add JWT generation and expand template variable processing
- Implement generateJwt function for creating JWT tokens - Add support for 'jwt' and 'jwt:length' template variables - Introduce new base64 and password generation shortcuts - Enhance template variable processing with additional utility functions
This commit is contained in:
@@ -349,7 +349,7 @@ describe("processTemplate", () => {
|
||||
{
|
||||
serviceName: "plausible",
|
||||
port: 8000,
|
||||
host: "${randomDomain}",
|
||||
host: "${hash}",
|
||||
},
|
||||
],
|
||||
env: {
|
||||
@@ -367,6 +367,7 @@ describe("processTemplate", () => {
|
||||
};
|
||||
|
||||
const result = processTemplate(template, mockSchema);
|
||||
console.log(result);
|
||||
expect(result.envs).toHaveLength(3);
|
||||
expect(result.domains).toHaveLength(1);
|
||||
expect(result.mounts).toHaveLength(1);
|
||||
|
||||
@@ -63,6 +63,10 @@ export function generateBase64(length: number): string {
|
||||
.substring(0, length);
|
||||
}
|
||||
|
||||
export function generateJwt(length = 256): string {
|
||||
return randomBytes(length).toString("hex");
|
||||
}
|
||||
|
||||
/**
|
||||
* Reads a template's docker-compose.yml file
|
||||
* First tries to fetch from GitHub, falls back to local cache if fetch fails
|
||||
|
||||
@@ -2,6 +2,7 @@ import type { Schema } from "./index";
|
||||
import {
|
||||
generateBase64,
|
||||
generateHash,
|
||||
generateJwt,
|
||||
generatePassword,
|
||||
generateRandomDomain,
|
||||
} from "./index";
|
||||
@@ -72,6 +73,10 @@ function processValue(
|
||||
if (varName === "randomDomain") {
|
||||
return generateRandomDomain(schema);
|
||||
}
|
||||
|
||||
if (varName === "base64") {
|
||||
return generateBase64(32);
|
||||
}
|
||||
if (varName.startsWith("base64:")) {
|
||||
const length = Number.parseInt(varName.split(":")[1], 10) || 32;
|
||||
return generateBase64(length);
|
||||
@@ -80,6 +85,11 @@ function processValue(
|
||||
const length = Number.parseInt(varName.split(":")[1], 10) || 16;
|
||||
return generatePassword(length);
|
||||
}
|
||||
|
||||
if (varName === "password") {
|
||||
return generatePassword(16);
|
||||
}
|
||||
|
||||
if (varName.startsWith("hash:")) {
|
||||
const length = Number.parseInt(varName.split(":")[1], 10) || 8;
|
||||
return generateHash(length);
|
||||
@@ -96,6 +106,15 @@ function processValue(
|
||||
return Math.floor(Math.random() * 65535).toString();
|
||||
}
|
||||
|
||||
if (varName === "jwt") {
|
||||
return generateJwt();
|
||||
}
|
||||
|
||||
if (varName.startsWith("jwt:")) {
|
||||
const length = Number.parseInt(varName.split(":")[1], 10) || 256;
|
||||
return generateJwt(length);
|
||||
}
|
||||
|
||||
// If not a utility function, try to get from variables
|
||||
return variables[varName] || match;
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user