mirror of
https://github.com/h44z/wg-portal.git
synced 2025-08-25 14:31:14 +00:00
Fixes & API unit testing (#58)
* api - add OperationID helps when using pyswagger and is visible via http://localhost:8123/swagger/index.html?displayOperationId=true gin-swagger can not set displayOperationId yet * api - match paramters to their property equivalents pascalcase & sometimes replacing the name (e.g. device -> DeviceName) * api - use ShouldBindJSON instead of BindJSON BindJSON sets the content-type text/plain * api - we renamed, we regenerated * device - allow - in DeviceName wg-example0.conf etc * api - more pascalcase & argument renames * api - marshal DeletedAt as string gorm.DeletedAt is of type sql.NullTime NullTime declares Time & Valid as properties DeletedAt marshals as time.Time swaggertype allows only basic types -> string * Peer - export UID/DeviceType in json UID/DeviceType is required, skipping in json, skips it in marshalling, next unmarshalling fails * assets - name forms for use with mechanize * api - match error message * add python3/pyswagger based unittesting - initializes a clean install by configuration via web service - tests the rest api * tests - test address exhaustion * tests - test network expansion Co-authored-by: Markus Koetter <koetter@cispa.de>
This commit is contained in:
@@ -50,6 +50,7 @@ type ApiError struct {
|
||||
// GetUsers godoc
|
||||
// @Tags Users
|
||||
// @Summary Retrieves all users
|
||||
// @ID GetUsers
|
||||
// @Produce json
|
||||
// @Success 200 {object} []users.User
|
||||
// @Failure 401 {object} ApiError
|
||||
@@ -66,8 +67,9 @@ func (s *ApiServer) GetUsers(c *gin.Context) {
|
||||
// GetUser godoc
|
||||
// @Tags Users
|
||||
// @Summary Retrieves user based on given Email
|
||||
// @ID GetUser
|
||||
// @Produce json
|
||||
// @Param email query string true "User Email"
|
||||
// @Param Email query string true "User Email"
|
||||
// @Success 200 {object} users.User
|
||||
// @Failure 400 {object} ApiError
|
||||
// @Failure 401 {object} ApiError
|
||||
@@ -76,9 +78,9 @@ func (s *ApiServer) GetUsers(c *gin.Context) {
|
||||
// @Router /backend/user [get]
|
||||
// @Security ApiBasicAuth
|
||||
func (s *ApiServer) GetUser(c *gin.Context) {
|
||||
email := strings.ToLower(strings.TrimSpace(c.Query("email")))
|
||||
email := strings.ToLower(strings.TrimSpace(c.Query("Email")))
|
||||
if email == "" {
|
||||
c.JSON(http.StatusBadRequest, ApiError{Message: "email parameter must be specified"})
|
||||
c.JSON(http.StatusBadRequest, ApiError{Message: "Email parameter must be specified"})
|
||||
return
|
||||
}
|
||||
|
||||
@@ -93,9 +95,10 @@ func (s *ApiServer) GetUser(c *gin.Context) {
|
||||
// PostUser godoc
|
||||
// @Tags Users
|
||||
// @Summary Creates a new user based on the given user model
|
||||
// @ID PostUser
|
||||
// @Accept json
|
||||
// @Produce json
|
||||
// @Param user body users.User true "User Model"
|
||||
// @Param User body users.User true "User Model"
|
||||
// @Success 200 {object} users.User
|
||||
// @Failure 400 {object} ApiError
|
||||
// @Failure 401 {object} ApiError
|
||||
@@ -106,7 +109,7 @@ func (s *ApiServer) GetUser(c *gin.Context) {
|
||||
// @Security ApiBasicAuth
|
||||
func (s *ApiServer) PostUser(c *gin.Context) {
|
||||
newUser := users.User{}
|
||||
if err := c.BindJSON(&newUser); err != nil {
|
||||
if err := c.ShouldBindJSON(&newUser); err != nil {
|
||||
c.JSON(http.StatusBadRequest, ApiError{Message: err.Error()})
|
||||
return
|
||||
}
|
||||
@@ -132,10 +135,11 @@ func (s *ApiServer) PostUser(c *gin.Context) {
|
||||
// PutUser godoc
|
||||
// @Tags Users
|
||||
// @Summary Updates a user based on the given user model
|
||||
// @ID PutUser
|
||||
// @Accept json
|
||||
// @Produce json
|
||||
// @Param email query string true "User Email"
|
||||
// @Param user body users.User true "User Model"
|
||||
// @Param Email query string true "User Email"
|
||||
// @Param User body users.User true "User Model"
|
||||
// @Success 200 {object} users.User
|
||||
// @Failure 400 {object} ApiError
|
||||
// @Failure 401 {object} ApiError
|
||||
@@ -145,21 +149,21 @@ func (s *ApiServer) PostUser(c *gin.Context) {
|
||||
// @Router /backend/user [put]
|
||||
// @Security ApiBasicAuth
|
||||
func (s *ApiServer) PutUser(c *gin.Context) {
|
||||
email := strings.ToLower(strings.TrimSpace(c.Query("email")))
|
||||
email := strings.ToLower(strings.TrimSpace(c.Query("Email")))
|
||||
if email == "" {
|
||||
c.JSON(http.StatusBadRequest, ApiError{Message: "email parameter must be specified"})
|
||||
c.JSON(http.StatusBadRequest, ApiError{Message: "Email parameter must be specified"})
|
||||
return
|
||||
}
|
||||
|
||||
updateUser := users.User{}
|
||||
if err := c.BindJSON(&updateUser); err != nil {
|
||||
if err := c.ShouldBindJSON(&updateUser); err != nil {
|
||||
c.JSON(http.StatusBadRequest, ApiError{Message: err.Error()})
|
||||
return
|
||||
}
|
||||
|
||||
// Changing email address is not allowed
|
||||
if email != updateUser.Email {
|
||||
c.JSON(http.StatusBadRequest, ApiError{Message: "email parameter must match the model email address"})
|
||||
c.JSON(http.StatusBadRequest, ApiError{Message: "Email parameter must match the model email address"})
|
||||
return
|
||||
}
|
||||
|
||||
@@ -184,10 +188,11 @@ func (s *ApiServer) PutUser(c *gin.Context) {
|
||||
// PatchUser godoc
|
||||
// @Tags Users
|
||||
// @Summary Updates a user based on the given partial user model
|
||||
// @ID PatchUser
|
||||
// @Accept json
|
||||
// @Produce json
|
||||
// @Param email query string true "User Email"
|
||||
// @Param user body users.User true "User Model"
|
||||
// @Param Email query string true "User Email"
|
||||
// @Param User body users.User true "User Model"
|
||||
// @Success 200 {object} users.User
|
||||
// @Failure 400 {object} ApiError
|
||||
// @Failure 401 {object} ApiError
|
||||
@@ -197,7 +202,7 @@ func (s *ApiServer) PutUser(c *gin.Context) {
|
||||
// @Router /backend/user [patch]
|
||||
// @Security ApiBasicAuth
|
||||
func (s *ApiServer) PatchUser(c *gin.Context) {
|
||||
email := strings.ToLower(strings.TrimSpace(c.Query("email")))
|
||||
email := strings.ToLower(strings.TrimSpace(c.Query("Email")))
|
||||
if email == "" {
|
||||
c.JSON(http.StatusBadRequest, ApiError{Message: "email parameter must be specified"})
|
||||
return
|
||||
@@ -250,8 +255,9 @@ func (s *ApiServer) PatchUser(c *gin.Context) {
|
||||
// DeleteUser godoc
|
||||
// @Tags Users
|
||||
// @Summary Deletes the specified user
|
||||
// @ID DeleteUser
|
||||
// @Produce json
|
||||
// @Param email query string true "User Email"
|
||||
// @Param Email query string true "User Email"
|
||||
// @Success 204 "No content"
|
||||
// @Failure 400 {object} ApiError
|
||||
// @Failure 401 {object} ApiError
|
||||
@@ -261,7 +267,7 @@ func (s *ApiServer) PatchUser(c *gin.Context) {
|
||||
// @Router /backend/user [delete]
|
||||
// @Security ApiBasicAuth
|
||||
func (s *ApiServer) DeleteUser(c *gin.Context) {
|
||||
email := strings.ToLower(strings.TrimSpace(c.Query("email")))
|
||||
email := strings.ToLower(strings.TrimSpace(c.Query("Email")))
|
||||
if email == "" {
|
||||
c.JSON(http.StatusBadRequest, ApiError{Message: "email parameter must be specified"})
|
||||
return
|
||||
@@ -284,8 +290,9 @@ func (s *ApiServer) DeleteUser(c *gin.Context) {
|
||||
// GetPeers godoc
|
||||
// @Tags Peers
|
||||
// @Summary Retrieves all peers for the given interface
|
||||
// @ID GetPeers
|
||||
// @Produce json
|
||||
// @Param device query string true "Device Name"
|
||||
// @Param DeviceName query string true "Device Name"
|
||||
// @Success 200 {object} []wireguard.Peer
|
||||
// @Failure 401 {object} ApiError
|
||||
// @Failure 403 {object} ApiError
|
||||
@@ -293,9 +300,9 @@ func (s *ApiServer) DeleteUser(c *gin.Context) {
|
||||
// @Router /backend/peers [get]
|
||||
// @Security ApiBasicAuth
|
||||
func (s *ApiServer) GetPeers(c *gin.Context) {
|
||||
deviceName := strings.ToLower(strings.TrimSpace(c.Query("device")))
|
||||
deviceName := strings.ToLower(strings.TrimSpace(c.Query("DeviceName")))
|
||||
if deviceName == "" {
|
||||
c.JSON(http.StatusBadRequest, ApiError{Message: "device parameter must be specified"})
|
||||
c.JSON(http.StatusBadRequest, ApiError{Message: "DeviceName parameter must be specified"})
|
||||
return
|
||||
}
|
||||
|
||||
@@ -312,8 +319,9 @@ func (s *ApiServer) GetPeers(c *gin.Context) {
|
||||
// GetPeer godoc
|
||||
// @Tags Peers
|
||||
// @Summary Retrieves the peer for the given public key
|
||||
// @ID GetPeer
|
||||
// @Produce json
|
||||
// @Param pkey query string true "Public Key (Base 64)"
|
||||
// @Param PublicKey query string true "Public Key (Base 64)"
|
||||
// @Success 200 {object} wireguard.Peer
|
||||
// @Failure 401 {object} ApiError
|
||||
// @Failure 403 {object} ApiError
|
||||
@@ -321,9 +329,9 @@ func (s *ApiServer) GetPeers(c *gin.Context) {
|
||||
// @Router /backend/peer [get]
|
||||
// @Security ApiBasicAuth
|
||||
func (s *ApiServer) GetPeer(c *gin.Context) {
|
||||
pkey := c.Query("pkey")
|
||||
pkey := c.Query("PublicKey")
|
||||
if pkey == "" {
|
||||
c.JSON(http.StatusBadRequest, ApiError{Message: "pkey parameter must be specified"})
|
||||
c.JSON(http.StatusBadRequest, ApiError{Message: "PublicKey parameter must be specified"})
|
||||
return
|
||||
}
|
||||
|
||||
@@ -338,10 +346,11 @@ func (s *ApiServer) GetPeer(c *gin.Context) {
|
||||
// PostPeer godoc
|
||||
// @Tags Peers
|
||||
// @Summary Creates a new peer based on the given peer model
|
||||
// @ID PostPeer
|
||||
// @Accept json
|
||||
// @Produce json
|
||||
// @Param device query string true "Device Name"
|
||||
// @Param peer body wireguard.Peer true "Peer Model"
|
||||
// @Param DeviceName query string true "Device Name"
|
||||
// @Param Peer body wireguard.Peer true "Peer Model"
|
||||
// @Success 200 {object} wireguard.Peer
|
||||
// @Failure 400 {object} ApiError
|
||||
// @Failure 401 {object} ApiError
|
||||
@@ -351,9 +360,9 @@ func (s *ApiServer) GetPeer(c *gin.Context) {
|
||||
// @Router /backend/peers [post]
|
||||
// @Security ApiBasicAuth
|
||||
func (s *ApiServer) PostPeer(c *gin.Context) {
|
||||
deviceName := strings.ToLower(strings.TrimSpace(c.Query("device")))
|
||||
deviceName := strings.ToLower(strings.TrimSpace(c.Query("DeviceName")))
|
||||
if deviceName == "" {
|
||||
c.JSON(http.StatusBadRequest, ApiError{Message: "device parameter must be specified"})
|
||||
c.JSON(http.StatusBadRequest, ApiError{Message: "DeviceName parameter must be specified"})
|
||||
return
|
||||
}
|
||||
|
||||
@@ -364,7 +373,7 @@ func (s *ApiServer) PostPeer(c *gin.Context) {
|
||||
}
|
||||
|
||||
newPeer := wireguard.Peer{}
|
||||
if err := c.BindJSON(&newPeer); err != nil {
|
||||
if err := c.ShouldBindJSON(&newPeer); err != nil {
|
||||
c.JSON(http.StatusBadRequest, ApiError{Message: err.Error()})
|
||||
return
|
||||
}
|
||||
@@ -390,10 +399,11 @@ func (s *ApiServer) PostPeer(c *gin.Context) {
|
||||
// PutPeer godoc
|
||||
// @Tags Peers
|
||||
// @Summary Updates the given peer based on the given peer model
|
||||
// @ID PutPeer
|
||||
// @Accept json
|
||||
// @Produce json
|
||||
// @Param pkey query string true "Public Key"
|
||||
// @Param peer body wireguard.Peer true "Peer Model"
|
||||
// @Param PublicKey query string true "Public Key"
|
||||
// @Param Peer body wireguard.Peer true "Peer Model"
|
||||
// @Success 200 {object} wireguard.Peer
|
||||
// @Failure 400 {object} ApiError
|
||||
// @Failure 401 {object} ApiError
|
||||
@@ -404,14 +414,14 @@ func (s *ApiServer) PostPeer(c *gin.Context) {
|
||||
// @Security ApiBasicAuth
|
||||
func (s *ApiServer) PutPeer(c *gin.Context) {
|
||||
updatePeer := wireguard.Peer{}
|
||||
if err := c.BindJSON(&updatePeer); err != nil {
|
||||
if err := c.ShouldBindJSON(&updatePeer); err != nil {
|
||||
c.JSON(http.StatusBadRequest, ApiError{Message: err.Error()})
|
||||
return
|
||||
}
|
||||
|
||||
pkey := c.Query("pkey")
|
||||
pkey := c.Query("PublicKey")
|
||||
if pkey == "" {
|
||||
c.JSON(http.StatusBadRequest, ApiError{Message: "pkey parameter must be specified"})
|
||||
c.JSON(http.StatusBadRequest, ApiError{Message: "PublicKey parameter must be specified"})
|
||||
return
|
||||
}
|
||||
|
||||
@@ -422,7 +432,7 @@ func (s *ApiServer) PutPeer(c *gin.Context) {
|
||||
|
||||
// Changing public key is not allowed
|
||||
if pkey != updatePeer.PublicKey {
|
||||
c.JSON(http.StatusBadRequest, ApiError{Message: "pkey parameter must match the model public key"})
|
||||
c.JSON(http.StatusBadRequest, ApiError{Message: "PublicKey parameter must match the model public key"})
|
||||
return
|
||||
}
|
||||
|
||||
@@ -446,10 +456,11 @@ func (s *ApiServer) PutPeer(c *gin.Context) {
|
||||
// PatchPeer godoc
|
||||
// @Tags Peers
|
||||
// @Summary Updates the given peer based on the given partial peer model
|
||||
// @ID PatchPeer
|
||||
// @Accept json
|
||||
// @Produce json
|
||||
// @Param pkey query string true "Public Key"
|
||||
// @Param peer body wireguard.Peer true "Peer Model"
|
||||
// @Param PublicKey query string true "Public Key"
|
||||
// @Param Peer body wireguard.Peer true "Peer Model"
|
||||
// @Success 200 {object} wireguard.Peer
|
||||
// @Failure 400 {object} ApiError
|
||||
// @Failure 401 {object} ApiError
|
||||
@@ -465,7 +476,7 @@ func (s *ApiServer) PatchPeer(c *gin.Context) {
|
||||
return
|
||||
}
|
||||
|
||||
pkey := c.Query("pkey")
|
||||
pkey := c.Query("PublicKey")
|
||||
if pkey == "" {
|
||||
c.JSON(http.StatusBadRequest, ApiError{Message: "pkey parameter must be specified"})
|
||||
return
|
||||
@@ -498,7 +509,7 @@ func (s *ApiServer) PatchPeer(c *gin.Context) {
|
||||
|
||||
// Changing public key is not allowed
|
||||
if pkey != mergedPeer.PublicKey {
|
||||
c.JSON(http.StatusBadRequest, ApiError{Message: "pkey parameter must match the model public key"})
|
||||
c.JSON(http.StatusBadRequest, ApiError{Message: "PublicKey parameter must match the model public key"})
|
||||
return
|
||||
}
|
||||
|
||||
@@ -522,8 +533,9 @@ func (s *ApiServer) PatchPeer(c *gin.Context) {
|
||||
// DeletePeer godoc
|
||||
// @Tags Peers
|
||||
// @Summary Updates the given peer based on the given partial peer model
|
||||
// @ID DeletePeer
|
||||
// @Produce json
|
||||
// @Param pkey query string true "Public Key"
|
||||
// @Param PublicKey query string true "Public Key"
|
||||
// @Success 202 "No Content"
|
||||
// @Failure 400 {object} ApiError
|
||||
// @Failure 401 {object} ApiError
|
||||
@@ -533,9 +545,9 @@ func (s *ApiServer) PatchPeer(c *gin.Context) {
|
||||
// @Router /backend/peer [delete]
|
||||
// @Security ApiBasicAuth
|
||||
func (s *ApiServer) DeletePeer(c *gin.Context) {
|
||||
pkey := c.Query("pkey")
|
||||
pkey := c.Query("PublicKey")
|
||||
if pkey == "" {
|
||||
c.JSON(http.StatusBadRequest, ApiError{Message: "pkey parameter must be specified"})
|
||||
c.JSON(http.StatusBadRequest, ApiError{Message: "PublicKey parameter must be specified"})
|
||||
return
|
||||
}
|
||||
|
||||
@@ -556,6 +568,7 @@ func (s *ApiServer) DeletePeer(c *gin.Context) {
|
||||
// GetDevices godoc
|
||||
// @Tags Interface
|
||||
// @Summary Get all devices
|
||||
// @ID GetDevices
|
||||
// @Produce json
|
||||
// @Success 200 {object} []wireguard.Device
|
||||
// @Failure 400 {object} ApiError
|
||||
@@ -580,8 +593,9 @@ func (s *ApiServer) GetDevices(c *gin.Context) {
|
||||
// GetDevice godoc
|
||||
// @Tags Interface
|
||||
// @Summary Get the given device
|
||||
// @ID GetDevice
|
||||
// @Produce json
|
||||
// @Param device query string true "Device Name"
|
||||
// @Param DeviceName query string true "Device Name"
|
||||
// @Success 200 {object} wireguard.Device
|
||||
// @Failure 400 {object} ApiError
|
||||
// @Failure 401 {object} ApiError
|
||||
@@ -590,9 +604,9 @@ func (s *ApiServer) GetDevices(c *gin.Context) {
|
||||
// @Router /backend/device [get]
|
||||
// @Security ApiBasicAuth
|
||||
func (s *ApiServer) GetDevice(c *gin.Context) {
|
||||
deviceName := strings.ToLower(strings.TrimSpace(c.Query("device")))
|
||||
deviceName := strings.ToLower(strings.TrimSpace(c.Query("DeviceName")))
|
||||
if deviceName == "" {
|
||||
c.JSON(http.StatusBadRequest, ApiError{Message: "device parameter must be specified"})
|
||||
c.JSON(http.StatusBadRequest, ApiError{Message: "DeviceName parameter must be specified"})
|
||||
return
|
||||
}
|
||||
|
||||
@@ -614,10 +628,11 @@ func (s *ApiServer) GetDevice(c *gin.Context) {
|
||||
// PutDevice godoc
|
||||
// @Tags Interface
|
||||
// @Summary Updates the given device based on the given device model (UNIMPLEMENTED)
|
||||
// @ID PutDevice
|
||||
// @Accept json
|
||||
// @Produce json
|
||||
// @Param device query string true "Device Name"
|
||||
// @Param body body wireguard.Device true "Device Model"
|
||||
// @Param DeviceName query string true "Device Name"
|
||||
// @Param Device body wireguard.Device true "Device Model"
|
||||
// @Success 200 {object} wireguard.Device
|
||||
// @Failure 400 {object} ApiError
|
||||
// @Failure 401 {object} ApiError
|
||||
@@ -628,14 +643,14 @@ func (s *ApiServer) GetDevice(c *gin.Context) {
|
||||
// @Security ApiBasicAuth
|
||||
func (s *ApiServer) PutDevice(c *gin.Context) {
|
||||
updateDevice := wireguard.Device{}
|
||||
if err := c.BindJSON(&updateDevice); err != nil {
|
||||
if err := c.ShouldBindJSON(&updateDevice); err != nil {
|
||||
c.JSON(http.StatusBadRequest, ApiError{Message: err.Error()})
|
||||
return
|
||||
}
|
||||
|
||||
deviceName := strings.ToLower(strings.TrimSpace(c.Query("device")))
|
||||
deviceName := strings.ToLower(strings.TrimSpace(c.Query("DeviceName")))
|
||||
if deviceName == "" {
|
||||
c.JSON(http.StatusBadRequest, ApiError{Message: "device parameter must be specified"})
|
||||
c.JSON(http.StatusBadRequest, ApiError{Message: "DeviceName parameter must be specified"})
|
||||
return
|
||||
}
|
||||
|
||||
@@ -653,7 +668,7 @@ func (s *ApiServer) PutDevice(c *gin.Context) {
|
||||
|
||||
// Changing device name is not allowed
|
||||
if deviceName != updateDevice.DeviceName {
|
||||
c.JSON(http.StatusBadRequest, ApiError{Message: "device parameter must match the model device name"})
|
||||
c.JSON(http.StatusBadRequest, ApiError{Message: "DeviceName parameter must match the model device name"})
|
||||
return
|
||||
}
|
||||
|
||||
@@ -665,10 +680,11 @@ func (s *ApiServer) PutDevice(c *gin.Context) {
|
||||
// PatchDevice godoc
|
||||
// @Tags Interface
|
||||
// @Summary Updates the given device based on the given partial device model (UNIMPLEMENTED)
|
||||
// @ID PatchDevice
|
||||
// @Accept json
|
||||
// @Produce json
|
||||
// @Param device query string true "Device Name"
|
||||
// @Param body body wireguard.Device true "Device Model"
|
||||
// @Param DeviceName query string true "Device Name"
|
||||
// @Param Device body wireguard.Device true "Device Model"
|
||||
// @Success 200 {object} wireguard.Device
|
||||
// @Failure 400 {object} ApiError
|
||||
// @Failure 401 {object} ApiError
|
||||
@@ -684,9 +700,9 @@ func (s *ApiServer) PatchDevice(c *gin.Context) {
|
||||
return
|
||||
}
|
||||
|
||||
deviceName := strings.ToLower(strings.TrimSpace(c.Query("device")))
|
||||
deviceName := strings.ToLower(strings.TrimSpace(c.Query("DeviceName")))
|
||||
if deviceName == "" {
|
||||
c.JSON(http.StatusBadRequest, ApiError{Message: "device parameter must be specified"})
|
||||
c.JSON(http.StatusBadRequest, ApiError{Message: "DeviceName parameter must be specified"})
|
||||
return
|
||||
}
|
||||
|
||||
@@ -723,7 +739,7 @@ func (s *ApiServer) PatchDevice(c *gin.Context) {
|
||||
|
||||
// Changing device name is not allowed
|
||||
if deviceName != mergedDevice.DeviceName {
|
||||
c.JSON(http.StatusBadRequest, ApiError{Message: "device parameter must match the model device name"})
|
||||
c.JSON(http.StatusBadRequest, ApiError{Message: "DeviceName parameter must match the model device name"})
|
||||
return
|
||||
}
|
||||
|
||||
@@ -742,8 +758,9 @@ type PeerDeploymentInformation struct {
|
||||
// GetPeerDeploymentInformation godoc
|
||||
// @Tags Provisioning
|
||||
// @Summary Retrieves all active peers for the given email address
|
||||
// @ID GetPeerDeploymentInformation
|
||||
// @Produce json
|
||||
// @Param email query string true "Email Address"
|
||||
// @Param Email query string true "Email Address"
|
||||
// @Success 200 {object} []PeerDeploymentInformation "All active WireGuard peers"
|
||||
// @Failure 401 {object} ApiError
|
||||
// @Failure 403 {object} ApiError
|
||||
@@ -751,9 +768,9 @@ type PeerDeploymentInformation struct {
|
||||
// @Router /provisioning/peers [get]
|
||||
// @Security GeneralBasicAuth
|
||||
func (s *ApiServer) GetPeerDeploymentInformation(c *gin.Context) {
|
||||
email := c.Query("email")
|
||||
email := c.Query("Email")
|
||||
if email == "" {
|
||||
c.JSON(http.StatusBadRequest, ApiError{Message: "email parameter must be specified"})
|
||||
c.JSON(http.StatusBadRequest, ApiError{Message: "Email parameter must be specified"})
|
||||
return
|
||||
}
|
||||
|
||||
@@ -792,8 +809,9 @@ func (s *ApiServer) GetPeerDeploymentInformation(c *gin.Context) {
|
||||
// GetPeerDeploymentConfig godoc
|
||||
// @Tags Provisioning
|
||||
// @Summary Retrieves the peer config for the given public key
|
||||
// @ID GetPeerDeploymentConfig
|
||||
// @Produce plain
|
||||
// @Param pkey query string true "Public Key (Base 64)"
|
||||
// @Param PublicKey query string true "Public Key (Base 64)"
|
||||
// @Success 200 {object} string "The WireGuard configuration file"
|
||||
// @Failure 401 {object} ApiError
|
||||
// @Failure 403 {object} ApiError
|
||||
@@ -801,9 +819,9 @@ func (s *ApiServer) GetPeerDeploymentInformation(c *gin.Context) {
|
||||
// @Router /provisioning/peer [get]
|
||||
// @Security GeneralBasicAuth
|
||||
func (s *ApiServer) GetPeerDeploymentConfig(c *gin.Context) {
|
||||
pkey := c.Query("pkey")
|
||||
pkey := c.Query("PublicKey")
|
||||
if pkey == "" {
|
||||
c.JSON(http.StatusBadRequest, ApiError{Message: "pkey parameter must be specified"})
|
||||
c.JSON(http.StatusBadRequest, ApiError{Message: "PublicKey parameter must be specified"})
|
||||
return
|
||||
}
|
||||
|
||||
@@ -849,9 +867,10 @@ type ProvisioningRequest struct {
|
||||
// PostPeerDeploymentConfig godoc
|
||||
// @Tags Provisioning
|
||||
// @Summary Creates the requested peer config and returns the config file
|
||||
// @ID PostPeerDeploymentConfig
|
||||
// @Accept json
|
||||
// @Produce plain
|
||||
// @Param body body ProvisioningRequest true "Provisioning Request Model"
|
||||
// @Param ProvisioningRequest body ProvisioningRequest true "Provisioning Request Model"
|
||||
// @Success 200 {object} string "The WireGuard configuration file"
|
||||
// @Failure 401 {object} ApiError
|
||||
// @Failure 403 {object} ApiError
|
||||
@@ -860,7 +879,7 @@ type ProvisioningRequest struct {
|
||||
// @Security GeneralBasicAuth
|
||||
func (s *ApiServer) PostPeerDeploymentConfig(c *gin.Context) {
|
||||
req := ProvisioningRequest{}
|
||||
if err := c.BindJSON(&req); err != nil {
|
||||
if err := c.ShouldBindJSON(&req); err != nil {
|
||||
c.JSON(http.StatusBadRequest, ApiError{Message: err.Error()})
|
||||
return
|
||||
}
|
||||
|
@@ -44,11 +44,12 @@ var doc = `{
|
||||
"Interface"
|
||||
],
|
||||
"summary": "Get the given device",
|
||||
"operationId": "GetDevice",
|
||||
"parameters": [
|
||||
{
|
||||
"type": "string",
|
||||
"description": "Device Name",
|
||||
"name": "device",
|
||||
"name": "DeviceName",
|
||||
"in": "query",
|
||||
"required": true
|
||||
}
|
||||
@@ -102,17 +103,18 @@ var doc = `{
|
||||
"Interface"
|
||||
],
|
||||
"summary": "Updates the given device based on the given device model (UNIMPLEMENTED)",
|
||||
"operationId": "PutDevice",
|
||||
"parameters": [
|
||||
{
|
||||
"type": "string",
|
||||
"description": "Device Name",
|
||||
"name": "device",
|
||||
"name": "DeviceName",
|
||||
"in": "query",
|
||||
"required": true
|
||||
},
|
||||
{
|
||||
"description": "Device Model",
|
||||
"name": "body",
|
||||
"name": "Device",
|
||||
"in": "body",
|
||||
"required": true,
|
||||
"schema": {
|
||||
@@ -175,17 +177,18 @@ var doc = `{
|
||||
"Interface"
|
||||
],
|
||||
"summary": "Updates the given device based on the given partial device model (UNIMPLEMENTED)",
|
||||
"operationId": "PatchDevice",
|
||||
"parameters": [
|
||||
{
|
||||
"type": "string",
|
||||
"description": "Device Name",
|
||||
"name": "device",
|
||||
"name": "DeviceName",
|
||||
"in": "query",
|
||||
"required": true
|
||||
},
|
||||
{
|
||||
"description": "Device Model",
|
||||
"name": "body",
|
||||
"name": "Device",
|
||||
"in": "body",
|
||||
"required": true,
|
||||
"schema": {
|
||||
@@ -247,6 +250,7 @@ var doc = `{
|
||||
"Interface"
|
||||
],
|
||||
"summary": "Get all devices",
|
||||
"operationId": "GetDevices",
|
||||
"responses": {
|
||||
"200": {
|
||||
"description": "OK",
|
||||
@@ -298,11 +302,12 @@ var doc = `{
|
||||
"Peers"
|
||||
],
|
||||
"summary": "Retrieves the peer for the given public key",
|
||||
"operationId": "GetPeer",
|
||||
"parameters": [
|
||||
{
|
||||
"type": "string",
|
||||
"description": "Public Key (Base 64)",
|
||||
"name": "pkey",
|
||||
"name": "PublicKey",
|
||||
"in": "query",
|
||||
"required": true
|
||||
}
|
||||
@@ -350,17 +355,18 @@ var doc = `{
|
||||
"Peers"
|
||||
],
|
||||
"summary": "Updates the given peer based on the given peer model",
|
||||
"operationId": "PutPeer",
|
||||
"parameters": [
|
||||
{
|
||||
"type": "string",
|
||||
"description": "Public Key",
|
||||
"name": "pkey",
|
||||
"name": "PublicKey",
|
||||
"in": "query",
|
||||
"required": true
|
||||
},
|
||||
{
|
||||
"description": "Peer Model",
|
||||
"name": "peer",
|
||||
"name": "Peer",
|
||||
"in": "body",
|
||||
"required": true,
|
||||
"schema": {
|
||||
@@ -420,11 +426,12 @@ var doc = `{
|
||||
"Peers"
|
||||
],
|
||||
"summary": "Updates the given peer based on the given partial peer model",
|
||||
"operationId": "DeletePeer",
|
||||
"parameters": [
|
||||
{
|
||||
"type": "string",
|
||||
"description": "Public Key",
|
||||
"name": "pkey",
|
||||
"name": "PublicKey",
|
||||
"in": "query",
|
||||
"required": true
|
||||
}
|
||||
@@ -481,17 +488,18 @@ var doc = `{
|
||||
"Peers"
|
||||
],
|
||||
"summary": "Updates the given peer based on the given partial peer model",
|
||||
"operationId": "PatchPeer",
|
||||
"parameters": [
|
||||
{
|
||||
"type": "string",
|
||||
"description": "Public Key",
|
||||
"name": "pkey",
|
||||
"name": "PublicKey",
|
||||
"in": "query",
|
||||
"required": true
|
||||
},
|
||||
{
|
||||
"description": "Peer Model",
|
||||
"name": "peer",
|
||||
"name": "Peer",
|
||||
"in": "body",
|
||||
"required": true,
|
||||
"schema": {
|
||||
@@ -553,11 +561,12 @@ var doc = `{
|
||||
"Peers"
|
||||
],
|
||||
"summary": "Retrieves all peers for the given interface",
|
||||
"operationId": "GetPeers",
|
||||
"parameters": [
|
||||
{
|
||||
"type": "string",
|
||||
"description": "Device Name",
|
||||
"name": "device",
|
||||
"name": "DeviceName",
|
||||
"in": "query",
|
||||
"required": true
|
||||
}
|
||||
@@ -608,17 +617,18 @@ var doc = `{
|
||||
"Peers"
|
||||
],
|
||||
"summary": "Creates a new peer based on the given peer model",
|
||||
"operationId": "PostPeer",
|
||||
"parameters": [
|
||||
{
|
||||
"type": "string",
|
||||
"description": "Device Name",
|
||||
"name": "device",
|
||||
"name": "DeviceName",
|
||||
"in": "query",
|
||||
"required": true
|
||||
},
|
||||
{
|
||||
"description": "Peer Model",
|
||||
"name": "peer",
|
||||
"name": "Peer",
|
||||
"in": "body",
|
||||
"required": true,
|
||||
"schema": {
|
||||
@@ -680,11 +690,12 @@ var doc = `{
|
||||
"Users"
|
||||
],
|
||||
"summary": "Retrieves user based on given Email",
|
||||
"operationId": "GetUser",
|
||||
"parameters": [
|
||||
{
|
||||
"type": "string",
|
||||
"description": "User Email",
|
||||
"name": "email",
|
||||
"name": "Email",
|
||||
"in": "query",
|
||||
"required": true
|
||||
}
|
||||
@@ -738,17 +749,18 @@ var doc = `{
|
||||
"Users"
|
||||
],
|
||||
"summary": "Updates a user based on the given user model",
|
||||
"operationId": "PutUser",
|
||||
"parameters": [
|
||||
{
|
||||
"type": "string",
|
||||
"description": "User Email",
|
||||
"name": "email",
|
||||
"name": "Email",
|
||||
"in": "query",
|
||||
"required": true
|
||||
},
|
||||
{
|
||||
"description": "User Model",
|
||||
"name": "user",
|
||||
"name": "User",
|
||||
"in": "body",
|
||||
"required": true,
|
||||
"schema": {
|
||||
@@ -808,11 +820,12 @@ var doc = `{
|
||||
"Users"
|
||||
],
|
||||
"summary": "Deletes the specified user",
|
||||
"operationId": "DeleteUser",
|
||||
"parameters": [
|
||||
{
|
||||
"type": "string",
|
||||
"description": "User Email",
|
||||
"name": "email",
|
||||
"name": "Email",
|
||||
"in": "query",
|
||||
"required": true
|
||||
}
|
||||
@@ -869,17 +882,18 @@ var doc = `{
|
||||
"Users"
|
||||
],
|
||||
"summary": "Updates a user based on the given partial user model",
|
||||
"operationId": "PatchUser",
|
||||
"parameters": [
|
||||
{
|
||||
"type": "string",
|
||||
"description": "User Email",
|
||||
"name": "email",
|
||||
"name": "Email",
|
||||
"in": "query",
|
||||
"required": true
|
||||
},
|
||||
{
|
||||
"description": "User Model",
|
||||
"name": "user",
|
||||
"name": "User",
|
||||
"in": "body",
|
||||
"required": true,
|
||||
"schema": {
|
||||
@@ -941,6 +955,7 @@ var doc = `{
|
||||
"Users"
|
||||
],
|
||||
"summary": "Retrieves all users",
|
||||
"operationId": "GetUsers",
|
||||
"responses": {
|
||||
"200": {
|
||||
"description": "OK",
|
||||
@@ -987,10 +1002,11 @@ var doc = `{
|
||||
"Users"
|
||||
],
|
||||
"summary": "Creates a new user based on the given user model",
|
||||
"operationId": "PostUser",
|
||||
"parameters": [
|
||||
{
|
||||
"description": "User Model",
|
||||
"name": "user",
|
||||
"name": "User",
|
||||
"in": "body",
|
||||
"required": true,
|
||||
"schema": {
|
||||
@@ -1052,11 +1068,12 @@ var doc = `{
|
||||
"Provisioning"
|
||||
],
|
||||
"summary": "Retrieves the peer config for the given public key",
|
||||
"operationId": "GetPeerDeploymentConfig",
|
||||
"parameters": [
|
||||
{
|
||||
"type": "string",
|
||||
"description": "Public Key (Base 64)",
|
||||
"name": "pkey",
|
||||
"name": "PublicKey",
|
||||
"in": "query",
|
||||
"required": true
|
||||
}
|
||||
@@ -1103,11 +1120,12 @@ var doc = `{
|
||||
"Provisioning"
|
||||
],
|
||||
"summary": "Retrieves all active peers for the given email address",
|
||||
"operationId": "GetPeerDeploymentInformation",
|
||||
"parameters": [
|
||||
{
|
||||
"type": "string",
|
||||
"description": "Email Address",
|
||||
"name": "email",
|
||||
"name": "Email",
|
||||
"in": "query",
|
||||
"required": true
|
||||
}
|
||||
@@ -1158,10 +1176,11 @@ var doc = `{
|
||||
"Provisioning"
|
||||
],
|
||||
"summary": "Creates the requested peer config and returns the config file",
|
||||
"operationId": "PostPeerDeploymentConfig",
|
||||
"parameters": [
|
||||
{
|
||||
"description": "Provisioning Request Model",
|
||||
"name": "body",
|
||||
"name": "ProvisioningRequest",
|
||||
"in": "body",
|
||||
"required": true,
|
||||
"schema": {
|
||||
@@ -1199,18 +1218,6 @@ var doc = `{
|
||||
}
|
||||
},
|
||||
"definitions": {
|
||||
"gorm.DeletedAt": {
|
||||
"type": "object",
|
||||
"properties": {
|
||||
"Time": {
|
||||
"type": "string"
|
||||
},
|
||||
"Valid": {
|
||||
"description": "Valid is true if Time is not NULL",
|
||||
"type": "boolean"
|
||||
}
|
||||
}
|
||||
},
|
||||
"server.ApiError": {
|
||||
"type": "object",
|
||||
"properties": {
|
||||
@@ -1280,7 +1287,7 @@ var doc = `{
|
||||
"type": "string"
|
||||
},
|
||||
"DeletedAt": {
|
||||
"$ref": "#/definitions/gorm.DeletedAt"
|
||||
"type": "string"
|
||||
},
|
||||
"Email": {
|
||||
"description": "required fields",
|
||||
@@ -1403,9 +1410,11 @@ var doc = `{
|
||||
"type": "object",
|
||||
"required": [
|
||||
"DeviceName",
|
||||
"DeviceType",
|
||||
"Email",
|
||||
"Identifier",
|
||||
"PublicKey"
|
||||
"PublicKey",
|
||||
"UID"
|
||||
],
|
||||
"properties": {
|
||||
"AllowedIPsSrvStr": {
|
||||
@@ -1432,6 +1441,9 @@ var doc = `{
|
||||
"DeviceName": {
|
||||
"type": "string"
|
||||
},
|
||||
"DeviceType": {
|
||||
"type": "string"
|
||||
},
|
||||
"Email": {
|
||||
"type": "string"
|
||||
},
|
||||
@@ -1467,6 +1479,10 @@ var doc = `{
|
||||
"description": "Core WireGuard Settings",
|
||||
"type": "string"
|
||||
},
|
||||
"UID": {
|
||||
"description": "uid for html identification",
|
||||
"type": "string"
|
||||
},
|
||||
"UpdatedAt": {
|
||||
"type": "string"
|
||||
},
|
||||
|
Reference in New Issue
Block a user