@@ -34,6 +34,12 @@ import (
34
34
"go.uber.org/zap"
35
35
)
36
36
37
+ const (
38
+ ObjectTypeApp = "app"
39
+ ObjectTypeChart = "chart"
40
+ ObjectTypePod = "pod"
41
+ )
42
+
37
43
type ImageScanRestHandler interface {
38
44
ScanExecutionList (w http.ResponseWriter , r * http.Request )
39
45
FetchExecutionDetail (w http.ResponseWriter , r * http.Request )
@@ -100,7 +106,7 @@ func (impl ImageScanRestHandlerImpl) ScanExecutionList(w http.ResponseWriter, r
100
106
101
107
IdToAppEnvPairs := make (map [int ][2 ]int )
102
108
for _ , item := range deployInfoList {
103
- if item .ScanObjectMetaId > 0 && (item .ObjectType == "app" || item .ObjectType == "chart" ) {
109
+ if item .ScanObjectMetaId > 0 && (item .ObjectType == ObjectTypeApp || item .ObjectType == ObjectTypeChart ) {
104
110
IdToAppEnvPairs [item .Id ] = [2 ]int {item .ScanObjectMetaId , item .EnvId }
105
111
}
106
112
}
@@ -112,7 +118,7 @@ func (impl ImageScanRestHandlerImpl) ScanExecutionList(w http.ResponseWriter, r
112
118
}
113
119
114
120
for _ , item := range deployInfoList {
115
- if item .ScanObjectMetaId > 0 && (item .ObjectType == "app" || item .ObjectType == "chart" ) {
121
+ if item .ScanObjectMetaId > 0 && (item .ObjectType == ObjectTypeApp || item .ObjectType == ObjectTypeChart ) {
116
122
appObject := appObjects [item .Id ]
117
123
envObject := envObjects [item .Id ]
118
124
if appObject != "" {
@@ -121,7 +127,7 @@ func (impl ImageScanRestHandlerImpl) ScanExecutionList(w http.ResponseWriter, r
121
127
if envObject != "" {
122
128
envRBACObjects = append (envRBACObjects , envObject )
123
129
}
124
- } else if item .ScanObjectMetaId > 0 && (item .ObjectType == "pod" ) {
130
+ } else if item .ScanObjectMetaId > 0 && (item .ObjectType == ObjectTypePod ) {
125
131
environments , err := impl .environmentService .GetByClusterId (item .ClusterId )
126
132
if err != nil {
127
133
common .WriteJsonResp (w , err , nil , http .StatusInternalServerError )
@@ -140,7 +146,7 @@ func (impl ImageScanRestHandlerImpl) ScanExecutionList(w http.ResponseWriter, r
140
146
podResults := impl .enforcer .EnforceInBatch (token , casbin .ResourceGlobalEnvironment , casbin .ActionGet , podRBACObjects )
141
147
142
148
for _ , item := range deployInfoList {
143
- if impl .enforcerUtil .IsAuthorizedForApp (item .ScanObjectMetaId , appResults , appIdtoApp ) && impl .enforcerUtil .IsAuthorizedForEnv (item .ScanObjectMetaId , item .EnvId , envResults , appIdtoApp , envIdToEnv ) {
149
+ if impl .enforcerUtil .IsAuthorizedForAppInAppResults (item .ScanObjectMetaId , appResults , appIdtoApp ) && impl .enforcerUtil .IsAuthorizedForEnvInEnvResults (item .ScanObjectMetaId , item .EnvId , envResults , appIdtoApp , envIdToEnv ) {
144
150
ids = append (ids , item .Id )
145
151
}
146
152
}
0 commit comments