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
The table of contents is too big for display.
Diff view
Diff view
  •  
  •  
  •  
8 changes: 8 additions & 0 deletions Wire.go
Original file line number Diff line number Diff line change
Expand Up @@ -125,6 +125,7 @@ import (
"github.com/devtron-labs/devtron/pkg/chart/gitOpsConfig"
chartRepoRepository "github.com/devtron-labs/devtron/pkg/chartRepo/repository"
"github.com/devtron-labs/devtron/pkg/commonService"
"github.com/devtron-labs/devtron/pkg/configDiff"
delete2 "github.com/devtron-labs/devtron/pkg/delete"
deployment2 "github.com/devtron-labs/devtron/pkg/deployment"
"github.com/devtron-labs/devtron/pkg/deployment/common"
Expand Down Expand Up @@ -711,6 +712,13 @@ func InitializeApp() (*App, error) {
scopedVariable.NewScopedVariableRestHandlerImpl,
wire.Bind(new(scopedVariable.ScopedVariableRestHandler), new(*scopedVariable.ScopedVariableRestHandlerImpl)),

router.NewDeploymentConfigurationRouter,
wire.Bind(new(router.DeploymentConfigurationRouter), new(*router.DeploymentConfigurationRouterImpl)),
restHandler.NewDeploymentConfigurationRestHandlerImpl,
wire.Bind(new(restHandler.DeploymentConfigurationRestHandler), new(*restHandler.DeploymentConfigurationRestHandlerImpl)),
configDiff.NewDeploymentConfigurationServiceImpl,
wire.Bind(new(configDiff.DeploymentConfigurationService), new(*configDiff.DeploymentConfigurationServiceImpl)),

router.NewTelemetryRouterImpl,
wire.Bind(new(router.TelemetryRouter), new(*router.TelemetryRouterImpl)),
restHandler.NewTelemetryRestHandlerImpl,
Expand Down
3 changes: 3 additions & 0 deletions api/bean/AppView.go
Original file line number Diff line number Diff line change
Expand Up @@ -144,6 +144,7 @@ type AppEnvironmentContainer struct {
type DeploymentDetailContainer struct {
InstalledAppId int `json:"installedAppId,omitempty"`
AppId int `json:"appId,omitempty"`
PcoId int `json:"pcoId"`
CdPipelineId int `json:"cdPipelineId,omitempty"`
TriggerType string `json:"triggerType,omitempty"`
ParentEnvironmentName string `json:"parentEnvironmentName"`
Expand Down Expand Up @@ -183,6 +184,8 @@ type DeploymentDetailContainer struct {
HelmPackageName string `json:"helmPackageName"`
HelmReleaseInstallStatus string `json:"-"`
DeploymentConfig *bean.DeploymentConfig `json:"-"`
IsPipelineTriggered bool `json:"isPipelineTriggered"`
ReleaseMode string `json:"releaseMode"`
}

type AppDetailContainer struct {
Expand Down
194 changes: 100 additions & 94 deletions api/helm-app/gRPC/applist.pb.go

Large diffs are not rendered by default.

1 change: 1 addition & 0 deletions api/helm-app/gRPC/applist.proto
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@ service ApplicationService {
rpc ValidateOCIRegistry(RegistryCredential) returns(OCIRegistryResponse) {}
rpc GetResourceTreeForExternalResources(ExternalResourceTreeRequest) returns(ResourceTreeResponse){}
rpc GetFluxAppDetail(FluxAppDetailRequest)returns(FluxAppDetail){}
rpc GetReleaseDetails(ReleaseIdentifier)returns(DeployedAppDetail){}

}

Expand Down
158 changes: 111 additions & 47 deletions api/helm-app/gRPC/applist_grpc.pb.go

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion api/helm-app/service/HelmAppService.go
Original file line number Diff line number Diff line change
Expand Up @@ -1136,7 +1136,7 @@ func (impl *HelmAppServiceImpl) appListRespProtoTransformer(deployedApps *gRPC.D
// do not add app in the list which are created using cd_pipelines (check combination of clusterId, namespace, releaseName)
var toExcludeFromList bool
for _, helmCdPipeline := range helmCdPipelines {
helmAppReleaseName := util2.BuildDeployedAppName(helmCdPipeline.App.AppName, helmCdPipeline.Environment.Name)
helmAppReleaseName := helmCdPipeline.DeploymentAppName
if deployedapp.AppName == helmAppReleaseName && int(deployedapp.EnvironmentDetail.ClusterId) == helmCdPipeline.Environment.ClusterId && deployedapp.EnvironmentDetail.Namespace == helmCdPipeline.Environment.Namespace {
toExcludeFromList = true
break
Expand Down
135 changes: 135 additions & 0 deletions api/restHandler/DeploymentConfigurationRestHandler.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,135 @@
package restHandler

import (
"fmt"
"github.com/devtron-labs/devtron/api/restHandler/common"
"github.com/devtron-labs/devtron/pkg/auth/authorisation/casbin"
"github.com/devtron-labs/devtron/pkg/auth/user"
"github.com/devtron-labs/devtron/pkg/configDiff"
"github.com/devtron-labs/devtron/pkg/configDiff/bean"
"github.com/devtron-labs/devtron/util/rbac"
"github.com/gorilla/schema"
"go.uber.org/zap"
"gopkg.in/go-playground/validator.v9"
"net/http"
)

type DeploymentConfigurationRestHandler interface {
ConfigAutoComplete(w http.ResponseWriter, r *http.Request)
GetConfigData(w http.ResponseWriter, r *http.Request)
}
type DeploymentConfigurationRestHandlerImpl struct {
logger *zap.SugaredLogger
userAuthService user.UserService
validator *validator.Validate
enforcerUtil rbac.EnforcerUtil
deploymentConfigurationService configDiff.DeploymentConfigurationService
enforcer casbin.Enforcer
}

func NewDeploymentConfigurationRestHandlerImpl(logger *zap.SugaredLogger,
userAuthService user.UserService,
enforcerUtil rbac.EnforcerUtil,
deploymentConfigurationService configDiff.DeploymentConfigurationService,
enforcer casbin.Enforcer,
) *DeploymentConfigurationRestHandlerImpl {
return &DeploymentConfigurationRestHandlerImpl{
logger: logger,
userAuthService: userAuthService,
enforcerUtil: enforcerUtil,
deploymentConfigurationService: deploymentConfigurationService,
enforcer: enforcer,
}
}

func (handler *DeploymentConfigurationRestHandlerImpl) ConfigAutoComplete(w http.ResponseWriter, r *http.Request) {
userId, err := handler.userAuthService.GetLoggedInUser(r)
if userId == 0 || err != nil {
common.WriteJsonResp(w, err, "Unauthorized User", http.StatusUnauthorized)
return
}
appId, err := common.ExtractIntQueryParam(w, r, "appId", 0)
if err != nil {
return
}
envId, err := common.ExtractIntQueryParam(w, r, "envId", 0)
if err != nil {
return
}

//RBAC START
token := r.Header.Get(common.TokenHeaderKey)
object := handler.enforcerUtil.GetAppRBACNameByAppId(appId)
ok := handler.enforcerUtil.CheckAppRbacForAppOrJob(token, object, casbin.ActionGet)
if !ok {
common.WriteJsonResp(w, fmt.Errorf("unauthorized user"), nil, http.StatusForbidden)
return
}
//RBAC END

res, err := handler.deploymentConfigurationService.ConfigAutoComplete(appId, envId)
if err != nil {
handler.logger.Errorw("service err, ConfigAutoComplete ", "appId", appId, "envId", envId, "err", err)
common.WriteJsonResp(w, err, nil, http.StatusInternalServerError)
return
}
common.WriteJsonResp(w, err, res, http.StatusOK)
}

func (handler *DeploymentConfigurationRestHandlerImpl) GetConfigData(w http.ResponseWriter, r *http.Request) {
userId, err := handler.userAuthService.GetLoggedInUser(r)
if userId == 0 || err != nil {
common.WriteJsonResp(w, err, "Unauthorized User", http.StatusUnauthorized)
return
}
configDataQueryParams, err := getConfigDataQueryParams(r)
if err != nil {
common.WriteJsonResp(w, err, nil, http.StatusBadRequest)
return
}

//RBAC START
token := r.Header.Get(common.TokenHeaderKey)
object := handler.enforcerUtil.GetAppRBACName(configDataQueryParams.AppName)
ok := handler.enforcerUtil.CheckAppRbacForAppOrJob(token, object, casbin.ActionGet)
if !ok {
common.WriteJsonResp(w, fmt.Errorf("unauthorized user"), nil, http.StatusForbidden)
return
}
//RBAC END

res, err := handler.deploymentConfigurationService.GetAllConfigData(r.Context(), configDataQueryParams)
if err != nil {
handler.logger.Errorw("service err, GetAllConfigData ", "err", err)
common.WriteJsonResp(w, err, nil, http.StatusInternalServerError)
return
}
res.IsAppAdmin = handler.enforceForAppAndEnv(configDataQueryParams.AppName, configDataQueryParams.EnvName, token, casbin.ActionUpdate)

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

func (handler *DeploymentConfigurationRestHandlerImpl) enforceForAppAndEnv(appName, envName string, token string, action string) bool {
object := handler.enforcerUtil.GetAppRBACNameByAppName(appName)
if ok := handler.enforcer.Enforce(token, casbin.ResourceApplications, action, object); !ok {
return false
}

object = handler.enforcerUtil.GetEnvRBACNameByAppAndEnvName(appName, envName)
if ok := handler.enforcer.Enforce(token, casbin.ResourceEnvironment, action, object); !ok {
return false
}
return true
}
func getConfigDataQueryParams(r *http.Request) (*bean.ConfigDataQueryParams, error) {
v := r.URL.Query()
var decoder = schema.NewDecoder()
decoder.IgnoreUnknownKeys(true)
queryParams := bean.ConfigDataQueryParams{}
err := decoder.Decode(&queryParams, v)
if err != nil {
return nil, err
}

return &queryParams, nil
}
23 changes: 12 additions & 11 deletions api/restHandler/ImageScanRestHandler.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ package restHandler
import (
"encoding/json"
"fmt"
securityBean "github.com/devtron-labs/devtron/pkg/security/bean"
"net/http"
"strconv"

Expand Down Expand Up @@ -70,7 +71,7 @@ func (impl ImageScanRestHandlerImpl) ScanExecutionList(w http.ResponseWriter, r
}

decoder := json.NewDecoder(r.Body)
var request *security.ImageScanRequest
var request *securityBean.ImageScanRequest
err = decoder.Decode(&request)
if err != nil {
impl.logger.Errorw("request err, ScanExecutionList", "err", err, "payload", request)
Expand All @@ -82,8 +83,8 @@ func (impl ImageScanRestHandlerImpl) ScanExecutionList(w http.ResponseWriter, r
if err != nil {
impl.logger.Errorw("service err, ScanExecutionList", "err", err, "payload", request)
if util.IsErrNoRows(err) {
responseList := make([]*security.ImageScanHistoryResponse, 0)
common.WriteJsonResp(w, nil, &security.ImageScanHistoryListingResponse{ImageScanHistoryResponse: responseList}, http.StatusOK)
responseList := make([]*securityBean.ImageScanHistoryResponse, 0)
common.WriteJsonResp(w, nil, &securityBean.ImageScanHistoryListingResponse{ImageScanHistoryResponse: responseList}, http.StatusOK)
} else {
common.WriteJsonResp(w, err, nil, http.StatusInternalServerError)
}
Expand Down Expand Up @@ -126,8 +127,8 @@ func (impl ImageScanRestHandlerImpl) ScanExecutionList(w http.ResponseWriter, r
if err != nil {
impl.logger.Errorw("service err, ScanExecutionList", "err", err, "payload", request)
if util.IsErrNoRows(err) {
responseList := make([]*security.ImageScanHistoryResponse, 0)
common.WriteJsonResp(w, nil, &security.ImageScanHistoryListingResponse{ImageScanHistoryResponse: responseList}, http.StatusOK)
responseList := make([]*securityBean.ImageScanHistoryResponse, 0)
common.WriteJsonResp(w, nil, &securityBean.ImageScanHistoryListingResponse{ImageScanHistoryResponse: responseList}, http.StatusOK)
} else {
common.WriteJsonResp(w, err, nil, http.StatusInternalServerError)
}
Expand Down Expand Up @@ -177,7 +178,7 @@ func (impl ImageScanRestHandlerImpl) FetchExecutionDetail(w http.ResponseWriter,
}
}
image := v.Get("image")
request := &security.ImageScanRequest{
request := &securityBean.ImageScanRequest{
ImageScanDeployInfoId: imageScanDeployInfoId,
Image: image,
ArtifactId: artifactId,
Expand All @@ -189,7 +190,7 @@ func (impl ImageScanRestHandlerImpl) FetchExecutionDetail(w http.ResponseWriter,
if err != nil {
impl.logger.Errorw("service err, FetchExecutionDetail", "err", err, "payload", request)
if util.IsErrNoRows(err) {
common.WriteJsonResp(w, nil, &security.ImageScanExecutionDetail{}, http.StatusOK)
common.WriteJsonResp(w, nil, &securityBean.ImageScanExecutionDetail{}, http.StatusOK)
} else {
common.WriteJsonResp(w, err, nil, http.StatusInternalServerError)
}
Expand Down Expand Up @@ -221,7 +222,7 @@ func (impl ImageScanRestHandlerImpl) FetchExecutionDetail(w http.ResponseWriter,
}
//RBAC
} else {
common.WriteJsonResp(w, err, &security.ImageScanExecutionDetail{}, http.StatusOK)
common.WriteJsonResp(w, err, &securityBean.ImageScanExecutionDetail{}, http.StatusOK)
}

common.WriteJsonResp(w, err, executionDetail, http.StatusOK)
Expand All @@ -230,7 +231,7 @@ func (impl ImageScanRestHandlerImpl) FetchExecutionDetail(w http.ResponseWriter,
func (impl ImageScanRestHandlerImpl) FetchMinScanResultByAppIdAndEnvId(w http.ResponseWriter, r *http.Request) {
v := r.URL.Query()
var appId, envId int
request := &security.ImageScanRequest{}
request := &securityBean.ImageScanRequest{}
appIds := v.Get("appId")
if len(appIds) > 0 {
appId, err := strconv.Atoi(appIds)
Expand Down Expand Up @@ -299,8 +300,8 @@ func (impl ImageScanRestHandlerImpl) VulnerabilityExposure(w http.ResponseWriter
if err != nil {
impl.logger.Errorw("service err, VulnerabilityExposure", "err", err, "payload", request)
if util.IsErrNoRows(err) {
responseList := make([]*security.ImageScanHistoryResponse, 0)
common.WriteJsonResp(w, nil, &security.ImageScanHistoryListingResponse{ImageScanHistoryResponse: responseList}, http.StatusOK)
responseList := make([]*securityBean.ImageScanHistoryResponse, 0)
common.WriteJsonResp(w, nil, &securityBean.ImageScanHistoryListingResponse{ImageScanHistoryResponse: responseList}, http.StatusOK)
} else {
common.WriteJsonResp(w, err, nil, http.StatusInternalServerError)
}
Expand Down
20 changes: 10 additions & 10 deletions api/restHandler/PolicyRestHandler.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,12 +20,12 @@ import (
"encoding/json"
"errors"
"fmt"
securityBean "github.com/devtron-labs/devtron/internal/sql/repository/security/bean"
"net/http"
"strconv"

"github.com/devtron-labs/devtron/api/bean"
"github.com/devtron-labs/devtron/api/restHandler/common"
security2 "github.com/devtron-labs/devtron/internal/sql/repository/security"
"github.com/devtron-labs/devtron/pkg/auth/authorisation/casbin"
user2 "github.com/devtron-labs/devtron/pkg/auth/user"
"github.com/devtron-labs/devtron/pkg/cluster"
Expand Down Expand Up @@ -221,18 +221,18 @@ func (impl PolicyRestHandlerImpl) GetPolicy(w http.ResponseWriter, r *http.Reque
req.Id = ids
}
var clusterId, environmentId, appId int
var policyLevel security2.PolicyLevel
if level == security2.Global.String() {
policyLevel = security2.Global
} else if level == security2.Cluster.String() {
var policyLevel securityBean.PolicyLevel
if level == securityBean.Global.String() {
policyLevel = securityBean.Global
} else if level == securityBean.Cluster.String() {
clusterId = req.Id
policyLevel = security2.Cluster
} else if level == security2.Environment.String() {
policyLevel = securityBean.Cluster
} else if level == securityBean.Environment.String() {
environmentId = req.Id
policyLevel = security2.Environment
} else if level == security2.Application.String() {
policyLevel = securityBean.Environment
} else if level == securityBean.Application.String() {
appId = req.Id
policyLevel = security2.Application
policyLevel = securityBean.Application
}

token := r.Header.Get("token")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -207,6 +207,11 @@ func (handler *PipelineConfigRestHandlerImpl) CreateCdPipeline(w http.ResponseWr
handler.Logger.Infow("request payload, CreateCdPipeline", "payload", cdPipeline)
userUploaded, err := handler.chartService.CheckIfChartRefUserUploadedByAppId(cdPipeline.AppId)
if !userUploaded {
for i, p := range cdPipeline.Pipelines {
if len(p.ReleaseMode) == 0 {
cdPipeline.Pipelines[i].ReleaseMode = util.PIPELINE_RELEASE_MODE_CREATE
}
}
err = handler.validator.Struct(cdPipeline)
if err != nil {
handler.Logger.Errorw("validation err, CreateCdPipeline", "err", err, "payload", cdPipeline)
Expand Down
31 changes: 31 additions & 0 deletions api/router/DeploymentConfigRouter.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
package router

import (
"github.com/devtron-labs/devtron/api/restHandler"
"github.com/gorilla/mux"
)

type DeploymentConfigurationRouter interface {
initDeploymentConfigurationRouter(configRouter *mux.Router)
}

type DeploymentConfigurationRouterImpl struct {
deploymentGroupRestHandler restHandler.DeploymentConfigurationRestHandler
}

func NewDeploymentConfigurationRouter(deploymentGroupRestHandler restHandler.DeploymentConfigurationRestHandler) *DeploymentConfigurationRouterImpl {
router := &DeploymentConfigurationRouterImpl{
deploymentGroupRestHandler: deploymentGroupRestHandler,
}
return router
}

func (router DeploymentConfigurationRouterImpl) initDeploymentConfigurationRouter(configRouter *mux.Router) {
configRouter.Path("/autocomplete").
HandlerFunc(router.deploymentGroupRestHandler.ConfigAutoComplete).
Methods("GET")
configRouter.Path("/data").
HandlerFunc(router.deploymentGroupRestHandler.GetConfigData).
Methods("GET")

}
8 changes: 6 additions & 2 deletions api/router/router.go
Original file line number Diff line number Diff line change
Expand Up @@ -114,6 +114,7 @@ type MuxRouter struct {
rbacRoleRouter user.RbacRoleRouter
scopedVariableRouter ScopedVariableRouter
ciTriggerCron cron.CiTriggerCron
deploymentConfigurationRouter DeploymentConfigurationRouter
infraConfigRouter infraConfig.InfraConfigRouter
argoApplicationRouter argoApplication.ArgoApplicationRouter
fluxApplicationRouter fluxApplication2.FluxApplicationRouter
Expand Down Expand Up @@ -146,6 +147,7 @@ func NewMuxRouter(logger *zap.SugaredLogger,
scopedVariableRouter ScopedVariableRouter,
ciTriggerCron cron.CiTriggerCron,
proxyRouter proxy.ProxyRouter,
deploymentConfigurationRouter DeploymentConfigurationRouter,
infraConfigRouter infraConfig.InfraConfigRouter,
argoApplicationRouter argoApplication.ArgoApplicationRouter,
devtronResourceRouter devtronResource.DevtronResourceRouter,
Expand Down Expand Up @@ -210,6 +212,7 @@ func NewMuxRouter(logger *zap.SugaredLogger,
rbacRoleRouter: rbacRoleRouter,
scopedVariableRouter: scopedVariableRouter,
ciTriggerCron: ciTriggerCron,
deploymentConfigurationRouter: deploymentConfigurationRouter,
infraConfigRouter: infraConfigRouter,
argoApplicationRouter: argoApplicationRouter,
devtronResourceRouter: devtronResourceRouter,
Expand Down Expand Up @@ -293,8 +296,9 @@ func (r MuxRouter) Init() {
chartRefRouter := r.Router.PathPrefix("/orchestrator/chartref").Subrouter()
r.ChartRefRouter.initChartRefRouter(chartRefRouter)

configMapRouter := r.Router.PathPrefix("/orchestrator/config").Subrouter()
r.ConfigMapRouter.initConfigMapRouter(configMapRouter)
configRouter := r.Router.PathPrefix("/orchestrator/config").Subrouter()
r.ConfigMapRouter.initConfigMapRouter(configRouter)
r.deploymentConfigurationRouter.initDeploymentConfigurationRouter(configRouter)

appStoreRouter := r.Router.PathPrefix("/orchestrator/app-store").Subrouter()
r.AppStoreRouter.Init(appStoreRouter)
Expand Down
Loading