1+ import { Constants } from "@/shared/utils/constants" ;
2+ import { AppTemplateContentModel , AppTemplateModel } from "../../model/app-template.model" ;
3+ import { AppExtendedModel } from "@/shared/model/app-extended.model" ;
4+ import crypto from "crypto" ;
5+
6+ export function getChiselAppTemplate ( config ?: {
7+ appName ?: string ,
8+ username ?: string ,
9+ password ?: string
10+ } ) : AppTemplateContentModel {
11+ return {
12+ inputSettings : [
13+ {
14+ key : "containerImageSource" ,
15+ label : "Container Image" ,
16+ value : "jpillora/chisel:latest" ,
17+ isEnvVar : false ,
18+ randomGeneratedIfEmpty : false ,
19+ } ,
20+ {
21+ key : "CHISEL_USER" ,
22+ label : "Username" ,
23+ value : config ?. username || "chisel" ,
24+ isEnvVar : true ,
25+ randomGeneratedIfEmpty : false ,
26+ } ,
27+ {
28+ key : "CHISEL_PASSWORD" ,
29+ label : "Password" ,
30+ value : config ?. password || "" ,
31+ isEnvVar : true ,
32+ randomGeneratedIfEmpty : true ,
33+ } ,
34+ ] ,
35+ appModel : {
36+ name : config ?. appName || "Chisel Tunnel" ,
37+ appType : 'APP' ,
38+ sourceType : 'CONTAINER' ,
39+ containerImageSource : "" ,
40+ replicas : 1 ,
41+ ingressNetworkPolicy : Constants . DEFAULT_INGRESS_NETWORK_POLICY_APPS ,
42+ egressNetworkPolicy : Constants . DEFAULT_EGRESS_NETWORK_POLICY_APPS ,
43+ envVars : `` ,
44+ useNetworkPolicy : true ,
45+ healthCheckPeriodSeconds : Constants . DEFAULT_HEALTH_CHECK_PERIOD_SECONDS ,
46+ healthCheckTimeoutSeconds : Constants . DEFAULT_HEALTH_CHECK_TIMEOUT_SECONDS ,
47+ healthCheckFailureThreshold : Constants . DEFAULT_HEALTH_CHECK_FAILURE_THRESHOLD ,
48+ containerArgs : '["server", "--keyfile", "/etc/chisel/chisel.key", "--auth", "$(CHISEL_USER):$(CHISEL_PASSWORD)", "--reverse"]' ,
49+ } ,
50+ appDomains : [ ] ,
51+ appVolumes : [ ] ,
52+ appFileMounts : [ ] ,
53+ appPorts : [ {
54+ port : 8080 ,
55+ } ] ,
56+ } ;
57+ }
58+
59+ export const chiselAppTemplate : AppTemplateModel = {
60+ name : "Chisel Tunnel" ,
61+ iconName : 'chisel.svg' ,
62+ templates : [
63+ getChiselAppTemplate ( )
64+ ] ,
65+ } ;
66+
67+ export const postCreateChiselAppTemplate = async ( createdApps : AppExtendedModel [ ] ) : Promise < AppExtendedModel [ ] > => {
68+ const app = createdApps [ 0 ] ;
69+
70+ const { privateKey } = crypto . generateKeyPairSync ( 'ec' , {
71+ namedCurve : 'P-256' ,
72+ privateKeyEncoding : { type : 'sec1' , format : 'pem' } ,
73+ publicKeyEncoding : { type : 'spki' , format : 'pem' } ,
74+ } ) ;
75+
76+ app . appFileMounts . push ( {
77+ containerMountPath : '/etc/chisel/chisel.key' ,
78+ content : privateKey ,
79+ } as any ) ;
80+
81+ return [ app ] ;
82+ } ;
0 commit comments