Class: Kamal::Configuration::Proxy
- Inherits:
-
Object
- Object
- Kamal::Configuration::Proxy
- Includes:
- Validation
- Defined in:
- lib/kamal/configuration/proxy.rb
Defined Under Namespace
Classes: Boot
Constant Summary collapse
- DEFAULT_LOG_REQUEST_HEADERS =
[ "Cache-Control", "Last-Modified", "User-Agent" ]
- CONTAINER_NAME =
"kamal-proxy"
Instance Attribute Summary collapse
-
#config ⇒ Object
readonly
Returns the value of attribute config.
-
#proxy_config ⇒ Object
readonly
Returns the value of attribute proxy_config.
-
#role_name ⇒ Object
readonly
Returns the value of attribute role_name.
-
#secrets ⇒ Object
readonly
Returns the value of attribute secrets.
Instance Method Summary collapse
- #app_port ⇒ Object
- #certificate_pem_content ⇒ Object
- #container_tls_cert ⇒ Object
- #container_tls_key ⇒ Object
- #custom_ssl_certificate? ⇒ Boolean
- #deploy_command_args(target:) ⇒ Object
- #deploy_options ⇒ Object
- #host_tls_cert ⇒ Object
- #host_tls_key ⇒ Object
- #hosts ⇒ Object
-
#initialize(config:, proxy_config:, role_name: nil, secrets:, context: "proxy") ⇒ Proxy
constructor
A new instance of Proxy.
- #merge(other) ⇒ Object
- #private_key_pem_content ⇒ Object
- #ssl? ⇒ Boolean
- #stop_command_args(**options) ⇒ Object
- #stop_options(drain_timeout: nil, message: nil) ⇒ Object
Methods included from Validation
Constructor Details
#initialize(config:, proxy_config:, role_name: nil, secrets:, context: "proxy") ⇒ Proxy
Returns a new instance of Proxy.
11 12 13 14 15 16 17 18 |
# File 'lib/kamal/configuration/proxy.rb', line 11 def initialize(config:, proxy_config:, role_name: nil, secrets:, context: "proxy") @config = config @proxy_config = proxy_config @proxy_config = {} if @proxy_config.nil? @role_name = role_name @secrets = secrets validate! @proxy_config, with: Kamal::Configuration::Validator::Proxy, context: context end |
Instance Attribute Details
#config ⇒ Object (readonly)
Returns the value of attribute config.
9 10 11 |
# File 'lib/kamal/configuration/proxy.rb', line 9 def config @config end |
#proxy_config ⇒ Object (readonly)
Returns the value of attribute proxy_config.
9 10 11 |
# File 'lib/kamal/configuration/proxy.rb', line 9 def proxy_config @proxy_config end |
#role_name ⇒ Object (readonly)
Returns the value of attribute role_name.
9 10 11 |
# File 'lib/kamal/configuration/proxy.rb', line 9 def role_name @role_name end |
#secrets ⇒ Object (readonly)
Returns the value of attribute secrets.
9 10 11 |
# File 'lib/kamal/configuration/proxy.rb', line 9 def secrets @secrets end |
Instance Method Details
#app_port ⇒ Object
20 21 22 |
# File 'lib/kamal/configuration/proxy.rb', line 20 def app_port proxy_config.fetch("app_port", 80) end |
#certificate_pem_content ⇒ Object
38 39 40 41 42 |
# File 'lib/kamal/configuration/proxy.rb', line 38 def certificate_pem_content ssl = proxy_config["ssl"] return nil unless ssl.is_a?(Hash) secrets[ssl["certificate_pem"]] end |
#container_tls_cert ⇒ Object
58 59 60 |
# File 'lib/kamal/configuration/proxy.rb', line 58 def container_tls_cert tls_path(config.proxy_boot.tls_container_directory, "cert.pem") end |
#container_tls_key ⇒ Object
62 63 64 |
# File 'lib/kamal/configuration/proxy.rb', line 62 def container_tls_key tls_path(config.proxy_boot.tls_container_directory, "key.pem") if custom_ssl_certificate? end |
#custom_ssl_certificate? ⇒ Boolean
32 33 34 35 36 |
# File 'lib/kamal/configuration/proxy.rb', line 32 def custom_ssl_certificate? ssl = proxy_config["ssl"] return false unless ssl.is_a?(Hash) ssl["certificate_pem"].present? && ssl["private_key_pem"].present? end |
#deploy_command_args(target:) ⇒ Object
93 94 95 |
# File 'lib/kamal/configuration/proxy.rb', line 93 def deploy_command_args(target:) optionize ({ target: "#{target}:#{app_port}" }).merge(), with: "=" end |
#deploy_options ⇒ Object
66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 |
# File 'lib/kamal/configuration/proxy.rb', line 66 def { host: hosts, tls: ssl? ? true : nil, "tls-certificate-path": container_tls_cert, "tls-private-key-path": container_tls_key, "deploy-timeout": seconds_duration(config.deploy_timeout), "drain-timeout": seconds_duration(config.drain_timeout), "health-check-interval": seconds_duration(proxy_config.dig("healthcheck", "interval")), "health-check-timeout": seconds_duration(proxy_config.dig("healthcheck", "timeout")), "health-check-path": proxy_config.dig("healthcheck", "path"), "target-timeout": seconds_duration(proxy_config["response_timeout"]), "buffer-requests": proxy_config.fetch("buffering", { "requests": true }).fetch("requests", true), "buffer-responses": proxy_config.fetch("buffering", { "responses": true }).fetch("responses", true), "buffer-memory": proxy_config.dig("buffering", "memory"), "max-request-body": proxy_config.dig("buffering", "max_request_body"), "max-response-body": proxy_config.dig("buffering", "max_response_body"), "path-prefix": proxy_config.dig("path_prefix"), "strip-path-prefix": proxy_config.dig("strip_path_prefix"), "forward-headers": proxy_config.dig("forward_headers"), "tls-redirect": proxy_config.dig("ssl_redirect"), "log-request-header": proxy_config.dig("logging", "request_headers") || DEFAULT_LOG_REQUEST_HEADERS, "log-response-header": proxy_config.dig("logging", "response_headers"), "error-pages": error_pages }.compact end |
#host_tls_cert ⇒ Object
50 51 52 |
# File 'lib/kamal/configuration/proxy.rb', line 50 def host_tls_cert tls_path(config.proxy_boot.tls_directory, "cert.pem") end |
#host_tls_key ⇒ Object
54 55 56 |
# File 'lib/kamal/configuration/proxy.rb', line 54 def host_tls_key tls_path(config.proxy_boot.tls_directory, "key.pem") end |
#hosts ⇒ Object
28 29 30 |
# File 'lib/kamal/configuration/proxy.rb', line 28 def hosts proxy_config["hosts"] || proxy_config["host"]&.split(",") || [] end |
#merge(other) ⇒ Object
108 109 110 |
# File 'lib/kamal/configuration/proxy.rb', line 108 def merge(other) self.class.new config: config, proxy_config: other.proxy_config.deep_merge(proxy_config), role_name: role_name, secrets: secrets end |
#private_key_pem_content ⇒ Object
44 45 46 47 48 |
# File 'lib/kamal/configuration/proxy.rb', line 44 def private_key_pem_content ssl = proxy_config["ssl"] return nil unless ssl.is_a?(Hash) secrets[ssl["private_key_pem"]] end |
#ssl? ⇒ Boolean
24 25 26 |
# File 'lib/kamal/configuration/proxy.rb', line 24 def ssl? proxy_config.fetch("ssl", false) end |
#stop_command_args(**options) ⇒ Object
104 105 106 |
# File 'lib/kamal/configuration/proxy.rb', line 104 def stop_command_args(**) optionize (**), with: "=" end |
#stop_options(drain_timeout: nil, message: nil) ⇒ Object
97 98 99 100 101 102 |
# File 'lib/kamal/configuration/proxy.rb', line 97 def (drain_timeout: nil, message: nil) { "drain-timeout": seconds_duration(drain_timeout), message: }.compact end |