Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: support image search #1846

Merged
merged 1 commit into from
Jan 11, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions api/api/api_interface.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}
9 changes: 9 additions & 0 deletions api/api_routers/version2/v2Routers.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
}

Expand Down
1 change: 1 addition & 0 deletions api/controller/manager.go
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,7 @@ type V2Manager interface {
api.ApplicationInterface
api.RegistryAuthSecretInterface
api.HelmInterface
api.RegistryInterface
}

var defaultV2Manager V2Manager
Expand Down
59 changes: 59 additions & 0 deletions api/controller/registry.go
Original file line number Diff line number Diff line change
@@ -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)
}
1 change: 1 addition & 0 deletions api/controller/resources.go
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,7 @@ type V2Routes struct {
RegistryAuthSecretStruct
K8sAttributeController
HelmStruct
Registry
}

// Show test
Expand Down
8 changes: 8 additions & 0 deletions api/model/registry.go
Original file line number Diff line number Diff line change
@@ -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