def edit_peer( peer: schemas.WGPeer, sess: Session = Depends(middleware.get_db) ): # Retrieve server from db server: models.WGServer = db.wireguard.get_server_by_id(sess, peer.server_id) # Generate peer configuration peer.configuration = script.wireguard.generate_config(dict( peer=peer, server=server )) # Update database record for Peer sess.query(models.WGPeer)\ .filter_by(id=peer.id)\ .update(peer.dict(exclude={"id"})) # Generate server configuration server.configuration = script.wireguard.generate_config(server) sess.add(server) sess.commit() return dict( peer=peer, server_configuration=server.configuration )
def edit_peer(peer: schemas.WGPeer, sess: Session = Depends(middleware.get_db)): server = schemas.WGServer(interface="")\ .from_orm(sess.query(models.WGServer).filter_by(id=peer.server_id).one()) peer.configuration = script.wireguard.generate_config( dict(peer=peer, server=server)) peer.sync(sess) return peer
def peer_edit(sess: Session, peer: schemas.WGPeer): # Retrieve server from db server: models.WGServer = get_server_by_id(sess, peer.server_id) # Generate peer configuration peer.configuration = script.wireguard.generate_config(dict( peer=peer, server=server )) # Update database record for Peer sess.query(models.WGPeer) \ .filter_by(id=peer.id) \ .update(peer.dict(exclude={"id"})) sess.commit() server_update_configuration(sess, server.id) return peer