Skip to content

Commit fd16464

Browse files
prkhrkatiamayushmAsh-expprakash100198vikramdevtron
authored
misc: Validation on payload and Error handling, API Specs revised (#6790)
* corrected api specs * specs enhance * Merge pull request #6771 from devtron-labs/fix-cron-job-suspend fix: cron job suspend * fix: update default sequence for bulk edit config table and correct README link * corrected specs * corrected specs * Improve CI status fetching logic in `CiHandlerImpl` to handle linked pipelines, add duplicate removal utility, and enhance logging and fallback mechanisms. * Refactor `CiHandlerImpl` to modularize and streamline CI pipeline status fetching, extracting common logic into reusable functions and improving linked pipeline handling. * Remove redundant comments in `CiHandler.go` to enhance code clarity and maintain consistency with refactored CI status handling logic. * Clean up redundant comments in `preparePipelineStatusLookup` to enhance readability and align with refactored CI pipeline handling logic. * Remove unused `mapWorkflowsToLinkedPipelines` function from `CiHandler.go` to enhance code clarity and eliminate dead code. * Extract `RemoveDuplicateInts` utility to `CiCdUtil.go` for reusability and replace the inlined method in `CiHandler.go`. * vendor for spec-validator * spec-fixes as per cursor when ran on results file * spec-fixes manually for /orchestrator path * script fix to run against server * naming changed from devtron-lab duplicated removed ap spec correction * removed extra code * wip: adding cluster status * fix cluster status * Enhance CI status fetching in `CiHandlerImpl` to handle linked pipelines. Add linked pipeline mapping and workflow statuses, refactor status population logic, and introduce reusable adapter methods for linked CI workflows. * framework.go update * api-spec fix api-spec fix api-spec fix api-spec fix API Error wrapper API Error wrapper specs fixes * spec fix * script fix * Update workflow status table scripts to latest version. * Update `authenticator` and `common-lib` dependencies to latest versions. * added sql ent files (#6780) * devops specs included * script fix * script fix * migration number chnage (#6783) * feat: add resource recommendation APIs and update openapi.yaml * feat: add Resource Recommendation to openapi.yaml * specs fix * redocly script to generate html * refact * refact * refact * doc: api spec merger * chore: test commit * misc: script name rectified in action file * misc: testing change in /spec * misc: test commit * misc: test commit * refact * refact * refact * refact * feat: action fix and resource recommender specs * fix: action fixes * chore: test trigger commit * chore: test run commit * chore: test commit * chore: test commit * feat: git push job in action file * feat: git push job in action file * chore: test commit * chore: test commit * chore: test commit * chore: test commit * fix panic * chore: test commit * chore: test commit * chore: test commit * fix: script misc chore fixes and trigger commit * fix: script fixes * fix: script fixes * fix: script fixes * fix: script fixes * fix: script fixes * fix: script fixes * fix: script fixes * create API token validation * misc: added support for cronjob annotations and probes (#6787) * added support for cronjob annotations and probes * support for older charts * reconfiguring semverCompare * removed restartPolicy from cronjob-config * added support for external-secrets.io/v1 * added default values for eso * older compatibility * rectify the semverCompare * added support for jobLabels and jobAnnotations * refact * refact * security policy specs fixed * refact * refact * refact * refact * refact * refact * ent separation * ent separation * feat: automate API specs workflow and documentation (#6786) * feat: api spec hosting mechanism * fix: trigger condition update on wf file * fix: remove old wf * refact in specs * generate-api-docs.sh fix --------- Co-authored-by: prakhar katiyar <[email protected]> Co-authored-by: prakhar katiyar <[email protected]> * driftSpec.yaml added * fix: API token generation api responses refactoring (#6788) * fix: API token generation api responses refactoring * fix: register custom validation against tag for api token name validations * fix: register custom validation against tag for api token name validations * Revert "fix: register custom validation against tag for api token name validations" This reverts commit 7593c27. * fix: remove `required` validation from Description and expiryAtInMs * fix: adding resource conflict api response in WriteJsonResp utility * fix: path params int validation updated to whole numbers only * fix: handled resource not found response for update and delete api, token * path corrected * cmscs added * corrected specs * fix: api responses (#6789) * fix: API token generation api responses refactoring * fix: register custom validation against tag for api token name validations * fix: register custom validation against tag for api token name validations * Revert "fix: register custom validation against tag for api token name validations" This reverts commit 7593c27. * fix: remove `required` validation from Description and expiryAtInMs * fix: adding resource conflict api response in WriteJsonResp utility * fix: path params int validation updated to whole numbers only * fix: handled resource not found response for update and delete api, token * fix: validation for SSO config name field * fix: enhanced query param validation for commit metadata for pipeline material * fix: disable updating clsutername and api name in update clsuter api * fix: enhanced api response in query param validation failure reeors in ge default deployment template * fix: disable modifying cluster nae and env name in update env api * fix: resolving review comments * fix: resolving review comments --------- Co-authored-by: iamayushm <[email protected]> Co-authored-by: Ash-exp <[email protected]> Co-authored-by: Prakash Kumar <[email protected]> Co-authored-by: ayushmaheshwari <[email protected]> Co-authored-by: Vikram <[email protected]> Co-authored-by: Shivam Nagar <[email protected]> Co-authored-by: SATYAsasini <[email protected]> Co-authored-by: Badal Kumar <[email protected]> Co-authored-by: satya_prakash <[email protected]>
1 parent 97ef69c commit fd16464

File tree

315 files changed

+42987
-21396
lines changed

Some content is hidden

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

315 files changed

+42987
-21396
lines changed

.github/workflows/api-linter.yaml

Lines changed: 0 additions & 26 deletions
This file was deleted.
Lines changed: 57 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,57 @@
1+
name: API Specs Merger
2+
3+
on:
4+
push:
5+
branches:
6+
- main
7+
paths:
8+
- 'specs/**'
9+
permissions:
10+
contents: write
11+
12+
jobs:
13+
lint-bundle-host:
14+
runs-on: ubuntu-latest
15+
steps:
16+
- name: Checkout repository
17+
uses: actions/checkout@v4
18+
with:
19+
ref: ${{ github.ref }}
20+
21+
- name: Set up Redocly CLI
22+
run: npm install -g @redocly/cli
23+
24+
- name: Run specs bundling script
25+
working-directory: ${{ github.workspace }}
26+
run: |
27+
chmod +x scripts/generate-api-docs.sh
28+
./scripts/generate-api-docs.sh
29+
30+
- name: Commit and push documentation
31+
env:
32+
GITHUB_TOKEN: ${{ secrets.GH_SYSTEMSDT_TOKEN }}
33+
run: |
34+
git config --local user.email "[email protected]"
35+
git config --local user.name "GitHub Action"
36+
37+
# Fetch the gh-pages branch
38+
git fetch origin gh-pages
39+
40+
# Create a separate worktree for the branch
41+
git worktree add /tmp/gh-pages gh-pages
42+
43+
# Copy generated docs into the worktree
44+
mkdir -p /tmp/gh-pages/docs/api-docs
45+
cp -r docs/api-docs/* /tmp/gh-pages/docs/api-docs/ || true
46+
47+
cd /tmp/gh-pages
48+
49+
git add .
50+
if git diff --staged --quiet; then
51+
echo "✅ No changes to commit"
52+
else
53+
git commit -m "📄 Update API documentation"
54+
git push origin gh-pages
55+
echo "🚀 Documentation pushed to gh-pages branch!"
56+
fi
57+

.github/workflows/build-docs.yaml

Lines changed: 0 additions & 63 deletions
This file was deleted.

.gitignore

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,5 +4,6 @@
44
.env
55
/cmd/external-app/devtron-ea
66
devtron
7-
7+
/tests/api-spec-validation/bin
8+
/tests/api-spec-validation/reports
89
.qodo

api/apiToken/ApiTokenRestHandler.go

Lines changed: 11 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -18,9 +18,6 @@ package apiToken
1818

1919
import (
2020
"encoding/json"
21-
"net/http"
22-
"strconv"
23-
2421
openapi "github.com/devtron-labs/devtron/api/openapi/openapiClient"
2522
"github.com/devtron-labs/devtron/api/restHandler/common"
2623
"github.com/devtron-labs/devtron/pkg/apiToken"
@@ -30,6 +27,8 @@ import (
3027
"github.com/juju/errors"
3128
"go.uber.org/zap"
3229
"gopkg.in/go-playground/validator.v9"
30+
"net/http"
31+
"strconv"
3332
)
3433

3534
type ApiTokenRestHandler interface {
@@ -62,7 +61,7 @@ func NewApiTokenRestHandlerImpl(logger *zap.SugaredLogger, apiTokenService apiTo
6261
func (impl ApiTokenRestHandlerImpl) GetAllApiTokens(w http.ResponseWriter, r *http.Request) {
6362
userId, err := impl.userService.GetLoggedInUser(r)
6463
if userId == 0 || err != nil {
65-
common.WriteJsonResp(w, err, "Unauthorized User", http.StatusUnauthorized)
64+
common.HandleUnauthorized(w, r)
6665
return
6766
}
6867

@@ -86,7 +85,7 @@ func (impl ApiTokenRestHandlerImpl) GetAllApiTokens(w http.ResponseWriter, r *ht
8685
func (impl ApiTokenRestHandlerImpl) CreateApiToken(w http.ResponseWriter, r *http.Request) {
8786
userId, err := impl.userService.GetLoggedInUser(r)
8887
if userId == 0 || err != nil {
89-
common.WriteJsonResp(w, err, "Unauthorized User", http.StatusUnauthorized)
88+
common.HandleUnauthorized(w, r)
9089
return
9190
}
9291

@@ -103,19 +102,15 @@ func (impl ApiTokenRestHandlerImpl) CreateApiToken(w http.ResponseWriter, r *htt
103102
err = decoder.Decode(&request)
104103
if err != nil {
105104
impl.logger.Errorw("err in decoding request in CreateApiToken", "err", err)
106-
common.WriteJsonResp(w, err, nil, http.StatusBadRequest)
105+
common.WriteJsonResp(w, errors.New("invalid JSON payload "+err.Error()), nil, http.StatusBadRequest)
107106
return
108107
}
109108

110-
// validate request
109+
// validate request structure
111110
err = impl.validator.Struct(request)
112111
if err != nil {
113-
impl.logger.Errorw("validation err in CreateApiToken", "err", err, "request", request)
114-
common.WriteJsonResp(w, err, nil, http.StatusBadRequest)
115-
return
116-
}
117-
if len(*request.Name) == 0 {
118-
common.WriteJsonResp(w, errors.New("name cannot be blank in the request"), nil, http.StatusBadRequest)
112+
impl.logger.Errorw("validation err in CreateApiToken ", "err", err, "request", request)
113+
common.HandleValidationErrors(w, r, err)
119114
return
120115
}
121116

@@ -132,7 +127,7 @@ func (impl ApiTokenRestHandlerImpl) CreateApiToken(w http.ResponseWriter, r *htt
132127
func (impl ApiTokenRestHandlerImpl) UpdateApiToken(w http.ResponseWriter, r *http.Request) {
133128
userId, err := impl.userService.GetLoggedInUser(r)
134129
if userId == 0 || err != nil {
135-
common.WriteJsonResp(w, err, "Unauthorized User", http.StatusUnauthorized)
130+
common.HandleUnauthorized(w, r)
136131
return
137132
}
138133

@@ -182,7 +177,7 @@ func (impl ApiTokenRestHandlerImpl) UpdateApiToken(w http.ResponseWriter, r *htt
182177
func (impl ApiTokenRestHandlerImpl) DeleteApiToken(w http.ResponseWriter, r *http.Request) {
183178
userId, err := impl.userService.GetLoggedInUser(r)
184179
if userId == 0 || err != nil {
185-
common.WriteJsonResp(w, err, "Unauthorized User", http.StatusUnauthorized)
180+
common.HandleUnauthorized(w, r)
186181
return
187182
}
188183

@@ -221,7 +216,7 @@ func (handler ApiTokenRestHandlerImpl) checkManagerAuth(resource, token, object
221216
func (impl ApiTokenRestHandlerImpl) GetAllApiTokensForWebhook(w http.ResponseWriter, r *http.Request) {
222217
userId, err := impl.userService.GetLoggedInUser(r)
223218
if userId == 0 || err != nil {
224-
common.WriteJsonResp(w, err, "Unauthorized User", http.StatusUnauthorized)
219+
common.HandleUnauthorized(w, r)
225220
return
226221
}
227222

api/appStore/InstalledAppRestHandler.go

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -177,7 +177,7 @@ func (handler *InstalledAppRestHandlerImpl) FetchAppOverview(w http.ResponseWrit
177177
func (handler InstalledAppRestHandlerImpl) GetAllInstalledApp(w http.ResponseWriter, r *http.Request) {
178178
userId, err := handler.userAuthService.GetLoggedInUser(r)
179179
if userId == 0 || err != nil {
180-
common.WriteJsonResp(w, err, "Unauthorized User", http.StatusUnauthorized)
180+
common.HandleUnauthorized(w, r)
181181
return
182182
}
183183
v := r.URL.Query()
@@ -343,7 +343,7 @@ func (handler InstalledAppRestHandlerImpl) GetAllInstalledApp(w http.ResponseWri
343343
func (handler *InstalledAppRestHandlerImpl) DeployBulk(w http.ResponseWriter, r *http.Request) {
344344
userId, err := handler.userAuthService.GetLoggedInUser(r)
345345
if userId == 0 || err != nil {
346-
common.WriteJsonResp(w, err, "Unauthorized User", http.StatusUnauthorized)
346+
common.HandleUnauthorized(w, r)
347347
return
348348
}
349349
decoder := json.NewDecoder(r.Body)
@@ -512,7 +512,7 @@ func (handler *InstalledAppRestHandlerImpl) getChartGroupInstallMetadata(req *ch
512512
func (handler *InstalledAppRestHandlerImpl) CheckAppExists(w http.ResponseWriter, r *http.Request) {
513513
userId, err := handler.userAuthService.GetLoggedInUser(r)
514514
if userId == 0 || err != nil {
515-
common.WriteJsonResp(w, err, "Unauthorized User", http.StatusUnauthorized)
515+
common.HandleUnauthorized(w, r)
516516
return
517517
}
518518
decoder := json.NewDecoder(r.Body)
@@ -538,7 +538,7 @@ func (impl *InstalledAppRestHandlerImpl) DefaultComponentInstallation(w http.Res
538538
userId, err := impl.userAuthService.GetLoggedInUser(r)
539539
if userId == 0 || err != nil {
540540
impl.Logger.Errorw("service err, DefaultComponentInstallation", "error", err, "userId", userId)
541-
common.WriteJsonResp(w, err, "Unauthorized User", http.StatusUnauthorized)
541+
common.HandleUnauthorized(w, r)
542542
return
543543
}
544544
vars := mux.Vars(r)
@@ -885,7 +885,7 @@ func (handler *InstalledAppRestHandlerImpl) fetchResourceTreeWithHibernateForACD
885885
func (handler *InstalledAppRestHandlerImpl) MigrateDeploymentTypeForChartStore(w http.ResponseWriter, r *http.Request) {
886886
userId, err := handler.userAuthService.GetLoggedInUser(r)
887887
if userId == 0 || err != nil {
888-
common.WriteJsonResp(w, err, "Unauthorized User", http.StatusUnauthorized)
888+
common.HandleUnauthorized(w, r)
889889
return
890890
}
891891

@@ -929,7 +929,7 @@ func (handler *InstalledAppRestHandlerImpl) MigrateDeploymentTypeForChartStore(w
929929
func (handler *InstalledAppRestHandlerImpl) TriggerChartStoreAppAfterMigration(w http.ResponseWriter, r *http.Request) {
930930
userId, err := handler.userAuthService.GetLoggedInUser(r)
931931
if userId == 0 || err != nil {
932-
common.WriteJsonResp(w, err, "Unauthorized User", http.StatusUnauthorized)
932+
common.HandleUnauthorized(w, r)
933933
return
934934
}
935935

0 commit comments

Comments
 (0)