Skip to content

Commit e4035b5

Browse files
committed
Merge branch 'develop' into feat-flux-cd
2 parents ea27b33 + 76e927f commit e4035b5

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

42 files changed

+1308
-213
lines changed

api/restHandler/ImageScanRestHandler.go

Lines changed: 45 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@ import (
2323
"github.com/devtron-labs/devtron/pkg/policyGovernance/security/imageScanning"
2424
securityBean "github.com/devtron-labs/devtron/pkg/policyGovernance/security/imageScanning/bean"
2525
security2 "github.com/devtron-labs/devtron/pkg/policyGovernance/security/imageScanning/repository"
26+
"github.com/devtron-labs/devtron/util/sliceUtil"
2627
"net/http"
2728
"strconv"
2829

@@ -104,6 +105,45 @@ func (impl ImageScanRestHandlerImpl) ScanExecutionList(w http.ResponseWriter, r
104105
return
105106
}
106107
token := r.Header.Get("token")
108+
isSuperAdmin := false
109+
if ok := impl.enforcer.Enforce(token, casbin.ResourceGlobal, casbin.ActionGet, "*"); ok {
110+
isSuperAdmin = true
111+
}
112+
var ids []int
113+
if isSuperAdmin {
114+
ids = sliceUtil.NewSliceFromFuncExec(filteredDeployInfoList, func(item *security2.ImageScanDeployInfo) int {
115+
return item.Id
116+
})
117+
} else {
118+
ids, err = impl.getAuthorisedImageScanDeployInfoIds(token, filteredDeployInfoList)
119+
if err != nil {
120+
impl.logger.Errorw("error in getting authorised image scan deploy info ids", "err", err)
121+
common.WriteJsonResp(w, err, nil, http.StatusInternalServerError)
122+
return
123+
}
124+
}
125+
126+
if len(ids) == 0 {
127+
responseList := make([]*securityBean.ImageScanHistoryResponse, 0)
128+
common.WriteJsonResp(w, nil, &securityBean.ImageScanHistoryListingResponse{ImageScanHistoryResponse: responseList}, http.StatusOK)
129+
return
130+
}
131+
132+
results, err := impl.imageScanService.FetchScanExecutionListing(request, ids)
133+
if err != nil {
134+
impl.logger.Errorw("service err, ScanExecutionList", "err", err, "payload", request)
135+
if util.IsErrNoRows(err) {
136+
responseList := make([]*securityBean.ImageScanHistoryResponse, 0)
137+
common.WriteJsonResp(w, nil, &securityBean.ImageScanHistoryListingResponse{ImageScanHistoryResponse: responseList}, http.StatusOK)
138+
} else {
139+
common.WriteJsonResp(w, err, nil, http.StatusInternalServerError)
140+
}
141+
return
142+
}
143+
common.WriteJsonResp(w, err, results, http.StatusOK)
144+
}
145+
146+
func (impl ImageScanRestHandlerImpl) getAuthorisedImageScanDeployInfoIds(token string, filteredDeployInfoList []*security2.ImageScanDeployInfo) ([]int, error) {
107147
var ids []int
108148
var appRBACObjects []string
109149
var envRBACObjects []string
@@ -119,8 +159,8 @@ func (impl ImageScanRestHandlerImpl) ScanExecutionList(w http.ResponseWriter, r
119159

120160
appObjects, envObjects, appIdtoApp, envIdToEnv, err := impl.enforcerUtil.GetAppAndEnvRBACNamesByAppAndEnvIds(IdToAppEnvPairs)
121161
if err != nil {
122-
common.WriteJsonResp(w, err, nil, http.StatusInternalServerError)
123-
return
162+
impl.logger.Errorw("error in getting app and env rbac objects", "err", err)
163+
return nil, err
124164
}
125165

126166
for _, item := range filteredDeployInfoList {
@@ -136,8 +176,8 @@ func (impl ImageScanRestHandlerImpl) ScanExecutionList(w http.ResponseWriter, r
136176
} else if item.ScanObjectMetaId > 0 && (item.ObjectType == ObjectTypePod) {
137177
environments, err := impl.environmentService.GetByClusterId(item.ClusterId)
138178
if err != nil {
139-
common.WriteJsonResp(w, err, nil, http.StatusInternalServerError)
140-
return
179+
impl.logger.Errorw("error in getting environments for cluster", "clusterId", item.ClusterId, "err", err)
180+
return nil, err
141181
}
142182
for _, environment := range environments {
143183
podObject := environment.EnvironmentIdentifier
@@ -163,25 +203,7 @@ func (impl ImageScanRestHandlerImpl) ScanExecutionList(w http.ResponseWriter, r
163203
}
164204
}
165205
}
166-
167-
if ids == nil || len(ids) == 0 {
168-
responseList := make([]*securityBean.ImageScanHistoryResponse, 0)
169-
common.WriteJsonResp(w, nil, &securityBean.ImageScanHistoryListingResponse{ImageScanHistoryResponse: responseList}, http.StatusOK)
170-
return
171-
}
172-
173-
results, err := impl.imageScanService.FetchScanExecutionListing(request, ids)
174-
if err != nil {
175-
impl.logger.Errorw("service err, ScanExecutionList", "err", err, "payload", request)
176-
if util.IsErrNoRows(err) {
177-
responseList := make([]*securityBean.ImageScanHistoryResponse, 0)
178-
common.WriteJsonResp(w, nil, &securityBean.ImageScanHistoryListingResponse{ImageScanHistoryResponse: responseList}, http.StatusOK)
179-
} else {
180-
common.WriteJsonResp(w, err, nil, http.StatusInternalServerError)
181-
}
182-
return
183-
}
184-
common.WriteJsonResp(w, err, results, http.StatusOK)
206+
return ids, nil
185207
}
186208

187209
func (impl ImageScanRestHandlerImpl) FetchExecutionDetail(w http.ResponseWriter, r *http.Request) {

api/restHandler/app/appInfo/AppInfoRestHandler.go

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -87,9 +87,23 @@ func (handler AppInfoRestHandlerImpl) GetAllLabels(w http.ResponseWriter, r *htt
8787
common.WriteJsonResp(w, err, "Unauthorized User", http.StatusUnauthorized)
8888
return
8989
}
90+
propagatedLabelsOnlyStr := r.URL.Query().Get("showPropagatedOnly")
91+
92+
var propagatedLabelsOnlyBool *bool
93+
if propagatedLabelsOnlyStr != "" {
94+
if val, err := strconv.ParseBool(propagatedLabelsOnlyStr); err == nil {
95+
propagatedLabelsOnlyBool = &val
96+
} else {
97+
// Invalid boolean value provided, treat as null (nil)
98+
propagatedLabelsOnlyBool = nil
99+
handler.logger.Infow("Invalid 'showPropagatedOnly' value from quey params — defaulting to nil", propagatedLabelsOnlyStr)
100+
}
101+
}
102+
90103
token := r.Header.Get("token")
91104
results := make([]*bean.AppLabelDto, 0)
92-
labels, err := handler.appService.FindAll()
105+
106+
labels, err := handler.appService.FindAll(propagatedLabelsOnlyBool)
93107
if err != nil {
94108
handler.logger.Errorw("service err, GetAllLabels", "err", err)
95109
common.WriteJsonResp(w, err, nil, http.StatusInternalServerError)

go.sum

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -237,10 +237,10 @@ github.com/denisenkom/go-mssqldb v0.0.0-20200428022330-06a60b6afbbc h1:VRRKCwnzq
237237
github.com/denisenkom/go-mssqldb v0.0.0-20200428022330-06a60b6afbbc/go.mod h1:xbL0rPBG9cCiLr28tMa8zpbdarY27NDyej4t/EjAShU=
238238
github.com/devtron-labs/argo-workflows/v3 v3.5.13 h1:3pINq0gXOSeTw2z/vYe+j80lRpSN5Rp/8mfQORh8SmU=
239239
github.com/devtron-labs/argo-workflows/v3 v3.5.13/go.mod h1:/vqxcovDPT4zqr4DjR5v7CF8ggpY1l3TSa2CIG3jmjA=
240-
github.com/devtron-labs/devtron-services/authenticator v0.0.0-20250619100439-8e8e182b498a h1:KGVcJLifitrmRj/Q6xxWDThc2bJUlJaFfrzc9PfLBnU=
241-
github.com/devtron-labs/devtron-services/authenticator v0.0.0-20250619100439-8e8e182b498a/go.mod h1:9LCkYfiWaEKIBkmxw9jX1GujvEMyHwmDtVsatffAkeU=
242-
github.com/devtron-labs/devtron-services/common-lib v0.0.0-20250619100439-8e8e182b498a h1:iQdc02/QUQ4P45Y/OEZXtbkES6+Tan2RJfg2wpJxaWQ=
243-
github.com/devtron-labs/devtron-services/common-lib v0.0.0-20250619100439-8e8e182b498a/go.mod h1:/Ciy9tD9OxZOWBDPIasM448H7uvSo4+ZJiExpfwBZpA=
240+
github.com/devtron-labs/devtron-services/authenticator v0.0.0-20250624130631-fd0c2f8fd85c h1:v+laregD1jjF1c7DUs9Aoo1alEOaOSSidgSFDAWv4uM=
241+
github.com/devtron-labs/devtron-services/authenticator v0.0.0-20250624130631-fd0c2f8fd85c/go.mod h1:9LCkYfiWaEKIBkmxw9jX1GujvEMyHwmDtVsatffAkeU=
242+
github.com/devtron-labs/devtron-services/common-lib v0.0.0-20250624130631-fd0c2f8fd85c h1:Lc6JZNufAA1gKTXfhJiEZ6BLPC9mHa89dKw0m6FmPpo=
243+
github.com/devtron-labs/devtron-services/common-lib v0.0.0-20250624130631-fd0c2f8fd85c/go.mod h1:/Ciy9tD9OxZOWBDPIasM448H7uvSo4+ZJiExpfwBZpA=
244244
github.com/devtron-labs/go-bitbucket v0.9.60-beta h1:VEx1jvDgdtDPS6A1uUFoaEi0l1/oLhbr+90xOwr6sDU=
245245
github.com/devtron-labs/go-bitbucket v0.9.60-beta/go.mod h1:GnuiCesvh8xyHeMCb+twm8lBR/kQzJYSKL28ZfObp1Y=
246246
github.com/devtron-labs/protos v0.0.3-0.20250323220609-ecf8a0f7305e h1:U6UdYbW8a7xn5IzFPd8cywjVVPfutGJCudjePAfL/Hs=

internal/sql/repository/pipelineConfig/AppLabelsRepository.go

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@ type AppLabelRepository interface {
4141
Delete(model *AppLabel, tx *pg.Tx) error
4242
FindById(id int) (*AppLabel, error)
4343
FindAllByIds(ids []int) ([]*AppLabel, error)
44-
FindAll() ([]*AppLabel, error)
44+
FindAll(propagated *bool) ([]*AppLabel, error)
4545
FindByLabelKey(key string) ([]*AppLabel, error)
4646
FindByAppIdAndKeyAndValue(appId int, key string, value string) (*AppLabel, error)
4747
FindByLabelValue(label string) ([]*AppLabel, error)
@@ -89,9 +89,16 @@ func (impl AppLabelRepositoryImpl) FindAllByIds(ids []int) ([]*AppLabel, error)
8989
err := impl.dbConnection.Model(&models).Where("id in (?)", pg.In(ids)).Order("updated_on desc").Select()
9090
return models, err
9191
}
92-
func (impl AppLabelRepositoryImpl) FindAll() ([]*AppLabel, error) {
92+
func (impl AppLabelRepositoryImpl) FindAll(propagated *bool) ([]*AppLabel, error) {
9393
var models []*AppLabel
94-
err := impl.dbConnection.Model(&models).Order("updated_on desc").Select()
94+
query := impl.dbConnection.Model(&models).
95+
Column("app_label.*", "App").
96+
Order("updated_on desc")
97+
// if propagated flag is not set then show all labels
98+
if propagated != nil {
99+
query = query.Where("propagate = ?", *propagated)
100+
}
101+
err := query.Select()
95102
return models, err
96103
}
97104
func (impl AppLabelRepositoryImpl) FindByLabelKey(key string) ([]*AppLabel, error) {

internal/sql/repository/pipelineConfig/CdWorfkflowRepository.go

Lines changed: 22 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -773,31 +773,41 @@ func (impl *CdWorkflowRepositoryImpl) FindDeployedCdWorkflowRunnersByPipelineId(
773773
}
774774

775775
func (impl *CdWorkflowRepositoryImpl) FindLatestCdWorkflowRunnerArtifactMetadataForAppAndEnvIds(appVsEnvIdMap map[int][]int, runnerType apiBean.WorkflowType) ([]*cdWorkflow.CdWorkflowRunnerArtifactMetadata, error) {
776-
var allRunners []*cdWorkflow.CdWorkflowRunnerArtifactMetadata
776+
var runners []*cdWorkflow.CdWorkflowRunnerArtifactMetadata
777+
778+
// Prepare the (app_id, env_id) tuple list for the query
779+
tupleList := make([]interface{}, 0, len(appVsEnvIdMap))
780+
for appId, envIds := range appVsEnvIdMap {
781+
for _, envId := range envIds {
782+
tupleList = append(tupleList, []interface{}{appId, envId})
783+
}
784+
}
785+
if len(tupleList) == 0 {
786+
return nil, nil
787+
}
788+
777789
query := `
778790
WITH RankedData AS (
779791
SELECT
780792
p.app_id AS "app_id",
781793
p.environment_id AS "env_id",
782-
p.deleted AS "deleted",
794+
p.deleted AS "deleted",
783795
wf.ci_artifact_id AS "ci_artifact_id",
784796
ci_artifact.parent_ci_artifact AS "parent_ci_artifact",
785797
ci_artifact.scanned AS "scanned",
786798
ROW_NUMBER() OVER (PARTITION BY p.app_id, p.environment_id ORDER BY cd_workflow_runner.id DESC) AS rn
787799
FROM cd_workflow_runner INNER JOIN cd_workflow wf ON wf.id = cd_workflow_runner.cd_workflow_id
788800
INNER JOIN pipeline p ON p.id = wf.pipeline_id
789801
INNER JOIN ci_artifact ON ci_artifact.id = wf.ci_artifact_id
790-
WHERE cd_workflow_runner.workflow_type = ? AND p.app_id = ? AND p.environment_id IN (?))
802+
WHERE cd_workflow_runner.workflow_type = ?
803+
AND (p.app_id, p.environment_id) IN ( ? )
804+
)
791805
SELECT "app_id","env_id","ci_artifact_id","parent_ci_artifact","scanned" FROM RankedData WHERE rn = 1 and deleted= false;
792806
`
793-
for appId, envIds := range appVsEnvIdMap {
794-
var runners []*cdWorkflow.CdWorkflowRunnerArtifactMetadata
795-
_, err := impl.dbConnection.Query(&runners, query, runnerType, appId, pg.In(envIds))
796-
if err != nil {
797-
impl.logger.Errorw("error in getting cdWfrs by appId and envIds and runner type", "appVsEnvIdMap", appVsEnvIdMap, "err", err)
798-
return nil, err
799-
}
800-
allRunners = append(allRunners, runners...)
807+
_, err := impl.dbConnection.Query(&runners, query, runnerType, pg.In(tupleList))
808+
if err != nil {
809+
impl.logger.Errorw("error in getting cdWfrs by appId and envIds and runner type", "appVsEnvIdMap", appVsEnvIdMap, "err", err)
810+
return nil, err
801811
}
802-
return allRunners, nil
812+
return runners, nil
803813
}

pkg/app/AppCrudOperationService.go

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,7 @@ type CrudOperationServiceConfig struct {
5959
type AppCrudOperationService interface {
6060
Create(request *bean.AppLabelDto, tx *pg.Tx) (*bean.AppLabelDto, error)
6161
FindById(id int) (*bean.AppLabelDto, error)
62-
FindAll() ([]*bean.AppLabelDto, error)
62+
FindAll(propagated *bool) ([]*bean.AppLabelDto, error)
6363
GetAppMetaInfo(appId int, installedAppId int, envId int) (*bean.AppMetaInfoDto, error)
6464
GetHelmAppMetaInfo(appId string) (*bean.AppMetaInfoDto, error)
6565
GetAppLabelsForDeployment(ctx context.Context, appId int, appName, envName string) ([]byte, error)
@@ -318,9 +318,9 @@ func (impl AppCrudOperationServiceImpl) FindById(id int) (*bean.AppLabelDto, err
318318
return label, nil
319319
}
320320

321-
func (impl AppCrudOperationServiceImpl) FindAll() ([]*bean.AppLabelDto, error) {
321+
func (impl AppCrudOperationServiceImpl) FindAll(propagated *bool) ([]*bean.AppLabelDto, error) {
322322
results := make([]*bean.AppLabelDto, 0)
323-
models, err := impl.appLabelRepository.FindAll()
323+
models, err := impl.appLabelRepository.FindAll(propagated)
324324
if err != nil && err != pg.ErrNoRows {
325325
impl.logger.Errorw("error in fetching FindAll app labels", "error", err)
326326
return nil, err
@@ -334,6 +334,7 @@ func (impl AppCrudOperationServiceImpl) FindAll() ([]*bean.AppLabelDto, error) {
334334
Key: model.Key,
335335
Value: model.Value,
336336
Propagate: model.Propagate,
337+
AppName: model.App.AppName,
337338
}
338339
results = append(results, dto)
339340
}

pkg/bean/app.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -914,6 +914,7 @@ type AppLabelDto struct {
914914
Value string `json:"value,notnull"`
915915
Propagate bool `json:"propagate,notnull"`
916916
AppId int `json:"appId,omitempty"`
917+
AppName string `json:"appName,omitempty"`
917918
UserId int32 `json:"-"`
918919
}
919920

0 commit comments

Comments
 (0)