Skip to content

Commit 87465ad

Browse files
fix: App create api validations (#5019)
* wip * error handling done * fix --------- Co-authored-by: ayushmaheshwari <ayush@devtron.ai>
1 parent 3763b65 commit 87465ad

File tree

1 file changed

+19
-0
lines changed

1 file changed

+19
-0
lines changed

api/restHandler/CoreAppRestHandler.go

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2143,6 +2143,25 @@ func (handler CoreAppRestHandlerImpl) ValidateAppWorkflowRequest(createAppWorkfl
21432143
if ciPipeline.AppId != workflow.CiPipeline.ParentAppId {
21442144
return fmt.Errorf("invalid parentAppId '%v' for the given parentCiPipeline '%v'", workflow.CiPipeline.ParentAppId, workflow.CiPipeline.ParentCiPipeline), http.StatusBadRequest
21452145
}
2146+
parentMaterialMap := make(map[int]*pipelineConfig.CiPipelineMaterial)
2147+
for _, material := range ciPipeline.CiPipelineMaterials {
2148+
parentMaterialMap[material.GitMaterialId] = material
2149+
}
2150+
for _, requestPipelineMaterial := range workflow.CiPipeline.CiPipelineMaterialsConfig {
2151+
parentMaterial, ok := parentMaterialMap[requestPipelineMaterial.GitMaterialId]
2152+
if !ok {
2153+
return fmt.Errorf("invalid material id - request material id should match parent material id for linked ci, request material id - '%v' ", requestPipelineMaterial.GitMaterialId), http.StatusBadRequest
2154+
}
2155+
if requestPipelineMaterial.Value != parentMaterial.Value {
2156+
return fmt.Errorf(" parentMaterialValue and request material value should match for linked ci - parent material value - %v child value %v ", requestPipelineMaterial.Value), http.StatusBadRequest
2157+
}
2158+
if requestPipelineMaterial.Type != parentMaterial.Type {
2159+
return fmt.Errorf(" parentMaterialType and request material value should match for linked ci - parent material type - %v child type %v ", requestPipelineMaterial.Type), http.StatusBadRequest
2160+
}
2161+
if requestPipelineMaterial.CheckoutPath != parentMaterial.CheckoutPath {
2162+
return fmt.Errorf(" parentMaterialType and request material CheckoutPath should match for linked ci - parent material CheckoutPath - %v child CheckoutPath %v ", requestPipelineMaterial.CheckoutPath), http.StatusBadRequest
2163+
}
2164+
}
21462165
}
21472166
ciMaterialCheckoutPaths := make([]string, 0)
21482167
for _, ciPipelineMaterialConfig := range workflow.CiPipeline.CiPipelineMaterialsConfig {

0 commit comments

Comments
 (0)