From 76983a1e682100fb43736a058b61ef71cc9e3f00 Mon Sep 17 00:00:00 2001 From: kc Date: Wed, 17 Jul 2024 15:06:26 +0000 Subject: [PATCH] add logger which doesn't break json parsing, as well as backwards compatible url plumbing --- config/domain.go | 21 +++++++++++++++++++++ config/http.go | 4 ++++ config/policy.go | 4 +++- config/tcp.go | 5 +++++ config/tls.go | 4 ++++ internal/tunnel/proto/msg.go | 3 +++ 6 files changed, 40 insertions(+), 1 deletion(-) diff --git a/config/domain.go b/config/domain.go index a45018d..01d9783 100644 --- a/config/domain.go +++ b/config/domain.go @@ -1,5 +1,26 @@ package config +type urlOption string + +func WithURL(name string) interface { + HTTPEndpointOption + TLSEndpointOption +} { + return urlOption(name) +} + +func (opt urlOption) ApplyHTTP(opts *httpOptions) { + opts.URL = string(opt) +} + +func (opt urlOption) ApplyTLS(opts *tlsOptions) { + opts.URL = string(opt) +} + +func (opt urlOption) ApplyTCP(opts *tcpOptions) { + opts.URL = string(opt) +} + type domainOption string // WithDomain sets the fully-qualified domain name for this edge. diff --git a/config/http.go b/config/http.go index 24c2c0c..b00421e 100644 --- a/config/http.go +++ b/config/http.go @@ -38,6 +38,9 @@ type httpOptions struct { // Defaults to [SchemeHTTPS]. Scheme Scheme + // The URL to request for this endpoint + URL string + // The fqdn to request for this edge Domain string @@ -88,6 +91,7 @@ type httpOptions struct { func (cfg *httpOptions) toProtoConfig() *proto.HTTPEndpoint { opts := &proto.HTTPEndpoint{ + URL: cfg.URL, Domain: cfg.Domain, Hostname: cfg.Hostname, Subdomain: cfg.Subdomain, diff --git a/config/policy.go b/config/policy.go index 2116815..2e93360 100644 --- a/config/policy.go +++ b/config/policy.go @@ -5,6 +5,7 @@ import ( "errors" "fmt" + "github.com/inconshreveable/log15" "gopkg.in/yaml.v3" po "golang.ngrok.com/ngrok/policy" @@ -77,7 +78,8 @@ func (p *policy) ApplyTCP(opts *tcpOptions) { // policyToString converts the policy into a JSON string representation. This is to help remap Policy to TrafficPolicy. func policyToString(p *policy) string { - fmt.Println("WithPolicy has been deprecated. Please use WithPolicyString instead, as WithPolicy will stop working soon.") + logger := log15.New() + logger.Warn("WithPolicy has been deprecated. Please use WithPolicyString instead, as WithPolicy will stop working soon.") val, err := json.Marshal(p) if err != nil { diff --git a/config/tcp.go b/config/tcp.go index aa4ee00..a199915 100644 --- a/config/tcp.go +++ b/config/tcp.go @@ -32,6 +32,10 @@ func TCPEndpoint(opts ...TCPEndpointOption) Tunnel { type tcpOptions struct { // Common tunnel configuration options. commonOpts + + // The URL address to request for this endpoint. + URL string + // The TCP address to request for this edge. RemoteAddr string // An HTTP Server to run traffic on @@ -48,6 +52,7 @@ func WithRemoteAddr(addr string) TCPEndpointOption { func (cfg *tcpOptions) toProtoConfig() *proto.TCPEndpoint { return &proto.TCPEndpoint{ + URL: cfg.URL, Addr: cfg.RemoteAddr, IPRestriction: cfg.commonOpts.CIDRRestrictions.toProtoConfig(), ProxyProto: proto.ProxyProto(cfg.commonOpts.ProxyProto), diff --git a/config/tls.go b/config/tls.go index 2f8c820..4ae7ece 100644 --- a/config/tls.go +++ b/config/tls.go @@ -35,6 +35,9 @@ type tlsOptions struct { // Common tunnel options commonOpts + // The URL to request for this endpoint + URL string + // The fqdn to request for this edge. Domain string @@ -61,6 +64,7 @@ type tlsOptions struct { func (cfg *tlsOptions) toProtoConfig() *proto.TLSEndpoint { opts := &proto.TLSEndpoint{ + URL: cfg.URL, Domain: cfg.Domain, ProxyProto: proto.ProxyProto(cfg.ProxyProto), diff --git a/internal/tunnel/proto/msg.go b/internal/tunnel/proto/msg.go index 3a0710c..e63fc7c 100644 --- a/internal/tunnel/proto/msg.go +++ b/internal/tunnel/proto/msg.go @@ -282,6 +282,7 @@ func ParseProxyProto(proxyProto string) (ProxyProto, bool) { } type HTTPEndpoint struct { + URL string Domain string Hostname string // public hostname of the bind Subdomain string @@ -308,6 +309,7 @@ type HTTPEndpoint struct { } type TCPEndpoint struct { + URL string Addr string ProxyProto @@ -318,6 +320,7 @@ type TCPEndpoint struct { } type TLSEndpoint struct { + URL string Domain string Hostname string // public hostname of the bind Subdomain string