mirror of
https://github.com/h44z/wg-portal.git
synced 2025-04-19 08:55:12 +00:00
use query param for public key in api requests (#11)
This commit is contained in:
parent
84e5359977
commit
d794f807ad
@ -313,15 +313,15 @@ func (s *ApiServer) GetPeers(c *gin.Context) {
|
||||
// @Tags Peers
|
||||
// @Summary Retrieves the peer for the given public key
|
||||
// @Produce json
|
||||
// @Param pkey path string true "Public Key (Base 64)"
|
||||
// @Param pkey query string true "Public Key (Base 64)"
|
||||
// @Success 200 {object} wireguard.Peer
|
||||
// @Failure 401 {object} ApiError
|
||||
// @Failure 403 {object} ApiError
|
||||
// @Failure 404 {object} ApiError
|
||||
// @Router /backend/peer/{pkey} [get]
|
||||
// @Router /backend/peer [get]
|
||||
// @Security ApiBasicAuth
|
||||
func (s *ApiServer) GetPeer(c *gin.Context) {
|
||||
pkey := c.Param("pkey")
|
||||
pkey := c.Query("pkey")
|
||||
if pkey == "" {
|
||||
c.JSON(http.StatusBadRequest, ApiError{Message: "pkey parameter must be specified"})
|
||||
return
|
||||
@ -392,7 +392,7 @@ func (s *ApiServer) PostPeer(c *gin.Context) {
|
||||
// @Summary Updates the given peer based on the given peer model
|
||||
// @Accept json
|
||||
// @Produce json
|
||||
// @Param pkey path string true "Public Key"
|
||||
// @Param pkey query string true "Public Key"
|
||||
// @Param peer body wireguard.Peer true "Peer Model"
|
||||
// @Success 200 {object} wireguard.Peer
|
||||
// @Failure 400 {object} ApiError
|
||||
@ -400,7 +400,7 @@ func (s *ApiServer) PostPeer(c *gin.Context) {
|
||||
// @Failure 403 {object} ApiError
|
||||
// @Failure 404 {object} ApiError
|
||||
// @Failure 500 {object} ApiError
|
||||
// @Router /backend/peer/{pkey} [put]
|
||||
// @Router /backend/peer [put]
|
||||
// @Security ApiBasicAuth
|
||||
func (s *ApiServer) PutPeer(c *gin.Context) {
|
||||
updatePeer := wireguard.Peer{}
|
||||
@ -409,7 +409,7 @@ func (s *ApiServer) PutPeer(c *gin.Context) {
|
||||
return
|
||||
}
|
||||
|
||||
pkey := c.Param("pkey")
|
||||
pkey := c.Query("pkey")
|
||||
if pkey == "" {
|
||||
c.JSON(http.StatusBadRequest, ApiError{Message: "pkey parameter must be specified"})
|
||||
return
|
||||
@ -448,7 +448,7 @@ func (s *ApiServer) PutPeer(c *gin.Context) {
|
||||
// @Summary Updates the given peer based on the given partial peer model
|
||||
// @Accept json
|
||||
// @Produce json
|
||||
// @Param pkey path string true "Public Key"
|
||||
// @Param pkey query string true "Public Key"
|
||||
// @Param peer body wireguard.Peer true "Peer Model"
|
||||
// @Success 200 {object} wireguard.Peer
|
||||
// @Failure 400 {object} ApiError
|
||||
@ -456,7 +456,7 @@ func (s *ApiServer) PutPeer(c *gin.Context) {
|
||||
// @Failure 403 {object} ApiError
|
||||
// @Failure 404 {object} ApiError
|
||||
// @Failure 500 {object} ApiError
|
||||
// @Router /backend/peer/{pkey} [patch]
|
||||
// @Router /backend/peer [patch]
|
||||
// @Security ApiBasicAuth
|
||||
func (s *ApiServer) PatchPeer(c *gin.Context) {
|
||||
patch, err := c.GetRawData()
|
||||
@ -465,7 +465,7 @@ func (s *ApiServer) PatchPeer(c *gin.Context) {
|
||||
return
|
||||
}
|
||||
|
||||
pkey := c.Param("pkey")
|
||||
pkey := c.Query("pkey")
|
||||
if pkey == "" {
|
||||
c.JSON(http.StatusBadRequest, ApiError{Message: "pkey parameter must be specified"})
|
||||
return
|
||||
@ -523,17 +523,17 @@ func (s *ApiServer) PatchPeer(c *gin.Context) {
|
||||
// @Tags Peers
|
||||
// @Summary Updates the given peer based on the given partial peer model
|
||||
// @Produce json
|
||||
// @Param pkey path string true "Public Key"
|
||||
// @Param pkey query string true "Public Key"
|
||||
// @Success 202 "No Content"
|
||||
// @Failure 400 {object} ApiError
|
||||
// @Failure 401 {object} ApiError
|
||||
// @Failure 403 {object} ApiError
|
||||
// @Failure 404 {object} ApiError
|
||||
// @Failure 500 {object} ApiError
|
||||
// @Router /backend/peer/{pkey} [delete]
|
||||
// @Router /backend/peer [delete]
|
||||
// @Security ApiBasicAuth
|
||||
func (s *ApiServer) DeletePeer(c *gin.Context) {
|
||||
pkey := c.Param("pkey")
|
||||
pkey := c.Query("pkey")
|
||||
if pkey == "" {
|
||||
c.JSON(http.StatusBadRequest, ApiError{Message: "pkey parameter must be specified"})
|
||||
return
|
||||
@ -793,15 +793,15 @@ func (s *ApiServer) GetPeerDeploymentInformation(c *gin.Context) {
|
||||
// @Tags Provisioning
|
||||
// @Summary Retrieves the peer config for the given public key
|
||||
// @Produce plain
|
||||
// @Param pkey path string true "Public Key (Base 64)"
|
||||
// @Param pkey query string true "Public Key (Base 64)"
|
||||
// @Success 200 {object} string "The WireGuard configuration file"
|
||||
// @Failure 401 {object} ApiError
|
||||
// @Failure 403 {object} ApiError
|
||||
// @Failure 404 {object} ApiError
|
||||
// @Router /provisioning/peer/{pkey} [get]
|
||||
// @Router /provisioning/peer [get]
|
||||
// @Security GeneralBasicAuth
|
||||
func (s *ApiServer) GetPeerDeploymentConfig(c *gin.Context) {
|
||||
pkey := c.Param("pkey")
|
||||
pkey := c.Query("pkey")
|
||||
if pkey == "" {
|
||||
c.JSON(http.StatusBadRequest, ApiError{Message: "pkey parameter must be specified"})
|
||||
return
|
||||
|
@ -285,7 +285,7 @@ var doc = `{
|
||||
}
|
||||
}
|
||||
},
|
||||
"/backend/peer/{pkey}": {
|
||||
"/backend/peer": {
|
||||
"get": {
|
||||
"security": [
|
||||
{
|
||||
@ -304,7 +304,7 @@ var doc = `{
|
||||
"type": "string",
|
||||
"description": "Public Key (Base 64)",
|
||||
"name": "pkey",
|
||||
"in": "path",
|
||||
"in": "query",
|
||||
"required": true
|
||||
}
|
||||
],
|
||||
@ -356,7 +356,7 @@ var doc = `{
|
||||
"type": "string",
|
||||
"description": "Public Key",
|
||||
"name": "pkey",
|
||||
"in": "path",
|
||||
"in": "query",
|
||||
"required": true
|
||||
},
|
||||
{
|
||||
@ -426,7 +426,7 @@ var doc = `{
|
||||
"type": "string",
|
||||
"description": "Public Key",
|
||||
"name": "pkey",
|
||||
"in": "path",
|
||||
"in": "query",
|
||||
"required": true
|
||||
}
|
||||
],
|
||||
@ -487,7 +487,7 @@ var doc = `{
|
||||
"type": "string",
|
||||
"description": "Public Key",
|
||||
"name": "pkey",
|
||||
"in": "path",
|
||||
"in": "query",
|
||||
"required": true
|
||||
},
|
||||
{
|
||||
@ -1039,7 +1039,7 @@ var doc = `{
|
||||
}
|
||||
}
|
||||
},
|
||||
"/provisioning/peer/{pkey}": {
|
||||
"/provisioning/peer": {
|
||||
"get": {
|
||||
"security": [
|
||||
{
|
||||
@ -1058,7 +1058,7 @@ var doc = `{
|
||||
"type": "string",
|
||||
"description": "Public Key (Base 64)",
|
||||
"name": "pkey",
|
||||
"in": "path",
|
||||
"in": "query",
|
||||
"required": true
|
||||
}
|
||||
],
|
||||
|
@ -93,10 +93,10 @@ func SetupApiRoutes(s *Server) {
|
||||
|
||||
apiV1Backend.GET("/peers/:device", api.GetPeers)
|
||||
apiV1Backend.POST("/peers/:device", api.PostPeer)
|
||||
apiV1Backend.GET("/peer/:pkey", api.GetPeer)
|
||||
apiV1Backend.PUT("/peer/:pkey", api.PutPeer)
|
||||
apiV1Backend.PATCH("/peer/:pkey", api.PatchPeer)
|
||||
apiV1Backend.DELETE("/peer/:pkey", api.DeletePeer)
|
||||
apiV1Backend.GET("/peer", api.GetPeer)
|
||||
apiV1Backend.PUT("/peer", api.PutPeer)
|
||||
apiV1Backend.PATCH("/peer", api.PatchPeer)
|
||||
apiV1Backend.DELETE("/peer", api.DeletePeer)
|
||||
|
||||
apiV1Backend.GET("/devices", api.GetDevices)
|
||||
apiV1Backend.GET("/device/:device", api.GetDevice)
|
||||
@ -108,7 +108,7 @@ func SetupApiRoutes(s *Server) {
|
||||
apiV1Deployment.Use(s.RequireApiAuthentication(""))
|
||||
|
||||
apiV1Deployment.GET("/peers/:email", api.GetPeerDeploymentInformation)
|
||||
apiV1Deployment.GET("/peer/:pkey", api.GetPeerDeploymentConfig)
|
||||
apiV1Deployment.GET("/peer", api.GetPeerDeploymentConfig)
|
||||
apiV1Deployment.POST("/peers", api.PostPeerDeploymentConfig)
|
||||
|
||||
// Swagger doc/ui
|
||||
|
Loading…
x
Reference in New Issue
Block a user