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

feature: bscp cmd/ lint #2640

Merged
merged 18 commits into from
Oct 8, 2023
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
1 change: 1 addition & 0 deletions bcs-services/bcs-bscp/cmd/api-server/api_server.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
* limitations under the License.
*/

// Package main is the entry point of the API server.
package main

import (
Expand Down
12 changes: 5 additions & 7 deletions bcs-services/bcs-bscp/cmd/api-server/app/app.go
Original file line number Diff line number Diff line change
Expand Up @@ -102,15 +102,13 @@ func (as *apiServer) listenAndServe() error {

go func() {
notifier := shutdown.AddNotifier()
select {
case <-notifier.Signal:
logs.Infof("start shutdown api server http server gracefully...")
<-notifier.Signal
logs.Infof("start shutdown api server http server gracefully...")

as.serve.Close()
notifier.Done()
_ = as.serve.Close()
notifier.Done()

logs.Infof("shutdown api server http server success...")
}
logs.Infof("shutdown api server http server success...")
}()

if network.TLS.Enable() {
Expand Down
6 changes: 4 additions & 2 deletions bcs-services/bcs-bscp/cmd/api-server/service/proxy.go
Original file line number Diff line number Diff line change
Expand Up @@ -103,7 +103,8 @@ func newAuthServerMux(dis serviced.Discover) (http.Handler, error) {
}

// new grpc mux.
mux := runtime.NewServeMux(grpcgw.MetadataOpt, grpcgw.JsonMarshalerOpt, grpcgw.BKErrorHandlerOpt, grpcgw.BSCPResponseOpt)
mux := runtime.NewServeMux(grpcgw.MetadataOpt, grpcgw.JsonMarshalerOpt, grpcgw.BKErrorHandlerOpt,
grpcgw.BSCPResponseOpt)

// register client to mux.
if err = pbas.RegisterAuthHandler(context.Background(), mux, conn); err != nil {
Expand Down Expand Up @@ -184,5 +185,6 @@ func newGrpcDialOption(dis serviced.Discover, tls cc.TLSConfig) ([]grpc.DialOpti

// newGrpcMux new grpc mux that has some processing of built-in http request to grpc request.
func newGrpcMux() *runtime.ServeMux {
return runtime.NewServeMux(grpcgw.MetadataOpt, grpcgw.JsonMarshalerOpt, grpcgw.BKErrorHandlerOpt, grpcgw.BSCPResponseOpt)
return runtime.NewServeMux(grpcgw.MetadataOpt, grpcgw.JsonMarshalerOpt, grpcgw.BKErrorHandlerOpt,
grpcgw.BSCPResponseOpt)
}
10 changes: 7 additions & 3 deletions bcs-services/bcs-bscp/cmd/api-server/service/routers.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ import (
)

// routers return router config handler
// nolint: funlen
linfang-canway marked this conversation as resolved.
Show resolved Hide resolved
func (p *proxy) routers() http.Handler {
r := chi.NewRouter()
r.Use(handler.RequestID)
Expand Down Expand Up @@ -92,19 +93,22 @@ func (p *proxy) routers() http.Handler {
// repo 上传 API, 此处因兼容老版本而保留,后续统一使用新接口
r.Route("/api/v1/api/create/content/upload", func(r chi.Router) {
r.Use(p.authorizer.UnifiedAuthentication)
r.With(p.authorizer.BizVerified, p.authorizer.AppVerified).Put("/biz_id/{biz_id}/app_id/{app_id}", p.repo.UploadFile)
r.With(p.authorizer.BizVerified, p.authorizer.AppVerified).Put("/biz_id/{biz_id}/app_id/{app_id}",
p.repo.UploadFile)
})

// repo 下载 API, 此处因兼容老版本而保留,后续统一使用新接口
r.Route("/api/v1/api/get/content/download", func(r chi.Router) {
r.Use(p.authorizer.UnifiedAuthentication)
r.With(p.authorizer.BizVerified, p.authorizer.AppVerified).Get("/biz_id/{biz_id}/app_id/{app_id}", p.repo.DownloadFile)
r.With(p.authorizer.BizVerified, p.authorizer.AppVerified).Get("/biz_id/{biz_id}/app_id/{app_id}",
p.repo.DownloadFile)
})

// repo 获取二进制元数据 API, 此处因兼容老版本而保留,后续统一使用新接口
r.Route("/api/v1/api/get/content/metadata", func(r chi.Router) {
r.Use(p.authorizer.UnifiedAuthentication)
r.With(p.authorizer.BizVerified, p.authorizer.AppVerified).Get("/biz_id/{biz_id}/app_id/{app_id}", p.repo.FileMetadata)
r.With(p.authorizer.BizVerified, p.authorizer.AppVerified).Get("/biz_id/{biz_id}/app_id/{app_id}",
p.repo.FileMetadata)
})

// 新的内容上传、下载相关接口,后续统一使用这组新接口
Expand Down
25 changes: 10 additions & 15 deletions bcs-services/bcs-bscp/cmd/auth-server/app/app.go
Original file line number Diff line number Diff line change
Expand Up @@ -182,16 +182,13 @@ func (as *authService) listenAndServe() error {

go func() {
notifier := shutdown.AddNotifier()
select {
case <-notifier.Signal:
logs.Infof("start shutdown auth server grpc server gracefully...")
<-notifier.Signal
logs.Infof("start shutdown auth server grpc server gracefully...")

as.serve.GracefulStop()
notifier.Done()
as.serve.GracefulStop()
notifier.Done()

logs.Infof("shutdown auth server grpc server success...")

}
logs.Infof("shutdown auth server grpc server success...")
}()

addr := net.JoinHostPort(network.BindIP, strconv.Itoa(int(network.RpcPort)))
Expand Down Expand Up @@ -225,15 +222,13 @@ func (as *authService) gwListenAndServe() error {

go func() {
notifier := shutdown.AddNotifier()
select {
case <-notifier.Signal:
logs.Infof("start shutdown auth server http server gracefully...")
<-notifier.Signal
logs.Infof("start shutdown auth server http server gracefully...")

as.gwServe.Close()
notifier.Done()
_ = as.gwServe.Close()
notifier.Done()

logs.Infof("shutdown auth server http server success...")
}
logs.Infof("shutdown auth server http server success...")
}()

if network.TLS.Enable() {
Expand Down
1 change: 1 addition & 0 deletions bcs-services/bcs-bscp/cmd/auth-server/auth_server.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
* limitations under the License.
*/

// Package main This is the entry point for the authentication server, providing authentication services.
package main

import "bscp.io/cmd/auth-server/cmd"
Expand Down
5 changes: 4 additions & 1 deletion bcs-services/bcs-bscp/cmd/auth-server/cmd/migrate.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
* limitations under the License.
*/

// Package cmd provides operations for upgrading the permission model.
package cmd

import (
Expand Down Expand Up @@ -57,6 +58,7 @@ var migrateInitCmd = &cobra.Command{
},
}

// NewIamSys new a iamSystem
func NewIamSys() (*sys.Sys, error) {

iamSettings := cc.AuthServer().IAM
Expand Down Expand Up @@ -95,7 +97,8 @@ func NewIamSys() (*sys.Sys, error) {
func init() {

// Add "--debug" flag to all migrate sub commands
migrateCmd.PersistentFlags().BoolP("debug", "d", false, "whether to debug output the execution process,, default is false")
migrateCmd.PersistentFlags().BoolP("debug", "d", false,
"whether to debug output the execution process,, default is false")

migrateCmd.AddCommand(migrateInitCmd)

Expand Down
27 changes: 14 additions & 13 deletions bcs-services/bcs-bscp/cmd/auth-server/service/auth/adaptor.go
Original file line number Diff line number Diff line change
Expand Up @@ -42,31 +42,32 @@ func AdaptAuthOptions(a *meta.ResourceAttribute) (client.ActionID, []client.Reso
return genAppResource(a)
case meta.Credential:
return genCredResource(a)
case meta.Commit, meta.ConfigItem, meta.Content, meta.CRInstance, meta.Release, meta.ReleasedCI, meta.Strategy, meta.StrategySet, meta.PSH, meta.Repo, meta.Sidecar:
case meta.Commit, meta.ConfigItem, meta.Content, meta.CRInstance, meta.Release, meta.ReleasedCI, meta.Strategy,
meta.StrategySet, meta.PSH, meta.Repo, meta.Sidecar:
return genSkipResource(a)
//case meta.Commit:
// case meta.Commit:
// return genCommitResource(a)
//case meta.ConfigItem:
// case meta.ConfigItem:
// return genConfigItemResource(a)
//case meta.Content:
// case meta.Content:
// return genContentResource(a)
//case meta.CRInstance:
// case meta.CRInstance:
// return genCRInstanceResource(a)
//case meta.Release:
// case meta.Release:
// return genReleaseRes(a)
//case meta.ReleasedCI:
// case meta.ReleasedCI:
// return genReleasedCIRes(a)
//case meta.Strategy:
// case meta.Strategy:
// return genStrategyRes(a)
//case meta.StrategySet:
// case meta.StrategySet:
// return genStrategySetRes(a)
//case meta.PSH:
// case meta.PSH:
// return genPSHRes(a)
//case meta.Repo:
// case meta.Repo:
// return genRepoRes(a)
//case meta.Sidecar:
// case meta.Sidecar:
// return genSidecarRes(a)
//case meta.Credential:
// case meta.Credential:
// return genCredentialRes(a)

default:
Expand Down
4 changes: 2 additions & 2 deletions bcs-services/bcs-bscp/cmd/auth-server/service/auth/auth.go
Original file line number Diff line number Diff line change
Expand Up @@ -48,8 +48,8 @@ type Auth struct {
}

// NewAuth new auth.
func NewAuth(auth auth.Authorizer, ds pbds.DataClient, disableAuth bool, iamClient *bkiam.IAM, disableWriteOpt *options.DisableWriteOption) (
*Auth, error) {
func NewAuth(auth auth.Authorizer, ds pbds.DataClient, disableAuth bool, iamClient *bkiam.IAM,
disableWriteOpt *options.DisableWriteOption) (*Auth, error) {

if auth == nil {
return nil, errf.New(errf.InvalidParameter, "auth is nil")
Expand Down
13 changes: 13 additions & 0 deletions bcs-services/bcs-bscp/cmd/auth-server/service/auth/gen_id.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ import (
)

// bizIDAssembleSymbol used to assemble biz_id and resource id's symbol, used in app id generation.
// nolint: unused
const bizIDAssembleSymbol = "-"

var (
Expand Down Expand Up @@ -304,6 +305,7 @@ func genCredResource(a *meta.ResourceAttribute) (client.ActionID, []client.Resou
}

// genCommitResource generate commit related iam resource.
// nolint: unused
func genCommitResource(a *meta.ResourceAttribute) (client.ActionID, []client.Resource, error) {
bizRes := client.Resource{
System: sys.SystemIDCMDB,
Expand Down Expand Up @@ -335,6 +337,7 @@ func genCommitResource(a *meta.ResourceAttribute) (client.ActionID, []client.Res
}

// genConfigItemResource generate config item related iam resource.
// nolint: unused
func genConfigItemResource(a *meta.ResourceAttribute) (client.ActionID, []client.Resource, error) {
bizRes := client.Resource{
System: sys.SystemIDCMDB,
Expand Down Expand Up @@ -372,6 +375,7 @@ func genConfigItemResource(a *meta.ResourceAttribute) (client.ActionID, []client
}

// genContentResource generate content related iam resource.
// nolint: unused
func genContentResource(a *meta.ResourceAttribute) (client.ActionID, []client.Resource, error) {
bizRes := client.Resource{
System: sys.SystemIDCMDB,
Expand Down Expand Up @@ -409,6 +413,7 @@ func genContentResource(a *meta.ResourceAttribute) (client.ActionID, []client.Re
}

// genCRInstanceResource generate current released instance related iam resource.
// nolint: unused
func genCRInstanceResource(a *meta.ResourceAttribute) (client.ActionID, []client.Resource, error) {
bizRes := client.Resource{
System: sys.SystemIDCMDB,
Expand Down Expand Up @@ -443,6 +448,7 @@ func genCRInstanceResource(a *meta.ResourceAttribute) (client.ActionID, []client
}

// genReleaseRes generate release related iam resource.
// nolint: unused
func genReleaseRes(a *meta.ResourceAttribute) (client.ActionID, []client.Resource, error) {
bizRes := client.Resource{
System: sys.SystemIDCMDB,
Expand Down Expand Up @@ -474,6 +480,7 @@ func genReleaseRes(a *meta.ResourceAttribute) (client.ActionID, []client.Resourc
}

// genReleasedCIRes generate released config item related iam resource.
// nolint: unused
func genReleasedCIRes(a *meta.ResourceAttribute) (client.ActionID, []client.Resource, error) {
bizRes := client.Resource{
System: sys.SystemIDCMDB,
Expand All @@ -491,6 +498,7 @@ func genReleasedCIRes(a *meta.ResourceAttribute) (client.ActionID, []client.Reso
}

// genStrategyRes generate strategy related iam resource.
// nolint: unused
func genStrategyRes(a *meta.ResourceAttribute) (client.ActionID, []client.Resource, error) {
bizRes := client.Resource{
System: sys.SystemIDCMDB,
Expand Down Expand Up @@ -534,6 +542,7 @@ func genStrategyRes(a *meta.ResourceAttribute) (client.ActionID, []client.Resour
}

// genStrategySetRes generate strategy set related iam resource.
// nolint: unused
func genStrategySetRes(a *meta.ResourceAttribute) (client.ActionID, []client.Resource, error) {
bizRes := client.Resource{
System: sys.SystemIDCMDB,
Expand Down Expand Up @@ -571,6 +580,7 @@ func genStrategySetRes(a *meta.ResourceAttribute) (client.ActionID, []client.Res
}

// genPSHRes generate published strategy history related iam resource.
// nolint: unused
func genPSHRes(a *meta.ResourceAttribute) (client.ActionID, []client.Resource, error) {
bizRes := client.Resource{
System: sys.SystemIDCMDB,
Expand All @@ -588,6 +598,7 @@ func genPSHRes(a *meta.ResourceAttribute) (client.ActionID, []client.Resource, e
}

// genRepoRes generate repo related iam resource.
// nolint: unused
func genRepoRes(a *meta.ResourceAttribute) (client.ActionID, []client.Resource, error) {
bizRes := client.Resource{
System: sys.SystemIDCMDB,
Expand All @@ -605,6 +616,7 @@ func genRepoRes(a *meta.ResourceAttribute) (client.ActionID, []client.Resource,
}

// genSidecarRes generate sidecar related iam resource.
// nolint: unused
func genSidecarRes(a *meta.ResourceAttribute) (client.ActionID, []client.Resource, error) {
bizRes := client.Resource{
System: sys.SystemIDCMDB,
Expand All @@ -622,6 +634,7 @@ func genSidecarRes(a *meta.ResourceAttribute) (client.ActionID, []client.Resourc
}

// genCredentialRes generate application credential related iam resource.
// nolint: unused
func genCredentialRes(a *meta.ResourceAttribute) (client.ActionID, []client.Resource, error) {
bizRes := client.Resource{
System: sys.SystemIDCMDB,
Expand Down
Loading
Loading