Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
37 commits
Select commit Hold shift + click to select a range
71df80d
added environment wise app workflow
vikramdevtron Feb 8, 2023
c0d29ad
app workflow list for environment
vikramdevtron Feb 9, 2023
8abed14
Merge branch 'main' into app-grouping
vikramdevtron Feb 9, 2023
601bc86
fix
vikramdevtron Feb 9, 2023
6af1f28
added new api for app grouping
vikramdevtron Feb 9, 2023
7913d2c
pipelines for env ids
vikramdevtron Feb 9, 2023
af6dfe0
fix
vikramdevtron Feb 9, 2023
eba130a
added workflow status api
vikramdevtron Feb 13, 2023
8273ad9
Merge branch 'main' into app-grouping
vikramdevtron Feb 13, 2023
e247f9c
added workflow status api
vikramdevtron Feb 13, 2023
072db2e
fix
vikramdevtron Feb 13, 2023
3c8048e
wip
vikramdevtron Feb 13, 2023
9784c38
wip
vikramdevtron Feb 13, 2023
6899b48
urls modified for app-grouping
vikramdevtron Feb 15, 2023
4a6ab0d
code refactor
vikramdevtron Feb 16, 2023
56be8ec
rbac added for app grouping api's
vikramdevtron Feb 16, 2023
226b33e
Merge branch 'main' into app-grouping
vikramdevtron Feb 16, 2023
e506bd6
added offset and size filter for env list for app grouping
vikramdevtron Feb 16, 2023
7929a28
offset and size refix for app grouping api
vikramdevtron Feb 16, 2023
0a71fdf
total count addeded for app grouping
vikramdevtron Feb 17, 2023
2f703bc
app count in app grouping api
vikramdevtron Feb 17, 2023
9784e08
handle no data found for app-grouping api's
vikramdevtron Feb 17, 2023
b7b58b7
pagination changes
vikramdevtron Feb 17, 2023
35b1bed
deployment status
vikramdevtron Feb 18, 2023
b48a5db
env deployemt status for app
vikramdevtron Feb 18, 2023
3358adf
env app deployment status fix
vikramdevtron Feb 18, 2023
c5a6462
fix
vikramdevtron Feb 18, 2023
98d1335
default size removed for app grouping list
vikramdevtron Feb 18, 2023
9d6e730
app deployment status for app grouping fix
vikramdevtron Feb 20, 2023
36981ed
review changes
vikramdevtron Feb 20, 2023
0d521c2
app listing size optional
vikramdevtron Feb 20, 2023
532e921
review changes rbac refactor
vikramdevtron Feb 20, 2023
2c79864
order by env name for app grouping env list
vikramdevtron Feb 20, 2023
6a3f0ea
token replaced by emailId for app grouping api's
vikramdevtron Feb 20, 2023
e6226ef
fixes
vikramdevtron Feb 20, 2023
2c21ad9
Merge branch 'main' into app-grouping
vikramdevtron Feb 21, 2023
752b742
review changes for const on app grouping
vikramdevtron Feb 21, 2023
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
3 changes: 3 additions & 0 deletions Wire.go
Original file line number Diff line number Diff line change
Expand Up @@ -819,6 +819,9 @@ func InitializeApp() (*App, error) {

kubernetesResourceAuditLogs.Newk8sResourceHistoryServiceImpl,
wire.Bind(new(kubernetesResourceAuditLogs.K8sResourceHistoryService), new(*kubernetesResourceAuditLogs.K8sResourceHistoryServiceImpl)),

router.NewAppGroupingRouterImpl,
wire.Bind(new(router.AppGroupingRouter), new(*router.AppGroupingRouterImpl)),
)
return &App{}, nil
}
11 changes: 6 additions & 5 deletions api/restHandler/AppListingRestHandler.go
Original file line number Diff line number Diff line change
Expand Up @@ -305,12 +305,13 @@ func (handler AppListingRestHandlerImpl) FetchAppsByEnvironment(w http.ResponseW
offset := fetchAppListingRequest.Offset
limit := fetchAppListingRequest.Size

if offset+limit <= len(apps) {
apps = apps[offset : offset+limit]
} else {
apps = apps[offset:]
if limit > 0 {
if offset+limit <= len(apps) {
apps = apps[offset : offset+limit]
} else {
apps = apps[offset:]
}
}

appContainerResponse := bean.AppContainerResponse{
AppContainers: apps,
AppCount: appsCount,
Expand Down
49 changes: 49 additions & 0 deletions api/restHandler/AppWorkflowRestHandler.go
Original file line number Diff line number Diff line change
Expand Up @@ -32,13 +32,15 @@ import (
"go.uber.org/zap"
"net/http"
"strconv"
"strings"
)

type AppWorkflowRestHandler interface {
CreateAppWorkflow(w http.ResponseWriter, r *http.Request)
FindAppWorkflow(w http.ResponseWriter, r *http.Request)
DeleteAppWorkflow(w http.ResponseWriter, r *http.Request)
FindAllWorkflows(w http.ResponseWriter, r *http.Request)
FindAppWorkflowByEnvironment(w http.ResponseWriter, r *http.Request)
}

type AppWorkflowRestHandlerImpl struct {
Expand Down Expand Up @@ -216,3 +218,50 @@ func (impl AppWorkflowRestHandlerImpl) FindAllWorkflows(w http.ResponseWriter, r
}
common.WriteJsonResp(w, nil, resp, http.StatusOK)
}

func (impl AppWorkflowRestHandlerImpl) FindAppWorkflowByEnvironment(w http.ResponseWriter, r *http.Request) {
vars := mux.Vars(r)
userId, err := impl.userAuthService.GetLoggedInUser(r)
if userId == 0 || err != nil {
common.WriteJsonResp(w, err, "Unauthorized User", http.StatusUnauthorized)
return
}
user, err := impl.userAuthService.GetById(userId)
if userId == 0 || err != nil {
common.WriteJsonResp(w, err, "Unauthorized User", http.StatusUnauthorized)
return
}
userEmailId := strings.ToLower(user.EmailId)
envId, err := strconv.Atoi(vars["envId"])
if err != nil {
impl.Logger.Errorw("bad request", "err", err)
common.WriteJsonResp(w, err, nil, http.StatusBadRequest)
return
}
workflows := make(map[string]interface{})
workflowsList, err := impl.appWorkflowService.FindAppWorkflowsByEnvironmentId(envId, userEmailId, impl.checkAuthBatch)
if err != nil {
impl.Logger.Errorw("error in fetching workflows for app", "err", err)
common.WriteJsonResp(w, err, nil, http.StatusInternalServerError)
return
}
workflows["envId"] = envId
if len(workflowsList) > 0 {
workflows["workflows"] = workflowsList
} else {
workflows["workflows"] = []appWorkflow.AppWorkflowDto{}
}
common.WriteJsonResp(w, err, workflows, http.StatusOK)
}

func (handler *AppWorkflowRestHandlerImpl) checkAuthBatch(emailId string, appObject []string, envObject []string) (map[string]bool, map[string]bool) {
var appResult map[string]bool
var envResult map[string]bool
if len(appObject) > 0 {
appResult = handler.enforcer.EnforceByEmailInBatch(emailId, casbin.ResourceApplications, casbin.ActionGet, appObject)
}
if len(envObject) > 0 {
envResult = handler.enforcer.EnforceByEmailInBatch(emailId, casbin.ResourceEnvironment, casbin.ActionGet, envObject)
}
return appResult, envResult
}
57 changes: 57 additions & 0 deletions api/restHandler/app/BuildPipelineRestHandler.go
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,8 @@ type DevtronAppBuildRestHandler interface {
CancelWorkflow(w http.ResponseWriter, r *http.Request)

UpdateBranchCiPipelinesWithRegex(w http.ResponseWriter, r *http.Request)
GetCiPipelineByEnvironment(w http.ResponseWriter, r *http.Request)
GetExternalCiByEnvironment(w http.ResponseWriter, r *http.Request)
}

type DevtronAppBuildMaterialRestHandler interface {
Expand Down Expand Up @@ -1243,3 +1245,58 @@ func (handler PipelineConfigRestHandlerImpl) FetchWorkflowDetails(w http.Respons
}
common.WriteJsonResp(w, err, resp, http.StatusOK)
}

func (handler PipelineConfigRestHandlerImpl) GetCiPipelineByEnvironment(w http.ResponseWriter, r *http.Request) {
vars := mux.Vars(r)
userId, err := handler.userAuthService.GetLoggedInUser(r)
if userId == 0 || err != nil {
common.WriteJsonResp(w, err, "Unauthorized User", http.StatusUnauthorized)
return
}
user, err := handler.userAuthService.GetById(userId)
if userId == 0 || err != nil {
common.WriteJsonResp(w, err, "Unauthorized User", http.StatusUnauthorized)
return
}
userEmailId := strings.ToLower(user.EmailId)
envId, err := strconv.Atoi(vars["envId"])
if err != nil {
handler.Logger.Errorw("request err, GetCdPipelines", "err", err, "envId", envId)
common.WriteJsonResp(w, err, nil, http.StatusBadRequest)
return
}
ciConf, err := handler.pipelineBuilder.GetCiPipelineByEnvironment(envId, userEmailId, handler.checkAuthBatch)
if err != nil {
handler.Logger.Errorw("service err, GetCiPipeline", "err", err, "envId", envId)
common.WriteJsonResp(w, err, nil, http.StatusInternalServerError)
return
}
common.WriteJsonResp(w, err, ciConf, http.StatusOK)
}

func (handler PipelineConfigRestHandlerImpl) GetExternalCiByEnvironment(w http.ResponseWriter, r *http.Request) {
vars := mux.Vars(r)
userId, err := handler.userAuthService.GetLoggedInUser(r)
if userId == 0 || err != nil {
common.WriteJsonResp(w, err, "Unauthorized User", http.StatusUnauthorized)
return
}
user, err := handler.userAuthService.GetById(userId)
if userId == 0 || err != nil {
common.WriteJsonResp(w, err, "Unauthorized User", http.StatusUnauthorized)
return
}
userEmailId := strings.ToLower(user.EmailId)
envId, err := strconv.Atoi(vars["envId"])
if err != nil {
common.WriteJsonResp(w, err, nil, http.StatusBadRequest)
return
}
ciConf, err := handler.pipelineBuilder.GetExternalCiByEnvironment(envId, userEmailId, handler.checkAuthBatch)
if err != nil {
handler.Logger.Errorw("service err, GetExternalCi", "err", err, "envId", envId)
common.WriteJsonResp(w, err, nil, http.StatusInternalServerError)
return
}
common.WriteJsonResp(w, err, ciConf, http.StatusOK)
}
49 changes: 42 additions & 7 deletions api/restHandler/app/DeploymentPipelineRestHandler.go
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ type DevtronAppDeploymentRestHandler interface {

IsReadyToTrigger(w http.ResponseWriter, r *http.Request)
FetchCdWorkflowDetails(w http.ResponseWriter, r *http.Request)
GetCdPipelinesByEnvironment(w http.ResponseWriter, r *http.Request)
}

type DevtronAppDeploymentConfigRestHandler interface {
Expand Down Expand Up @@ -1578,13 +1579,7 @@ func (handler PipelineConfigRestHandlerImpl) GetCdPipelineById(w http.ResponseWr
return
}

envId, err := handler.pipelineBuilder.GetEnvironmentByCdPipelineId(pipelineId)
if err != nil {
common.WriteJsonResp(w, err, nil, http.StatusBadRequest)
return
}

envObject := handler.enforcerUtil.GetEnvRBACNameByCdPipelineIdAndEnvId(pipelineId, envId)
envObject := handler.enforcerUtil.GetEnvRBACNameByCdPipelineIdAndEnvId(pipelineId)
if ok := handler.enforcer.Enforce(token, casbin.ResourceEnvironment, casbin.ActionUpdate, envObject); !ok {
common.WriteJsonResp(w, fmt.Errorf("unauthorized user"), "Unauthorized User", http.StatusForbidden)
return
Expand Down Expand Up @@ -1874,3 +1869,43 @@ func (handler PipelineConfigRestHandlerImpl) UpgradeForAllApps(w http.ResponseWr
response["failed"] = failedIds
common.WriteJsonResp(w, err, response, http.StatusOK)
}

func (handler PipelineConfigRestHandlerImpl) GetCdPipelinesByEnvironment(w http.ResponseWriter, r *http.Request) {
vars := mux.Vars(r)
userId, err := handler.userAuthService.GetLoggedInUser(r)
if userId == 0 || err != nil {
common.WriteJsonResp(w, err, "Unauthorized User", http.StatusUnauthorized)
return
}
user, err := handler.userAuthService.GetById(userId)
if userId == 0 || err != nil {
common.WriteJsonResp(w, err, "Unauthorized User", http.StatusUnauthorized)
return
}
userEmailId := strings.ToLower(user.EmailId)
envId, err := strconv.Atoi(vars["envId"])
if err != nil {
handler.Logger.Errorw("request err, GetCdPipelines", "err", err, "envId", envId)
common.WriteJsonResp(w, err, nil, http.StatusBadRequest)
return
}
results, err := handler.pipelineBuilder.GetCdPipelinesByEnvironment(envId, userEmailId, handler.checkAuthBatch)
if err != nil {
handler.Logger.Errorw("service err, GetCdPipelines", "err", err, "envId", envId)
common.WriteJsonResp(w, err, nil, http.StatusInternalServerError)
return
}
common.WriteJsonResp(w, err, results, http.StatusOK)
}

func (handler *PipelineConfigRestHandlerImpl) checkAuthBatch(emailId string, appObject []string, envObject []string) (map[string]bool, map[string]bool) {
var appResult map[string]bool
var envResult map[string]bool
if len(appObject) > 0 {
appResult = handler.enforcer.EnforceByEmailInBatch(emailId, casbin.ResourceApplications, casbin.ActionGet, appObject)
}
if len(envObject) > 0 {
envResult = handler.enforcer.EnforceByEmailInBatch(emailId, casbin.ResourceEnvironment, casbin.ActionGet, envObject)
}
return appResult, envResult
}
Loading