Skip to content

Commit

Permalink
Merge pull request #198 from ngrok/mo/bindings-to-binding
Browse files Browse the repository at this point in the history
endpoints bind to a single binding
  • Loading branch information
Megalonia authored Jan 22, 2025
2 parents 2f9c905 + b4bdf1a commit 2d002d1
Show file tree
Hide file tree
Showing 11 changed files with 76 additions and 83 deletions.
9 changes: 7 additions & 2 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,9 +1,14 @@
## 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 @@ -24,7 +29,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: 18 additions & 0 deletions config/binding.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
package config

type binding string

// WithBinding configures ingress for an endpoint
//
// The requestedBinding argument specifies the type of ingress for the endpoint.
func WithBinding(requestedBinding string) interface {
HTTPEndpointOption
TLSEndpointOption
TCPEndpointOption
} {
return binding(requestedBinding)
}

func (b binding) ApplyTLS(cfg *tlsOptions) { cfg.Binding = string(b) }
func (b binding) ApplyTCP(cfg *tcpOptions) { cfg.Binding = string(b) }
func (b binding) ApplyHTTP(cfg *httpOptions) { cfg.Binding = string(b) }
45 changes: 45 additions & 0 deletions config/binding_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
package config

import (
"testing"
)

func testBinding[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{
Binding: ptr(""),
},
},
{
name: "with public bindings",
opts: optsFunc(WithBinding("public")),
expectExtra: &matchBindExtra{
Binding: ptr("public"),
},
},
{
name: "with internal bindings",
opts: optsFunc(WithBinding("internal")),
expectExtra: &matchBindExtra{
Binding: ptr("internal"),
},
},
}

cases.runAll(t)
}

func TestBinding(t *testing.T) {
testBinding[*httpOptions](t, HTTPEndpoint)
testBinding[*tlsOptions](t, TLSEndpoint)
testBinding[*tcpOptions](t, TCPEndpoint)
}
30 changes: 0 additions & 30 deletions config/bindings.go

This file was deleted.

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

This file was deleted.

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.
Bindings []string
Binding 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
Bindings *[]string
Binding *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,
Bindings: cfg.Bindings,
Binding: cfg.Binding,
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,
Bindings: cfg.Bindings,
Binding: cfg.Binding,
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,
Bindings: cfg.Bindings,
Binding: cfg.Binding,
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
Bindings []string
Binding string
PoolingEnabled bool
}

Expand Down

0 comments on commit 2d002d1

Please sign in to comment.