Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

add logger which doesn't break json parsing #175

Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading