Browse Source

* Added route for retrieving configuration directly when adding new peer

* Added example in documentation
pull/29/head
Per-Arne Andersen 4 years ago
parent
commit
5d4ca2e96a
  1. 6
      README.md
  2. 0
      docker/push.sh
  3. 14
      wg_dashboard_backend/routers/v1/peer.py

6
README.md

@ -94,7 +94,7 @@ The API docs is found [here](./docs/api.md).
2. Go to edit profile 2. Go to edit profile
3. Create API-Key and take note of the key. Use the X-API-Key header to authenticate. 3. Create API-Key and take note of the key. Use the X-API-Key header to authenticate.
4. Example: `curl -i -H "X-API-Key: <key-goes-here>" http://<host>:<port>/api/v1/users/api-key/list` 4. Example: `curl -i -H "X-API-Key: <key-goes-here>" http://<host>:<port>/api/v1/users/api-key/list`
5. Example 2: `curl -X POST "http://<host>:<port>/api/v1/peer/add/configuration" -H "accept: application/json" -H "Content-Type: application/json" -H "X-API-Key: <api-key-here>" -d "{\"server_interface\":\"wg0\"}"`
# Environment variables # Environment variables
| Environment | Description | Recommended | | Environment | Description | Recommended |
|------------------|---------------------------------------------------------------------------|-------------| |------------------|---------------------------------------------------------------------------|-------------|
@ -135,7 +135,3 @@ The API docs is found [here](./docs/api.md).
- Implement multi-server support (setting up site-2-site servers from the GUI) - Implement multi-server support (setting up site-2-site servers from the GUI)
- Extending multi-server support to enable custom access lists (A peer can be assigned to multiple servers, as part of the ACL) - Extending multi-server support to enable custom access lists (A peer can be assigned to multiple servers, as part of the ACL)
### Other
* Eventual bugfixes
* Improve Auth
* Improve everything...

0
docker/push.sh

14
wg_dashboard_backend/routers/v1/peer.py

@ -2,6 +2,7 @@ import ipaddress
import itertools import itertools
from fastapi import APIRouter, Depends, HTTPException from fastapi import APIRouter, Depends, HTTPException
from sqlalchemy.orm import Session from sqlalchemy.orm import Session
from starlette.responses import PlainTextResponse
import const import const
import models import models
@ -48,6 +49,10 @@ def add_peer(
sess: Session = Depends(middleware.get_db) sess: Session = Depends(middleware.get_db)
): ):
server = schemas.WGServer(interface=peer_add.server_interface).from_db(sess) server = schemas.WGServer(interface=peer_add.server_interface).from_db(sess)
if server is None:
raise HTTPException(500, detail="The server-interface '%s' does not exist!" % peer_add.server_interface)
peer = schemas.WGPeer(server_id=server.id) peer = schemas.WGPeer(server_id=server.id)
if server.v6_address: if server.v6_address:
@ -86,6 +91,15 @@ def add_peer(
return schemas.WGPeer.from_orm(db_peer) return schemas.WGPeer.from_orm(db_peer)
@router.post("/add/configuration")
def add_peer_get_config(peer_add: schemas.WGPeerAdd,
sess: Session = Depends(middleware.get_db)
):
wg_peer: schemas.WGPeer = add_peer(peer_add, sess)
return PlainTextResponse(wg_peer.configuration)
@router.post("/delete", response_model=schemas.WGPeer) @router.post("/delete", response_model=schemas.WGPeer)
def delete_peer( def delete_peer(
peer: schemas.WGPeer, peer: schemas.WGPeer,

Loading…
Cancel
Save