Skip to content

Commit

Permalink
feat: 新增文件夹导入导出及标签搜索 (#3475)
Browse files Browse the repository at this point in the history
  • Loading branch information
LidolLxf committed Sep 11, 2024
1 parent ca718ae commit 7ee648a
Show file tree
Hide file tree
Showing 20 changed files with 4,192 additions and 3,047 deletions.
466 changes: 466 additions & 0 deletions bcs-services/cluster-resources/cmd/http.go

Large diffs are not rendered by default.

1 change: 1 addition & 0 deletions bcs-services/cluster-resources/cmd/init.go
Original file line number Diff line number Diff line change
Expand Up @@ -342,6 +342,7 @@ func (crSvc *clusterResourcesService) initHTTPService() error {
log.Info(crSvc.ctx, "register grpc service handler to path /")
originMux := http.NewServeMux()
originMux.Handle("/", router)
originMux.Handle("/clusterresources/api/v1/", NewAPIRouter(crSvc))

// 检查是否需要启用 swagger 服务
if crSvc.conf.Swagger.Enabled {
Expand Down
102 changes: 49 additions & 53 deletions bcs-services/cluster-resources/go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -40,45 +40,45 @@ replace (

require (
github.com/Masterminds/sprig/v3 v3.2.3
github.com/Tencent/bk-bcs/bcs-common v0.0.0-20230920065036-5ec367ec2378
github.com/Tencent/bk-bcs/bcs-common v0.0.0-20240829030428-e44f1984734f
github.com/TencentBlueKing/gopkg v1.1.0
github.com/TencentBlueKing/iam-go-sdk v0.1.5
github.com/TencentBlueKing/iam-go-sdk v0.1.6
// fork 自 https://github.com/signalfx/splunk-otel-go/tree/main/instrumentation/k8s.io/client-go/splunkclient-go
// 待升级到 go1.18 后,可直接引用社区的包
github.com/adevjoe/opentelemetry-go-contrib/instrumentation/k8s.io/client-go v1.0.2
github.com/alicebob/miniredis v2.5.0+incompatible
github.com/araddon/dateparse v0.0.0-20210429162001-6b43995a97de
github.com/dustin/go-humanize v1.0.0
github.com/envoyproxy/protoc-gen-validate v1.0.2
github.com/envoyproxy/protoc-gen-validate v1.0.4
github.com/fatih/structs v1.1.0
github.com/go-micro/plugins/v4/registry/etcd v1.1.0
github.com/go-micro/plugins/v4/server/grpc v1.2.0
github.com/go-redis/cache/v8 v8.4.3
github.com/go-redis/redis/v8 v8.11.5
github.com/go-resty/resty/v2 v2.7.0
github.com/go-resty/resty/v2 v2.12.0
github.com/golang-jwt/jwt/v4 v4.5.0
github.com/golang/glog v1.1.0
github.com/golang/protobuf v1.5.3
github.com/google/uuid v1.3.1
github.com/golang/glog v1.2.0
github.com/golang/protobuf v1.5.4
github.com/google/uuid v1.6.0
github.com/gorilla/mux v1.8.0
github.com/grpc-ecosystem/grpc-gateway v1.16.0
github.com/hako/durafmt v0.0.0-20210608085754-5c1018a4e16b
github.com/mitchellh/mapstructure v1.5.0
github.com/patrickmn/go-cache v2.1.0+incompatible
github.com/pkg/errors v0.9.1
github.com/prometheus/client_golang v1.16.0
github.com/prometheus/client_golang v1.19.0
github.com/sirupsen/logrus v1.9.3
github.com/spf13/cast v1.5.0
github.com/stretchr/testify v1.8.4
github.com/stretchr/testify v1.9.0
github.com/tmc/grpc-websocket-proxy v0.0.0-20201229170055-e5319fda7802
go-micro.dev/v4 v4.10.2
go.opentelemetry.io/contrib/instrumentation/net/http/otelhttp v0.45.0
go.opentelemetry.io/otel v1.19.0
go.opentelemetry.io/otel/trace v1.19.0
go.uber.org/zap v1.19.1
google.golang.org/genproto v0.0.0-20230803162519-f966b187b2e5 // indirect
google.golang.org/grpc v1.58.3
google.golang.org/protobuf v1.31.0
google.golang.org/genproto v0.0.0-20240123012728-ef4313101c80 // indirect
google.golang.org/grpc v1.62.1
google.golang.org/protobuf v1.33.0
gopkg.in/natefinch/lumberjack.v2 v2.0.0
gopkg.in/yaml.v3 v3.0.1
k8s.io/api v0.29.0
Expand All @@ -103,40 +103,36 @@ require (
github.com/Masterminds/goutils v1.1.1 // indirect
github.com/Masterminds/semver/v3 v3.2.1 // indirect
github.com/Microsoft/go-winio v0.6.1 // indirect
github.com/ProtonMail/go-crypto v0.0.0-20220824120805-4b6e5c587895 // indirect
github.com/Tencent/bk-bcs/bcs-common/pkg/otel v0.0.0-20230606084703-25ffabad186a
github.com/acomagu/bufpipe v1.0.3 // indirect
github.com/ProtonMail/go-crypto v1.0.0 // indirect
github.com/alicebob/gopher-json v0.0.0-20230218143504-906a9b012302 // indirect
github.com/benbjohnson/clock v1.3.0 // indirect
github.com/beorn7/perks v1.0.1 // indirect
github.com/bitly/go-simplejson v0.5.0 // indirect
github.com/bmizerany/assert v0.0.0-20160611221934-b7ed37b82869 // indirect
github.com/cenkalti/backoff/v4 v4.2.1 // indirect
github.com/cespare/xxhash/v2 v2.2.0 // indirect
github.com/cloudflare/circl v1.2.0 // indirect
github.com/cloudflare/circl v1.3.7 // indirect
github.com/coreos/go-semver v0.3.0
github.com/coreos/go-systemd/v22 v22.3.2 // indirect
github.com/cpuguy83/go-md2man/v2 v2.0.3 // indirect
github.com/davecgh/go-spew v1.1.1 // indirect
github.com/dgryski/go-rendezvous v0.0.0-20200823014737-9f7001d12a5f // indirect
github.com/emirpasic/gods v1.18.1 // indirect
github.com/evanphx/json-patch/v5 v5.5.0 // indirect
github.com/felixge/httpsnoop v1.0.3 // indirect
github.com/felixge/httpsnoop v1.0.4 // indirect
github.com/fsnotify/fsnotify v1.6.0 // indirect
github.com/ghodss/yaml v1.0.0 // indirect
github.com/go-acme/lego/v4 v4.4.0 // indirect
github.com/go-git/gcfg v1.5.0 // indirect
github.com/go-git/go-billy/v5 v5.3.1 // indirect
github.com/go-git/go-git/v5 v5.4.2 // indirect
github.com/go-logr/logr v1.3.0 // indirect
github.com/go-git/gcfg v1.5.1-0.20230307220236-3a3c6141e376 // indirect
github.com/go-git/go-billy/v5 v5.5.0 // indirect
github.com/go-git/go-git/v5 v5.12.0 // indirect
github.com/go-logr/logr v1.4.1 // indirect
github.com/go-logr/stdr v1.2.2 // indirect
github.com/go-openapi/jsonpointer v0.20.0 // indirect
github.com/go-openapi/jsonreference v0.20.2 // indirect
github.com/go-openapi/spec v0.20.6 // indirect
github.com/go-openapi/swag v0.22.4 // indirect
github.com/go-playground/locales v0.14.1 // indirect
github.com/go-playground/universal-translator v0.18.1 // indirect
github.com/go-playground/validator/v10 v10.11.2 // indirect
github.com/go-playground/validator/v10 v10.19.0 // indirect
github.com/gobwas/httphead v0.1.0 // indirect
github.com/gobwas/pool v0.2.1 // indirect
github.com/gobwas/ws v1.0.4 // indirect
Expand All @@ -155,12 +151,10 @@ require (
github.com/json-iterator/go v1.1.12 // indirect
github.com/kevinburke/ssh_config v1.2.0 // indirect
github.com/klauspost/compress v1.16.0 // indirect
github.com/leodido/go-urn v1.2.2 // indirect
github.com/leodido/go-urn v1.4.0 // indirect
github.com/mailru/easyjson v0.7.7 // indirect
github.com/matttproud/golang_protobuf_extensions v1.0.4 // indirect
github.com/miekg/dns v1.1.50 // indirect
github.com/mitchellh/copystructure v1.2.0 // indirect
github.com/mitchellh/go-homedir v1.1.0 // indirect
github.com/mitchellh/hashstructure v1.1.0 // indirect
github.com/mitchellh/reflectwalk v1.0.2 // indirect
github.com/moby/spdystream v0.2.0 // indirect
Expand All @@ -171,22 +165,22 @@ require (
github.com/oxtoacart/bpool v0.0.0-20190530202638-03653db5a59c // indirect
github.com/parnurzeal/gorequest v0.2.16 // indirect
github.com/pmezard/go-difflib v1.0.0 // indirect
github.com/prometheus/client_model v0.4.0 // indirect
github.com/prometheus/common v0.44.0 // indirect
github.com/prometheus/procfs v0.10.1 // indirect
github.com/prometheus/client_model v0.5.0 // indirect
github.com/prometheus/common v0.48.0 // indirect
github.com/prometheus/procfs v0.12.0 // indirect
github.com/russross/blackfriday/v2 v2.1.0 // indirect
github.com/sergi/go-diff v1.2.0 // indirect
github.com/sergi/go-diff v1.3.2-0.20230802210424-5b0b94c5c0d3 // indirect
github.com/shopspring/decimal v1.3.1 // indirect
github.com/spf13/pflag v1.0.5 // indirect
github.com/swaggo/files v1.0.1 // indirect
github.com/swaggo/http-swagger v1.3.4
github.com/swaggo/swag v1.8.1 // indirect
github.com/ugorji/go/codec v1.2.9 // indirect
github.com/ugorji/go/codec v1.2.11 // indirect
github.com/urfave/cli/v2 v2.3.0 // indirect
github.com/vmihailenco/go-tinylfu v0.2.2 // indirect
github.com/vmihailenco/msgpack/v5 v5.3.4 // indirect
github.com/vmihailenco/tagparser/v2 v2.0.0 // indirect
github.com/xanzy/ssh-agent v0.3.2 // indirect
github.com/xanzy/ssh-agent v0.3.3 // indirect
github.com/xdg-go/pbkdf2 v1.0.0 // indirect
github.com/xdg-go/scram v1.1.2 // indirect
github.com/xdg-go/stringprep v1.0.4 // indirect
Expand All @@ -198,19 +192,18 @@ require (
go.opentelemetry.io/otel/metric v1.19.0 // indirect
go.uber.org/atomic v1.10.0 // indirect
go.uber.org/multierr v1.11.0 // indirect
golang.org/x/crypto v0.17.0 // indirect
golang.org/x/crypto v0.21.0 // indirect
golang.org/x/exp v0.0.0-20230315142452-642cacee5cc0 // indirect
golang.org/x/mod v0.11.0 // indirect
golang.org/x/net v0.17.0 // indirect
golang.org/x/oauth2 v0.10.0 // indirect
golang.org/x/sync v0.3.0
golang.org/x/sys v0.15.0 // indirect
golang.org/x/term v0.15.0 // indirect
golang.org/x/mod v0.12.0 // indirect
golang.org/x/net v0.23.0 // indirect
golang.org/x/oauth2 v0.18.0 // indirect
golang.org/x/sync v0.6.0
golang.org/x/sys v0.18.0 // indirect
golang.org/x/term v0.18.0 // indirect
golang.org/x/text v0.14.0 // indirect
golang.org/x/time v0.3.0 // indirect
golang.org/x/tools v0.10.0 // indirect
google.golang.org/appengine v1.6.7 // indirect
google.golang.org/grpc/examples v0.0.0-20211102180624-670c133e568e // indirect
golang.org/x/time v0.5.0 // indirect
golang.org/x/tools v0.13.0 // indirect
google.golang.org/appengine v1.6.8 // indirect
gopkg.in/inf.v0 v0.9.1 // indirect
gopkg.in/tomb.v1 v1.0.0-20141024135613-dd632973f1e7 // indirect
gopkg.in/warnings.v0 v0.1.2 // indirect
Expand All @@ -225,35 +218,37 @@ require (
)

require (
github.com/Tencent/bk-bcs/bcs-services/pkg v0.0.0-20230701022721-8cbd62252af8
github.com/TencentBlueKing/bk-audit-go-sdk v0.0.5 // indirect
github.com/Tencent/bk-bcs/bcs-services/pkg v0.0.0-20240829030428-e44f1984734f
github.com/TencentBlueKing/bk-audit-go-sdk v0.0.6 // indirect
)

require (
github.com/Tencent/bk-bcs/bcs-common/pkg/audit v0.0.0-20231031062827-2cd36075dfea
github.com/Tencent/bk-bcs/bcs-common/pkg/auth v0.0.0-20230921024236-fc3b5f7e6d87
github.com/Tencent/bk-bcs/bcs-scenarios/kourse v0.0.0-20231011121510-d30829b961ad
github.com/go-redis/redis/extra/redisotel/v8 v8.11.5
github.com/googleapis/gnostic v0.5.5
github.com/mitchellh/hashstructure/v2 v2.0.2
go.opentelemetry.io/contrib/instrumentation/go.mongodb.org/mongo-driver/mongo/otelmongo v0.44.0
google.golang.org/genproto/googleapis/api v0.0.0-20230726155614-23370e0ffb3e
google.golang.org/genproto/googleapis/api v0.0.0-20240318140521-94a12d6c2237
helm.sh/helm/v3 v3.14.0
k8s.io/apiextensions-apiserver v0.29.0
)

require (
dario.cat/mergo v1.0.0 // indirect
github.com/Azure/go-ansiterm v0.0.0-20230124172434-306776ec8161 // indirect
github.com/MakeNowJust/heredoc v1.0.0 // indirect
github.com/bmizerany/assert v0.0.0-20160611221934-b7ed37b82869 // indirect
github.com/chai2010/gettext-go v1.0.2 // indirect
github.com/cyphar/filepath-securejoin v0.2.4 // indirect
github.com/evanphx/json-patch v5.7.0+incompatible // indirect
github.com/exponent-io/jsonpath v0.0.0-20151013193312-d6023ce2651d // indirect
github.com/fatih/camelcase v1.0.0 // indirect
github.com/gabriel-vasile/mimetype v1.4.3 // indirect
github.com/go-errors/errors v1.4.2 // indirect
github.com/go-redis/redis/extra/rediscmd/v8 v8.11.5 // indirect
github.com/go-sql-driver/mysql v1.7.1 // indirect
github.com/golang-migrate/migrate/v4 v4.16.2 // indirect
github.com/golang-migrate/migrate/v4 v4.17.0 // indirect
github.com/golang/groupcache v0.0.0-20210331224755-41bb18bfe9da // indirect
github.com/google/btree v1.0.1 // indirect
github.com/google/shlex v0.0.0-20191202100458-e7afc7fbc510 // indirect
github.com/gregjones/httpcache v0.0.0-20180305231024-9cad4c3443a7 // indirect
Expand All @@ -266,19 +261,20 @@ require (
github.com/monochromegane/go-gitignore v0.0.0-20200626010858-205db1a8cc00 // indirect
github.com/montanaflynn/stats v0.0.0-20171201202039-1bf9dbcd8cbe // indirect
github.com/peterbourgon/diskv v2.0.1+incompatible // indirect
github.com/pjbgf/sha1cd v0.3.0 // indirect
github.com/russross/blackfriday v1.5.2 // indirect
github.com/signalfx/splunk-otel-go v1.4.0 // indirect
github.com/skeema/knownhosts v1.2.2 // indirect
github.com/spf13/cobra v1.8.0 // indirect
github.com/xeipuuv/gojsonpointer v0.0.0-20190905194746-02993c407bfb // indirect
github.com/xeipuuv/gojsonreference v0.0.0-20180127040603-bd5ef7bd5415 // indirect
github.com/xeipuuv/gojsonschema v1.2.0 // indirect
github.com/xlab/treeprint v1.2.0 // indirect
go.starlark.net v0.0.0-20230525235612-a134d8f9ddca // indirect
google.golang.org/genproto/googleapis/rpc v0.0.0-20230822172742-b8732ec3820d // indirect
google.golang.org/genproto/googleapis/rpc v0.0.0-20240318140521-94a12d6c2237 // indirect
k8s.io/cli-runtime v0.29.0 // indirect
k8s.io/component-base v0.29.0 // indirect
k8s.io/klog v1.0.0 // indirect
k8s.io/kubernetes v0.0.0-00010101000000-000000000000 // indirect
k8s.io/kubernetes v1.13.0 // indirect
sigs.k8s.io/kustomize/api v0.13.5-0.20230601165947-6ce0bf390ce3 // indirect
sigs.k8s.io/kustomize/kyaml v0.14.3-0.20230601165947-6ce0bf390ce3 // indirect
)
Original file line number Diff line number Diff line change
Expand Up @@ -106,7 +106,8 @@ func (t *TemplateSpaceAction) Get(ctx context.Context, id string) (map[string]in
}

// List xxx
func (t *TemplateSpaceAction) List(ctx context.Context, name string) ([]map[string]interface{}, error) {
func (t *TemplateSpaceAction) List(
ctx context.Context, req *clusterRes.ListTemplateSpaceReq) ([]map[string]interface{}, error) {
if err := t.checkAccess(ctx); err != nil {
return nil, err
}
Expand All @@ -121,9 +122,16 @@ func (t *TemplateSpaceAction) List(ctx context.Context, name string) ([]map[stri
entity.FieldKeyProjectCode: p.Code,
}
// 如果名称不为空,则通过文件夹名称模糊查询
if name != "" {
if req.GetName() != "" {
operatorM[entity.FieldKeyName] = operator.M{
"$regex": name,
"$regex": req.GetName(),
}
}

// 文件夹标签筛选
if len(req.GetTags()) != 0 {
operatorM[entity.FieldKeyTags] = operator.M{
"$all": req.GetTags(),
}
}

Expand Down Expand Up @@ -189,6 +197,7 @@ func (t *TemplateSpaceAction) Create(ctx context.Context, req *clusterRes.Create
Name: req.GetName(),
ProjectCode: p.Code,
Description: req.GetDescription(),
Tags: req.GetTags(),
}
id, err := t.model.CreateTemplateSpace(ctx, templateSpace)
if err != nil {
Expand Down Expand Up @@ -257,6 +266,7 @@ func (t *TemplateSpaceAction) Update(ctx context.Context, req *clusterRes.Update
updateTemplateSpace := entity.M{
"name": req.GetName(),
"description": req.GetDescription(),
"tags": req.GetTags(),
}
if err = t.model.UpdateTemplateSpace(ctx, req.GetId(), updateTemplateSpace); err != nil {
return err
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ func (h *Handler) GetTemplateSpace(
func (h *Handler) ListTemplateSpace(
ctx context.Context, in *clusterRes.ListTemplateSpaceReq, out *clusterRes.CommonListResp) error {
action := templatespace.NewTemplateSpaceAction(h.model)
data, err := action.List(ctx, in.Name)
data, err := action.List(ctx, in)
if err != nil {
return err
}
Expand Down
3 changes: 3 additions & 0 deletions bcs-services/cluster-resources/pkg/i18n/contants.go
Original file line number Diff line number Diff line change
Expand Up @@ -42,3 +42,6 @@ var langMap = map[string]string{

// MetadataCookiesKey 在 GoMicro Metadata 中,Cookie 的键名
const MetadataCookiesKey = "Grpcgateway-Cookie"

// LangCookieName 语言版本 Cookie 名称
const LangCookieName = "blueking_language"
13 changes: 13 additions & 0 deletions bcs-services/cluster-resources/pkg/i18n/i18n.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ package i18n

import (
"context"
"net/http"
"strings"

"go-micro.dev/v4/metadata"
Expand Down Expand Up @@ -45,6 +46,18 @@ func GetLangFromCookies(md metadata.Metadata) string {
return DefaultLang
}

// GetLangFromReqCookies 从 Cookies 中获取语言版本
func GetLangFromReqCookies(req *http.Request) string {
cookie, err := req.Cookie(LangCookieName)
if err != nil {
return DefaultLang
}
if lang, ok := langMap[strings.ToLower(cookie.Value)]; ok {
return lang
}
return DefaultLang
}

// GetLangFromContext 从 Context 中获取语言版本
func GetLangFromContext(ctx context.Context) string {
if lang := ctx.Value(ctxkey.LangKey); lang != nil {
Expand Down
2 changes: 2 additions & 0 deletions bcs-services/cluster-resources/pkg/i18n/locale/lc_msgs.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@
en: "Do not have permission to view this project"
- msgID: 无权限访问
en: "No access permission"
- msgID: templateSpaceNames没找到或者无权限访问
en: "templateSpaceNames not found or no access permission"
- msgID: 环境名称已存在
en: "The environment name already exists."
- msgID: 视图名称重复
Expand Down
1 change: 1 addition & 0 deletions bcs-services/cluster-resources/pkg/store/entity/keys.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ const (
FieldKeyVersion = "version"
FieldKeyTemplateName = "templateName"
FieldKeyEnv = "env"
FieldKeyTags = "tags"

FieldKeyCreateBy = "createBy"
FieldKeyCreator = "creator"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ type TemplateSpace struct {
ProjectCode string `json:"projectCode" bson:"projectCode"`
Description string `json:"description" bson:"description"`
Fav bool `json:"fav" bson:"-"` // 是否收藏
Tags []string `json:"tags" bson:"tags"`
}

// ToMap trans templatespace to map
Expand All @@ -36,5 +37,6 @@ func (t *TemplateSpace) ToMap() map[string]interface{} {
m["projectCode"] = t.ProjectCode
m["description"] = t.Description
m["fav"] = t.Fav
m["tags"] = t.Tags
return m
}
1 change: 1 addition & 0 deletions bcs-services/cluster-resources/pkg/store/store.go
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@ type ClusterResourcesModel interface {
GetTemplateSpace(ctx context.Context, id string) (*entity.TemplateSpace, error)
ListTemplateSpace(ctx context.Context, cond *operator.Condition) ([]*entity.TemplateSpace, error)
CreateTemplateSpace(ctx context.Context, templateSpace *entity.TemplateSpace) (string, error)
CreateTemplateSpaceBatch(ctx context.Context, templateSpace []*entity.TemplateSpace) error
UpdateTemplateSpace(ctx context.Context, id string, templateSpace entity.M) error
DeleteTemplateSpace(ctx context.Context, id string) error

Expand Down
Loading

0 comments on commit 7ee648a

Please sign in to comment.