Browse Source

Merge pull request #1560 from gravitl/bugfix_v0.16.0_swagger_sections

Fix sections for /server/ and /users/ paths in Swagger docs
Alex Feiszli 2 years ago
parent
commit
7ac9d1d307
4 changed files with 124 additions and 63 deletions
  1. 1 1
      controllers/docs.go
  2. 33 3
      controllers/server.go
  3. 10 10
      controllers/user.go
  4. 80 49
      swagger.yaml

+ 1 - 1
controllers/docs.go

@@ -11,7 +11,7 @@
 //
 //
 //     Schemes: https
 //     Schemes: https
 //     BasePath: /
 //     BasePath: /
-//     Version: 0.15.2
+//     Version: 0.16.0
 //     Host: netmaker.io
 //     Host: netmaker.io
 //
 //
 //     Consumes:
 //     Consumes:

+ 33 - 3
controllers/server.go

@@ -50,7 +50,37 @@ func allowUsers(next http.Handler) http.HandlerFunc {
 	}
 	}
 }
 }
 
 
-// swagger:route GET /api/server/getserverinfo nodes getServerInfo
+// swagger:route DELETE /api/server/removenetwork/{network} server removeNetwork
+//
+// Remove a network from the server.
+//
+//		Schemes: https
+//
+// 		Security:
+//   		oauth
+//
+//		Responses:
+//			200: stringJSONResponse
+func removeNetwork(w http.ResponseWriter, r *http.Request) {
+	// Set header
+	w.Header().Set("Content-Type", "application/json")
+
+	// get params
+	var params = mux.Vars(r)
+	network := params["network"]
+	err := logic.DeleteNetwork(network)
+	if err != nil {
+		logger.Log(0, r.Header.Get("user"),
+			fmt.Sprintf("failed to delete network [%s]: %v", network, err))
+		json.NewEncoder(w).Encode(fmt.Sprintf("could not remove network %s from server", network))
+		return
+	}
+	logger.Log(1, r.Header.Get("user"),
+		fmt.Sprintf("deleted network [%s]: %v", network, err))
+	json.NewEncoder(w).Encode(fmt.Sprintf("network %s removed from server", network))
+}
+
+// swagger:route GET /api/server/getserverinfo server getServerInfo
 //
 //
 // Get the server configuration.
 // Get the server configuration.
 //
 //
@@ -71,7 +101,7 @@ func getServerInfo(w http.ResponseWriter, r *http.Request) {
 	//w.WriteHeader(http.StatusOK)
 	//w.WriteHeader(http.StatusOK)
 }
 }
 
 
-// swagger:route GET /api/server/getconfig nodes getConfig
+// swagger:route GET /api/server/getconfig server getConfig
 //
 //
 // Get the server configuration.
 // Get the server configuration.
 //
 //
@@ -97,7 +127,7 @@ func getConfig(w http.ResponseWriter, r *http.Request) {
 	//w.WriteHeader(http.StatusOK)
 	//w.WriteHeader(http.StatusOK)
 }
 }
 
 
-// swagger:route POST /api/server/register nodes register
+// swagger:route POST /api/server/register server register
 //
 //
 // Registers a client with the server and return the Certificate Authority and certificate.
 // Registers a client with the server and return the Certificate Authority and certificate.
 //
 //

+ 10 - 10
controllers/user.go

@@ -38,7 +38,7 @@ func userHandlers(r *mux.Router) {
 	r.HandleFunc("/api/oauth/register/{regKey}", auth.RegisterNodeSSO).Methods("GET")
 	r.HandleFunc("/api/oauth/register/{regKey}", auth.RegisterNodeSSO).Methods("GET")
 }
 }
 
 
-// swagger:route POST /api/users/adm/authenticate nodes authenticateUser
+// swagger:route POST /api/users/adm/authenticate user authenticateUser
 //
 //
 // Node authenticates using its password and retrieves a JWT for authorization.
 // Node authenticates using its password and retrieves a JWT for authorization.
 //
 //
@@ -110,7 +110,7 @@ func authenticateUser(response http.ResponseWriter, request *http.Request) {
 	response.Write(successJSONResponse)
 	response.Write(successJSONResponse)
 }
 }
 
 
