Add initial attempt at env-var based flag specification (and tests). #187
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
This PR introduces a new capability. It is unfinished (only flagging is supported) and this PR is where discussion of ongoing development can be had with upstream project owner. This work is being done with @rossbruniges.
What?
I'm working for a client whose Django website is "stateless" (i.e. does not have a database backend). This branch makes it easy to use three arbitrary "buckets" for specifying flags defined in environment variables: ALPHA, BETA and ALL, thus making it possible to use Waffle with websites that are not backed by a database.
Why?
My client wants to use feature flags and Waffle is awesome. Furthermore, not all websites are "typical" in that they use a database for storing state.
How?
There are three arbitrary buckets: ALPHA, BETA and ALL. ALPHA and BETA have named users associated with them and flags set for each bucket will only be active for those users. ALL related flags apply to all users. The choice of arbitrary bucket names was made to reflect the common pattern of rolling out a feature first in "alpha", then "beta" and then to "all" users. It is assumed that once a feature has been around long enough and there's no requirement for it to be on/off at short notice, then the flag related code should be removed from this feature.
We use the following environment variables for specifying flag/user state:
WAFFLE_USE_ENV_VARS
- a simple truthy flag to indicate that waffle should use the env vars instead of the database when checking if aflag_is_active
.WAFFLE_ALPHA_USERS
- a comma separated list of usernames for those in the ALPHA bucket (the stateless Django app will need to implement a faux-request.user.username
to identify the individual users).WAFFLE_BETA_USERS
- as with WAFFLE_ALPHA_USERS but for BETA users.WAFFLE_ALPHA_FLAGS
- a comma separated list of flags in the ALPHA bucket.WAFFLE_BETA_FLAGS
- a comma separated list of flags in the BETA bucket.WAFFLE_ALL_FLAGS
- a comma separated list of flags in the ALL bucket.WAFFLE_SWITCHES
- TBD.WAFFLE_SAMPLES
- TBD.This is most definitely a first draft of this functionality. I'm not precious about my code: comments, constructive critique and ideas are most welcome. "Not interested" is also a valid response! :-)
In any case, my client needs this feature so I'll be working on it over the coming weeks and, if useful, would like to make the work available upstream.