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 }