heroweb/herowebserver/data_populate.py

118 lines
2.3 KiB
Python

from infoserver.db import DB
from infoserver.dbmem import DBMem
from infoserver.model import ACE, ACL, Group, InfoPointer, RightEnum, User
db = DB("authdb_example", reset=True)
# Create a user and save it
user1 = db.user.set(
User(
email="user@example.com",
description="Test user",
profile="Profile data",
)
)
user2 = db.user.set(
User(
email="user2@example.com",
description="Test user 2",
profile="Profile data 2",
)
)
user3 = db.user.set(
User(
email="mariobassem12@gmail.com",
description="Test user 3",
profile="Profile data 3",
)
)
user4 = db.user.set(User(email="kristof@incubaid.com"))
# Load a user
loaded_user = db.user.get("user@example.com")
print(loaded_user)
# List all users
all_users = db.user.list()
print(all_users)
# Create a group and save it
group = Group(name="admins", users=[user1.email, user3.email, user4.email])
db.group.set(group)
group = Group(name="moreusers", users=[user2.email], groups=["admins"])
db.group.set(group)
# Load a group
loaded_group = db.group.get("admins")
print(loaded_group)
loaded_group = db.group.get("moreusers")
print(loaded_group)
# List all groups
all_groups = db.group.list()
print("all groups")
print(all_groups)
# Create an ACL and InfoPointer object and save it
acl = db.acl.set(
ACL(
name="MainACL",
entries=[
ACE(user=user2.email, right=RightEnum.read),
ACE(group="admins", right=RightEnum.admin),
],
)
)
info = InfoPointer(
name="BoardInfo",
path="/tmp",
acl=[acl.name],
description="Important file",
expiration="2025-01-01",
)
db.info.set(info)
acl2 = db.acl.set(
ACL(
name="myACL",
entries=[
ACE(user=user2.email, right=RightEnum.read),
],
)
)
info = InfoPointer(
name="myinfo",
path="/tmp/dir1",
acl=[acl2.name, acl.name],
description="Not Important",
expiration="2025-01-01",
)
# import pudb; pudb.set_trace()
db.info.set(info)
# Load an info object
loaded_info = db.info.get("BoardInfo")
print(loaded_info)
# List all info objects
all_info = db.info.list()
print(all_info)
# List all ACLs
all_acls = db.acl.list()
print(all_acls)
dbmem = DBMem(db, user4.email)
print("get users from group moreusers")
print(dbmem.group_get_users(loaded_group.name))