-// swagger:route GET /api/users/adm/hasadmin nodes hasAdmin
+// swagger:route GET /api/users/adm/hasadmin user hasAdmin
 //
 //
 // Checks whether the server has an admin.
 // Checks whether the server has an admin.
 //
 //
@@ -150,7 +150,7 @@ func GetUserInternal(username string) (models.User, error) {
 	return user, err
 	return user, err
 }
 }
 
 
-// swagger:route GET /api/users/{username} nodes getUser
+// swagger:route GET /api/users/{username} user getUser
 //
 //
 // Get an individual user.
 // Get an individual user.
 //
 //
@@ -178,7 +178,7 @@ func getUser(w http.ResponseWriter, r *http.Request) {
 	json.NewEncoder(w).Encode(user)
 	json.NewEncoder(w).Encode(user)
 }
 }
 
 
-// swagger:route GET /api/users nodes getUsers
+// swagger:route GET /api/users user getUsers
 //
 //
 // Get all users.
 // Get all users.
 //
 //
@@ -205,7 +205,7 @@ func getUsers(w http.ResponseWriter, r *http.Request) {
 	json.NewEncoder(w).Encode(users)
 	json.NewEncoder(w).Encode(users)
 }
 }
 
 
-// swagger:route POST /api/users/adm/createadmin nodes createAdmin
+// swagger:route POST /api/users/adm/createadmin user createAdmin
 //
 //
 // Make a user an admin.
 // Make a user an admin.
 //
 //
@@ -247,7 +247,7 @@ func createAdmin(w http.ResponseWriter, r *http.Request) {
 	json.NewEncoder(w).Encode(admin)
 	json.NewEncoder(w).Encode(admin)
 }
 }
 
 
-// swagger:route POST /api/users/{username} nodes createUser
+// swagger:route POST /api/users/{username} user createUser
 //
 //
 // Create a user.
 // Create a user.
 //
 //
@@ -281,7 +281,7 @@ func createUser(w http.ResponseWriter, r *http.Request) {
 	json.NewEncoder(w).Encode(user)
 	json.NewEncoder(w).Encode(user)
 }
 }
 
 
-// swagger:route PUT /api/users/networks/{username} nodes updateUserNetworks
+// swagger:route PUT /api/users/networks/{username} user updateUserNetworks
 //
 //
 // Updates the networks of the given user.
 // Updates the networks of the given user.
 //
 //
@@ -331,7 +331,7 @@ func updateUserNetworks(w http.ResponseWriter, r *http.Request) {
 	json.NewEncoder(w).Encode(user)
 	json.NewEncoder(w).Encode(user)
 }
 }
 
 
-// swagger:route PUT /api/users/{username} nodes updateUser
+// swagger:route PUT /api/users/{username} user updateUser
 //
 //
 // Update a user.
 // Update a user.
 //
 //
@@ -382,7 +382,7 @@ func updateUser(w http.ResponseWriter, r *http.Request) {
 	json.NewEncoder(w).Encode(user)
 	json.NewEncoder(w).Encode(user)
 }
 }
 
 
-// swagger:route PUT /api/users/{username}/adm nodes updateUserAdm
+// swagger:route PUT /api/users/{username}/adm user updateUserAdm
 //
 //
 // Updates the given admin user's info (as long as the user is an admin).
 // Updates the given admin user's info (as long as the user is an admin).
 //
 //
@@ -434,7 +434,7 @@ func updateUserAdm(w http.ResponseWriter, r *http.Request) {
 	json.NewEncoder(w).Encode(user)
 	json.NewEncoder(w).Encode(user)
 }
 }
 
 
-// swagger:route DELETE /api/users/{username} nodes deleteUser
+// swagger:route DELETE /api/users/{username} user deleteUser
 //
 //
 // Delete a user.
 // Delete a user.
 //
 //

+ 80 - 49
swagger.yaml

