feat: add support for global properties

This commit is contained in:
Jose Diaz-Gonzalez committed 2024-01-23 03:00:27 -05:00
1 parent 22f27ea2d3
commit 62c8cb770e
5 files changed
+166 -55

No files matched your search

+52
View File
@@ -0,0 +1,52 @@
package scheduler_k3s
import (
"encoding/json"
"fmt"
"github.com/dokku/dokku/plugins/common"
)
type PortMap struct {
ContainerPort int32 `json:"container_port"`
HostPort int32 `json:"host_port"`
Scheme string `json:"scheme"`
}
func (p PortMap) String() string {
return fmt.Sprintf("%s-%d-%d", p.Scheme, p.HostPort, p.ContainerPort)
}
func (p PortMap) IsAllowedHttp() bool {
return p.Scheme == "http" || p.ContainerPort == 80
}
func (p PortMap) IsAllowedHttps() bool {
return p.Scheme == "https" || p.ContainerPort == 443
}
func getPortMaps(appName string) ([]PortMap, error) {
portMaps := []PortMap{}
output, err := common.PlugnTriggerOutputAsString("ports-get", []string{appName, "json"}...)
if err != nil {
return portMaps, err
}
err = json.Unmarshal([]byte(output), &portMaps)
if err != nil {
return portMaps, err
}
allowedMappings := []PortMap{}
for _, portMap := range portMaps {
if !portMap.IsAllowedHttp() && !portMap.IsAllowedHttps() {
// todo: log warning
continue
}
allowedMappings = append(allowedMappings, portMap)
}
return allowedMappings, nil
}