Skip to content

Commit

Permalink
Refactor to perform early return
Browse files Browse the repository at this point in the history
  • Loading branch information
gpoul committed Dec 15, 2020
1 parent 41980c6 commit a1e5abc
Showing 1 changed file with 10 additions and 13 deletions.
23 changes: 10 additions & 13 deletions events/README_ClientVPN.md
Original file line number Diff line number Diff line change
Expand Up @@ -31,24 +31,21 @@ func handler(request events.ClientVPNConnectionHandlerRequest) (events.ClientVPN

log.Printf("SOURCE IP: %s", sourceIP)

postureCompliance := []string{}

allowed, ok := AllowedIPs[sourceIP]
if !ok {
allowed = false
postureCompliance = []string{"BlockedSourceIP"}
}

if allowed {
if allowed, ok := AllowedIPs[sourceIP]; ok && allowed {
log.Printf("Allowing access from: %s", sourceIP)
} else {
log.Printf("Blocking access from: %s", sourceIP)
return events.ClientVPNConnectionHandlerResponse{
Allow: true,
ErrorMsgOnFailedPostureCompliance: "",
PostureComplianceStatuses: []string{},
SchemaVersion: "v1",
}, nil
}

log.Printf("Blocking access from: %s", sourceIP)
return events.ClientVPNConnectionHandlerResponse{
Allow: allowed,
Allow: false,
ErrorMsgOnFailedPostureCompliance: "You're accessing from a blocked IP range.",
PostureComplianceStatuses: postureCompliance,
PostureComplianceStatuses: []string{"BlockedSourceIP"},
SchemaVersion: "v1",
}, nil
}
Expand Down

0 comments on commit a1e5abc

Please sign in to comment.