@@ -746,7 +746,7 @@ info:
 
 
         API calls must be authenticated via a header of the format -H “Authorization: Bearer <YOUR_SECRET_KEY>” There are two methods to obtain YOUR_SECRET_KEY: 1. Using the masterkey. By default, this value is “secret key,” but you should change this on your instance and keep it secure. This value can be set via env var at startup or in a config file (config/environments/< env >.yaml). See the [Netmaker](https://docs.netmaker.org/index.html) documentation for more details. 2. Using a JWT received for a node. This can be retrieved by calling the /api/nodes/<network>/authenticate endpoint, as documented below.
         API calls must be authenticated via a header of the format -H “Authorization: Bearer <YOUR_SECRET_KEY>” There are two methods to obtain YOUR_SECRET_KEY: 1. Using the masterkey. By default, this value is “secret key,” but you should change this on your instance and keep it secure. This value can be set via env var at startup or in a config file (config/environments/< env >.yaml). See the [Netmaker](https://docs.netmaker.org/index.html) documentation for more details. 2. Using a JWT received for a node. This can be retrieved by calling the /api/nodes/<network>/authenticate endpoint, as documented below.
     title: Netmaker
     title: Netmaker
-    version: 0.15.2
+    version: 0.16.0
 paths:
 paths:
     /api/dns:
     /api/dns:
         get:
         get:
@@ -1087,6 +1087,13 @@ paths:
     /api/networks/{networkname}:
     /api/networks/{networkname}:
         delete:
         delete:
             operationId: deleteNetwork
             operationId: deleteNetwork
+            parameters:
+                - description: Network Name
+                  in: path
+                  name: networkname
+                  required: true
+                  type: string
+                  x-go-name: NetworkName
             responses:
             responses:
                 "200":
                 "200":
                     $ref: '#/responses/stringJSONResponse'
                     $ref: '#/responses/stringJSONResponse'
@@ -1097,6 +1104,13 @@ paths:
                 - networks
                 - networks
         get:
         get:
             operationId: getNetwork
             operationId: getNetwork
+            parameters:
+                - description: Network Name
+                  in: path
+                  name: networkname
+                  required: true
+                  type: string
+                  x-go-name: NetworkName
             responses:
             responses:
                 "200":
                 "200":
                     $ref: '#/responses/networkBodyResponse'
                     $ref: '#/responses/networkBodyResponse'
@@ -1114,6 +1128,12 @@ paths:
                   schema:
                   schema:
                     $ref: '#/definitions/Network'
                     $ref: '#/definitions/Network'
                   x-go-name: Network
                   x-go-name: Network
+                - description: Network Name
+                  in: path
+                  name: networkname
+                  required: true
+                  type: string
+                  x-go-name: NetworkName
             responses:
             responses:
                 "200":
                 "200":
                     $ref: '#/responses/networkBodyResponse'
                     $ref: '#/responses/networkBodyResponse'
@@ -1126,6 +1146,12 @@ paths:
         get:
         get:
             operationId: getNetworkACL
             operationId: getNetworkACL
             parameters:
             parameters:
+                - description: Network Name
+                  in: path
+                  name: networkname
+                  required: true
+                  type: string
+                  x-go-name: NetworkName
                 - description: ACL Container
                 - description: ACL Container
                   in: body
                   in: body
                   name: acl_container
                   name: acl_container
@@ -1143,6 +1169,12 @@ paths:
         put:
         put:
             operationId: updateNetworkACL
             operationId: updateNetworkACL
             parameters:
             parameters:
+                - description: Network Name
+                  in: path
+                  name: networkname
+                  required: true
+                  type: string
+                  x-go-name: NetworkName
                 - description: ACL Container
                 - description: ACL Container
                   in: body
                   in: body
                   name: acl_container
                   name: acl_container
@@ -1160,6 +1192,13 @@ paths:
     /api/networks/{networkname}/keys:
     /api/networks/{networkname}/keys:
         get:
         get:
             operationId: getAccessKeys
             operationId: getAccessKeys
+            parameters:
+                - description: Network Name
+                  in: path
+                  name: networkname
+                  required: true
+                  type: string
+                  x-go-name: NetworkName
             responses:
             responses:
                 "200":
                 "200":
                     $ref: '#/responses/accessKeySliceBodyResponse'
                     $ref: '#/responses/accessKeySliceBodyResponse'
@@ -1171,6 +1210,12 @@ paths:
         post:
         post:
             operationId: createAccessKey
             operationId: createAccessKey
             parameters:
             parameters:
+                - description: Network Name
+                  in: path
+                  name: networkname
+                  required: true
+                  type: string
+                  x-go-name: NetworkName
                 - description: Access Key
                 - description: Access Key
                   in: body
                   in: body
                   name: access_key
                   name: access_key
@@ -1189,6 +1234,12 @@ paths:
         delete:
         delete:
             operationId: deleteAccessKey
             operationId: deleteAccessKey
             parameters:
             parameters:
+                - description: Network Name
+                  in: path
+                  name: networkname
+                  required: true
+                  type: string
+                  x-go-name: NetworkName
                 - description: Access Key Name
                 - description: Access Key Name
                   in: path
                   in: path
                   name: access_key_name
                   name: access_key_name
@@ -1206,6 +1257,13 @@ paths:
     /api/networks/{networkname}/keyupdate:
     /api/networks/{networkname}/keyupdate:
         post:
         post:
             operationId: keyUpdate
             operationId: keyUpdate
+            parameters:
+                - description: Network Name
+                  in: path
+                  name: networkname
+                  required: true
+                  type: string
+                  x-go-name: NetworkName
             responses:
             responses:
                 "200":
                 "200":
                     $ref: '#/responses/networkBodyResponse'
                     $ref: '#/responses/networkBodyResponse'
@@ -1217,6 +1275,13 @@ paths:
     /api/networks/{networkname}/nodelimit:
     /api/networks/{networkname}/nodelimit:
         put:
         put:
             operationId: updateNetworkNodeLimit
             operationId: updateNetworkNodeLimit
+            parameters:
+                - description: Network Name
+                  in: path
+                  name: networkname
+                  required: true
+                  type: string
+                  x-go-name: NetworkName
             responses:
             responses:
                 "200":
                 "200":
                     $ref: '#/responses/networkBodyResponse'
                     $ref: '#/responses/networkBodyResponse'
@@ -1239,13 +1304,6 @@ paths:
     /api/nodes/{network}:
     /api/nodes/{network}:
         get:
         get:
             operationId: getNetworkNodes
             operationId: getNetworkNodes
-            parameters:
-                - description: Network
-                  in: path
-                  name: network
-                  required: true
-                  type: string
-                  x-go-name: Network
             responses:
             responses:
                 "200":
                 "200":
                     $ref: '#/responses/nodeSliceResponse'
                     $ref: '#/responses/nodeSliceResponse'
@@ -1256,13 +1314,6 @@ paths:
                 - nodes
                 - nodes
         post:
         post:
             operationId: createNode
             operationId: createNode
-            parameters:
-                - description: Network
-                  in: path
-                  name: network
-                  required: true
-                  type: string
-                  x-go-name: Network
             responses:
             responses:
                 "200":
                 "200":
                     $ref: '#/responses/nodeGetResponse'
                     $ref: '#/responses/nodeGetResponse'
@@ -1537,12 +1588,6 @@ paths:
         post:
         post:
             operationId: authenticate
             operationId: authenticate
             parameters:
             parameters:
-                - description: Network
-                  in: path
-                  name: network
-                  required: true
-                  type: string
-                  x-go-name: Network
                 - description: AuthParams
                 - description: AuthParams
                   in: body
                   in: body
                   name: auth_params
                   name: auth_params
@@ -1560,13 +1605,6 @@ paths:
     /api/nodes/adm/{network}/lastmodified:
     /api/nodes/adm/{network}/lastmodified:
         get:
         get:
             operationId: getLastModified
             operationId: getLastModified
-            parameters:
-                - description: Network
-                  in: path
-                  name: network
-                  required: true
-                  type: string
-                  x-go-name: Network
             responses:
             responses:
                 "200":
                 "200":
                     $ref: '#/responses/nodeLastModifiedResponse'
                     $ref: '#/responses/nodeLastModifiedResponse'
@@ -1593,7 +1631,7 @@ paths:
                 - https
                 - https
             summary: Get the server configuration.
             summary: Get the server configuration.
             tags:
             tags:
-                - nodes
+                - server
     /api/server/getserverinfo:
     /api/server/getserverinfo:
         get:
         get:
             operationId: getServerInfo
             operationId: getServerInfo
@@ -1604,7 +1642,7 @@ paths:
                 - https
                 - https
             summary: Get the server configuration.
             summary: Get the server configuration.
             tags:
             tags:
-                - nodes
+                - server
     /api/server/register:
     /api/server/register:
         post:
         post:
             operationId: register
             operationId: register
@@ -1622,17 +1660,10 @@ paths:
                 - https
                 - https
             summary: Registers a client with the server and return the Certificate Authority and certificate.
             summary: Registers a client with the server and return the Certificate Authority and certificate.
             tags:
             tags:
-                - nodes
+                - server
     /api/server/removenetwork/{network}:
     /api/server/removenetwork/{network}:
         delete:
         delete:
             operationId: removeNetwork
             operationId: removeNetwork
-            parameters:
-                - description: Network
-                  in: path
-                  name: network
-                  required: true
-                  type: string
-                  x-go-name: Network
             responses:
             responses:
                 "200":
                 "200":
                     $ref: '#/responses/stringJSONResponse'
                     $ref: '#/responses/stringJSONResponse'
@@ -1640,7 +1671,7 @@ paths:
                 - https
                 - https
             summary: Remove a network from the server.
             summary: Remove a network from the server.
             tags:
             tags:
-                - nodes
+                - server
     /api/users:
     /api/users:
         get:
         get:
             operationId: getUsers
             operationId: getUsers
@@ -1651,7 +1682,7 @@ paths:
                 - https
                 - https
             summary: Get all users.
             summary: Get all users.
             tags:
             tags:
-                - nodes
+                - user
     /api/users/{username}:
     /api/users/{username}:
         delete:
         delete:
             operationId: deleteUser
             operationId: deleteUser
@@ -1669,7 +1700,7 @@ paths:
                 - https
                 - https
             summary: Delete a user.
             summary: Delete a user.
             tags:
             tags:
-                - nodes
+                - user
         get:
         get:
             operationId: getUser
             operationId: getUser
             parameters:
             parameters:
@@ -1686,7 +1717,7 @@ paths:
                 - https
                 - https
             summary: Get an individual user.
             summary: Get an individual user.
             tags:
             tags:
-                - nodes
+                - user
         post:
         post:
             operationId: createUser
             operationId: createUser
             parameters:
             parameters:
@@ -1709,7 +1740,7 @@ paths:
                 - https
                 - https
             summary: Create a user.
             summary: Create a user.
             tags:
             tags:
-                - nodes
+                - user
         put:
         put:
             operationId: updateUser
             operationId: updateUser
             parameters:
             parameters:
@@ -1732,7 +1763,7 @@ paths:
                 - https
                 - https
             summary: Update a user.
             summary: Update a user.
             tags:
             tags:
-                - nodes
+                - user
     /api/users/{username}/adm:
     /api/users/{username}/adm:
         put:
         put:
             operationId: updateUserAdm
             operationId: updateUserAdm
@@ -1750,7 +1781,7 @@ paths:
                 - https
                 - https
             summary: Updates the given admin user's info (as long as the user is an admin).
             summary: Updates the given admin user's info (as long as the user is an admin).
             tags:
             tags:
-                - nodes
+                - user
     /api/users/adm/authenticate:
     /api/users/adm/authenticate:
         post:
         post:
             operationId: authenticateUser
             operationId: authenticateUser
@@ -1768,7 +1799,7 @@ paths:
                 - https
                 - https
             summary: Node authenticates using its password and retrieves a JWT for authorization.
             summary: Node authenticates using its password and retrieves a JWT for authorization.
             tags:
             tags:
-                - nodes
+                - user
     /api/users/adm/createadmin:
     /api/users/adm/createadmin:
         post:
         post:
             operationId: createAdmin
             operationId: createAdmin
@@ -1786,7 +1817,7 @@ paths:
                 - https
                 - https
             summary: Make a user an admin.
             summary: Make a user an admin.
             tags:
             tags:
-                - nodes
+                - user
     /api/users/adm/hasadmin:
     /api/users/adm/hasadmin:
         get:
         get:
             operationId: hasAdmin
             operationId: hasAdmin
@@ -1797,7 +1828,7 @@ paths:
                 - https
                 - https
             summary: Checks whether the server has an admin.
             summary: Checks whether the server has an admin.
             tags:
             tags:
-                - nodes
+                - user
     /api/users/networks/{username}:
     /api/users/networks/{username}:
         put:
         put:
             operationId: updateUserNetworks
             operationId: updateUserNetworks
@@ -1821,7 +1852,7 @@ paths:
                 - https
                 - https
             summary: Updates the networks of the given user.
             summary: Updates the networks of the given user.
             tags:
             tags:
-                - nodes
+                - user
     /meshclient/files/{filename}:
     /meshclient/files/{filename}:
         get:
         get:
             operationId: fileServer
             operationId: fileServer