1Panel/backend/app/api/v1/image_repo.go

144 lines
4.4 KiB
Go
Raw Normal View History

2022-10-09 16:17:15 +08:00
package v1
import (
2022-10-18 18:39:45 +08:00
"github.com/1Panel-dev/1Panel/backend/app/api/v1/helper"
"github.com/1Panel-dev/1Panel/backend/app/dto"
"github.com/1Panel-dev/1Panel/backend/constant"
2022-10-09 16:17:15 +08:00
"github.com/gin-gonic/gin"
)
2023-01-04 22:31:51 +08:00
// @Tags Container Image-repo
// @Summary Page image repos
2023-01-04 22:31:51 +08:00
// @Description 获取镜像仓库列表分页
// @Accept json
2023-02-07 18:48:32 +08:00
// @Param request body dto.SearchWithPage true "request"
2023-01-04 22:31:51 +08:00
// @Produce json
// @Success 200 {object} dto.PageResult
// @Security ApiKeyAuth
// @Router /containers/repo/search [post]
func (b *BaseApi) SearchRepo(c *gin.Context) {
2023-02-07 18:48:32 +08:00
var req dto.SearchWithPage
2023-10-27 14:19:26 +08:00
if err := helper.CheckBindAndValidate(&req, c); err != nil {
return
}
2022-10-09 16:17:15 +08:00
total, list, err := imageRepoService.Page(req)
if err != nil {
helper.ErrorWithDetail(c, constant.CodeErrInternalServer, constant.ErrTypeInternalServer, err)
return
}
helper.SuccessWithData(c, dto.PageResult{
Items: list,
Total: total,
})
}
2023-01-04 22:31:51 +08:00
// @Tags Container Image-repo
// @Summary List image repos
2023-01-04 22:31:51 +08:00
// @Description 获取镜像仓库列表
// @Produce json
// @Success 200 {array} dto.ImageRepoOption
2023-01-04 22:31:51 +08:00
// @Security ApiKeyAuth
// @Router /containers/repo [get]
func (b *BaseApi) ListRepo(c *gin.Context) {
list, err := imageRepoService.List()
if err != nil {
helper.ErrorWithDetail(c, constant.CodeErrInternalServer, constant.ErrTypeInternalServer, err)
return
}
helper.SuccessWithData(c, list)
}
2023-02-27 11:46:23 +08:00
// @Tags Container Image-repo
// @Summary Load repo status
// @Description 获取 docker 仓库状态
// @Accept json
// @Param request body dto.OperateByID true "request"
// @Produce json
// @Success 200
// @Security ApiKeyAuth
// @Router /containers/repo/status [get]
func (b *BaseApi) CheckRepoStatus(c *gin.Context) {
var req dto.OperateByID
2023-10-27 14:19:26 +08:00
if err := helper.CheckBindAndValidate(&req, c); err != nil {
2023-02-27 11:46:23 +08:00
return
}
2023-10-27 14:19:26 +08:00
2023-02-27 11:46:23 +08:00
if err := imageRepoService.Login(req); err != nil {
helper.ErrorWithDetail(c, constant.CodeErrInternalServer, constant.ErrTypeInternalServer, err)
return
}
helper.SuccessWithData(c, nil)
}
2023-01-04 22:31:51 +08:00
// @Tags Container Image-repo
// @Summary Create image repo
// @Description 创建镜像仓库
// @Accept json
2023-02-27 11:46:23 +08:00
// @Param request body dto.ImageRepoDelete true "request"
2023-01-04 22:31:51 +08:00
// @Produce json
// @Success 200
// @Security ApiKeyAuth
// @Router /containers/repo [post]
2023-10-07 15:46:44 +08:00
// @x-panel-log {"bodyKeys":["name"],"paramKeys":[],"BeforeFunctions":[],"formatZH":"创建镜像仓库 [name]","formatEN":"create image repo [name]"}
2022-10-09 16:17:15 +08:00
func (b *BaseApi) CreateRepo(c *gin.Context) {
var req dto.ImageRepoCreate
2023-10-27 14:19:26 +08:00
if err := helper.CheckBindAndValidate(&req, c); err != nil {
2022-10-09 16:17:15 +08:00
return
}
2023-10-27 14:19:26 +08:00
2022-10-09 16:17:15 +08:00
if err := imageRepoService.Create(req); err != nil {
helper.ErrorWithDetail(c, constant.CodeErrInternalServer, constant.ErrTypeInternalServer, err)
return
}
helper.SuccessWithData(c, nil)
}
2023-01-04 22:31:51 +08:00
// @Tags Container Image-repo
// @Summary Delete image repo
// @Description 删除镜像仓库
// @Accept json
// @Param request body dto.ImageRepoDelete true "request"
// @Produce json
// @Success 200
// @Security ApiKeyAuth
// @Router /containers/repo/del [post]
2023-10-07 15:46:44 +08:00
// @x-panel-log {"bodyKeys":["ids"],"paramKeys":[],"BeforeFunctions":[{"input_column":"id","input_value":"ids","isList":true,"db":"image_repos","output_column":"name","output_value":"names"}],"formatZH":"删除镜像仓库 [names]","formatEN":"delete image repo [names]"}
2022-10-09 16:17:15 +08:00
func (b *BaseApi) DeleteRepo(c *gin.Context) {
var req dto.ImageRepoDelete
2023-10-27 14:19:26 +08:00
if err := helper.CheckBindAndValidate(&req, c); err != nil {
2022-10-09 16:17:15 +08:00
return
}
if err := imageRepoService.BatchDelete(req); err != nil {
2022-10-09 16:17:15 +08:00
helper.ErrorWithDetail(c, constant.CodeErrInternalServer, constant.ErrTypeInternalServer, err)
return
}
helper.SuccessWithData(c, nil)
}
2023-01-04 22:31:51 +08:00
// @Tags Container Image-repo
// @Summary Update image repo
// @Description 更新镜像仓库
// @Accept json
// @Param request body dto.ImageRepoUpdate true "request"
// @Produce json
// @Success 200
// @Security ApiKeyAuth
// @Router /containers/repo/update [post]
2023-10-07 15:46:44 +08:00
// @x-panel-log {"bodyKeys":["id"],"paramKeys":[],"BeforeFunctions":[{"input_column":"id","input_value":"id","isList":false,"db":"image_repos","output_column":"name","output_value":"name"}],"formatZH":"更新镜像仓库 [name]","formatEN":"update image repo information [name]"}
2022-10-09 16:17:15 +08:00
func (b *BaseApi) UpdateRepo(c *gin.Context) {
var req dto.ImageRepoUpdate
2023-10-27 14:19:26 +08:00
if err := helper.CheckBindAndValidate(&req, c); err != nil {
2022-10-09 16:17:15 +08:00
return
}
if err := imageRepoService.Update(req); err != nil {
2022-10-09 16:17:15 +08:00
helper.ErrorWithDetail(c, constant.CodeErrInternalServer, constant.ErrTypeInternalServer, err)
return
}
helper.SuccessWithData(c, nil)
}