Skip to content

Commit

Permalink
Merge pull request #190 from ngrok/ryan/with-traffic-policy-function
Browse files Browse the repository at this point in the history
alias `WithTrafficPolicy` to `WithPolicyString`
  • Loading branch information
TheConcierge authored Oct 9, 2024
2 parents 43a9f8c + ab951d5 commit c6f5414
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 6 deletions.
6 changes: 6 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,9 @@
## 1.11.0

Changes:

- Adds `WithTrafficPolicy` function, replacing `WithPolicyString`

## 1.10.0

Enhancements:
Expand Down
18 changes: 14 additions & 4 deletions config/policy.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,10 +15,10 @@ type rule po.Rule
type action po.Action
type trafficPolicy string

// WithPolicyString configures this edge with the provided policy configuration
// passed as a json or yaml string and overwrites any previously-set traffic policy
// WithTrafficPolicy configures this edge with the provided policy configuration
// passed as a json or yaml string and overwrites any previously-set traffic policy.
// https://ngrok.com/docs/http/traffic-policy
func WithPolicyString(str string) interface {
func WithTrafficPolicy(str string) interface {
HTTPEndpointOption
TLSEndpointOption
TCPEndpointOption
Expand All @@ -29,6 +29,16 @@ func WithPolicyString(str string) interface {
return trafficPolicy(str)
}

// WithPolicyString is deprecated, use WithTrafficPolicy instead.
// https://ngrok.com/docs/http/traffic-policy/
func WithPolicyString(str string) interface {
HTTPEndpointOption
TLSEndpointOption
TCPEndpointOption
} {
return WithTrafficPolicy(str)
}

func (p trafficPolicy) ApplyTLS(opts *tlsOptions) {
opts.TrafficPolicy = string(p)
}
Expand All @@ -51,7 +61,7 @@ func isYamlStr(yamlStr string) bool {
return yaml.Unmarshal([]byte(yamlStr), &yml) == nil
}

// WithPolicy is deprecated, use WithPolicyString instead.
// WithPolicy is deprecated, use WithTrafficPolicy instead.
// https://ngrok.com/docs/http/traffic-policy/
func WithPolicy(p po.Policy) interface {
HTTPEndpointOption
Expand Down
4 changes: 2 additions & 2 deletions config/policy_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,7 @@ inbound:
{
name: "with valid JSON policy string",
opts: optsFunc(
WithPolicyString(`
WithTrafficPolicy(`
{
"inbound":[
{
Expand Down Expand Up @@ -145,7 +145,7 @@ inbound:
{
name: "with valid YAML policy string",
opts: optsFunc(
WithPolicyString(yamlPolicy)),
WithTrafficPolicy(yamlPolicy)),
expectOpts: func(t *testing.T, opts *O) {
actual := getPolicies(opts)
require.NotEmpty(t, actual)
Expand Down

0 comments on commit c6f5414

Please sign in to comment.