New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Proof of Concept Changes to support filtering flags by CIDR ranges #332
Conversation
…ways off for a given CIDR range
Oh, one important one that I left out, there aren't any migrations yet. It doesn't look like there's a test project in the repo so I was wondering if any of the contributors could provide any guidance/docs on how to generate migrations? Or does everyone usually just hand code them? |
Definite 👍 to more testing. I'm not sure if
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It would be ideal if we had some method of determining when the external dependencies are missing, and notifying the user via admin UI and management command output.
@@ -175,6 +178,16 @@ class AbstractBaseFlag(BaseModel): | |||
help_text=_('Activate this flag for users with one of these languages (comma-separated list)'), | |||
verbose_name=_('Languages'), | |||
) | |||
cidr_range_always_on = models.TextField( |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Add validation on these fields to ensure the ranges are real.
@@ -4,6 +4,9 @@ | |||
from decimal import Decimal | |||
import logging | |||
|
|||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Remove.
|
||
from django.conf import settings | ||
from django.core.cache import caches | ||
from ipware import get_client_ip |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'd love to see CIDR ranges supported. I've dealt with client IP a lot in django-ratelimit as well, and I'd consider possibly moving this to something like waffle.ext....
As ipware's readme indicates, correctly determining client IP behind a proxy is super environment-specific (this is why Django itself dropped the SetRemoteAddrFromForwardedFor
middleware all the way back in 1.1). I'd be strongly tempted to defer that to application code (or another library if you want to configure ipware).
Maybe make the protocol something like: set a value on the request (possibly request.META['WAFFLE_IP']
or something) and Waffle will use that value, falling back to request.META['REMOTE_ADDR']
.
Then you could provide middleware e.g. waffle.ext.middleware.WaffleClientIPMiddleware
that depends on ipware
(but only add it as an optional dependency, and add a system check to the middleware module for it) and sets request.META['WAFFLE_IP']
.
That way users could also optionally write their own middleware to set the value based on their environments. For example, on my own projects I usually like to use something like X-Client-IP/Proto
or Cluster-Client-IP/Proto
from the edge, to avoid dealing with parsing XFF correctly, so I could write a small middleware to copy HTTP_X_CLIENT_IP
to WAFFLE_IP
.
It's also probably worth scoping these fields to IPv4 to enable expansion to IPv6 ranges in the future
I wanted to sketch out what an API/changeset might look like for #37
TODO: