package client import ( "net/url" "os" ) // transportTarget applies the scoped Docker transport aliases embedded in an // authoring/debug prompt CLI prefix. It rewrites the requested endpoint only when // both aliases are present, valid ws/wss URLs with source != target, and the // requested URL exactly equals SOURCE. Anything else is dialed unchanged, so // remote and unmatched targets are never redirected. func transportTarget(requested string) string { source := os.Getenv("PIPELINES_TRANSPORT_SOURCE") target := os.Getenv("PIPELINES_TRANSPORT_TARGET") if source == "" || target == "" || source == target { return requested } if !validWebSocketURL(source) || !validWebSocketURL(target) { return requested } if requested == source { return target } return requested } func validWebSocketURL(value string) bool { u, err := url.Parse(value) if err != nil { return false } return (u.Scheme == "ws" || u.Scheme == "wss") && u.Hostname() != "" && u.User == nil && u.Fragment == "" }