refactor: move all port management code to standalone ports plugin
This change makes interacting with port mappings more clear - folks might previously set the port mapping to the proxy type or vice-versa. The existing proxy:ports* commands still exist but will show a deprecation warning for a single minor release.
This commit is contained in:
1 parent
a0b84d52ef
commit
64f0f2674d
43 files changed
+894
-553
No files matched your search
@@ -0,0 +1,71 @@
|
||||
package ports
|
||||
|
||||
import (
|
||||
"github.com/dokku/dokku/plugins/config"
|
||||
)
|
||||
|
||||
// TriggerPostCertsRemove unsets port config vars after SSL cert is added
|
||||
func TriggerPostCertsRemove(appName string) error {
|
||||
keys := []string{"DOKKU_PROXY_SSL_PORT"}
|
||||
if err := config.UnsetMany(appName, keys, false); err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
return removePortMaps(appName, filterAppPortMaps(appName, "https", 443))
|
||||
}
|
||||
|
||||
// TriggerPostCertsUpdate sets port config vars after SSL cert is added
|
||||
func TriggerPostCertsUpdate(appName string) error {
|
||||
port := config.GetWithDefault(appName, "DOKKU_PROXY_PORT", "")
|
||||
sslPort := config.GetWithDefault(appName, "DOKKU_PROXY_SSL_PORT", "")
|
||||
portMaps := getPortMaps(appName)
|
||||
|
||||
toUnset := []string{}
|
||||
if port == "80" {
|
||||
toUnset = append(toUnset, "DOKKU_PROXY_PORT")
|
||||
}
|
||||
if sslPort == "443" {
|
||||
toUnset = append(toUnset, "DOKKU_PROXY_SSL_PORT")
|
||||
}
|
||||
|
||||
if len(toUnset) > 0 {
|
||||
if err := config.UnsetMany(appName, toUnset, false); err != nil {
|
||||
return err
|
||||
}
|
||||
}
|
||||
|
||||
var http80Ports []PortMap
|
||||
for _, portMap := range portMaps {
|
||||
if portMap.Scheme == "http" && portMap.HostPort == 80 {
|
||||
http80Ports = append(http80Ports, portMap)
|
||||
}
|
||||
}
|
||||
|
||||
if len(http80Ports) > 0 {
|
||||
var https443Ports []PortMap
|
||||
for _, portMap := range portMaps {
|
||||
if portMap.Scheme == "https" && portMap.HostPort == 443 {
|
||||
https443Ports = append(https443Ports, portMap)
|
||||
}
|
||||
}
|
||||
|
||||
if err := removePortMaps(appName, https443Ports); err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
var toAdd []PortMap
|
||||
for _, portMap := range http80Ports {
|
||||
toAdd = append(toAdd, PortMap{
|
||||
Scheme: "https",
|
||||
HostPort: 443,
|
||||
ContainerPort: portMap.ContainerPort,
|
||||
})
|
||||
}
|
||||
|
||||
if err := addPortMaps(appName, toAdd); err != nil {
|
||||
return err
|
||||
}
|
||||
}
|
||||
|
||||
return nil
|
||||
}
|
||||
Reference in new issue
Block a user