package server import ( "git.a-wan.net/alan/pipelines/internal/protocol" "net/url" "os" "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}} }