Skip to content

Commit

Permalink
feat: ext argo app rbac and missing common features (#5528)
Browse files Browse the repository at this point in the history
* 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>
  • Loading branch information
3 people authored Aug 9, 2024
1 parent 8391e55 commit c0aac33
Show file tree
Hide file tree
Showing 33 changed files with 3,251 additions and 1,459 deletions.
3 changes: 2 additions & 1 deletion Wire.go
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@ import (
"github.com/devtron-labs/devtron/api/deployment"
"github.com/devtron-labs/devtron/api/devtronResource"
"github.com/devtron-labs/devtron/api/externalLink"
fluxApplication "github.com/devtron-labs/devtron/api/fluxApplication"
client "github.com/devtron-labs/devtron/api/helm-app"
"github.com/devtron-labs/devtron/api/infraConfig"
"github.com/devtron-labs/devtron/api/k8s"
Expand Down Expand Up @@ -200,7 +201,7 @@ func InitializeApp() (*App, error) {
build.BuildWireSet,
deployment2.DeploymentWireSet,
argoApplication.ArgoApplicationWireSet,

fluxApplication.FluxApplicationWireSet,
eventProcessor.EventProcessorWireSet,
workflow3.WorkflowWireSet,

Expand Down
94 changes: 94 additions & 0 deletions api/fluxApplication/FluxApplicationRestHandler.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,94 @@
package fluxApplication

import (
"errors"
"github.com/devtron-labs/devtron/api/restHandler/common"
"github.com/devtron-labs/devtron/pkg/auth/authorisation/casbin"
clientErrors "github.com/devtron-labs/devtron/pkg/errors"
"github.com/devtron-labs/devtron/pkg/fluxApplication"
"github.com/gorilla/mux"
"go.uber.org/zap"
"net/http"
)

type FluxApplicationRestHandler interface {
ListFluxApplications(w http.ResponseWriter, r *http.Request)
GetApplicationDetail(w http.ResponseWriter, r *http.Request)
}

type FluxApplicationRestHandlerImpl struct {
fluxApplicationService fluxApplication.FluxApplicationService
logger *zap.SugaredLogger
enforcer casbin.Enforcer
}

func NewFluxApplicationRestHandlerImpl(fluxApplicationService fluxApplication.FluxApplicationService,
logger *zap.SugaredLogger, enforcer casbin.Enforcer) *FluxApplicationRestHandlerImpl {
return &FluxApplicationRestHandlerImpl{
fluxApplicationService: fluxApplicationService,
logger: logger,
enforcer: enforcer,
}

}

func (handler *FluxApplicationRestHandlerImpl) ListFluxApplications(w http.ResponseWriter, r *http.Request) {

//handle super-admin RBAC
token := r.Header.Get("token")
if ok := handler.enforcer.Enforce(token, casbin.ResourceGlobal, casbin.ActionGet, "*"); !ok {
common.WriteJsonResp(w, errors.New("unauthorized"), nil, http.StatusForbidden)
return
}
v := r.URL.Query()
clusterIdString := v.Get("clusterIds")
var clusterIds []int
var err error

//handling when the clusterIds string is empty ,it will not support the
if len(clusterIdString) == 0 {
handler.logger.Errorw("error in getting cluster ids", "error", err, "clusterIds", clusterIds)
common.WriteJsonResp(w, errors.New("error in getting cluster ids"), nil, http.StatusBadRequest)
return
}
clusterIds, err = common.ExtractIntArrayQueryParam(w, r, "clusterIds")
if err != nil {
handler.logger.Errorw("error in parsing cluster ids", "error", err, "clusterIds", clusterIds)
return
}
handler.logger.Debugw("extracted ClusterIds successfully ", "clusterIds", clusterIds)
handler.fluxApplicationService.ListFluxApplications(r.Context(), clusterIds, w)
}

func (handler *FluxApplicationRestHandlerImpl) GetApplicationDetail(w http.ResponseWriter, r *http.Request) {
vars := mux.Vars(r)
appIdString := vars["appId"]
appIdentifier, err := fluxApplication.DecodeFluxExternalAppId(appIdString)
if err != nil {
common.WriteJsonResp(w, err, nil, http.StatusBadRequest)
return
}
if appIdentifier.IsKustomizeApp == true && appIdentifier.Name == "flux-system" && appIdentifier.Namespace == "flux-system" {

common.WriteJsonResp(w, errors.New("cannot proceed for the flux system root level "), nil, http.StatusBadRequest)
return
}

// handle super-admin RBAC
token := r.Header.Get("token")
if ok := handler.enforcer.Enforce(token, casbin.ResourceGlobal, casbin.ActionGet, "*"); !ok {
common.WriteJsonResp(w, errors.New("unauthorized"), nil, http.StatusForbidden)
return
}

res, err := handler.fluxApplicationService.GetFluxAppDetail(r.Context(), appIdentifier)
if err != nil {
apiError := clientErrors.ConvertToApiError(err)
if apiError != nil {
err = apiError
}
common.WriteJsonResp(w, err, nil, http.StatusInternalServerError)
return
}
common.WriteJsonResp(w, err, res, http.StatusOK)
}
27 changes: 27 additions & 0 deletions api/fluxApplication/FluxApplicationRouter.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
package fluxApplication

import (
"github.com/gorilla/mux"
)

type FluxApplicationRouter interface {
InitFluxApplicationRouter(fluxApplicationRouter *mux.Router)
}

type FluxApplicationRouterImpl struct {
fluxApplicationRestHandler FluxApplicationRestHandler
}

func NewFluxApplicationRouterImpl(fluxApplicationRestHandler FluxApplicationRestHandler) *FluxApplicationRouterImpl {
return &FluxApplicationRouterImpl{
fluxApplicationRestHandler: fluxApplicationRestHandler,
}
}

func (impl *FluxApplicationRouterImpl) InitFluxApplicationRouter(fluxApplicationRouter *mux.Router) {
fluxApplicationRouter.Path("").
Methods("GET").
HandlerFunc(impl.fluxApplicationRestHandler.ListFluxApplications)
fluxApplicationRouter.Path("/app").Queries("appId", "{appId}").
HandlerFunc(impl.fluxApplicationRestHandler.GetApplicationDetail).Methods("GET")
}
17 changes: 17 additions & 0 deletions api/fluxApplication/wire_fluxApplication.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
package fluxApplication

import (
"github.com/devtron-labs/devtron/pkg/fluxApplication"
"github.com/google/wire"
)

var FluxApplicationWireSet = wire.NewSet(
fluxApplication.NewFluxApplicationServiceImpl,
wire.Bind(new(fluxApplication.FluxApplicationService), new(*fluxApplication.FluxApplicationServiceImpl)),

NewFluxApplicationRestHandlerImpl,
wire.Bind(new(FluxApplicationRestHandler), new(*FluxApplicationRestHandlerImpl)),

NewFluxApplicationRouterImpl,
wire.Bind(new(FluxApplicationRouter), new(*FluxApplicationRouterImpl)),
)
Loading

0 comments on commit c0aac33

Please sign in to comment.