-
Notifications
You must be signed in to change notification settings - Fork 556
External links extention for app level #2573
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
Show all changes
121 commits
Select commit
Hold shift + click to select a range
d00b60a
api spec update
gireesh-naidu 29de140
repository update for monitoring tool
gireesh-naidu 5e6eee0
added external_link_identifier _mapping repository
gireesh-naidu 0007b1b
updated external_link repository
gireesh-naidu 0905cf2
removed external_link_cluster_mapping repository file
gireesh-naidu e555159
api spec update
gireesh-naidu 427a537
updated create external link method
gireesh-naidu cc89dee
struct change and identifier passed by pointer
gireesh-naidu 7fc247f
updated fetch api
gireesh-naidu 8a90b3e
query updates
gireesh-naidu 097bf66
fetching cluster level links for a particular app and wrote code for …
gireesh-naidu 361f908
delete api code update
gireesh-naidu d5042a5
unwanted comments deleted
gireesh-naidu b528d9d
implemented get links rest handler
gireesh-naidu 5e34927
added edit access check for delete operation
gireesh-naidu 40f2851
modified update,delete and create handlers
gireesh-naidu f5ba9b4
wire
gireesh-naidu d62cf85
struct update
gireesh-naidu 8d404a6
fix err check condition
gireesh-naidu 31e2ace
fixed returning
gireesh-naidu b38547c
testing roles code
gireesh-naidu 0f9bf85
wire
gireesh-naidu aa1f1ff
removed commented code
gireesh-naidu 06b84b0
sending action as argument to roleChecker
gireesh-naidu 3301613
rbac by appname and envid
gireesh-naidu d3efce5
appListing api to fetch all the active installed apps and devtron apps
gireesh-naidu b5e2d07
query fix
gireesh-naidu fb4afdf
comments fix
gireesh-naidu 1a26de3
redundant check removed
gireesh-naidu aba0866
removed commented code
gireesh-naidu 1ae280f
fix
gireesh-naidu d1660e3
sql migration script added for external links feat
gireesh-naidu acf7991
added env_id and changed the enforcing to app-level
gireesh-naidu 108eda8
code review changes
gireesh-naidu 671388f
appid passing
gireesh-naidu 8c81f31
rolecheck api at handler level
gireesh-naidu 2fb96c5
check roles api enhanced
gireesh-naidu 90c1f12
scripts updated
gireesh-naidu 552d2ec
script number update
gireesh-naidu 5ceb5c2
added last deployedAt field in other env api
gireesh-naidu 77b1730
code refactor
gireesh-naidu 7f6077a
commented commands removed
gireesh-naidu e71e1a1
fix
gireesh-naidu 72c89f2
fix
gireesh-naidu 1183853
merge main
gireesh-naidu e297ec5
Merge remote-tracking branch 'origin/external_links_extention' into e…
gireesh-naidu 57d63de
query indentation fix
gireesh-naidu 0832b4d
query indentation fix
gireesh-naidu cd2eb53
last deployed time query
gireesh-naidu f6d50be
fix
gireesh-naidu e233dfe
fix
gireesh-naidu b371437
query added for last deployed time
gireesh-naidu fc0ee4e
query update
gireesh-naidu fb9794d
response fix
gireesh-naidu 0aa077f
error messages corrected
gireesh-naidu d0bcf9a
removed unused code
gireesh-naidu 2450cb7
unit tests added
gireesh-naidu 345d8e0
unit tests added for fetch api
gireesh-naidu 645d20d
unit tests done for fetch api
gireesh-naidu eeffd6b
unit tests done for update api
gireesh-naidu 23deee2
tests updated
gireesh-naidu 9501174
condition fix
gireesh-naidu cc168d2
param check updated
gireesh-naidu a043664
removed unused code
gireesh-naidu 4e64588
removed unused code
gireesh-naidu 7874d66
checks for global level links
gireesh-naidu 03fc102
added new tools and category field
gireesh-naidu 76e8d3c
delete fix
gireesh-naidu 8a64728
delete api fix
gireesh-naidu 7e5d9b0
test cmt
gireesh-naidu ebabada
wire
gireesh-naidu 6bfb9f0
code review changes
gireesh-naidu cc9a920
error fix
gireesh-naidu 0d60a1a
code review changes
gireesh-naidu 71265cc
api error messages updated
gireesh-naidu 78cb8f2
api error messages updated
gireesh-naidu cb7d9d2
global link type switching fix
gireesh-naidu 353c01a
fix
gireesh-naidu 2547b99
other env query fix
gireesh-naidu 04fe5fc
query fix
gireesh-naidu 5b10a01
merge main
gireesh-naidu a049c68
script number updated
gireesh-naidu 2e67f60
code review changes
gireesh-naidu 0c5cd43
removed extra auth check in service layer
gireesh-naidu 4790b50
test
gireesh-naidu b4482ea
test
gireesh-naidu bc447cd
check role API fix
kripanshdevtron bffb5ce
qa bug fix(some active links not showing)
gireesh-naidu 13d4910
Merge branch 'main' into external_links_extention
gireesh-naidu 6b6a63f
unit testcases modified
gireesh-naidu a015c17
unit testcases modified with max coverage
gireesh-naidu d1b80e9
integration test cases added
gireesh-naidu 5bfa3ce
integration test cases added for update api
gireesh-naidu 1bfefc8
integration test cases added for delete api
gireesh-naidu 8d832fb
fixed cleandb func
gireesh-naidu ff4a9e7
invalid input tests added
gireesh-naidu d16439a
added admin edit test
gireesh-naidu 3f38613
config changes
gireesh-naidu d01618d
cleaning un-used methods
gireesh-naidu 4a608c5
default config vals added
gireesh-naidu 104ee79
querying based on app type condition
gireesh-naidu db5c64f
removed unused functions
gireesh-naidu 75bb60f
tests added for monitoring tools repo
gireesh-naidu f72f98a
test cases added for fetch active external links by identifier
gireesh-naidu f0b532a
integration test added for apps to apps update link case
gireesh-naidu 16d9ed9
removed un used code
gireesh-naidu 15de03f
removed un used code
gireesh-naidu cc087f7
fix
gireesh-naidu b1f10f2
script number updated
gireesh-naidu 2693b86
Merge branch 'main' into external_links_extention
gireesh-naidu c6befb9
removed un-necessary logic
gireesh-naidu 60e0b52
changed native query to orm queries
gireesh-naidu 8f50031
no rows handling
gireesh-naidu 2f6ee03
code review changes
gireesh-naidu 2807cda
test skips added
gireesh-naidu 11ebdcd
no rows error logic removed from resthandler layer
gireesh-naidu 8a5c89d
native query to orm query
gireesh-naidu 4ff56b6
code review changes
gireesh-naidu ef2e5f8
script number updated
gireesh-naidu f73cac3
merge main
gireesh-naidu 1672261
vendor files update
gireesh-naidu File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -19,10 +19,13 @@ package externalLink | |
|
|
||
| import ( | ||
| "encoding/json" | ||
| "fmt" | ||
| "github.com/devtron-labs/devtron/api/restHandler/common" | ||
| "github.com/devtron-labs/devtron/pkg/externalLink" | ||
| "github.com/devtron-labs/devtron/pkg/user" | ||
| "github.com/devtron-labs/devtron/pkg/user/casbin" | ||
| "github.com/devtron-labs/devtron/util/rbac" | ||
| "github.com/go-pg/pg" | ||
| "github.com/gorilla/mux" | ||
| "github.com/juju/errors" | ||
| "go.uber.org/zap" | ||
|
|
@@ -42,24 +45,61 @@ type ExternalLinkRestHandlerImpl struct { | |
| externalLinkService externalLink.ExternalLinkService | ||
| userService user.UserService | ||
| enforcer casbin.Enforcer | ||
| enforcerUtil rbac.EnforcerUtil | ||
| } | ||
|
|
||
| func NewExternalLinkRestHandlerImpl(logger *zap.SugaredLogger, | ||
| externalLinkService externalLink.ExternalLinkService, | ||
| userService user.UserService, | ||
| enforcer casbin.Enforcer, | ||
| enforcerUtil rbac.EnforcerUtil, | ||
| ) *ExternalLinkRestHandlerImpl { | ||
| return &ExternalLinkRestHandlerImpl{ | ||
| logger: logger, | ||
| externalLinkService: externalLinkService, | ||
| userService: userService, | ||
| enforcer: enforcer, | ||
| enforcerUtil: enforcerUtil, | ||
| } | ||
| } | ||
| func (impl ExternalLinkRestHandlerImpl) CreateExternalLinks(w http.ResponseWriter, r *http.Request) { | ||
|
|
||
| func (impl ExternalLinkRestHandlerImpl) roleCheckHelper(w http.ResponseWriter, r *http.Request, action string) (int32, string, error) { | ||
| userId, err := impl.userService.GetLoggedInUser(r) | ||
| if userId == 0 || err != nil { | ||
| common.WriteJsonResp(w, err, "Unauthorized User", http.StatusUnauthorized) | ||
| return userId, "", fmt.Errorf("unauthorized error") | ||
| } | ||
| userRole := "" | ||
| v := r.URL.Query() | ||
| //put this check from identifiers itself,don't get this appname from query params | ||
| appId := v.Get("appId") | ||
| token := r.Header.Get("token") | ||
| if v.Has("appId") { | ||
| id, err := strconv.Atoi(appId) | ||
| if err != nil { | ||
| impl.logger.Errorw("error occurred while converting appId to integer", "err", err, "appId", appId) | ||
| common.WriteJsonResp(w, errors.New("Invalid request"), nil, http.StatusBadRequest) | ||
| return userId, "", fmt.Errorf("invalid request query param appId = %s", appId) | ||
| } | ||
| object := impl.enforcerUtil.GetAppRBACNameByAppId(id) | ||
| if ok := impl.enforcer.Enforce(token, casbin.ResourceApplications, action, object); !ok { | ||
| common.WriteJsonResp(w, errors.New("unauthorized"), nil, http.StatusForbidden) | ||
| return userId, "", fmt.Errorf("unauthorized error") | ||
| } | ||
| userRole = externalLink.ADMIN_ROLE | ||
| } else { | ||
| if ok := impl.enforcer.Enforce(token, casbin.ResourceGlobal, action, "*"); !ok { | ||
| common.WriteJsonResp(w, errors.New("unauthorized"), nil, http.StatusForbidden) | ||
| return userId, "", fmt.Errorf("unauthorized error") | ||
| } | ||
| userRole = externalLink.SUPER_ADMIN_ROLE | ||
| } | ||
| return userId, userRole, nil | ||
| } | ||
| func (impl ExternalLinkRestHandlerImpl) CreateExternalLinks(w http.ResponseWriter, r *http.Request) { | ||
| userId, userRole, err := impl.roleCheckHelper(w, r, casbin.ActionCreate) | ||
| if err != nil { | ||
| impl.logger.Errorw("error in CreateExternalLinks ", "err", err) | ||
| return | ||
| } | ||
| decoder := json.NewDecoder(r.Body) | ||
|
|
@@ -70,15 +110,8 @@ func (impl ExternalLinkRestHandlerImpl) CreateExternalLinks(w http.ResponseWrite | |
| common.WriteJsonResp(w, err, nil, http.StatusBadRequest) | ||
| return | ||
| } | ||
|
|
||
| token := r.Header.Get("token") | ||
| if ok := impl.enforcer.Enforce(token, casbin.ResourceGlobal, casbin.ActionCreate, "*"); !ok { | ||
| common.WriteJsonResp(w, errors.New("unauthorized"), nil, http.StatusForbidden) | ||
| return | ||
| } | ||
|
|
||
| res, err := impl.externalLinkService.Create(beans, userId) | ||
| if err != nil { | ||
| res, err := impl.externalLinkService.Create(beans, userId, userRole) | ||
| if err != nil && err != pg.ErrNoRows { | ||
| impl.logger.Errorw("service err, SaveLink", "err", err, "payload", beans) | ||
| common.WriteJsonResp(w, err, nil, http.StatusInternalServerError) | ||
| return | ||
|
|
@@ -92,10 +125,9 @@ func (impl ExternalLinkRestHandlerImpl) GetExternalLinkMonitoringTools(w http.Re | |
| return | ||
| } | ||
|
|
||
| // auth free api as we using this for multiple places | ||
|
|
||
| // auth free api as we are using this for multiple places | ||
| res, err := impl.externalLinkService.GetAllActiveTools() | ||
| if err != nil { | ||
| if err != nil && err != pg.ErrNoRows { | ||
| impl.logger.Errorw("service err, GetAllActiveTools", "err", err) | ||
| common.WriteJsonResp(w, err, nil, http.StatusInternalServerError) | ||
| return | ||
|
|
@@ -108,38 +140,62 @@ func (impl ExternalLinkRestHandlerImpl) GetExternalLinks(w http.ResponseWriter, | |
| common.WriteJsonResp(w, err, "Unauthorized User", http.StatusUnauthorized) | ||
| return | ||
| } | ||
|
|
||
| v := r.URL.Query() | ||
| id := v.Get("clusterId") | ||
| clusterId := 0 | ||
| if len(id) > 0 { | ||
| clusterId, err = strconv.Atoi(id) | ||
| if err != nil { | ||
| common.WriteJsonResp(w, err, nil, http.StatusBadRequest) | ||
| return | ||
| } | ||
| } | ||
| clusterId := v.Get("clusterId") | ||
| linkType := v.Get("type") | ||
| identifier := v.Get("identifier") | ||
|
|
||
| //apply auth only in case when requested for all links | ||
| if clusterId == 0 { | ||
| token := r.Header.Get("token") | ||
| token := r.Header.Get("token") | ||
| if len(identifier) == 0 && len(linkType) == 0 && len(clusterId) == 0 { | ||
| if ok := impl.enforcer.Enforce(token, casbin.ResourceGlobal, casbin.ActionGet, "*"); !ok { | ||
| common.WriteJsonResp(w, errors.New("unauthorized"), nil, http.StatusForbidden) | ||
| return | ||
| } | ||
| } | ||
| clusterIdNumber := 0 | ||
| res, err := impl.externalLinkService.FetchAllActiveLinksByLinkIdentifier(nil, clusterIdNumber) | ||
| if err != nil { | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. error is not logged and handled properly |
||
| impl.logger.Errorw("service err, FetchAllActive", "err", err) | ||
| common.WriteJsonResp(w, err, nil, http.StatusInternalServerError) | ||
| return | ||
| } | ||
| common.WriteJsonResp(w, err, res, http.StatusOK) | ||
| return | ||
|
|
||
| res, err := impl.externalLinkService.FetchAllActiveLinks(clusterId) | ||
| if err != nil { | ||
| impl.logger.Errorw("service err, FetchAllActive", "err", err) | ||
| common.WriteJsonResp(w, err, nil, http.StatusInternalServerError) | ||
| } else if len(identifier) != 0 && len(linkType) != 0 { //api to get external links from app-level external links tab and from app-details page | ||
| clusterIdNumber := 0 | ||
| if len(clusterId) != 0 { //api call from app-detail page | ||
| clusterIdNumber, err = strconv.Atoi(clusterId) | ||
| if err != nil { | ||
| impl.logger.Errorw("error occurred while parsing cluster_id", "clusterId", clusterId, "err", err) | ||
| common.WriteJsonResp(w, err, nil, http.StatusBadRequest) | ||
| return | ||
| } | ||
| } | ||
| linkIdentifier := &externalLink.LinkIdentifier{ | ||
| Type: linkType, | ||
| Identifier: identifier, | ||
| ClusterId: 0, | ||
| } | ||
| res, err := impl.externalLinkService.FetchAllActiveLinksByLinkIdentifier(linkIdentifier, clusterIdNumber) | ||
| if err != nil { | ||
| impl.logger.Errorw("service err, FetchAllActive", "err", err) | ||
| common.WriteJsonResp(w, err, nil, http.StatusInternalServerError) | ||
| return | ||
| } | ||
| common.WriteJsonResp(w, err, res, http.StatusOK) | ||
| return | ||
| } | ||
| common.WriteJsonResp(w, err, res, http.StatusOK) | ||
|
|
||
| impl.logger.Errorw("invalid request, FetchAllActive external links", "err", err) | ||
| common.WriteJsonResp(w, err, nil, http.StatusBadRequest) | ||
| return | ||
|
|
||
| } | ||
|
|
||
| func (impl ExternalLinkRestHandlerImpl) UpdateExternalLink(w http.ResponseWriter, r *http.Request) { | ||
| userId, err := impl.userService.GetLoggedInUser(r) | ||
| if userId == 0 || err != nil { | ||
| common.WriteJsonResp(w, err, "Unauthorized User", http.StatusUnauthorized) | ||
| userId, userRole, err := impl.roleCheckHelper(w, r, casbin.ActionUpdate) | ||
| if err != nil { | ||
| return | ||
| } | ||
| decoder := json.NewDecoder(r.Body) | ||
|
|
@@ -152,45 +208,32 @@ func (impl ExternalLinkRestHandlerImpl) UpdateExternalLink(w http.ResponseWriter | |
| } | ||
| bean.UserId = userId | ||
|
|
||
| token := r.Header.Get("token") | ||
| if ok := impl.enforcer.Enforce(token, casbin.ResourceGlobal, casbin.ActionUpdate, "*"); !ok { | ||
| common.WriteJsonResp(w, errors.New("unauthorized"), nil, http.StatusForbidden) | ||
| return | ||
| } | ||
|
|
||
| impl.logger.Infow("request payload, UpdateLink", "err", err, "bean", bean) | ||
| res, err := impl.externalLinkService.Update(&bean) | ||
| res, err := impl.externalLinkService.Update(&bean, userRole) | ||
| if err != nil { | ||
| impl.logger.Errorw("service err, Update Links", "err", err, "bean", bean) | ||
| common.WriteJsonResp(w, err, nil, http.StatusInternalServerError) | ||
| return | ||
| } | ||
| common.WriteJsonResp(w, err, res, http.StatusOK) | ||
| } | ||
|
|
||
| func (impl ExternalLinkRestHandlerImpl) DeleteExternalLink(w http.ResponseWriter, r *http.Request) { | ||
| userId, err := impl.userService.GetLoggedInUser(r) | ||
| if userId == 0 || err != nil { | ||
| common.WriteJsonResp(w, err, "Unauthorized User", http.StatusUnauthorized) | ||
| userId, userRole, err := impl.roleCheckHelper(w, r, casbin.ActionDelete) | ||
| if err != nil { | ||
| return | ||
| } | ||
| params := mux.Vars(r) | ||
| id := params["id"] | ||
| idi, err := strconv.Atoi(id) | ||
| linkId, err := strconv.Atoi(id) | ||
| if err != nil { | ||
| impl.logger.Errorw("request err, DeleteExternalLink", "err", err, "id", id) | ||
| impl.logger.Errorw("request err, DeleteExternalLink", "id", id, "err", err) | ||
| common.WriteJsonResp(w, err, nil, http.StatusBadRequest) | ||
| return | ||
| } | ||
|
|
||
| token := r.Header.Get("token") | ||
| if ok := impl.enforcer.Enforce(token, casbin.ResourceGlobal, casbin.ActionDelete, "*"); !ok { | ||
| common.WriteJsonResp(w, errors.New("unauthorized"), nil, http.StatusForbidden) | ||
| return | ||
| } | ||
|
|
||
| res, err := impl.externalLinkService.DeleteLink(idi, userId) | ||
| res, err := impl.externalLinkService.DeleteLink(linkId, userId, userRole) | ||
| if err != nil { | ||
| impl.logger.Errorw("service err, delete Links", "err", err, "id", idi) | ||
| impl.logger.Errorw("service err, delete Links", "err", err, "linkId", linkId) | ||
| common.WriteJsonResp(w, err, nil, http.StatusInternalServerError) | ||
| return | ||
| } | ||
|
|
||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
err is not logged