Skip to content
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

Unleash #3

Open
wants to merge 3 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
21 changes: 20 additions & 1 deletion backend/main.py
Original file line number Diff line number Diff line change
@@ -1,11 +1,30 @@
from fastapi import FastAPI, Query
from UnleashClient import UnleashClient
from UnleashClient.cache import FileCache
from pathlib import Path

cache = FileCache("BootstrappedCache")
cache.bootstrap_from_file(Path("/app/flags.json"))
client = UnleashClient(
url="http://host.docker.internal:4242/api/",
app_name="playground",
custom_headers={'Authorization': 'default:development.064b6f40e22f2f55a716667bf736ad2185a0831dded7a1de99ac33ac'},
cache=cache,
request_timeout=3,
request_retries=0)

client.initialize_client()

app = FastAPI()

@app.get("/{id}")
def read_root(id: int, language: str | None = Query(None)):
app_context = {
"id": str(id),
"language": language
}

return {
"feature_enabled": False,
"feature_enabled": client.is_enabled("my_cool_feature", app_context),
"ab_test_flag": False
}
4 changes: 3 additions & 1 deletion docker-compose.yml
Original file line number Diff line number Diff line change
Expand Up @@ -9,4 +9,6 @@ services:
ports:
- "8000:8000"
volumes:
- .:/app
- .:/app
extra_hosts:
- "host.docker.internal:host-gateway"
1 change: 1 addition & 0 deletions flags.json
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
{"version":2,"features":[{"name":"my_cool_feature","type":"release","enabled":true,"project":"default","stale":false,"strategies":[{"name":"flexibleRollout","constraints":[{"values":["pt"],"inverted":false,"operator":"IN","contextName":"language","caseInsensitive":false}],"parameters":{"groupId":"my_cool_feature","rollout":"100","stickiness":"id"},"variants":[]}],"variants":[],"description":null,"impressionData":false}],"query":{"project":["default"],"environment":"development","inlineSegmentConstraints":true},"meta":{"revisionId":23,"etag":"\"6ef7ec5a:23\"","queryHash":"6ef7ec5a"}}
1 change: 1 addition & 0 deletions requirements.txt
Original file line number Diff line number Diff line change
@@ -1,2 +1,3 @@
fastapi
uvicorn
UnleashClient