mirror of
https://gitee.com/rainbond/Rainbond.git
synced 2024-11-29 18:27:58 +08:00
feat: support image search (#1846)
This commit is contained in:
parent
2a4e3b219d
commit
4ac23ecef9
@ -287,3 +287,9 @@ type PodInterface interface {
|
||||
type RegistryAuthSecretInterface interface {
|
||||
RegistryAuthSecret(w http.ResponseWriter, r *http.Request)
|
||||
}
|
||||
|
||||
// RegistryInterface registry interface
|
||||
type RegistryInterface interface {
|
||||
GetAllRepo(w http.ResponseWriter, r *http.Request)
|
||||
GetTagsByRepoName(w http.ResponseWriter, r *http.Request)
|
||||
}
|
||||
|
@ -63,6 +63,15 @@ func (v2 *V2) Routes() chi.Router {
|
||||
r.Mount("/enterprise/{enterprise_id}", v2.enterpriseRouter())
|
||||
r.Mount("/monitor", v2.monitorRouter())
|
||||
r.Mount("/helm", v2.helmRouter())
|
||||
r.Mount("/proxy-pass", v2.proxyRoute())
|
||||
|
||||
return r
|
||||
}
|
||||
|
||||
func (v2 *V2) proxyRoute() chi.Router {
|
||||
r := chi.NewRouter()
|
||||
r.Post("/registry/repos", controller.GetManager().GetAllRepo)
|
||||
r.Post("/registry/tags", controller.GetManager().GetTagsByRepoName)
|
||||
return r
|
||||
}
|
||||
|
||||
|
@ -50,6 +50,7 @@ type V2Manager interface {
|
||||
api.ApplicationInterface
|
||||
api.RegistryAuthSecretInterface
|
||||
api.HelmInterface
|
||||
api.RegistryInterface
|
||||
}
|
||||
|
||||
var defaultV2Manager V2Manager
|
||||
|
59
api/controller/registry.go
Normal file
59
api/controller/registry.go
Normal file
@ -0,0 +1,59 @@
|
||||
package controller
|
||||
|
||||
import (
|
||||
api_model "github.com/goodrain/rainbond/api/model"
|
||||
"github.com/goodrain/rainbond/api/util/bcode"
|
||||
"github.com/goodrain/rainbond/builder/sources/registry"
|
||||
httputil "github.com/goodrain/rainbond/util/http"
|
||||
"github.com/sirupsen/logrus"
|
||||
"net/http"
|
||||
)
|
||||
|
||||
// Registry -
|
||||
type Registry struct {
|
||||
}
|
||||
|
||||
// GetAllRepo 根据镜像仓库账号密码 获取所有的镜像仓库
|
||||
func (r2 *Registry) GetAllRepo(w http.ResponseWriter, r *http.Request) {
|
||||
var req api_model.SearchByDomainRequest
|
||||
ok := httputil.ValidatorRequestStructAndErrorResponse(r, w, &req, nil)
|
||||
if !ok {
|
||||
return
|
||||
}
|
||||
c, err := registry.NewInsecure(req.Domain, req.UserName, req.Password)
|
||||
if err != nil {
|
||||
httputil.ReturnBcodeError(r, w, bcode.NewBadRequest(err.Error()))
|
||||
logrus.Errorf("get repositories error %s", err.Error())
|
||||
return
|
||||
}
|
||||
repositories, err := c.Repositories()
|
||||
if err != nil {
|
||||
httputil.ReturnBcodeError(r, w, bcode.NewBadRequest(err.Error()))
|
||||
logrus.Errorf("get repositories error %s", err.Error())
|
||||
return
|
||||
}
|
||||
httputil.ReturnSuccess(r, w, repositories)
|
||||
}
|
||||
|
||||
// GetTagsByRepoName 根据镜像仓库账号密码 获取镜像tags
|
||||
func (r2 *Registry) GetTagsByRepoName(w http.ResponseWriter, r *http.Request) {
|
||||
var req api_model.SearchByDomainRequest
|
||||
ok := httputil.ValidatorRequestStructAndErrorResponse(r, w, &req, nil)
|
||||
if !ok {
|
||||
return
|
||||
}
|
||||
c, err := registry.NewInsecure(req.Domain, req.UserName, req.Password)
|
||||
if err != nil {
|
||||
httputil.ReturnBcodeError(r, w, bcode.NewBadRequest(err.Error()))
|
||||
logrus.Errorf("get tags error %s", err.Error())
|
||||
return
|
||||
}
|
||||
|
||||
tags, err := c.Tags(r.URL.Query().Get("repo"))
|
||||
if err != nil {
|
||||
httputil.ReturnBcodeError(r, w, bcode.NewBadRequest(err.Error()))
|
||||
logrus.Errorf("get tags error %s", err.Error())
|
||||
return
|
||||
}
|
||||
httputil.ReturnSuccess(r, w, tags)
|
||||
}
|
@ -64,6 +64,7 @@ type V2Routes struct {
|
||||
RegistryAuthSecretStruct
|
||||
K8sAttributeController
|
||||
HelmStruct
|
||||
Registry
|
||||
}
|
||||
|
||||
// Show test
|
||||
|
8
api/model/registry.go
Normal file
8
api/model/registry.go
Normal file
@ -0,0 +1,8 @@
|
||||
package model
|
||||
|
||||
// SearchByDomainRequest 根据地址账号密码查询所有的仓库信息
|
||||
type SearchByDomainRequest struct {
|
||||
Domain string `json:"domain" validate:"domain|required"`
|
||||
UserName string `json:"username"`
|
||||
Password string `json:"password"`
|
||||
}
|
Loading…
Reference in New Issue
Block a user