Skip to content

Commit

Permalink
Merge branch 'main' into plugin-creation-oss
Browse files Browse the repository at this point in the history
  • Loading branch information
prakash100198 committed Aug 28, 2024
2 parents 4060ef5 + 26784d5 commit 0415cee
Show file tree
Hide file tree
Showing 93 changed files with 4,464 additions and 1,679 deletions.
7 changes: 4 additions & 3 deletions .gitbook.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ redirects:
setup/upgrade/devtron-upgrade-0.2.x-0.3.x: getting-started/upgrade/devtron-upgrade-0.2.x-0.3.x
setup/global-configurations: user-guide/global-configurations/README.md
setup/global-configurations/gitops: user-guide/global-configurations/gitops.md
setup/global-configurations/custom-charts: user-guide/global-configurations/custom-charts.md
setup/global-configurations/custom-charts: user-guide/global-configurations/deployment-charts.md
setup/global-configurations/user-access: user-guide/global-configurations/authorization/user-access.md
setup/global-configurations/external-links: user-guide/global-configurations/external-links.md
setup/global-configurations/projects: user-guide/global-configurations/projects.md
Expand Down Expand Up @@ -109,7 +109,7 @@ redirects:
getting-started/global-configurations/filter-condition: user-guide/global-configurations/filter-condition.md
getting-started/global-configurations/build-infra: user-guide/global-configurations/build-infra.md
getting-started/global-configurations/gitops: user-guide/global-configurations/gitops.md
getting-started/global-configurations/custom-charts: user-guide/global-configurations/custom-charts.md
getting-started/global-configurations/custom-charts: user-guide/global-configurations/deployment-charts.md
getting-started/global-configurations/external-links: user-guide/global-configurations/external-links.md
getting-started/global-configurations/projects: user-guide/global-configurations/projects.md
getting-started/global-configurations/manage-notification: user-guide/global-configurations/manage-notification.md
Expand All @@ -127,4 +127,5 @@ redirects:
user-guide/clusters: user-guide/resource-browser.md
usage/clusters: user-guide/resource-browser.md
global-configurations/authorization/sso-login/okta: user-guide/global-configurations/authorization/sso/okta.md
usage/applications/creating-application/ci-pipeline/ci-build-pre-post-plugins: user-guide/creating-application/workflow/ci-build-pre-post-plugins.md
usage/applications/creating-application/ci-pipeline/ci-build-pre-post-plugins: user-guide/creating-application/workflow/ci-build-pre-post-plugins.md
global-configurations/custom-charts: user-guide/global-configurations/deployment-charts.md
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
1 change: 1 addition & 0 deletions api/bean/ConfigMapAndSecret.go
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ type ConfigMapJson struct {
type ConfigSecretRootJson struct {
ConfigSecretJson ConfigSecretJson `json:"ConfigSecrets"`
}

type ConfigSecretJson struct {
Enabled bool `json:"enabled"`
Secrets []*ConfigSecretMap `json:"secrets"`
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 0415cee

Please sign in to comment.