Skip to content

Commit

Permalink
Merge pull request #199 from ngrok/revert-198-mo/bindings-to-binding
Browse files Browse the repository at this point in the history
Revert "endpoints bind to a single binding "
  • Loading branch information
Megalonia authored Feb 13, 2025
2 parents 2d002d1 + e0a5452 commit cf88d3f
Show file tree
Hide file tree
Showing 11 changed files with 83 additions and 76 deletions.
9 changes: 2 additions & 7 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,14 +1,9 @@
## 1.13.0

Breaking changes:

- Renames pre-release option `WithBindings` to `WithBinding`

## 1.12.0

Breaking changes:

- Renames pre-release option `WithAllowsPooling` to `WithPoolingEnabled`
-

## 1.11.0

Expand All @@ -29,7 +24,7 @@ Enhancements:
- Adds fasthttp example
- Adds `WithBindings` option
- Adds support for `TrafficPolicy` field

Changes:

- Replace log adapter module license symlinks with full files
Expand Down
18 changes: 0 additions & 18 deletions config/binding.go

This file was deleted.

45 changes: 0 additions & 45 deletions config/binding_test.go

This file was deleted.

30 changes: 30 additions & 0 deletions config/bindings.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
package config

type bindings []string

// WithBinding configures ingress for an endpoint
//
// The requestedBindings argument specifies the type of ingress for the endpoint.
func WithBindings(requestedBindings ...string) interface {
HTTPEndpointOption
TLSEndpointOption
TCPEndpointOption
} {
ret := bindings{}
for _, binding := range requestedBindings {
ret = append(ret, binding)
}
return ret
}

func (b bindings) ApplyTLS(cfg *tlsOptions) {
cfg.Bindings = []string(b)
}

func (b bindings) ApplyTCP(cfg *tcpOptions) {
cfg.Bindings = []string(b)
}

func (b bindings) ApplyHTTP(cfg *httpOptions) {
cfg.Bindings = []string(b)
}
45 changes: 45 additions & 0 deletions config/bindings_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
package config

import (
"testing"
)

func testBindings[T tunnelConfigPrivate, OT any](t *testing.T,
makeOpts func(...OT) Tunnel,
) {
optsFunc := func(opts ...any) Tunnel {
return makeOpts(assertSlice[OT](opts)...)
}

cases := testCases[T, any]{
{
name: "absent",
opts: optsFunc(),
expectExtra: &matchBindExtra{
Bindings: ptr([]string{}),
},
},
{
name: "with bindings",
opts: optsFunc(WithBindings("public")),
expectExtra: &matchBindExtra{
Bindings: ptr([]string{"public"}),
},
},
{
name: "with bindings with spread op",
opts: optsFunc(WithBindings([]string{"public"}...)),
expectExtra: &matchBindExtra{
Bindings: ptr([]string{"public"}),
},
},
}

cases.runAll(t)
}

func TestBindings(t *testing.T) {
testBindings[*httpOptions](t, HTTPEndpoint)
testBindings[*tlsOptions](t, TLSEndpoint)
testBindings[*tcpOptions](t, TCPEndpoint)
}
2 changes: 1 addition & 1 deletion config/common.go
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ type commonOpts struct {
TrafficPolicy string

// Enables ingress for ngrok endpoints.
Binding string
Bindings []string

// Allows the endpoint to pool with other endpoints with the same host/port/binding
PoolingEnabled bool
Expand Down
2 changes: 1 addition & 1 deletion config/config_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ type matchBindExtra struct {
Token *string
IPPolicyRef *string
Metadata *string
Binding *string
Bindings *[]string
}

func (m matchBindExtra) RequireMatches(t *testing.T, actual proto.BindExtra) {
Expand Down
2 changes: 1 addition & 1 deletion config/http.go
Original file line number Diff line number Diff line change
Expand Up @@ -150,7 +150,7 @@ func (cfg httpOptions) Extra() proto.BindExtra {
Name: cfg.Name,
Metadata: cfg.Metadata,
Description: cfg.Description,
Binding: cfg.Binding,
Bindings: cfg.Bindings,
PoolingEnabled: cfg.PoolingEnabled,
}
}
Expand Down
2 changes: 1 addition & 1 deletion config/tcp.go
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,7 @@ func (cfg tcpOptions) Extra() proto.BindExtra {
Name: cfg.Name,
Metadata: cfg.Metadata,
Description: cfg.Description,
Binding: cfg.Binding,
Bindings: cfg.Bindings,
PoolingEnabled: cfg.PoolingEnabled,
}
}
Expand Down
2 changes: 1 addition & 1 deletion config/tls.go
Original file line number Diff line number Diff line change
Expand Up @@ -102,7 +102,7 @@ func (cfg tlsOptions) Extra() proto.BindExtra {
Name: cfg.Name,
Metadata: cfg.Metadata,
Description: cfg.Description,
Binding: cfg.Binding,
Bindings: cfg.Bindings,
PoolingEnabled: cfg.PoolingEnabled,
}
}
Expand Down
2 changes: 1 addition & 1 deletion internal/tunnel/proto/msg.go
Original file line number Diff line number Diff line change
Expand Up @@ -226,7 +226,7 @@ type BindExtra struct {
IPPolicyRef string
Metadata string
Description string
Binding string
Bindings []string
PoolingEnabled bool
}

Expand Down

0 comments on commit cf88d3f

Please sign in to comment.