Skip to content

Commit

Permalink
refactor!: rename requested_* to request_* (#39)
Browse files Browse the repository at this point in the history
  • Loading branch information
danroc authored Nov 22, 2024
1 parent 158d83b commit 416da9d
Show file tree
Hide file tree
Showing 4 changed files with 24 additions and 24 deletions.
4 changes: 2 additions & 2 deletions examples/caddy/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ X-Forwarded-Proto: http
Geoblock logs:

```log
geoblock-1 | time="2024-11-19T23:09:06Z" level=info msg="Request authorized" requested_domain=whoami-1.local requested_method=GET source_asn=0 source_country= source_ip=172.19.0.1 source_org=
geoblock-1 | time="2024-11-19T23:09:06Z" level=info msg="Request authorized" request_domain=whoami-1.local request_method=GET source_asn=0 source_country= source_ip=172.19.0.1 source_org=
```

**❌ Blocked:**
Expand All @@ -66,5 +66,5 @@ curl: (22) The requested URL returned error: 403
Geoblock logs:

```log
geoblock-1 | time="2024-11-19T23:09:16Z" level=warning msg="Request denied" requested_domain=whoami-2.local requested_method=GET source_asn=0 source_country= source_ip=172.19.0.1 source_org=
geoblock-1 | time="2024-11-19T23:09:16Z" level=warning msg="Request denied" request_domain=whoami-2.local request_method=GET source_asn=0 source_country= source_ip=172.19.0.1 source_org=
```
4 changes: 2 additions & 2 deletions examples/nginx/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ X-Real-Ip: 172.18.0.1
Geoblock logs:

```log
geoblock-1 | time="2024-11-19T19:12:40Z" level=info msg="Request authorized" requested_domain=whoami-1.local requested_method=GET source_asn=0 source_country= source_ip=172.18.0.1 source_org=
geoblock-1 | time="2024-11-19T19:12:40Z" level=info msg="Request authorized" request_domain=whoami-1.local request_method=GET source_asn=0 source_country= source_ip=172.18.0.1 source_org=
```

**❌ Blocked:**
Expand All @@ -69,5 +69,5 @@ curl: (22) The requested URL returned error: 403
Geoblock logs:

```log
geoblock-1 | time="2024-11-19T19:12:41Z" level=warning msg="Request denied" requested_domain=whoami-2.local requested_method=GET source_asn=0 source_country= source_ip=172.18.0.1 source_org=
geoblock-1 | time="2024-11-19T19:12:41Z" level=warning msg="Request denied" request_domain=whoami-2.local request_method=GET source_asn=0 source_country= source_ip=172.18.0.1 source_org=
```
4 changes: 2 additions & 2 deletions examples/traefik/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ X-Real-Ip: 172.18.0.1
Geoblock logs:

```log
geoblock-1 | time="2024-11-19T19:12:40Z" level=info msg="Request authorized" requested_domain=whoami-1.local requested_method=GET source_asn=0 source_country= source_ip=172.18.0.1 source_org=
geoblock-1 | time="2024-11-19T19:12:40Z" level=info msg="Request authorized" request_domain=whoami-1.local request_method=GET source_asn=0 source_country= source_ip=172.18.0.1 source_org=
```

**❌ Blocked:**
Expand All @@ -68,5 +68,5 @@ curl: (22) The requested URL returned error: 403
Geoblock logs:

```log
geoblock-1 | time="2024-11-19T19:12:41Z" level=warning msg="Request denied" requested_domain=whoami-2.local requested_method=GET source_asn=0 source_country= source_ip=172.18.0.1 source_org=
geoblock-1 | time="2024-11-19T19:12:41Z" level=warning msg="Request denied" request_domain=whoami-2.local request_method=GET source_asn=0 source_country= source_ip=172.18.0.1 source_org=
```
36 changes: 18 additions & 18 deletions pkg/server/server.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,12 +25,12 @@ const (

// Fields used in the log messages.
const (
FieldRequestedDomain = "requested_domain"
FieldRequestedMethod = "requested_method"
FieldSourceIP = "source_ip"
FieldSourceCountry = "source_country"
FieldSourceASN = "source_asn"
FieldSourceOrg = "source_org"
FieldRequestDomain = "request_domain"
FieldRequestMethod = "request_method"
FieldSourceIP = "source_ip"
FieldSourceCountry = "source_country"
FieldSourceASN = "source_asn"
FieldSourceOrg = "source_org"
)

// Metrics contains the metric values of the server.
Expand Down Expand Up @@ -66,9 +66,9 @@ func getForwardAuth(
// probably means that the request didn't come from the reverse proxy.
if origin == "" || domain == "" || method == "" {
log.WithFields(log.Fields{
FieldRequestedDomain: domain,
FieldRequestedMethod: method,
FieldSourceIP: origin,
FieldRequestDomain: domain,
FieldRequestMethod: method,
FieldSourceIP: origin,
}).Error("Missing required headers")
writer.WriteHeader(http.StatusBadRequest)
metrics.Invalid.Add(1)
Expand All @@ -80,9 +80,9 @@ func getForwardAuth(
sourceIP := net.ParseIP(origin)
if sourceIP == nil {
log.WithFields(log.Fields{
FieldRequestedDomain: domain,
FieldRequestedMethod: method,
FieldSourceIP: origin,
FieldRequestDomain: domain,
FieldRequestMethod: method,
FieldSourceIP: origin,
}).Error("Invalid source IP")
writer.WriteHeader(http.StatusBadRequest)
metrics.Invalid.Add(1)
Expand All @@ -100,12 +100,12 @@ func getForwardAuth(
}

logFields := log.Fields{
FieldRequestedDomain: domain,
FieldRequestedMethod: method,
FieldSourceIP: sourceIP,
FieldSourceCountry: resolved.CountryCode,
FieldSourceASN: resolved.ASN,
FieldSourceOrg: resolved.Organization,
FieldRequestDomain: domain,
FieldRequestMethod: method,
FieldSourceIP: sourceIP,
FieldSourceCountry: resolved.CountryCode,
FieldSourceASN: resolved.ASN,
FieldSourceOrg: resolved.Organization,
}

if engine.Authorize(query) {
Expand Down

0 comments on commit 416da9d

Please sign in to comment.