Skip to content

Commit

Permalink
fix: code style (merge request !1290)
Browse files Browse the repository at this point in the history
Squash merge branch 'fix/style' into 'master'
  • Loading branch information
adevjoe authored and ifooth committed Jul 19, 2023
1 parent d89a291 commit b69444b
Show file tree
Hide file tree
Showing 12 changed files with 75 additions and 73 deletions.
3 changes: 2 additions & 1 deletion .code.yml
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@ source:
# Misc
- /bcs-scenarios/kourse
- /bcs-common/pkg/bcsapi/storage/tkex/gamedeployment/v1alpha1/gamedeployment.go
- /bcs-common/pkg/bcsapiv4/storage/tkex/gamedeployment/v1alpha1/gamedeployment.go
- /bcs-common/pkg/esb/apigateway/bkdata/types.go
- /bcs-runtime/bcs-k8s/bcs-component/bcs-cluster-autoscaler/core/scale_up.go
- /bcs-runtime/bcs-k8s/bcs-component/bcs-cluster-autoscaler/simulator/drain.go
Expand Down Expand Up @@ -105,4 +106,4 @@ source:
- .*/mesosproto/.*
- .*/swagger-ui/.*
- .*/swagger/.*
- .*/third_party/.*
- .*/third_party/.*
29 changes: 15 additions & 14 deletions bcs-services/cluster-resources/cmd/init.go
Original file line number Diff line number Diff line change
Expand Up @@ -321,20 +321,7 @@ func (crSvc *clusterResourcesService) initHTTPService() error {
log.Info(crSvc.ctx, "swagger doc is enabled")
// 加载 swagger.json
// 配置 swagger-ui 服务
originMux.HandleFunc("/swagger/", func(w http.ResponseWriter, r *http.Request) {
// 提取 URL 的扩展名
ext := filepath.Ext(r.URL.Path)
// 检查扩展名是否为 ".json"
if ext == ".json" {
// 设置响应头
w.Header().Set("Content-Type", "application/json")
file, _ := swagger.Assets.ReadFile("data/cluster-resources.swagger.json")
w.Write(file)
return
} else {
httpSwagger.Handler(httpSwagger.URL("/swagger/cluster-resources.swagger.json")).ServeHTTP(w, r)
}
})
originMux.HandleFunc("/swagger/", handlerSwagger)
}

httpPort := strconv.Itoa(crSvc.conf.Server.HTTPPort)
Expand Down Expand Up @@ -366,6 +353,20 @@ func (crSvc *clusterResourcesService) initHTTPService() error {
return nil
}

func handlerSwagger(w http.ResponseWriter, r *http.Request) {
// 提取 URL 的扩展名
ext := filepath.Ext(r.URL.Path)
// 检查扩展名是否为 ".json"
if ext == ".json" {
// 设置响应头
w.Header().Set("Content-Type", "application/json")
file, _ := swagger.Assets.ReadFile("data/cluster-resources.swagger.json")
w.Write(file)
return
}
httpSwagger.Handler(httpSwagger.URL("/swagger/cluster-resources.swagger.json")).ServeHTTP(w, r)
}

