Feature toggle as a service - Powered by Unleash
The Unleash Feature Toggle Service gets all its configurations from environment variables. Here's the description of the variables that have to be provided:
User validation:
ORG
: The Github organization users have to be member of.TEAM
: The Github organization team users have to be member of.
Database:
DATABASE_NAME
: The database to use backing this instance.DATABASE_HOST
: The database hostname or ip address.DATABASE_USERNAME
: The database username.DATABASE_PASSWORD
: The database password.
OAuth2:
GH_CLIENT_ID
: The Github OAuth App Client ID.GH_CLIENT_SECRET
: The Github OAuth App Client Secret.GH_CALLBACK_URL
: The OAuth callback URL.
API Access:
ADMIN_ACCESS_TOKEN
: The Admin API Bearer token that admins have to authenticate with.CLIENT_ACCESS_TOKEN
: The Client API Bearer token that clients have to authenticate with.
Security:
SESSION_SECRET
: Token used to encrypt the user session cookie.
$ yarn install --production
$ node index.js
$ docker built -t unleash .
$ docker run --rm -d -p 4242:4242 unleash
Unleash provides an API client.
Install:
$ pip install UnleashClient
Example:
from UnleashClient import UnleashClient
headers = {'Authorization': f'Bearer {CLIENT_ACCESS_TOKEN}'}
client = UnleashClient(url="http://localhost:4242/api",
app_name="My App",
custom_headers=headers)
client.initialize_client()
if client.is_enabled("quay-mirror"):
print('quay-mirror toogle is enabled!')
client.destroy()
There's no client for the Admin API. Let's use requests
then.
Install:
$ pip install requests
Example:
import requests
headers = {'Authorization': f'Bearer {ADMIN_ACCESS_TOKEN}'}
data = {"enabled": False,
"strategies": [{"name": "default"}]}
res = requests.put('http://localhost:4242/api/admin/features/quay-mirror',
headers=headers, json=data)
res.raise_for_status()