Skip to content

Commit c0aac33

Browse files
RajeevRanjan27Rajeev DevtronRajeev Devtron
authored
feat: ext argo app rbac and missing common features (#5528)
* app list logic completed and proto is yet to generate * resolved the proto file issue * modified the proto and go routine call handling * corrected the proto file datatype changes * applied the list of flux apps in given cluster * resolved the conversations * incorporated the review changes * modified the fluxhandler and handlled the errros * resolved the coversations * implemented the flush for streaming the data to client * incorporated comments * Added the spec file for fluxcd App listing * added the app type in the struct * changed the fluxAppType data type * resolve * redefined the query params to process with * specs for flux app list added * added the flux app detail * minor changes around the app listing response * Resolved the decoder appId function * Added the spec for the app detail api * changed the field of flux app detail dto * taken merge from main and grpc code resolved * taken merge from main and wire run * Added the rbac for the list Events and resource Deletion * handled the error in listing of apps with errror field in grpc * Revert "taken merge from main and wire run" This reverts commit 252d199. * Revert "handled the error in listing of apps with errror field in grpc" This reverts commit df08766. * Added the error in the Listing of flux apps * generated the grpc code * modified the logic for error handling in flux app listing and app detailing part * took merge from main and run make * added the handler message for the root app i.e flux-system * added the rbac for update of resources * minor changes: resolved the review comments after review * took merge from main and executed the make cmd too * added the debugger points in the flux app listing * completed rbac for list events, get resources, getTerminalSession,updation, deletion of resources,get pod logs, resource url and pod log downloads * removed the debugger points * resolved the comment and incorporated the changes * modified the verifyRbacForAppRequests function * Added the hibernate and unhibernate function for flux * added the constants for making the redundency less * refactor the unhibernate code part * removed the previous coded comments * resolved minor changes from comments * added the rbac for podLogs and k8sresourceurls * added some rbac for the external argo with validation of resources * added the handling of resource urls and hibernation * added the ea part of ext argo and also made changes in the k8shandlers * executed make after merging * resolved the comments and removed the commented codes * added the ea mode router of flux * modified the request for external argo during terminal session connect * executed the make after sync from main * took merge from main and executed make * resolved comments * after resolving comments executed make --------- Co-authored-by: Rajeev Devtron <rajeevdevtron@Rajeevs-MacBook-Pro.local> Co-authored-by: Rajeev Devtron <rajeevdevtron@192.168.1.31>
1 parent 8391e55 commit c0aac33

33 files changed

+3251
-1459
lines changed

Wire.go

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,7 @@ import (
4141
"github.com/devtron-labs/devtron/api/deployment"
4242
"github.com/devtron-labs/devtron/api/devtronResource"
4343
"github.com/devtron-labs/devtron/api/externalLink"
44+
fluxApplication "github.com/devtron-labs/devtron/api/fluxApplication"
4445
client "github.com/devtron-labs/devtron/api/helm-app"
4546
"github.com/devtron-labs/devtron/api/infraConfig"
4647
"github.com/devtron-labs/devtron/api/k8s"
@@ -200,7 +201,7 @@ func InitializeApp() (*App, error) {
200201
build.BuildWireSet,
201202
deployment2.DeploymentWireSet,
202203
argoApplication.ArgoApplicationWireSet,
203-
204+
fluxApplication.FluxApplicationWireSet,
204205
eventProcessor.EventProcessorWireSet,
205206
workflow3.WorkflowWireSet,
206207

Lines changed: 94 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,94 @@
1+
package fluxApplication
2+
3+
import (
4+
"errors"
5+
"github.com/devtron-labs/devtron/api/restHandler/common"
6+
"github.com/devtron-labs/devtron/pkg/auth/authorisation/casbin"
7+
clientErrors "github.com/devtron-labs/devtron/pkg/errors"
8+
"github.com/devtron-labs/devtron/pkg/fluxApplication"
9+
"github.com/gorilla/mux"
10+
"go.uber.org/zap"
11+
"net/http"
12+
)
13+
14+
type FluxApplicationRestHandler interface {
15+
ListFluxApplications(w http.ResponseWriter, r *http.Request)
16+
GetApplicationDetail(w http.ResponseWriter, r *http.Request)
17+
}
18+
19+
type FluxApplicationRestHandlerImpl struct {
20+
fluxApplicationService fluxApplication.FluxApplicationService
21+
logger *zap.SugaredLogger
22+
enforcer casbin.Enforcer
23+
}
24+
25+
func NewFluxApplicationRestHandlerImpl(fluxApplicationService fluxApplication.FluxApplicationService,
26+
logger *zap.SugaredLogger, enforcer casbin.Enforcer) *FluxApplicationRestHandlerImpl {
27+
return &FluxApplicationRestHandlerImpl{
28+
fluxApplicationService: fluxApplicationService,
29+
logger: logger,
30+
enforcer: enforcer,
31+
}
32+
33+
}
34+
35+
func (handler *FluxApplicationRestHandlerImpl) ListFluxApplications(w http.ResponseWriter, r *http.Request) {
36+
37+
//handle super-admin RBAC
38+
token := r.Header.Get("token")
39+
if ok := handler.enforcer.Enforce(token, casbin.ResourceGlobal, casbin.ActionGet, "*"); !ok {
40+
common.WriteJsonResp(w, errors.New("unauthorized"), nil, http.StatusForbidden)
41+
return
42+
}
43+
v := r.URL.Query()
44+
clusterIdString := v.Get("clusterIds")
45+
var clusterIds []int
46+
var err error
47+
48+
//handling when the clusterIds string is empty ,it will not support the
49+
if len(clusterIdString) == 0 {
50+
handler.logger.Errorw("error in getting cluster ids", "error", err, "clusterIds", clusterIds)
51+
common.WriteJsonResp(w, errors.New("error in getting cluster ids"), nil, http.StatusBadRequest)
52+
return
53+
}
54+
clusterIds, err = common.ExtractIntArrayQueryParam(w, r, "clusterIds")
55+
if err != nil {
56+
handler.logger.Errorw("error in parsing cluster ids", "error", err, "clusterIds", clusterIds)
57+
return
58+
}
59+
handler.logger.Debugw("extracted ClusterIds successfully ", "clusterIds", clusterIds)
60+
handler.fluxApplicationService.ListFluxApplications(r.Context(), clusterIds, w)
61+
}
62+
63+
func (handler *FluxApplicationRestHandlerImpl) GetApplicationDetail(w http.ResponseWriter, r *http.Request) {
64+
vars := mux.Vars(r)
65+
appIdString := vars["appId"]
66+
appIdentifier, err := fluxApplication.DecodeFluxExternalAppId(appIdString)
67+
if err != nil {
68+
common.WriteJsonResp(w, err, nil, http.StatusBadRequest)
69+
return
70+
}
71+
if appIdentifier.IsKustomizeApp == true && appIdentifier.Name == "flux-system" && appIdentifier.Namespace == "flux-system" {
72+
73+
common.WriteJsonResp(w, errors.New("cannot proceed for the flux system root level "), nil, http.StatusBadRequest)
74+
return
75+
}
76+
77+
// handle super-admin RBAC
78+
token := r.Header.Get("token")
79+
if ok := handler.enforcer.Enforce(token, casbin.ResourceGlobal, casbin.ActionGet, "*"); !ok {
80+
common.WriteJsonResp(w, errors.New("unauthorized"), nil, http.StatusForbidden)
81+
return
82+
}
83+
84+
res, err := handler.fluxApplicationService.GetFluxAppDetail(r.Context(), appIdentifier)
85+
if err != nil {
86+
apiError := clientErrors.ConvertToApiError(err)
87+
if apiError != nil {
88+
err = apiError
89+
}
90+
common.WriteJsonResp(w, err, nil, http.StatusInternalServerError)
91+
return
92+
}
93+
common.WriteJsonResp(w, err, res, http.StatusOK)
94+
}
Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
package fluxApplication
2+
3+
import (
4+
"github.com/gorilla/mux"
5+
)
6+
7+
type FluxApplicationRouter interface {
8+
InitFluxApplicationRouter(fluxApplicationRouter *mux.Router)
9+
}
10+
11+
type FluxApplicationRouterImpl struct {
12+
fluxApplicationRestHandler FluxApplicationRestHandler
13+
}
14+
15+
func NewFluxApplicationRouterImpl(fluxApplicationRestHandler FluxApplicationRestHandler) *FluxApplicationRouterImpl {
16+
return &FluxApplicationRouterImpl{
17+
fluxApplicationRestHandler: fluxApplicationRestHandler,
18+
}
19+
}
20+
21+
func (impl *FluxApplicationRouterImpl) InitFluxApplicationRouter(fluxApplicationRouter *mux.Router) {
22+
fluxApplicationRouter.Path("").
23+
Methods("GET").
24+
HandlerFunc(impl.fluxApplicationRestHandler.ListFluxApplications)
25+
fluxApplicationRouter.Path("/app").Queries("appId", "{appId}").
26+
HandlerFunc(impl.fluxApplicationRestHandler.GetApplicationDetail).Methods("GET")
27+
}
Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
package fluxApplication
2+
3+
import (
4+
"github.com/devtron-labs/devtron/pkg/fluxApplication"
5+
"github.com/google/wire"
6+
)
7+
8+
var FluxApplicationWireSet = wire.NewSet(
9+
fluxApplication.NewFluxApplicationServiceImpl,
10+
wire.Bind(new(fluxApplication.FluxApplicationService), new(*fluxApplication.FluxApplicationServiceImpl)),
11+
12+
NewFluxApplicationRestHandlerImpl,
13+
wire.Bind(new(FluxApplicationRestHandler), new(*FluxApplicationRestHandlerImpl)),
14+
15+
NewFluxApplicationRouterImpl,
16+
wire.Bind(new(FluxApplicationRouter), new(*FluxApplicationRouterImpl)),
17+
)

0 commit comments

Comments
 (0)