Skip to content

Commit

Permalink
rename policy module components
Browse files Browse the repository at this point in the history
  • Loading branch information
Abdiramen committed Feb 1, 2024
1 parent 6343962 commit daa19ff
Show file tree
Hide file tree
Showing 10 changed files with 56 additions and 57 deletions.
2 changes: 1 addition & 1 deletion api/ingress/v1alpha1/httpsedge_types.go
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,7 @@ type HTTPSEdgeRouteSpec struct {
// WebhookVerification is webhook verification configuration to apply to this route
WebhookVerification *EndpointWebhookVerification `json:"webhookVerification,omitempty"`

Policies *EndpointPolicies `json:"policies,omitempty"`
Policy *EndpointPolicy `json:"policy,omitempty"`
}

// HTTPSEdgeSpec defines the desired state of HTTPSEdge
Expand Down
46 changes: 23 additions & 23 deletions api/ingress/v1alpha1/ngrok_common.go
Original file line number Diff line number Diff line change
Expand Up @@ -431,16 +431,16 @@ func (amazon *EndpointOAuthAmazon) ToNgrok(clientSecret *string) *ngrok.Endpoint
return mod
}

type EndpointPolicies struct {
// Determines if the policy will be applied to traffic
type EndpointPolicy struct {
// Determines if the rule will be applied to traffic
Enabled *bool `json:"enabled,omitempty"`
// Policies for inbound traffic
Inbound []EndpointPolicy `json:"inbound,omitempty"`
// Policies for outbound traffic
Outbound []EndpointPolicy `json:"outbound,omitempty"`
// Inbound traffic rule
Inbound []EndpointRule `json:"inbound,omitempty"`
// Outbound traffic rule
Outbound []EndpointRule `json:"outbound,omitempty"`
}

type EndpointPolicy struct {
type EndpointRule struct {
// Expressions
Expressions []string `json:"expressions,omitempty"`
// Actions
Expand All @@ -457,50 +457,50 @@ type EndpointAction struct {
Config json.RawMessage `json:"config,omitempty"`
}

func (policies *EndpointPolicies) ToNgrok() *ngrok.EndpointPolicies {
if policies == nil {
func (policy *EndpointPolicy) ToNgrok() *ngrok.EndpointPolicy {
if policy == nil {
return nil
}

var inbound []ngrok.EndpointPolicy
for _, policy := range policies.Inbound {
p := policy
var inbound []ngrok.EndpointRule
for _, rule := range policy.Inbound {
p := rule
inbound = append(inbound, *p.ToNgrok())
}
var outbound []ngrok.EndpointPolicy
for _, policy := range policies.Outbound {
p := policy
var outbound []ngrok.EndpointRule
for _, rule := range policy.Outbound {
p := rule
mod := p.ToNgrok()
if mod != nil {
outbound = append(outbound, *mod)
}
}

return &ngrok.EndpointPolicies{
Enabled: policies.Enabled,
return &ngrok.EndpointPolicy{
Enabled: policy.Enabled,
Inbound: inbound,
Outbound: outbound,
}
}

func (policy *EndpointPolicy) ToNgrok() *ngrok.EndpointPolicy {
if policy == nil {
func (rule *EndpointRule) ToNgrok() *ngrok.EndpointRule {
if rule == nil {
return nil
}

var actions []ngrok.EndpointAction
for _, action := range policy.Actions {
for _, action := range rule.Actions {
a := action
mod := a.ToNgrok()
if mod != nil {
actions = append(actions, *mod)
}
}

return &ngrok.EndpointPolicy{
Expressions: policy.Expressions,
return &ngrok.EndpointRule{
Expressions: rule.Expressions,
Actions: actions,
Name: policy.Name,
Name: rule.Name,
}
}

Expand Down
8 changes: 4 additions & 4 deletions api/ingress/v1alpha1/ngrokmoduleset_types.go
Original file line number Diff line number Diff line change
Expand Up @@ -39,8 +39,8 @@ type NgrokModuleSetModules struct {
IPRestriction *EndpointIPPolicy `json:"ipRestriction,omitempty"`
// OAuth configuration for this module set
OAuth *EndpointOAuth `json:"oauth,omitempty"`
// Policies configuration for this module set
Policies *EndpointPolicies `json:"policies,omitempty"`
// Policy configuration for this module set
Policy *EndpointPolicy `json:"policy,omitempty"`
// OIDC configuration for this module set
OIDC *EndpointOIDC `json:"oidc,omitempty"`
// SAML configuration for this module set
Expand Down Expand Up @@ -85,8 +85,8 @@ func (ms *NgrokModuleSet) Merge(o *NgrokModuleSet) {
if omod.OAuth != nil {
msmod.OAuth = omod.OAuth
}
if omod.Policies != nil {
msmod.Policies = omod.Policies
if omod.Policy != nil {
msmod.Policy = omod.Policy
}
if omod.OIDC != nil {
msmod.OIDC = omod.OIDC
Expand Down
2 changes: 1 addition & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ require (
github.com/go-logr/logr v1.2.4
github.com/golang/mock v1.4.4
github.com/imdario/mergo v0.3.16
github.com/ngrok/ngrok-api-go/v5 v5.2.1-0.20240117170843-c468056fd303
github.com/ngrok/ngrok-api-go/v5 v5.2.1-0.20240130152650-a2fe7413fe39
github.com/onsi/ginkgo/v2 v2.11.0
github.com/onsi/gomega v1.27.10
github.com/spf13/cobra v1.7.0
Expand Down
4 changes: 2 additions & 2 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -415,8 +415,8 @@ github.com/munnerz/goautoneg v0.0.0-20191010083416-a7dc8b61c822 h1:C3w9PqII01/Oq
github.com/munnerz/goautoneg v0.0.0-20191010083416-a7dc8b61c822/go.mod h1:+n7T8mK8HuQTcFwEeznm/DIxMOiR9yIdICNftLE1DvQ=
github.com/mwitkow/go-conntrack v0.0.0-20161129095857-cc309e4a2223/go.mod h1:qRWi+5nqEBWmkhHvq77mSJWrCKwh8bxhgT7d/eI7P4U=
github.com/nbutton23/zxcvbn-go v0.0.0-20180912185939-ae427f1e4c1d/go.mod h1:o96djdrsSGy3AWPyBgZMAGfxZNfgntdJG+11KU4QvbU=
github.com/ngrok/ngrok-api-go/v5 v5.2.1-0.20240117170843-c468056fd303 h1:td6hx8jy4X+U/Ed/zl6gTrCVmyldZ7tMNJQHa2YvcXc=
github.com/ngrok/ngrok-api-go/v5 v5.2.1-0.20240117170843-c468056fd303/go.mod h1:UVTaHI5B4gEsfHCOZTlRg8WkT6+KBijIkVtjpDqCyIU=
github.com/ngrok/ngrok-api-go/v5 v5.2.1-0.20240130152650-a2fe7413fe39 h1:aCLT9jRnyt8UeIbDZK3nSysil0OttzCwYBJ+46vVIGA=
github.com/ngrok/ngrok-api-go/v5 v5.2.1-0.20240130152650-a2fe7413fe39/go.mod h1:UVTaHI5B4gEsfHCOZTlRg8WkT6+KBijIkVtjpDqCyIU=
github.com/niemeyer/pretty v0.0.0-20200227124842-a10e7caefd8e/go.mod h1:zD1mROLANZcx1PVRCS0qkT7pwLkGfwJo4zjcN/Tysno=
github.com/nxadm/tail v1.4.8 h1:nPr65rt6Y5JFSKQO7qToXr7pePgD6Gwiw05lkbyAQTE=
github.com/nxadm/tail v1.4.8/go.mod h1:+ncqLTQzXmGhMZNUePPaPqPvBxHAIsmXswZKocGu+AU=
Expand Down

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

20 changes: 10 additions & 10 deletions internal/controller/ingress/httpsedge_controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -523,7 +523,7 @@ func (u *edgeRouteModuleUpdater) updateModulesForRoute(ctx context.Context, rout
u.setEdgeRouteOIDC,
u.setEdgeRouteSAML,
u.setEdgeRouteWebhookVerification,
u.setEdgeRoutePolicies,
u.setEdgeRoutePolicy,
}

for _, f := range funcs {
Expand Down Expand Up @@ -1030,26 +1030,26 @@ func (r *HTTPSEdgeReconciler) takeOfflineWithoutAuth(ctx context.Context, route
return nil
}

func (u *edgeRouteModuleUpdater) setEdgeRoutePolicies(ctx context.Context, route *ngrok.HTTPSEdgeRoute, routeSpec *ingressv1alpha1.HTTPSEdgeRouteSpec) error {
func (u *edgeRouteModuleUpdater) setEdgeRoutePolicy(ctx context.Context, route *ngrok.HTTPSEdgeRoute, routeSpec *ingressv1alpha1.HTTPSEdgeRouteSpec) error {
log := ctrl.LoggerFrom(ctx)
policies := routeSpec.Policies
client := u.clientset.Policies()
policy := routeSpec.Policy
client := u.clientset.Policy()

module := policies.ToNgrok()
module := policy.ToNgrok()

// Early return if nothing to be done
if module == nil {
if route.Policies == nil {
u.logMatches(log, "Policies", routeModuleComparisonBothNil)
if route.Policy == nil {
u.logMatches(log, "Policy", routeModuleComparisonBothNil)
return nil
}

log.Info("Deleting Policies module")
log.Info("Deleting Policy module")
return client.Delete(ctx, edgeRouteItem(route))
}

log.Info("Updating Policies module")
_, err := client.Replace(ctx, &ngrok.EdgeRoutePoliciesReplace{
log.Info("Updating Policy module")
_, err := client.Replace(ctx, &ngrok.EdgeRoutePolicyReplace{
EdgeID: route.EdgeID,
ID: route.ID,
Module: *module,
Expand Down
12 changes: 6 additions & 6 deletions internal/ngrokapi/edge_modules_https.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ import (
"github.com/ngrok/ngrok-api-go/v5/edge_modules/https_edge_route_ip_restriction"
"github.com/ngrok/ngrok-api-go/v5/edge_modules/https_edge_route_oauth"
"github.com/ngrok/ngrok-api-go/v5/edge_modules/https_edge_route_oidc"
"github.com/ngrok/ngrok-api-go/v5/edge_modules/https_edge_route_policies"
"github.com/ngrok/ngrok-api-go/v5/edge_modules/https_edge_route_policy"
"github.com/ngrok/ngrok-api-go/v5/edge_modules/https_edge_route_request_headers"
"github.com/ngrok/ngrok-api-go/v5/edge_modules/https_edge_route_response_headers"
"github.com/ngrok/ngrok-api-go/v5/edge_modules/https_edge_route_saml"
Expand Down Expand Up @@ -56,7 +56,7 @@ type HTTPSEdgeRouteModulesClientset interface {
Compression() *https_edge_route_compression.Client
IPRestriction() *https_edge_route_ip_restriction.Client
OAuth() *https_edge_route_oauth.Client
Policies() *https_edge_route_policies.Client
Policy() *https_edge_route_policy.Client
OIDC() *https_edge_route_oidc.Client
RequestHeaders() *https_edge_route_request_headers.Client
ResponseHeaders() *https_edge_route_response_headers.Client
Expand All @@ -71,7 +71,7 @@ type defaultHTTPSEdgeRouteModulesClientset struct {
compression *https_edge_route_compression.Client
ipRestriction *https_edge_route_ip_restriction.Client
oauth *https_edge_route_oauth.Client
policies *https_edge_route_policies.Client
policy *https_edge_route_policy.Client
oidc *https_edge_route_oidc.Client
requestHeaders *https_edge_route_request_headers.Client
responseHeaders *https_edge_route_response_headers.Client
Expand All @@ -87,7 +87,7 @@ func newHTTPSEdgeRouteModulesClient(config *ngrok.ClientConfig) *defaultHTTPSEdg
compression: https_edge_route_compression.NewClient(config),
ipRestriction: https_edge_route_ip_restriction.NewClient(config),
oauth: https_edge_route_oauth.NewClient(config),
policies: https_edge_route_policies.NewClient(config),
policy: https_edge_route_policy.NewClient(config),
oidc: https_edge_route_oidc.NewClient(config),
requestHeaders: https_edge_route_request_headers.NewClient(config),
responseHeaders: https_edge_route_response_headers.NewClient(config),
Expand Down Expand Up @@ -117,8 +117,8 @@ func (c *defaultHTTPSEdgeRouteModulesClientset) OAuth() *https_edge_route_oauth.
return c.oauth
}

func (c *defaultHTTPSEdgeRouteModulesClientset) Policies() *https_edge_route_policies.Client {
return c.policies
func (c *defaultHTTPSEdgeRouteModulesClientset) Policy() *https_edge_route_policy.Client {
return c.policy
}

func (c *defaultHTTPSEdgeRouteModulesClientset) OIDC() *https_edge_route_oidc.Client {
Expand Down
2 changes: 1 addition & 1 deletion internal/store/driver.go
Original file line number Diff line number Diff line change
Expand Up @@ -629,7 +629,7 @@ func (d *Driver) calculateHTTPSEdges() map[string]ingressv1alpha1.HTTPSEdge {
IPRestriction: modSet.Modules.IPRestriction,
Headers: modSet.Modules.Headers,
OAuth: modSet.Modules.OAuth,
Policies: modSet.Modules.Policies,
Policy: modSet.Modules.Policy,
OIDC: modSet.Modules.OIDC,
SAML: modSet.Modules.SAML,
WebhookVerification: modSet.Modules.WebhookVerification,
Expand Down

0 comments on commit daa19ff

Please sign in to comment.