func (crSvc *clusterResourcesService) run(httpAddr string, dualStackListener net.Listener) {
var err error
log.Info(crSvc.ctx, "start http gateway server on address %s", httpAddr)
Expand Down
6 changes: 3 additions & 3 deletions bcs-services/pkg/bcs-auth-v4/cloudaccount/application.go
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ func (cls AccountInstances) BuildInstances() [][]iam.Instance {
if cls.IsCreateAccount && len(cls.Data) > 0 {
for i := range cls.Data {
iamInstances = append(iamInstances, []iam.Instance{
iam.Instance{
{
ResourceType: string(project.SysProject),
ResourceID: cls.Data[i].Project,
},
Expand All @@ -51,11 +51,11 @@ func (cls AccountInstances) BuildInstances() [][]iam.Instance {

for i := range cls.Data {
iamInstances = append(iamInstances, []iam.Instance{
iam.Instance{
{
ResourceType: string(project.SysProject),
ResourceID: cls.Data[i].Project,
},
iam.Instance{
{
ResourceType: string(SysCloudAccount),
ResourceID: cls.Data[i].Account,
},
Expand Down
4 changes: 2 additions & 2 deletions bcs-services/pkg/bcs-auth-v4/cloudaccount/helper.go
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ type AccountResourceNode struct {
func (arn AccountResourceNode) BuildResourceNodes() []iam.ResourceNode {
if arn.IsCreateAccount {
return []iam.ResourceNode{
iam.ResourceNode{
{
System: arn.SystemID,
RType: string(project.SysProject),
RInstance: arn.ProjectID,
Expand All @@ -70,7 +70,7 @@ func (arn AccountResourceNode) BuildResourceNodes() []iam.ResourceNode {
}

return []iam.ResourceNode{
iam.ResourceNode{
{
System: arn.SystemID,
RType: string(SysCloudAccount),
RInstance: arn.AccountID,
Expand Down
10 changes: 5 additions & 5 deletions bcs-services/pkg/bcs-auth-v4/cluster/application.go
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ func (cls ClusterInstances) BuildInstances() [][]iam.Instance {
if cls.IsCreateCluster && len(cls.Data) > 0 {
for i := range cls.Data {
iamInstances = append(iamInstances, []iam.Instance{
iam.Instance{
{
ResourceType: string(project.SysProject),
ResourceID: cls.Data[i].Project,
},
Expand All @@ -51,11 +51,11 @@ func (cls ClusterInstances) BuildInstances() [][]iam.Instance {

for i := range cls.Data {
iamInstances = append(iamInstances, []iam.Instance{
iam.Instance{
{
ResourceType: string(project.SysProject),
ResourceID: cls.Data[i].Project,
},
iam.Instance{
{
ResourceType: string(SysCluster),
ResourceID: cls.Data[i].Cluster,
},
Expand All @@ -76,11 +76,11 @@ func (cls ClusterScopedInstances) BuildInstances() [][]iam.Instance {

for i := range cls.Data {
iamInstances = append(iamInstances, []iam.Instance{
iam.Instance{
{
ResourceType: string(project.SysProject),
ResourceID: cls.Data[i].Project,
},
iam.Instance{
{
ResourceType: string(SysCluster),
ResourceID: cls.Data[i].Cluster,
},
Expand Down
6 changes: 3 additions & 3 deletions bcs-services/pkg/bcs-auth-v4/cluster/helper.go
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ type ClusterResourceNode struct {
func (crn ClusterResourceNode) BuildResourceNodes() []iam.ResourceNode {
if crn.IsCreateCluster {
return []iam.ResourceNode{
iam.ResourceNode{
{
System: crn.SystemID,
RType: string(project.SysProject),
RInstance: crn.ProjectID,
Expand All @@ -79,7 +79,7 @@ func (crn ClusterResourceNode) BuildResourceNodes() []iam.ResourceNode {
}

return []iam.ResourceNode{
iam.ResourceNode{
{
System: crn.SystemID,
RType: string(SysCluster),
RInstance: crn.ClusterID,
Expand All @@ -101,7 +101,7 @@ type ClusterScopedResourceNode struct {
// BuildResourceNodes build namespace scoped iam.ResourceNode
func (csr ClusterScopedResourceNode) BuildResourceNodes() []iam.ResourceNode {
return []iam.ResourceNode{
iam.ResourceNode{
{
System: csr.SystemID,
RType: string(SysCluster),
RInstance: csr.ClusterID,
Expand Down
42 changes: 21 additions & 21 deletions bcs-services/pkg/bcs-auth-v4/manager/cluster.go
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ func (c *Cluster) buildClusterCreateScope() iam.AuthorizationScope {
return iam.BuildAuthorizationScope(project.SysProject, []iam.ActionID{
cluster.ClusterCreate,
}, []iam.LevelResource{
iam.LevelResource{
{
Type: string(project.SysProject),
ID: c.ProjectID,
Name: c.ProjectName,
Expand All @@ -73,12 +73,12 @@ func (c *Cluster) buildClusterOtherScope() iam.AuthorizationScope {
return iam.BuildAuthorizationScope(cluster.SysCluster, []iam.ActionID{
cluster.ClusterManage, cluster.ClusterDelete, cluster.ClusterView, cluster.ClusterUse,
}, []iam.LevelResource{
iam.LevelResource{
{
Type: string(project.SysProject),
ID: c.ProjectID,
Name: c.ProjectName,
},
iam.LevelResource{
{
Type: string(cluster.SysCluster),
ID: c.ClusterID,
Name: c.ClusterName,
Expand All @@ -90,12 +90,12 @@ func (c *Cluster) buildClusterViewScope() iam.AuthorizationScope {
return iam.BuildAuthorizationScope(cluster.SysCluster, []iam.ActionID{
cluster.ClusterView},
[]iam.LevelResource{
iam.LevelResource{
{
Type: string(project.SysProject),
ID: c.ProjectID,
Name: c.ProjectName,
},
iam.LevelResource{
{
Type: string(cluster.SysCluster),
ID: c.ClusterID,
Name: c.ClusterName,
Expand All @@ -107,12 +107,12 @@ func (c *Cluster) buildClusterScopedScope() iam.AuthorizationScope {
return iam.BuildAuthorizationScope(cluster.SysCluster, []iam.ActionID{
cluster.ClusterScopedCreate, cluster.ClusterScopedDelete, cluster.ClusterScopedUpdate, cluster.ClusterScopedView,
}, []iam.LevelResource{
iam.LevelResource{
{
Type: string(project.SysProject),
ID: c.ProjectID,
Name: c.ProjectName,
},
iam.LevelResource{
{
Type: string(cluster.SysCluster),
ID: c.ClusterID,
Name: c.ClusterName,
Expand All @@ -124,12 +124,12 @@ func (c *Cluster) buildClusterScopedViewScope() iam.AuthorizationScope {
return iam.BuildAuthorizationScope(cluster.SysCluster, []iam.ActionID{
cluster.ClusterScopedView,
}, []iam.LevelResource{
iam.LevelResource{
{
Type: string(project.SysProject),
ID: c.ProjectID,
Name: c.ProjectName,
},
iam.LevelResource{
{
Type: string(cluster.SysCluster),
ID: c.ClusterID,
Name: c.ClusterName,
Expand All @@ -141,12 +141,12 @@ func (c *Cluster) buildNamespaceCreateListScope() iam.AuthorizationScope {
return iam.BuildAuthorizationScope(cluster.SysCluster, []iam.ActionID{
namespace.NameSpaceCreate, namespace.NameSpaceList,
}, []iam.LevelResource{
iam.LevelResource{
{
Type: string(project.SysProject),
ID: c.ProjectID,
Name: c.ProjectName,
},
iam.LevelResource{
{
Type: string(cluster.SysCluster),
ID: c.ClusterID,
Name: c.ClusterName,
Expand All @@ -158,12 +158,12 @@ func (c *Cluster) buildNamespaceListScope() iam.AuthorizationScope {
return iam.BuildAuthorizationScope(cluster.SysCluster, []iam.ActionID{
namespace.NameSpaceList,
}, []iam.LevelResource{
iam.LevelResource{
{
Type: string(project.SysProject),
ID: c.ProjectID,
Name: c.ProjectName,
},
iam.LevelResource{
{
Type: string(cluster.SysCluster),
ID: c.ClusterID,
Name: c.ClusterName,
Expand All @@ -175,12 +175,12 @@ func (c *Cluster) buildNamespaceOtherScope() iam.AuthorizationScope {
return iam.BuildAuthorizationScope(namespace.SysNamespace, []iam.ActionID{
namespace.NameSpaceDelete, namespace.NameSpaceUpdate, namespace.NameSpaceView,
}, []iam.LevelResource{
iam.LevelResource{
{
Type: string(project.SysProject),
ID: c.ProjectID,
Name: c.ProjectName,
},
iam.LevelResource{
{
Type: string(cluster.SysCluster),
ID: c.ClusterID,
Name: c.ClusterName,
Expand All @@ -192,12 +192,12 @@ func (c *Cluster) buildNamespaceViewScope() iam.AuthorizationScope {
return iam.BuildAuthorizationScope(namespace.SysNamespace, []iam.ActionID{
namespace.NameSpaceView,
}, []iam.LevelResource{
iam.LevelResource{
{
Type: string(project.SysProject),
ID: c.ProjectID,
Name: c.ProjectName,
},
iam.LevelResource{
{
Type: string(cluster.SysCluster),
ID: c.ClusterID,
Name: c.ClusterName,
Expand All @@ -210,12 +210,12 @@ func (c *Cluster) buildNamespaceScopedScope() iam.AuthorizationScope {
namespace.NameSpaceScopedCreate, namespace.NameSpaceScopedDelete, namespace.NameSpaceScopedUpdate,
namespace.NameSpaceScopedView,
}, []iam.LevelResource{
iam.LevelResource{
{
Type: string(project.SysProject),
ID: c.ProjectID,
Name: c.ProjectName,
},
iam.LevelResource{
{
Type: string(cluster.SysCluster),
ID: c.ClusterID,
Name: c.ClusterName,
Expand All @@ -227,12 +227,12 @@ func (c *Cluster) buildNamespaceScopedViewScope() iam.AuthorizationScope {
return iam.BuildAuthorizationScope(namespace.SysNamespace, []iam.ActionID{
namespace.NameSpaceScopedView,
}, []iam.LevelResource{
iam.LevelResource{
{
Type: string(project.SysProject),
ID: c.ProjectID,
Name: c.ProjectName,
},
iam.LevelResource{
{
Type: string(cluster.SysCluster),
ID: c.ClusterID,
Name: c.ClusterName,
Expand Down
Loading

0 comments on commit b69444b

Please sign in to comment.