Initial pipelines server, CLI, TUI, and Go installation
This commit is contained in:
@@ -0,0 +1,31 @@
|
||||
package server
|
||||
|
||||
import (
|
||||
"net/url"
|
||||
"os"
|
||||
"pipelines/internal/protocol"
|
||||
"regexp"
|
||||
"strings"
|
||||
)
|
||||
|
||||
var notificationTopic = regexp.MustCompile(`^[-_A-Za-z0-9]{1,64}$`)
|
||||
|
||||
func publicNtfyBase(text string) string {
|
||||
u, err := url.Parse(text)
|
||||
if err != nil || u.Hostname() == "" || (u.Scheme != "http" && u.Scheme != "https") || u.User != nil || u.RawQuery != "" || u.Fragment != "" || (u.Path != "" && u.Path != "/") {
|
||||
return ""
|
||||
}
|
||||
return strings.TrimRight(u.String(), "/")
|
||||
}
|
||||
|
||||
func notificationEndpoints() []protocol.NotificationEndpoint {
|
||||
u, err := url.Parse(os.Getenv("PIPELINES_NTFY_URL"))
|
||||
if err != nil || u.Hostname() == "" || (u.Scheme != "http" && u.Scheme != "https") || u.User != nil || u.RawQuery != "" || u.Fragment != "" || u.RawPath != "" {
|
||||
return nil
|
||||
}
|
||||
topic := strings.TrimPrefix(u.Path, "/")
|
||||
if !notificationTopic.MatchString(topic) {
|
||||
return nil
|
||||
}
|
||||
return []protocol.NotificationEndpoint{{Destination: "system", ServerURL: publicNtfyBase(os.Getenv("PIPELINES_NTFY_PUBLIC_URL")), Topic: topic}}
|
||||
}
|
||||
Reference in New Issue
Block a user