mirror of
https://github.com/kubevela/kubevela.git
synced 2026-05-16 14:27:00 +00:00
* Generate restful api based on Swagger As OpenAPI has to be quickly developped to support front-end developement, so did the restufl api docs. Based on swagger, generate the docs automatically * fix conflicts and add application list annotation
78 lines
2.3 KiB
Go
78 lines
2.3 KiB
Go
package server
|
|
|
|
import (
|
|
"github.com/oam-dev/kubevela/pkg/server/util"
|
|
"github.com/oam-dev/kubevela/pkg/serverlib"
|
|
"github.com/oam-dev/kubevela/pkg/utils/env"
|
|
|
|
"github.com/gin-gonic/gin"
|
|
)
|
|
|
|
// UpdateApps is placeholder for updating applications
|
|
func (s *APIServer) UpdateApps(c *gin.Context) {
|
|
}
|
|
|
|
// GetApp requests an application by the namespaced name in the gin.Context
|
|
func (s *APIServer) GetApp(c *gin.Context) {
|
|
envName := c.Param("envName")
|
|
envMeta, err := env.GetEnvByName(envName)
|
|
if err != nil {
|
|
util.HandleError(c, util.StatusInternalServerError, err)
|
|
return
|
|
}
|
|
namespace := envMeta.Namespace
|
|
appName := c.Param("appName")
|
|
ctx := util.GetContext(c)
|
|
applicationMeta, err := serverlib.RetrieveApplicationStatusByName(ctx, s.KubeClient, appName, namespace)
|
|
if err != nil {
|
|
util.HandleError(c, util.StatusInternalServerError, err)
|
|
return
|
|
}
|
|
util.AssembleResponse(c, applicationMeta, nil)
|
|
}
|
|
|
|
// ListApps requests a list of application by the namespace in the gin.Context
|
|
// @tags applications
|
|
// @ID ListApplications
|
|
// @Summary list all applications
|
|
// @Param envName path string true "environment name"
|
|
// @Success 200 {object} apis.Response{code=int,data=[]apis.ApplicationMeta}
|
|
// @Failure 500 {object} apis.Response{code=int,data=string}
|
|
// @Router /envs/{envName}/apps [get]
|
|
func (s *APIServer) ListApps(c *gin.Context) {
|
|
envName := c.Param("envName")
|
|
envMeta, err := env.GetEnvByName(envName)
|
|
if err != nil {
|
|
util.HandleError(c, util.StatusInternalServerError, err)
|
|
return
|
|
}
|
|
namespace := envMeta.Namespace
|
|
|
|
ctx := util.GetContext(c)
|
|
applicationMetaList, err := serverlib.ListApplications(ctx, s.KubeClient, serverlib.Option{Namespace: namespace})
|
|
if err != nil {
|
|
util.HandleError(c, util.StatusInternalServerError, err.Error())
|
|
return
|
|
}
|
|
util.AssembleResponse(c, applicationMetaList, nil)
|
|
}
|
|
|
|
// DeleteApps deletes an application by the namespacedname in the gin.Context
|
|
func (s *APIServer) DeleteApps(c *gin.Context) {
|
|
envName := c.Param("envName")
|
|
envMeta, err := env.GetEnvByName(envName)
|
|
if err != nil {
|
|
util.HandleError(c, util.StatusInternalServerError, err)
|
|
return
|
|
}
|
|
appName := c.Param("appName")
|
|
|
|
o := serverlib.DeleteOptions{
|
|
Client: s.KubeClient,
|
|
Env: envMeta,
|
|
AppName: appName,
|
|
}
|
|
message, err := o.DeleteApp()
|
|
util.AssembleResponse(c, message, err)
|
|
}
|