Skip to content

Commit f568052

Browse files
authored
Merge pull request #6807 from devtron-labs/api-specs-post
misc: Api specs and validations added
2 parents f17457f + be881db commit f568052

File tree

60 files changed

+9877
-1893
lines changed

Some content is hidden

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

60 files changed

+9877
-1893
lines changed

CHANGELOG/release-notes-v1.8.0.md

Lines changed: 57 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,57 @@
1+
## v1.8.0
2+
3+
## Enhancements
4+
- feat: added the plugin for aws ecr retagging (#6695)
5+
- feat: Argo version update v2.13.3(#6817)
6+
- feat: ArgoCD v2.13.3 support for private chart providers (#6766)
7+
- feat: flux cd deployment (#6660)
8+
- feat: add app name in labels list api (#6688)
9+
- feat: Audit ci trigger, precd and post cd trigger so that retrigger can happen from last failed config snapshot (#6659)
10+
- feat: optimize ci cd workflow (#6744)
11+
- feat: automate API specs workflow and documentation (#6786)
12+
13+
## Bugs
14+
- fix: argo sync (#6718)
15+
- fix: cluster delete (#6706)
16+
- fix: Notifier v1 removed (#6705)
17+
- fix: app clone panic (#6696)
18+
- fix: Spdy migration to websocket (#6682)
19+
- fix: Fix scanning optimisation (#6683)
20+
- fix: panic in logs api (#6684)
21+
- fix: Empty migration seq (#6673)
22+
- fix: Removing default value of idleReplicaCount (#6721)
23+
- fix: send HideApiToken env var in api token create and update response (#6727)
24+
- fix: removed timeout notification (#6760)
25+
- fix: unify unit formatting and conversion for CPU and memory in cluster resources (#6768)
26+
- fix: cron job suspend (#6771)
27+
- fix: panic app group (#6785)
28+
- fix: api responses enhancements (#6797)
29+
- fix: post apis minor validations (#6811)
30+
- fix: dex scopes override default required scopes (#6816)
31+
- fix: error handler correction (#6824)
32+
33+
## Others
34+
- chore: added sql file of 4.21 (#6716)
35+
- misc: added support for service extraSpec (#6702)
36+
- chore: when output dir path is /devtroncd in any pipeline stage step then the ci runner is stuck in recursive self-copy situation (#6686)
37+
- misc: Removing default value of idleReplicaCount (#6730)
38+
- chore: chart service crud and configProperties (#6642)
39+
- misc: Added Github Actions for linting and building api specs (#6720)
40+
- misc: open api spec addition (#6750)
41+
- misc: Updated the build-docs.yaml (#6752)
42+
- misc: fixing swagger openapi.yaml (#6751)
43+
- misc: adding codeowner for swagger api spec (#6754)
44+
- misc: swagger api spec fixes (#6755)
45+
- misc: Update openapi spec (#6758)
46+
- misc: updated the title of openapi specs (#6759)
47+
- misc: Timeout main notification (#6761)
48+
- misc: Api changes for env enhancement (#6769)
49+
- misc: changes in description of api spec (#6767)
50+
- chore: Update `authenticator` and `common-lib` dependencies to latest versions. (#6779)
51+
- chore: added sql files for sync (#6780)
52+
- chore: migration number chnage (#6783)
53+
- chore: add resource recommendation APIs and update openapi.yaml (#6784)
54+
- misc: added support for cronjob annotations and probes (#6787)
55+
- misc: Validation on payload and Error handling, API Specs revised (#6790)
56+
- misc: sql query param refacter (#6810)
57+

api/appStore/chartGroup/ChartGroupRestHandler.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -191,7 +191,7 @@ func (impl *ChartGroupRestHandlerImpl) GetChartGroupWithChartMetaData(w http.Res
191191
}
192192

193193
// Use enhanced parameter parsing with context
194-
chartGroupId, err := common.ExtractIntPathParamWithContext(w, r, "chartGroupId", "chart group")
194+
chartGroupId, err := common.ExtractIntPathParamWithContext(w, r, "chartGroupId")
195195
if err != nil {
196196
// Error already written by ExtractIntPathParamWithContext
197197
return
@@ -223,7 +223,7 @@ func (impl *ChartGroupRestHandlerImpl) GetChartGroupInstallationDetail(w http.Re
223223
}
224224

225225
// Use enhanced parameter parsing with context
226-
chartGroupId, err := common.ExtractIntPathParamWithContext(w, r, "chartGroupId", "chart group")
226+
chartGroupId, err := common.ExtractIntPathParamWithContext(w, r, "chartGroupId")
227227
if err != nil {
228228
// Error already written by ExtractIntPathParamWithContext
229229
return

api/auth/user/UserRestHandler.go

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -210,7 +210,7 @@ func (handler UserRestHandlerImpl) GetById(w http.ResponseWriter, r *http.Reques
210210
}
211211

212212
// Use enhanced parameter parsing with context
213-
id, err := common.ExtractIntPathParamWithContext(w, r, "id", "user")
213+
id, err := common.ExtractIntPathParamWithContext(w, r, "id")
214214
if err != nil {
215215
// Error already written by ExtractIntPathParamWithContext
216216
return
@@ -334,7 +334,7 @@ func (handler UserRestHandlerImpl) DeleteUser(w http.ResponseWriter, r *http.Req
334334
}
335335

336336
// Use enhanced parameter parsing with context
337-
id, err := common.ExtractIntPathParamWithContext(w, r, "id", "user")
337+
id, err := common.ExtractIntPathParamWithContext(w, r, "id")
338338
if err != nil {
339339
// Error already written by ExtractIntPathParamWithContext
340340
return
@@ -427,7 +427,7 @@ func (handler UserRestHandlerImpl) BulkDeleteUsers(w http.ResponseWriter, r *htt
427427

428428
func (handler UserRestHandlerImpl) FetchRoleGroupById(w http.ResponseWriter, r *http.Request) {
429429
// Use enhanced parameter parsing with context
430-
id, err := common.ExtractIntPathParamWithContext(w, r, "id", "role group")
430+
id, err := common.ExtractIntPathParamWithContext(w, r, "id")
431431
if err != nil {
432432
// Error already written by ExtractIntPathParamWithContext
433433
return

api/chartRepo/ChartRepositoryRestHandler.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -85,7 +85,7 @@ func (handler *ChartRepositoryRestHandlerImpl) GetChartRepoById(w http.ResponseW
8585
}
8686

8787
// Use enhanced parameter parsing with context
88-
id, err := common.ExtractIntPathParamWithContext(w, r, "id", "chart repository")
88+
id, err := common.ExtractIntPathParamWithContext(w, r, "id")
8989
if err != nil {
9090
// Error already written by ExtractIntPathParamWithContext
9191
return

api/cluster/ClusterRestHandler.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -356,7 +356,7 @@ func (impl ClusterRestHandlerImpl) FindByIds(w http.ResponseWriter, r *http.Requ
356356

357357
func (impl ClusterRestHandlerImpl) FindById(w http.ResponseWriter, r *http.Request) {
358358
// Use enhanced parameter parsing with context
359-
clusterId, err := common.ExtractIntPathParamWithContext(w, r, "id", "cluster")
359+
clusterId, err := common.ExtractIntPathParamWithContext(w, r, "id")
360360
if err != nil {
361361
// Error already written by ExtractIntPathParamWithContext
362362
return
@@ -734,7 +734,7 @@ func (impl ClusterRestHandlerImpl) GetClusterNamespaces(w http.ResponseWriter, r
734734
isActionUserSuperAdmin = true
735735
}
736736
// extract cluster and handle response on error
737-
clusterId, err := common.ExtractIntPathParamWithContext(w, r, "clusterId", "cluster")
737+
clusterId, err := common.ExtractIntPathParamWithContext(w, r, "clusterId")
738738
if err != nil {
739739
impl.logger.Error("error in parsing clusterId", "clusterId", clusterId, "err", err)
740740
return

api/cluster/EnvironmentRestHandler.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -314,7 +314,7 @@ func (impl EnvironmentRestHandlerImpl) Update(w http.ResponseWriter, r *http.Req
314314

315315
func (impl EnvironmentRestHandlerImpl) FindById(w http.ResponseWriter, r *http.Request) {
316316
// Use enhanced parameter parsing with context
317-
envId, err := common.ExtractIntPathParamWithContext(w, r, "id", "environment")
317+
envId, err := common.ExtractIntPathParamWithContext(w, r, "id")
318318
if err != nil {
319319
// Error already written by ExtractIntPathParamWithContext
320320
return

api/k8s/application/k8sApplicationRestHandler.go

Lines changed: 17 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1002,14 +1002,19 @@ func (handler *K8sApplicationRestHandlerImpl) CreateEphemeralContainer(w http.Re
10021002
common.WriteJsonResp(w, err, nil, http.StatusBadRequest)
10031003
return
10041004
}
1005-
if err = handler.validator.Struct(request); err != nil || (request.BasicData == nil && request.AdvancedData == nil) {
1006-
if err != nil {
1007-
err = errors.New("invalid request payload")
1008-
}
1009-
handler.logger.Errorw("invalid request payload", "err", err, "payload", request)
1005+
if request.BasicData == nil && request.AdvancedData == nil {
1006+
err = errors.New("invalid request payload, neither basic data nor advanced data provided")
1007+
handler.logger.Errorw("invalid request payload missing basic data and invalid data", "err", err, "payload", request)
10101008
common.WriteJsonResp(w, err, nil, http.StatusBadRequest)
10111009
return
10121010
}
1011+
err = handler.validator.Struct(request)
1012+
if err != nil {
1013+
handler.logger.Errorw("invalid request payload", "err", err, "payload", request)
1014+
//common.WriteJsonResp(w, err, nil, http.StatusBadRequest)
1015+
common.HandleValidationErrors(w, r, err)
1016+
return
1017+
}
10131018
// check for super admin
10141019
restricted := handler.restrictTerminalAccessForNonSuperUsers(w, token)
10151020
if restricted {
@@ -1079,6 +1084,13 @@ func (handler *K8sApplicationRestHandlerImpl) DeleteEphemeralContainer(w http.Re
10791084
_, err = handler.k8sApplicationService.TerminatePodEphemeralContainer(request)
10801085
if err != nil {
10811086
handler.logger.Errorw("error occurred in terminating ephemeral container", "err", err, "requestPayload", request)
1087+
if err.Error() == bean4.EXTERNAL_EPHIMERAL_CONTAINER_ERR {
1088+
common.WriteJsonResp(w, err, nil, http.StatusForbidden)
1089+
return
1090+
} else if err.Error() == bean4.EPHEMERAL_CONTAINER_NOT_FOUND_ERR {
1091+
common.WriteJsonResp(w, err, nil, http.StatusNotFound)
1092+
return
1093+
}
10821094
common.WriteJsonResp(w, err, nil, http.StatusInternalServerError)
10831095
return
10841096
}

api/middleware/ErrorHandlingMiddleware.go

Lines changed: 3 additions & 48 deletions
Original file line numberDiff line numberDiff line change
@@ -19,12 +19,11 @@ package middleware
1919
import (
2020
"context"
2121
"fmt"
22-
"github.com/devtron-labs/devtron/internal/util"
23-
"github.com/gorilla/mux"
24-
"go.uber.org/zap"
2522
"net/http"
26-
"strconv"
2723
"time"
24+
25+
"github.com/gorilla/mux"
26+
"go.uber.org/zap"
2827
)
2928

3029
// ErrorHandlingMiddleware provides enhanced error handling and logging for REST handlers
@@ -156,47 +155,3 @@ func GetRequestContext(r *http.Request) *RequestContext {
156155
}
157156
return nil
158157
}
159-
160-
// LogError logs an error with request context for better debugging
161-
func (m *ErrorHandlingMiddleware) LogError(r *http.Request, err error, operation string) {
162-
reqCtx := GetRequestContext(r)
163-
if reqCtx != nil {
164-
m.logger.Errorw("Request error",
165-
"requestId", reqCtx.RequestID,
166-
"operation", operation,
167-
"error", err,
168-
"method", reqCtx.Method,
169-
"path", reqCtx.Path,
170-
"resourceType", reqCtx.ResourceType,
171-
"resourceId", reqCtx.ResourceID,
172-
)
173-
} else {
174-
m.logger.Errorw("Request error",
175-
"operation", operation,
176-
"error", err,
177-
"method", r.Method,
178-
"path", r.URL.Path,
179-
)
180-
}
181-
}
182-
183-
// ValidateIntPathParam validates and extracts an integer path parameter with enhanced error handling
184-
func ValidateIntPathParam(r *http.Request, paramName string) (int, *util.ApiError) {
185-
vars := mux.Vars(r)
186-
paramValue := vars[paramName]
187-
188-
if paramValue == "" {
189-
return 0, util.NewMissingRequiredFieldError(paramName)
190-
}
191-
192-
id, err := strconv.Atoi(paramValue)
193-
if err != nil {
194-
return 0, util.NewInvalidPathParameterError(paramName, paramValue)
195-
}
196-
197-
if id <= 0 {
198-
return 0, util.NewValidationErrorForField(paramName, "must be a positive integer")
199-
}
200-
201-
return id, nil
202-
}

api/restHandler/CoreAppRestHandler.go

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -155,11 +155,9 @@ func (handler CoreAppRestHandlerImpl) GetAppAllDetail(w http.ResponseWriter, r *
155155
return
156156
}
157157

158-
vars := mux.Vars(r)
159-
appId, err := strconv.Atoi(vars["appId"])
158+
appId, err := common.ExtractIntPathParamWithContext(w, r, "appId")
160159
if err != nil {
161-
handler.logger.Errorw("request err, GetAppAllDetail", "err", err, "appId", vars["appId"])
162-
common.WriteInvalidAppIdError(w, vars["appId"])
160+
common.WriteJsonResp(w, err, nil, http.StatusBadRequest)
163161
return
164162
}
165163

api/restHandler/NotificationRestHandler.go

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -220,13 +220,13 @@ func (impl NotificationRestHandlerImpl) DeleteNotificationSettings(w http.Respon
220220

221221
func (impl NotificationRestHandlerImpl) GetAllNotificationSettings(w http.ResponseWriter, r *http.Request) {
222222
// Use enhanced parameter parsing with context
223-
size, err := common.ExtractIntPathParamWithContext(w, r, "size", "pagination")
223+
size, err := common.ExtractIntPathParamWithContext(w, r, "size")
224224
if err != nil {
225225
// Error already written by ExtractIntPathParamWithContext
226226
return
227227
}
228228

229-
offset, err := common.ExtractIntPathParamWithContext(w, r, "offset", "pagination")
229+
offset, err := common.ExtractIntPathParamWithContext(w, r, "offset")
230230
if err != nil {
231231
// Error already written by ExtractIntPathParamWithContext
232232
return
@@ -522,7 +522,7 @@ func (impl NotificationRestHandlerImpl) FindSESConfig(w http.ResponseWriter, r *
522522
}
523523

524524
// Use enhanced parameter parsing with context
525-
id, err := common.ExtractIntPathParamWithContext(w, r, "id", "SES config")
525+
id, err := common.ExtractIntPathParamWithContext(w, r, "id")
526526
if err != nil {
527527
// Error already written by ExtractIntPathParamWithContext
528528
return
@@ -551,7 +551,7 @@ func (impl NotificationRestHandlerImpl) FindSlackConfig(w http.ResponseWriter, r
551551
}
552552

553553
// Use enhanced parameter parsing with context
554-
id, err := common.ExtractIntPathParamWithContext(w, r, "id", "Slack config")
554+
id, err := common.ExtractIntPathParamWithContext(w, r, "id")
555555
if err != nil {
556556
// Error already written by ExtractIntPathParamWithContext
557557
return

0 commit comments

Comments
 (0)