Skip to content

Commit

Permalink
refactor IPAccessControl fill and extractTo as helper functions
Browse files Browse the repository at this point in the history
  • Loading branch information
jeffy-mathew committed Jan 10, 2025
1 parent 718e91f commit edca49e
Showing 1 changed file with 24 additions and 16 deletions.
40 changes: 24 additions & 16 deletions apidef/oas/server.go
Original file line number Diff line number Diff line change
Expand Up @@ -100,14 +100,7 @@ func (s *Server) Fill(api apidef.APIDefinition) {
s.EventHandlers = nil
}

if s.IPAccessControl == nil {
s.IPAccessControl = &IPAccessControl{}
}

s.IPAccessControl.Fill(api)
if ShouldOmit(s.IPAccessControl) {
s.IPAccessControl = nil
}
s.fillIPAccessControl(api)
}

// ExtractTo extracts *Server into *apidef.APIDefinition.
Expand Down Expand Up @@ -168,14 +161,7 @@ func (s *Server) ExtractTo(api *apidef.APIDefinition) {

s.EventHandlers.ExtractTo(api)

if s.IPAccessControl == nil {
s.IPAccessControl = &IPAccessControl{}
defer func() {
s.IPAccessControl = nil
}()
}

s.IPAccessControl.ExtractTo(api)
s.extractIPAccessControlTo(api)
}

// ListenPath is the base path on Tyk to which requests for this API
Expand Down Expand Up @@ -338,3 +324,25 @@ func (i *IPAccessControl) ExtractTo(api *apidef.APIDefinition) {
api.BlacklistedIPs = i.Block
api.AllowedIPs = i.Allow
}

func (s *Server) fillIPAccessControl(api apidef.APIDefinition) {
if s.IPAccessControl == nil {
s.IPAccessControl = &IPAccessControl{}
}

s.IPAccessControl.Fill(api)
if ShouldOmit(s.IPAccessControl) {
s.IPAccessControl = nil
}
}

func (s *Server) extractIPAccessControlTo(api *apidef.APIDefinition) {
if s.IPAccessControl == nil {
s.IPAccessControl = &IPAccessControl{}
defer func() {
s.IPAccessControl = nil
}()
}

s.IPAccessControl.ExtractTo(api)
}

0 comments on commit edca49e

Please sign in to comment.