@@ -6,12 +6,13 @@ class Kamal::Configuration::Proxy
66
77 delegate :argumentize , :optionize , to : Kamal ::Utils
88
9- attr_reader :config , :proxy_config
9+ attr_reader :config , :proxy_config , :secrets
1010
11- def initialize ( config :, proxy_config :, context : "proxy" )
11+ def initialize ( config :, proxy_config :, secrets : , context : "proxy" )
1212 @config = config
1313 @proxy_config = proxy_config
1414 @proxy_config = { } if @proxy_config . nil?
15+ @secrets = secrets
1516 validate! @proxy_config , with : Kamal ::Configuration ::Validator ::Proxy , context : context
1617 end
1718
@@ -27,10 +28,42 @@ def hosts
2728 proxy_config [ "hosts" ] || proxy_config [ "host" ] &.split ( "," ) || [ ]
2829 end
2930
31+ def custom_ssl_certificate?
32+ ssl = proxy_config [ "ssl" ]
33+ return false unless ssl . is_a? ( Hash )
34+ ssl [ "certificate_pem" ] . present? && ssl [ "private_key_pem" ] . present?
35+ end
36+
37+ def certificate_pem_content
38+ ssl = proxy_config [ "ssl" ]
39+ return nil unless ssl . is_a? ( Hash )
40+ secrets [ ssl [ "certificate_pem" ] ]
41+ end
42+
43+ def private_key_pem_content
44+ ssl = proxy_config [ "ssl" ]
45+ return nil unless ssl . is_a? ( Hash )
46+ secrets [ ssl [ "private_key_pem" ] ]
47+ end
48+
49+ def certificate_pem
50+ tls_file_path ( "cert.pem" )
51+ end
52+
53+ def private_key_pem
54+ tls_file_path ( "key.pem" )
55+ end
56+
57+ def tls_file_path ( filename )
58+ File . join ( config . proxy_boot . tls_container_directory , filename ) if custom_ssl_certificate?
59+ end
60+
3061 def deploy_options
3162 {
3263 host : hosts ,
33- tls : proxy_config [ "ssl" ] . presence ,
64+ tls : ssl? ? true : nil ,
65+ "tls-certificate-path" : certificate_pem ,
66+ "tls-private-key-path" : private_key_pem ,
3467 "deploy-timeout" : seconds_duration ( config . deploy_timeout ) ,
3568 "drain-timeout" : seconds_duration ( config . drain_timeout ) ,
3669 "health-check-interval" : seconds_duration ( proxy_config . dig ( "healthcheck" , "interval" ) ) ,
@@ -68,7 +101,7 @@ def stop_command_args(**options)
68101 end
69102
70103 def merge ( other )
71- self . class . new config : config , proxy_config : proxy_config . deep_merge ( other . proxy_config )
104+ self . class . new config : config , proxy_config : proxy_config . deep_merge ( other . proxy_config ) , secrets : secrets
72105 end
73106
74107 private
0 commit comments