-
Notifications
You must be signed in to change notification settings - Fork 485
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge branch 'main' into plugin-creation-oss
- Loading branch information
Showing
93 changed files
with
4,464 additions
and
1,679 deletions.
There are no files selected for viewing
This file contains 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 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 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 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 |
---|---|---|
@@ -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) | ||
} |
This file contains 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 |
---|---|---|
@@ -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") | ||
} |
This file contains 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 |
---|---|---|
@@ -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)), | ||
) |
Oops, something went wrong.