plotly / dash-enterprise-auth

Python Auth Client for Dash Enterprise
MIT License
4 stars 3 forks source link

[FEATURE] Add testing mode and test users for developing locally and in workspaces #39

Open celia-lm opened 2 weeks ago

celia-lm commented 2 weeks ago

Something like this:

import dash_enterprise_auth as auth

auth.dev(
    development=True, # or os.environ.get("DASH_ENTERPRISE_ENV", "WORKSPACE")=="WORKSPACE"
    test_users=[
        {"username":"john", "groups":["/marketing"]},
        {"username":"lisa", "groups":["/marketing", "/interns"]},
        {"username":"tim", "groups":["/hr", "/interns"]},
    ],
    active_user="lisa"
    )

# when user runs auth.get_user_data(), something like this gets run in the background:
# https://github.com/plotly/dash-enterprise-auth/blob/main/dash_enterprise_auth/__init__.py#L104
if auth.dev.get("development"):
    return auth.dev.active_user
    #return auth.dev.test_users.get(auth.dev.active_user)

People who have requested this:

celia-lm commented 2 weeks ago

Workaround?

import dash_enterprise_auth as auth

class DevAuth:
    def __init__(self, test_users, active_user):
        self.test_users = test_users
        self.active_user = active_user

    def get_user_data(self):
        return self.test_users.get(self.active_user)

    def get_username(self):
        return self.active_user

DEV = False

if DEV:
# you can also create another condition 
    auth = DevAuth(
        test_users={
            "john":{"username":"john", "groups":["/marketing"]},
            "lisa":{"username":"lisa", "groups":["/marketing", "/interns"]},
            "tim":{"username":"tim", "groups":["/hr", "/interns"]},
        },
        active_user="lisa"
    )