def seed(): """Add seed data to the database.""" session: Session = db.session print("Seeding account types") account_types = [1,"Special"],[2,"Adherent"],[3,"Club interne"],[4,"Club externe"],[5,"Association externe"] session.bulk_save_objects([ AccountType( id=e[0], name=e[1] ) for e in account_types ]) print("Seeding MiNET accounts") accounts = [1, 1, "MiNET frais techniques", True, None, True, True],[2, 1, "MiNET frais asso", True, None, True, True] session.bulk_save_objects([ Account( id=e[0], type=e[1], name=e[2], actif=e[3], adherent_id=e[4], compte_courant=e[5], pinned=e[6] ) for e in accounts ]) print("Seeding Products") products = [1,"Cable 3m", 3, 3],[2,"Cable 5m", 5, 5],[3,"Adaptateur USB/Ethernet", 13.00, 13.00],[4,"Adaptateur USB-C/Ethernet", 12.00, 12.00] session.bulk_save_objects([ Product( id=e[0], name=e[1], buying_price=e[2], selling_price=e[3] ) for e in products ]) print("Seeding payment methods") payment_methods = [1,"Liquide"],[2,"Chèque"],[3,"Carte bancaire"],[4,"Virement"],[5,"Stripe"],[6,"Aucun"] session.bulk_save_objects([ PaymentMethod( id=e[0], name=e[1] ) for e in payment_methods ]) print("Seeding cashbox") session.add(Caisse( fond=0, coffre=0 )) print("Seeding vlans") vlans = [41, "157.159.41.0/24", "2001:660:3203:401::/64", "157.159.41.1/32", ""], [35, "10.42.0.0/16", "", "", ""], [36, "157.159.192.0/22", "", "157.159.195.0/24", ""], [30, "172.30.0.0/16", "", "", ""] session.bulk_save_objects([ Vlan( numero=e[0], adresses=e[1], adressesv6=e[2], excluded_addr=e[3], excluded_addrv6=e[4] ) for e in vlans ]) print("Seeding Rooms") session.bulk_save_objects([ Chambre( id=i, numero=i, description="Chambre " + str(i), vlan_id=1 ) for i in range(1, 30) ]) print("Seeding Switchs") switchs = [1, "Switch local", "192.168.102.219", "adh5"], session.bulk_save_objects([ Switch( id=e[0], description=e[1], ip=e[2], communaute=e[3], ) for e in switchs ]) print("Seeding 30 Ports Switch local + link to room") session.bulk_save_objects([ Port( rcom=0, numero="1/0/" + str(i), oid="1010" + str(i), switch_id=1, chambre_id=i ) for i in range(1, 30) ]) print("Seeding role mapping for oidc") session.bulk_save_objects( [ AuthenticationRoleMapping( identifier="adh6_admin", role=i, authentication=AuthenticationMethod.OIDC ) for i in [Roles.ADMIN_READ, Roles.ADMIN_WRITE, Roles.NETWORK_READ, Roles.NETWORK_WRITE, Roles.ADMIN_PROD] ] ) session.bulk_save_objects( [ AuthenticationRoleMapping( identifier="adh6_treso", role=i, authentication=AuthenticationMethod.OIDC ) for i in [Roles.TRESO_READ, Roles.TRESO_WRITE] ] ) session.commit()
def oidc_treasurer_write_role(): return AuthenticationRoleMapping(authentication=AuthenticationMethod.OIDC, identifier="treasurer", role=Roles.TRESO_WRITE)
def oidc_network_write_role(): return AuthenticationRoleMapping(authentication=AuthenticationMethod.OIDC, identifier="network", role=Roles.NETWORK_WRITE)
def oidc_admin_write_role(): return AuthenticationRoleMapping(authentication=AuthenticationMethod.OIDC, identifier="admin", role=Roles.ADMIN_WRITE)
def oidc_admin_read_role(): return AuthenticationRoleMapping(authentication=AuthenticationMethod.OIDC, identifier="admin", role=Roles.ADMIN_READ)
def oidc_admin_prod_role(): return AuthenticationRoleMapping(authentication=AuthenticationMethod.OIDC, identifier="production", role=Roles.ADMIN_PROD)
def api_key_admin_write_roles(): return AuthenticationRoleMapping( authentication=AuthenticationMethod.API_KEY, identifier=str(api_key_admin().id), role=Roles.ADMIN_WRITE)
def api_key_user_roles(): return AuthenticationRoleMapping( authentication=AuthenticationMethod.API_KEY, identifier=str(api_key_user().id), role=Roles.USER)