Skip to content

Commit

Permalink
add logger which doesn't break json parsing, as well as backwards
Browse files Browse the repository at this point in the history
compatible url plumbing
  • Loading branch information
KristopherPaulsen committed Jul 17, 2024
1 parent ac81e74 commit 76983a1
Show file tree
Hide file tree
Showing 6 changed files with 40 additions and 1 deletion.
21 changes: 21 additions & 0 deletions config/domain.go
Original file line number Diff line number Diff line change
@@ -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.
Expand Down
4 changes: 4 additions & 0 deletions config/http.go
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down Expand Up @@ -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,
Expand Down
4 changes: 3 additions & 1 deletion config/policy.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import (
"errors"
"fmt"

"github.com/inconshreveable/log15"
"gopkg.in/yaml.v3"

po "golang.ngrok.com/ngrok/policy"
Expand Down Expand Up @@ -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 {
Expand Down
5 changes: 5 additions & 0 deletions config/tcp.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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),
Expand Down
4 changes: 4 additions & 0 deletions config/tls.go
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand All @@ -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),

Expand Down
3 changes: 3 additions & 0 deletions internal/tunnel/proto/msg.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -308,6 +309,7 @@ type HTTPEndpoint struct {
}

type TCPEndpoint struct {
URL string
Addr string
ProxyProto

Expand All @@ -318,6 +320,7 @@ type TCPEndpoint struct {
}

type TLSEndpoint struct {
URL string
Domain string
Hostname string // public hostname of the bind
Subdomain string
Expand Down

0 comments on commit 76983a1

Please sign in to comment.