mirror of
https://github.com/kubevela/kubevela.git
synced 2026-08-27 16:17:34 +00:00
Fix: delete addon registry (#2594)
* Fix: delete addon registry * add validate Git should not be empty * fix token could be nil * GitSource Repo url is a must
This commit is contained in:
@@ -26,7 +26,7 @@ type AddonRegistry struct {
|
||||
|
||||
// GitAddonSource defines the information about the Git as addon source
|
||||
type GitAddonSource struct {
|
||||
URL string `json:"url,omitempty"`
|
||||
URL string `json:"url,omitempty" validate:"required"`
|
||||
Path string `json:"path,omitempty"`
|
||||
Token string `json:"token,omitempty"`
|
||||
}
|
||||
|
||||
@@ -51,7 +51,7 @@ type EmptyResponse struct{}
|
||||
// CreateAddonRegistryRequest defines the format for addon registry create request
|
||||
type CreateAddonRegistryRequest struct {
|
||||
Name string `json:"name" validate:"checkname"`
|
||||
Git *model.GitAddonSource `json:"git,omitempty"`
|
||||
Git *model.GitAddonSource `json:"git,omitempty" validate:"required"`
|
||||
}
|
||||
|
||||
// AddonRegistryMeta defines the format for a single addon registry
|
||||
|
||||
@@ -5,7 +5,6 @@ import (
|
||||
"context"
|
||||
"errors"
|
||||
"fmt"
|
||||
"net/http"
|
||||
"net/url"
|
||||
"path"
|
||||
"sort"
|
||||
@@ -47,6 +46,7 @@ const (
|
||||
type AddonUsecase interface {
|
||||
GetAddonRegistryModel(ctx context.Context, name string) (*model.AddonRegistry, error)
|
||||
CreateAddonRegistry(ctx context.Context, req apis.CreateAddonRegistryRequest) (*apis.AddonRegistryMeta, error)
|
||||
DeleteAddonRegistry(ctx context.Context, name string) error
|
||||
ListAddonRegistries(ctx context.Context) ([]*apis.AddonRegistryMeta, error)
|
||||
ListAddons(ctx context.Context, detailed bool, query string) ([]*apis.DetailAddonResponse, error)
|
||||
StatusAddon(name string) (*apis.AddonStatusResponse, error)
|
||||
@@ -158,6 +158,10 @@ func (u *addonUsecaseImpl) ListAddons(ctx context.Context, detailed bool, query
|
||||
return addons, nil
|
||||
}
|
||||
|
||||
func (u *addonUsecaseImpl) DeleteAddonRegistry(ctx context.Context, name string) error {
|
||||
return u.ds.Delete(ctx, &model.AddonRegistry{Name: name})
|
||||
}
|
||||
|
||||
func (u *addonUsecaseImpl) CreateAddonRegistry(ctx context.Context, req apis.CreateAddonRegistryRequest) (*apis.AddonRegistryMeta, error) {
|
||||
r := addonRegistryModelFromCreateAddonRegistryRequest(req)
|
||||
|
||||
@@ -312,13 +316,11 @@ func hasAddon(addons []*apis.DetailAddonResponse, name string) bool {
|
||||
func getAddonsFromGit(baseURL, dir, token string, detailed bool) ([]*apis.DetailAddonResponse, error) {
|
||||
addons := []*apis.DetailAddonResponse{}
|
||||
dec := yaml.NewDecodingSerializer(unstructured.UnstructuredJSONScheme)
|
||||
var tc *http.Client
|
||||
var ts oauth2.TokenSource
|
||||
if token != "" {
|
||||
ts := oauth2.StaticTokenSource(
|
||||
&oauth2.Token{AccessToken: token},
|
||||
)
|
||||
tc = oauth2.NewClient(context.Background(), ts)
|
||||
ts = oauth2.StaticTokenSource(&oauth2.Token{AccessToken: token})
|
||||
}
|
||||
tc := oauth2.NewClient(context.Background(), ts)
|
||||
tc.Timeout = time.Second * 10
|
||||
clt := github.NewClient(tc)
|
||||
// TODO add error handling
|
||||
|
||||
@@ -108,6 +108,11 @@ func (s *addonRegistryWebService) deleteAddonRegistry(req *restful.Request, res
|
||||
bcode.ReturnError(req, res, err)
|
||||
return
|
||||
}
|
||||
err = s.addonUsecase.DeleteAddonRegistry(req.Request.Context(), r.Name)
|
||||
if err != nil {
|
||||
bcode.ReturnError(req, res, err)
|
||||
return
|
||||
}
|
||||
|
||||
if err := res.WriteEntity(*utils.ConvertAddonRegistryModel2AddonRegistryMeta(r)); err != nil {
|
||||
bcode.ReturnError(req, res, err)
|
||||
|
||||
Reference in New Issue
Block a user