(versionDir string, appDetail *model.AppDetail)
| 1380 | } |
| 1381 | |
| 1382 | func handleLocalAppDetail(versionDir string, appDetail *model.AppDetail) error { |
| 1383 | fileOp := files.NewFileOp() |
| 1384 | dockerComposePath := path.Join(versionDir, "docker-compose.yml") |
| 1385 | if !fileOp.Stat(dockerComposePath) { |
| 1386 | return buserr.WithName("ErrFileNotFound", "docker-compose.yml") |
| 1387 | } |
| 1388 | dockerComposeByte, _ := fileOp.GetContent(dockerComposePath) |
| 1389 | if dockerComposeByte == nil { |
| 1390 | return buserr.WithName("ErrFileParseApp", "docker-compose.yml") |
| 1391 | } |
| 1392 | appDetail.DockerCompose = string(dockerComposeByte) |
| 1393 | paramPath := path.Join(versionDir, "data.yml") |
| 1394 | if !fileOp.Stat(paramPath) { |
| 1395 | return buserr.WithName("ErrFileNotFound", "data.yml") |
| 1396 | } |
| 1397 | paramByte, _ := fileOp.GetContent(paramPath) |
| 1398 | if paramByte == nil { |
| 1399 | return buserr.WithName("ErrFileNotFound", "data.yml") |
| 1400 | } |
| 1401 | appParamConfig := dto.LocalAppParam{} |
| 1402 | if err := yaml.Unmarshal(paramByte, &appParamConfig); err != nil { |
| 1403 | return buserr.WithMap("ErrFileParseApp", map[string]interface{}{"name": "data.yml", "err": err.Error()}, err) |
| 1404 | } |
| 1405 | dataJson, err := json.Marshal(appParamConfig.AppParams) |
| 1406 | if err != nil { |
| 1407 | return buserr.WithMap("ErrFileParseApp", map[string]interface{}{"name": "data.yml", "err": err.Error()}, err) |
| 1408 | } |
| 1409 | var appParam dto.AppForm |
| 1410 | if err = json.Unmarshal(dataJson, &appParam); err != nil { |
| 1411 | return buserr.WithMap("ErrFileParseApp", map[string]interface{}{"name": "data.yml", "err": err.Error()}, err) |
| 1412 | } |
| 1413 | for _, formField := range appParam.FormFields { |
| 1414 | if strings.Contains(formField.EnvKey, " ") { |
| 1415 | return buserr.WithName("ErrAppParamKey", formField.EnvKey) |
| 1416 | } |
| 1417 | } |
| 1418 | |
| 1419 | var dataMap map[string]interface{} |
| 1420 | err = yaml.Unmarshal(paramByte, &dataMap) |
| 1421 | if err != nil { |
| 1422 | return buserr.WithMap("ErrFileParseApp", map[string]interface{}{"name": "data.yml", "err": err.Error()}, err) |
| 1423 | } |
| 1424 | |
| 1425 | additionalProperties, _ := dataMap["additionalProperties"].(map[string]interface{}) |
| 1426 | formFieldsInterface, ok := additionalProperties["formFields"] |
| 1427 | if ok { |
| 1428 | formFields, ok := formFieldsInterface.([]interface{}) |
| 1429 | if !ok { |
| 1430 | return buserr.WithName("ErrAppParamKey", "formFields") |
| 1431 | } |
| 1432 | for _, item := range formFields { |
| 1433 | field := item.(map[string]interface{}) |
| 1434 | for key, value := range field { |
| 1435 | if value == nil { |
| 1436 | return buserr.WithName("ErrAppParamKey", key) |
| 1437 | } |
| 1438 | } |
| 1439 | } |
no test coverage detected