Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
24 changes: 12 additions & 12 deletions Wire.go
Original file line number Diff line number Diff line change
Expand Up @@ -65,11 +65,11 @@ import (
"github.com/devtron-labs/devtron/pkg/app"
"github.com/devtron-labs/devtron/pkg/appClone"
"github.com/devtron-labs/devtron/pkg/appClone/batch"
appStore "github.com/devtron-labs/devtron/pkg/appStore"
appStoreBean "github.com/devtron-labs/devtron/pkg/appStore/bean"
appStoreDeploymentFullMode "github.com/devtron-labs/devtron/pkg/appStore/deployment/fullMode"
repository4 "github.com/devtron-labs/devtron/pkg/appStore/deployment/repository"
"github.com/devtron-labs/devtron/pkg/appStore/deployment/service"
appStoreDeploymentGitopsTool "github.com/devtron-labs/devtron/pkg/appStore/deployment/tool/gitops"
appStoreRepository "github.com/devtron-labs/devtron/pkg/appStore/repository"
"github.com/devtron-labs/devtron/pkg/appWorkflow"
"github.com/devtron-labs/devtron/pkg/attributes"
"github.com/devtron-labs/devtron/pkg/commonService"
Expand Down Expand Up @@ -430,8 +430,8 @@ func InitializeApp() (*App, error) {

appStoreRestHandler.NewInstalledAppRestHandlerImpl,
wire.Bind(new(appStoreRestHandler.InstalledAppRestHandler), new(*appStoreRestHandler.InstalledAppRestHandlerImpl)),
appStore.NewInstalledAppServiceImpl,
wire.Bind(new(appStore.InstalledAppService), new(*appStore.InstalledAppServiceImpl)),
service.NewInstalledAppServiceImpl,
wire.Bind(new(service.InstalledAppService), new(*service.InstalledAppServiceImpl)),

appStoreRestHandler.NewAppStoreRouterImpl,
wire.Bind(new(appStoreRestHandler.AppStoreRouter), new(*appStoreRestHandler.AppStoreRouterImpl)),
Expand Down Expand Up @@ -514,18 +514,18 @@ func InitializeApp() (*App, error) {
router.NewBatchOperationRouterImpl,
wire.Bind(new(router.BatchOperationRouter), new(*router.BatchOperationRouterImpl)),

appStoreRepository.NewChartGroupReposotoryImpl,
wire.Bind(new(appStoreRepository.ChartGroupReposotory), new(*appStoreRepository.ChartGroupReposotoryImpl)),
appStoreRepository.NewChartGroupEntriesRepositoryImpl,
wire.Bind(new(appStoreRepository.ChartGroupEntriesRepository), new(*appStoreRepository.ChartGroupEntriesRepositoryImpl)),
appStore.NewChartGroupServiceImpl,
wire.Bind(new(appStore.ChartGroupService), new(*appStore.ChartGroupServiceImpl)),
repository4.NewChartGroupReposotoryImpl,
wire.Bind(new(repository4.ChartGroupReposotory), new(*repository4.ChartGroupReposotoryImpl)),
repository4.NewChartGroupEntriesRepositoryImpl,
wire.Bind(new(repository4.ChartGroupEntriesRepository), new(*repository4.ChartGroupEntriesRepositoryImpl)),
service.NewChartGroupServiceImpl,
wire.Bind(new(service.ChartGroupService), new(*service.ChartGroupServiceImpl)),
restHandler.NewChartGroupRestHandlerImpl,
wire.Bind(new(restHandler.ChartGroupRestHandler), new(*restHandler.ChartGroupRestHandlerImpl)),
router.NewChartGroupRouterImpl,
wire.Bind(new(router.ChartGroupRouter), new(*router.ChartGroupRouterImpl)),
appStoreRepository.NewChartGroupDeploymentRepositoryImpl,
wire.Bind(new(appStoreRepository.ChartGroupDeploymentRepository), new(*appStoreRepository.ChartGroupDeploymentRepositoryImpl)),
repository4.NewChartGroupDeploymentRepositoryImpl,
wire.Bind(new(repository4.ChartGroupDeploymentRepository), new(*repository4.ChartGroupDeploymentRepositoryImpl)),

commonService.NewCommonServiceImpl,
wire.Bind(new(commonService.CommonService), new(*commonService.CommonServiceImpl)),
Expand Down
31 changes: 10 additions & 21 deletions api/appStore/AppStoreRouter.go
Original file line number Diff line number Diff line change
Expand Up @@ -47,45 +47,34 @@ func NewAppStoreRouterImpl(restHandler InstalledAppRestHandler,
}

func (router AppStoreRouterImpl) Init(configRouter *mux.Router) {

configRouter.Path("/application/update").
HandlerFunc(router.deployRestHandler.UpdateInstalledApp).Methods("PUT")

// deployment router starts
appStoreDeploymentSubRouter := configRouter.PathPrefix("/deployment").Subrouter()
router.appStoreDeploymentRouter.Init(appStoreDeploymentSubRouter)
// deployment router ends

configRouter.Path("/application/exists").
HandlerFunc(router.deployRestHandler.CheckAppExists).Methods("POST")
configRouter.Path("/group/install").
HandlerFunc(router.deployRestHandler.DeployBulk).Methods("POST")
// values router starts
appStoreValuesSubRouter := configRouter.PathPrefix("/values").Subrouter()
router.appStoreValuesRouter.Init(appStoreValuesSubRouter)
// values router ends

// discover router starts
appStoreDiscoverSubRouter := configRouter.PathPrefix("/discover").Subrouter()
router.appStoreDiscoverRouter.Init(appStoreDiscoverSubRouter)
// discover router ends

configRouter.Path("/application/update").
HandlerFunc(router.deployRestHandler.UpdateInstalledApp).Methods("PUT")
configRouter.Path("/application/exists").
HandlerFunc(router.deployRestHandler.CheckAppExists).Methods("POST")
configRouter.Path("/group/install").
HandlerFunc(router.deployRestHandler.DeployBulk).Methods("POST")
configRouter.Path("/installed-app/detail").Queries("installed-app-id", "{installed-app-id}").Queries("env-id", "{env-id}").
HandlerFunc(router.deployRestHandler.FetchAppDetailsForInstalledApp).
Methods("GET")

configRouter.Path("/installed-app").
HandlerFunc(router.deployRestHandler.GetAllInstalledApp).Methods("GET")

configRouter.Path("/application/version/{installedAppVersionId}").
HandlerFunc(router.deployRestHandler.GetInstalledAppVersion).Methods("GET")

// values router starts
appStoreValuesSubRouter := configRouter.PathPrefix("/values").Subrouter()
router.appStoreValuesRouter.Init(appStoreValuesSubRouter)
// values router ends

configRouter.Path("/cluster-component/install/{clusterId}").
HandlerFunc(router.deployRestHandler.DefaultComponentInstallation).Methods("POST")

configRouter.Path("/installed-app/deployment-history").Queries("installedAppId", "{installedAppId}").
HandlerFunc(router.deployRestHandler.GetDeploymentHistory).Methods("GET")
configRouter.Path("/installed-app/deployment-history/info").Queries("installedAppId", "{installedAppId}").Queries("version", "{version}").
HandlerFunc(router.deployRestHandler.GetDeploymentHistoryValues).Methods("GET")
}
Original file line number Diff line number Diff line change
Expand Up @@ -28,9 +28,8 @@ import (
"github.com/devtron-labs/devtron/client/argocdServer/application"
"github.com/devtron-labs/devtron/internal/constants"
"github.com/devtron-labs/devtron/internal/util"
"github.com/devtron-labs/devtron/pkg/appStore"
appStoreBean "github.com/devtron-labs/devtron/pkg/appStore/bean"
appStoreDeployment "github.com/devtron-labs/devtron/pkg/appStore/deployment"
"github.com/devtron-labs/devtron/pkg/appStore/deployment/service"
"github.com/devtron-labs/devtron/pkg/cluster"
"github.com/devtron-labs/devtron/pkg/user"
"github.com/devtron-labs/devtron/pkg/user/casbin"
Expand All @@ -53,26 +52,24 @@ type InstalledAppRestHandler interface {
CheckAppExists(w http.ResponseWriter, r *http.Request)
DefaultComponentInstallation(w http.ResponseWriter, r *http.Request)
FetchAppDetailsForInstalledApp(w http.ResponseWriter, r *http.Request)
GetDeploymentHistory(w http.ResponseWriter, r *http.Request)
GetDeploymentHistoryValues(w http.ResponseWriter, r *http.Request)
}

type InstalledAppRestHandlerImpl struct {
Logger *zap.SugaredLogger
userAuthService user.UserService
enforcer casbin.Enforcer
enforcerUtil rbac.EnforcerUtil
installedAppService appStore.InstalledAppService
installedAppService service.InstalledAppService
validator *validator.Validate
clusterService cluster.ClusterService
acdServiceClient application.ServiceClient
appStoreDeploymentService appStoreDeployment.AppStoreDeploymentService
appStoreDeploymentService service.AppStoreDeploymentService
}

func NewInstalledAppRestHandlerImpl(Logger *zap.SugaredLogger, userAuthService user.UserService,
enforcer casbin.Enforcer, enforcerUtil rbac.EnforcerUtil, installedAppService appStore.InstalledAppService,
enforcer casbin.Enforcer, enforcerUtil rbac.EnforcerUtil, installedAppService service.InstalledAppService,
validator *validator.Validate, clusterService cluster.ClusterService, acdServiceClient application.ServiceClient,
appStoreDeploymentService appStoreDeployment.AppStoreDeploymentService,
appStoreDeploymentService service.AppStoreDeploymentService,
) *InstalledAppRestHandlerImpl {
return &InstalledAppRestHandlerImpl{
Logger: Logger,
Expand Down Expand Up @@ -468,74 +465,4 @@ func (handler *InstalledAppRestHandlerImpl) FetchAppDetailsForInstalledApp(w htt
handler.Logger.Infow("appName and envName not found - avoiding resource tree call", "app", appDetail.AppName, "env", appDetail.EnvironmentName)
}
common.WriteJsonResp(w, err, appDetail, http.StatusOK)
}

func (handler *InstalledAppRestHandlerImpl) GetDeploymentHistory(w http.ResponseWriter, r *http.Request) {
vars := mux.Vars(r)
installedAppId, err := strconv.Atoi(vars["installedAppId"])
if err != nil {
handler.Logger.Errorw("request err", "error", err, "installedAppId", installedAppId)
common.WriteJsonResp(w, err, nil, http.StatusBadRequest)
return
}
token := r.Header.Get("token")
installedApp, err := handler.appStoreDeploymentService.GetInstalledApp(installedAppId)
if err != nil {
handler.Logger.Errorw("service err, GetDeploymentHistoryValues", "err", err, "installedAppId", installedAppId)
common.WriteJsonResp(w, err, nil, http.StatusInternalServerError)
return
}
//rbac block starts from here
object := handler.enforcerUtil.GetHelmObject(installedApp.AppId, installedApp.EnvironmentId)
if ok := handler.enforcer.Enforce(token, casbin.ResourceHelmApp, casbin.ActionGet, object); !ok {
common.WriteJsonResp(w, fmt.Errorf("unauthorized user"), nil, http.StatusForbidden)
return
}
//rback block ends here
response, err := handler.installedAppService.GetInstalledAppVersionHistory(installedAppId)
if err != nil {
common.WriteJsonResp(w, err, nil, http.StatusInternalServerError)
return
}

common.WriteJsonResp(w, err, response, http.StatusOK)
}

func (handler *InstalledAppRestHandlerImpl) GetDeploymentHistoryValues(w http.ResponseWriter, r *http.Request) {
vars := mux.Vars(r)
installedAppId, err := strconv.Atoi(vars["installedAppId"])
if err != nil {
handler.Logger.Errorw("request err", "error", err, "installedAppId", installedAppId)
common.WriteJsonResp(w, err, nil, http.StatusBadRequest)
return
}
installedAppVersionHistoryId, err := strconv.Atoi(vars["version"])
if err != nil {
handler.Logger.Errorw("request err", "error", err, "installedAppVersionHistoryId", installedAppVersionHistoryId)
common.WriteJsonResp(w, err, nil, http.StatusBadRequest)
return
}

token := r.Header.Get("token")
installedApp, err := handler.appStoreDeploymentService.GetInstalledApp(installedAppId)
if err != nil {
handler.Logger.Errorw("service err, GetDeploymentHistoryValues", "err", err, "installedAppId", installedAppId)
common.WriteJsonResp(w, err, nil, http.StatusInternalServerError)
return
}
//rbac block starts from here
object := handler.enforcerUtil.GetHelmObject(installedApp.AppId, installedApp.EnvironmentId)
if ok := handler.enforcer.Enforce(token, casbin.ResourceHelmApp, casbin.ActionGet, object); !ok {
common.WriteJsonResp(w, fmt.Errorf("unauthorized user"), nil, http.StatusForbidden)
return
}
//rback block ends here

response, err := handler.installedAppService.GetInstalledAppVersionHistoryValues(installedAppVersionHistoryId)
if err != nil {
common.WriteJsonResp(w, err, nil, http.StatusInternalServerError)
return
}

common.WriteJsonResp(w, err, response, http.StatusOK)
}
}
69 changes: 5 additions & 64 deletions api/appStore/deployment/AppStoreDeploymentRestHandler.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,12 +24,11 @@ import (
"fmt"
client "github.com/devtron-labs/devtron/api/helm-app"
openapi "github.com/devtron-labs/devtron/api/helm-app/openapiClient"
openapi2 "github.com/devtron-labs/devtron/api/openapi/openapiClient"
"github.com/devtron-labs/devtron/api/restHandler/common"
"github.com/devtron-labs/devtron/internal/util"
appStoreBean "github.com/devtron-labs/devtron/pkg/appStore/bean"
appStoreDeployment "github.com/devtron-labs/devtron/pkg/appStore/deployment"
appStoreDeploymentCommon "github.com/devtron-labs/devtron/pkg/appStore/deployment/common"
"github.com/devtron-labs/devtron/pkg/appStore/deployment/service"
"github.com/devtron-labs/devtron/pkg/user"
"github.com/devtron-labs/devtron/pkg/user/casbin"
util2 "github.com/devtron-labs/devtron/util"
Expand All @@ -40,15 +39,13 @@ import (
"net/http"
"strconv"
"strings"
"time"
)

type AppStoreDeploymentRestHandler interface {
InstallApp(w http.ResponseWriter, r *http.Request)
GetInstalledAppsByAppStoreId(w http.ResponseWriter, r *http.Request)
DeleteInstalledApp(w http.ResponseWriter, r *http.Request)
LinkHelmApplicationToChartStore(w http.ResponseWriter, r *http.Request)
RollbackApplication(w http.ResponseWriter, r *http.Request)
}

type AppStoreDeploymentRestHandlerImpl struct {
Expand All @@ -57,14 +54,15 @@ type AppStoreDeploymentRestHandlerImpl struct {
enforcer casbin.Enforcer
enforcerUtil rbac.EnforcerUtil
enforcerUtilHelm rbac.EnforcerUtilHelm
appStoreDeploymentService appStoreDeployment.AppStoreDeploymentService
appStoreDeploymentService service.AppStoreDeploymentService
appStoreDeploymentServiceC appStoreDeploymentCommon.AppStoreDeploymentCommonService
validator *validator.Validate
helmAppService client.HelmAppService
helmAppRestHandler client.HelmAppRestHandler
}

func NewAppStoreDeploymentRestHandlerImpl(Logger *zap.SugaredLogger, userAuthService user.UserService,
enforcer casbin.Enforcer, enforcerUtil rbac.EnforcerUtil, enforcerUtilHelm rbac.EnforcerUtilHelm, appStoreDeploymentService appStoreDeployment.AppStoreDeploymentService,
enforcer casbin.Enforcer, enforcerUtil rbac.EnforcerUtil, enforcerUtilHelm rbac.EnforcerUtilHelm, appStoreDeploymentService service.AppStoreDeploymentService,
validator *validator.Validate, helmAppService client.HelmAppService, appStoreDeploymentServiceC appStoreDeploymentCommon.AppStoreDeploymentCommonService,
) *AppStoreDeploymentRestHandlerImpl {
return &AppStoreDeploymentRestHandlerImpl{
Expand Down Expand Up @@ -314,61 +312,4 @@ func (handler *AppStoreDeploymentRestHandlerImpl) LinkHelmApplicationToChartStor
}

common.WriteJsonResp(w, err, res, http.StatusOK)
}

func (handler *AppStoreDeploymentRestHandlerImpl) RollbackApplication(w http.ResponseWriter, r *http.Request) {
request := &openapi2.RollbackReleaseRequest{}
decoder := json.NewDecoder(r.Body)
err := decoder.Decode(request)
if err != nil {
common.WriteJsonResp(w, err, nil, http.StatusBadRequest)
return
}

userId, err := handler.userAuthService.GetLoggedInUser(r)
if userId == 0 || err != nil {
common.WriteJsonResp(w, err, "Unauthorized User", http.StatusUnauthorized)
return
}

// get installed app which can not be null
installedApp, err := handler.appStoreDeploymentService.GetInstalledApp(int(request.GetInstalledAppId()))
if err != nil {
handler.Logger.Errorw("Error in getting installed app", "err", err)
common.WriteJsonResp(w, err, nil, http.StatusInternalServerError)
return
}
installedApp.UserId = userId
if installedApp == nil {
handler.Logger.Errorw("Installed App can not be null", "request", request)
common.WriteJsonResp(w, err, nil, http.StatusInternalServerError)
return
}

//rbac block starts from here
var rbacObject string
token := r.Header.Get("token")
if installedApp.AppOfferingMode == util2.SERVER_MODE_HYPERION {
rbacObject = handler.enforcerUtilHelm.GetHelmObjectByClusterId(installedApp.ClusterId, installedApp.Namespace, installedApp.AppName)
} else {
rbacObject = handler.enforcerUtil.GetHelmObjectByAppNameAndEnvId(installedApp.AppName, installedApp.EnvironmentId)
}
if ok := handler.enforcer.Enforce(token, casbin.ResourceHelmApp, casbin.ActionUpdate, rbacObject); !ok {
common.WriteJsonResp(w, fmt.Errorf("unauthorized user"), nil, http.StatusForbidden)
return
}
//rbac block ends here

ctx, cancel := context.WithTimeout(context.Background(), 60*time.Second)
defer cancel()
success, err := handler.appStoreDeploymentService.RollbackApplication(ctx, request, installedApp, userId)
if err != nil {
handler.Logger.Errorw("Error in Rollback release", "err", err, "payload", request)
common.WriteJsonResp(w, err, nil, http.StatusInternalServerError)
return
}
res := &openapi2.RollbackReleaseResponse{
Success: &success,
}
common.WriteJsonResp(w, err, res, http.StatusOK)
}
}
3 changes: 0 additions & 3 deletions api/appStore/deployment/AppStoreDeploymentRouter.go
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,4 @@ func (router AppStoreDeploymentRouterImpl) Init(configRouter *mux.Router) {

configRouter.Path("/application/helm/link-to-chart-store").
HandlerFunc(router.appStoreDeploymentRestHandler.LinkHelmApplicationToChartStore).Methods("PUT")

configRouter.Path("/application/rollback").
HandlerFunc(router.appStoreDeploymentRestHandler.RollbackApplication).Methods("PUT")
}
Loading