2022-10-09 08:17:15 +00:00
|
|
|
package v1
|
|
|
|
|
|
|
|
import (
|
2022-10-18 10:39:45 +00: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"
|
|
|
|
"github.com/1Panel-dev/1Panel/backend/global"
|
2022-10-09 08:17:15 +00:00
|
|
|
"github.com/gin-gonic/gin"
|
|
|
|
)
|
|
|
|
|
2023-01-04 14:31:51 +00:00
|
|
|
// @Tags Container Image-repo
|
2023-01-05 03:57:03 +00:00
|
|
|
// @Summary Page image repos
|
2023-01-04 14:31:51 +00:00
|
|
|
// @Description 获取镜像仓库列表分页
|
|
|
|
// @Accept json
|
2023-02-07 10:48:32 +00:00
|
|
|
// @Param request body dto.SearchWithPage true "request"
|
2023-01-04 14:31:51 +00:00
|
|
|
// @Produce json
|
|
|
|
// @Success 200 {object} dto.PageResult
|
|
|
|
// @Security ApiKeyAuth
|
|
|
|
// @Router /containers/repo/search [post]
|
2022-10-10 07:14:49 +00:00
|
|
|
func (b *BaseApi) SearchRepo(c *gin.Context) {
|
2023-02-07 10:48:32 +00:00
|
|
|
var req dto.SearchWithPage
|
2022-10-09 08:17:15 +00:00
|
|
|
if err := c.ShouldBindJSON(&req); err != nil {
|
|
|
|
helper.ErrorWithDetail(c, constant.CodeErrBadRequest, constant.ErrTypeInvalidParams, err)
|
|
|
|
return
|
|
|
|
}
|
2022-10-10 07:14:49 +00:00
|
|
|
if err := global.VALID.Struct(req); err != nil {
|
|
|
|
helper.ErrorWithDetail(c, constant.CodeErrBadRequest, constant.ErrTypeInvalidParams, err)
|
|
|
|
return
|
|
|
|
}
|
2022-10-09 08:17:15 +00: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 14:31:51 +00:00
|
|
|
// @Tags Container Image-repo
|
2023-01-05 03:57:03 +00:00
|
|
|
// @Summary List image repos
|
2023-01-04 14:31:51 +00:00
|
|
|
// @Description 获取镜像仓库列表
|
|
|
|
// @Produce json
|
|
|
|
// @Success 200 {anrry} dto.ImageRepoOption
|
|
|
|
// @Security ApiKeyAuth
|
|
|
|
// @Router /containers/repo [get]
|
2022-10-10 07:14:49 +00:00
|
|
|
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 03:46:23 +00: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
|
|
|
|
if err := c.ShouldBindJSON(&req); err != nil {
|
|
|
|
helper.ErrorWithDetail(c, constant.CodeErrBadRequest, constant.ErrTypeInvalidParams, err)
|
|
|
|
return
|
|
|
|
}
|
|
|
|
if err := global.VALID.Struct(req); err != nil {
|
|
|
|
helper.ErrorWithDetail(c, constant.CodeErrBadRequest, constant.ErrTypeInvalidParams, err)
|
|
|
|
return
|
|
|
|
}
|
|
|
|
if err := imageRepoService.Login(req); err != nil {
|
|
|
|
helper.ErrorWithDetail(c, constant.CodeErrInternalServer, constant.ErrTypeInternalServer, err)
|
|
|
|
return
|
|
|
|
}
|
|
|
|
helper.SuccessWithData(c, nil)
|
|
|
|
}
|
|
|
|
|
2023-01-04 14:31:51 +00:00
|
|
|
// @Tags Container Image-repo
|
|
|
|
// @Summary Create image repo
|
|
|
|
// @Description 创建镜像仓库
|
|
|
|
// @Accept json
|
2023-02-27 03:46:23 +00:00
|
|
|
// @Param request body dto.ImageRepoDelete true "request"
|
2023-01-04 14:31:51 +00:00
|
|
|
// @Produce json
|
|
|
|
// @Success 200
|
|
|
|
// @Security ApiKeyAuth
|
|
|
|
// @Router /containers/repo [post]
|
|
|
|
// @x-panel-log {"bodyKeys":["name"],"paramKeys":[],"BeforeFuntions":[],"formatZH":"创建镜像仓库 [name]","formatEN":"create image repo [name]"}
|
2022-10-09 08:17:15 +00:00
|
|
|
func (b *BaseApi) CreateRepo(c *gin.Context) {
|
|
|
|
var req dto.ImageRepoCreate
|
|
|
|
if err := c.ShouldBindJSON(&req); err != nil {
|
|
|
|
helper.ErrorWithDetail(c, constant.CodeErrBadRequest, constant.ErrTypeInvalidParams, err)
|
|
|
|
return
|
|
|
|
}
|
|
|
|
if err := global.VALID.Struct(req); err != nil {
|
|
|
|
helper.ErrorWithDetail(c, constant.CodeErrBadRequest, constant.ErrTypeInvalidParams, err)
|
|
|
|
return
|
|
|
|
}
|
|
|
|
if err := imageRepoService.Create(req); err != nil {
|
|
|
|
helper.ErrorWithDetail(c, constant.CodeErrInternalServer, constant.ErrTypeInternalServer, err)
|
|
|
|
return
|
|
|
|
}
|
|
|
|
helper.SuccessWithData(c, nil)
|
|
|
|
}
|
|
|
|
|
2023-01-04 14:31:51 +00: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]
|
|
|
|
// @x-panel-log {"bodyKeys":["ids"],"paramKeys":[],"BeforeFuntions":[{"input_colume":"id","input_value":"ids","isList":true,"db":"image_repos","output_colume":"name","output_value":"names"}],"formatZH":"删除镜像仓库 [names]","formatEN":"delete image repo [names]"}
|
2022-10-09 08:17:15 +00:00
|
|
|
func (b *BaseApi) DeleteRepo(c *gin.Context) {
|
2022-12-20 05:23:01 +00:00
|
|
|
var req dto.ImageRepoDelete
|
2022-10-09 08:17:15 +00:00
|
|
|
if err := c.ShouldBindJSON(&req); err != nil {
|
|
|
|
helper.ErrorWithDetail(c, constant.CodeErrBadRequest, constant.ErrTypeInvalidParams, err)
|
|
|
|
return
|
|
|
|
}
|
|
|
|
if err := global.VALID.Struct(req); err != nil {
|
|
|
|
helper.ErrorWithDetail(c, constant.CodeErrBadRequest, constant.ErrTypeInvalidParams, err)
|
|
|
|
return
|
|
|
|
}
|
|
|
|
|
2022-12-20 05:23:01 +00:00
|
|
|
if err := imageRepoService.BatchDelete(req); err != nil {
|
2022-10-09 08:17:15 +00:00
|
|
|
helper.ErrorWithDetail(c, constant.CodeErrInternalServer, constant.ErrTypeInternalServer, err)
|
|
|
|
return
|
|
|
|
}
|
|
|
|
helper.SuccessWithData(c, nil)
|
|
|
|
}
|
|
|
|
|
2023-01-04 14:31:51 +00: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]
|
|
|
|
// @x-panel-log {"bodyKeys":["id"],"paramKeys":[],"BeforeFuntions":[{"input_column":"id","input_value":"id","isList":false,"db":"image_repos","output_colume":"name","output_value":"name"}],"formatZH":"更新镜像仓库 [name]","formatEN":"update image repo information [name]"}
|
2022-10-09 08:17:15 +00:00
|
|
|
func (b *BaseApi) UpdateRepo(c *gin.Context) {
|
|
|
|
var req dto.ImageRepoUpdate
|
|
|
|
if err := c.ShouldBindJSON(&req); err != nil {
|
|
|
|
helper.ErrorWithDetail(c, constant.CodeErrBadRequest, constant.ErrTypeInvalidParams, err)
|
|
|
|
return
|
|
|
|
}
|
|
|
|
if err := global.VALID.Struct(req); err != nil {
|
|
|
|
helper.ErrorWithDetail(c, constant.CodeErrBadRequest, constant.ErrTypeInvalidParams, err)
|
|
|
|
return
|
|
|
|
}
|
|
|
|
|
2022-12-18 15:00:24 +00:00
|
|
|
if err := imageRepoService.Update(req); err != nil {
|
2022-10-09 08:17:15 +00:00
|
|
|
helper.ErrorWithDetail(c, constant.CodeErrInternalServer, constant.ErrTypeInternalServer, err)
|
|
|
|
return
|
|
|
|
}
|
|
|
|
helper.SuccessWithData(c, nil)
|
|
|
|
}
|