Skip to content

Commit 9c09419

Browse files
Merge branch 'main' into incorrect-commit-info
2 parents 394997c + 0c07299 commit 9c09419

File tree

99 files changed

+7317
-713
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

99 files changed

+7317
-713
lines changed

.github/ISSUE_TEMPLATE/bug.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ name: "🐛 Bug Report"
22
description: "Submit a bug report to help us improve"
33
title: "Bug: "
44
labels: [bug]
5-
assignees: ["prakarsh-dt","anupdhiran"]
5+
assignees: ["prakarsh-dt"]
66
body:
77
- type: markdown
88
attributes:

.github/ISSUE_TEMPLATE/feature.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ name: 🚀 Feature
22
description: "Submit a proposal for a new feature"
33
title: "Feature: "
44
labels: ["enhancement"]
5-
assignees: ["prakarsh-dt","nishant-d","anupdhiran"]
5+
assignees: ["prakarsh-dt","nishant-d"]
66
body:
77
- type: markdown
88
attributes:

api/appStore/AppStoreStatusTimelineRestHandler.go

Lines changed: 1 addition & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
package appStore
22

33
import (
4-
"fmt"
54
"github.com/devtron-labs/devtron/api/restHandler/common"
65
"github.com/devtron-labs/devtron/pkg/app/status"
76
"github.com/devtron-labs/devtron/pkg/user/casbin"
@@ -56,13 +55,7 @@ func (handler AppStoreStatusTimelineRestHandlerImpl) FetchTimelinesForAppStore(w
5655
return
5756
}
5857
}
59-
resourceName := handler.enforcerUtil.GetAppRBACNameByAppId(installedAppId)
60-
token := r.Header.Get("token")
61-
if ok := handler.enforcer.Enforce(token, casbin.ResourceApplications, casbin.ActionGet, resourceName); !ok {
62-
common.WriteJsonResp(w, fmt.Errorf("unauthorized user"), "Unauthorized User", http.StatusForbidden)
63-
return
64-
}
65-
58+
//rbac will already be handled at app level
6659
timelines, err := handler.pipelineStatusTimelineService.FetchTimelinesForAppStore(installedAppId, envId, installedAppVersionHistoryId)
6760
if err != nil {
6861
handler.logger.Errorw("error in getting pipeline status timelines by installedAppVersionHistoryId", "err", err, "installedAppVersionHistoryId", installedAppVersionHistoryId, "installedAppId", installedAppId, "envId", envId)

api/appStore/discover/AppStoreRestHandler.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -83,7 +83,7 @@ func (handler *AppStoreRestHandlerImpl) FindAllApps(w http.ResponseWriter, r *ht
8383
}
8484
}
8585
}
86-
appStoreName := v.Get("appStoreName")
86+
appStoreName := strings.ToLower(v.Get("appStoreName"))
8787

8888
offset := 0
8989
offsetStr := v.Get("offset")

api/appbean/AppDetail.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -58,6 +58,7 @@ type DockerBuildConfig struct {
5858
Args map[string]string `json:"args,omitempty"`
5959
TargetPlatform string `json:"targetPlatform"`
6060
DockerBuildOptions map[string]string `json:"dockerBuildOptions,omitempty"`
61+
BuildContext string `json:"buildContext"`
6162
}
6263

6364
type DeploymentTemplate struct {

api/helm-app/HelmAppRestHandler.go

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -313,7 +313,7 @@ func (handler *HelmAppRestHandlerImpl) DeleteApplication(w http.ResponseWriter,
313313
}
314314

315315
func (handler *HelmAppRestHandlerImpl) UpdateApplication(w http.ResponseWriter, r *http.Request) {
316-
request := &openapi.UpdateReleaseRequest{}
316+
request := &UpdateApplicationRequestDto{}
317317
decoder := json.NewDecoder(r.Body)
318318
err := decoder.Decode(request)
319319
if err != nil {
@@ -336,9 +336,9 @@ func (handler *HelmAppRestHandlerImpl) UpdateApplication(w http.ResponseWriter,
336336
return
337337
}
338338
//RBAC enforcer Ends
339-
339+
request.SourceAppType = SOURCE_EXTERNAL_HELM_APP
340340
// update application externally
341-
res, err := handler.helmAppService.UpdateApplication(r.Context(), appIdentifier, request, API_CALLER_EXTERNAL_HELM_APP)
341+
res, err := handler.helmAppService.UpdateApplication(r.Context(), appIdentifier, request)
342342
if err != nil {
343343
common.WriteJsonResp(w, err, nil, http.StatusInternalServerError)
344344
return

api/helm-app/HelmAppService.go

Lines changed: 25 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -36,17 +36,6 @@ import (
3636
"time"
3737
)
3838

39-
const (
40-
DEFAULT_CLUSTER = "default_cluster"
41-
DEFAULT_CLUSTER_ID = 1
42-
API_CALLER_DEVTRON_APP ApiCallerAppType = "devtron-app"
43-
API_CALLER_HELM_APP ApiCallerAppType = "helm-app"
44-
API_CALLER_EXTERNAL_HELM_APP ApiCallerAppType = "external-helm-app"
45-
API_CALLER_UNKNOWN ApiCallerAppType = "unknown"
46-
)
47-
48-
type ApiCallerAppType string
49-
5039
type HelmAppService interface {
5140
ListHelmApplications(ctx context.Context, clusterIds []int, w http.ResponseWriter, token string, helmAuth func(token string, object string) bool)
5241
GetApplicationDetail(ctx context.Context, app *AppIdentifier) (*AppDetail, error)
@@ -60,18 +49,18 @@ type HelmAppService interface {
6049
GetValuesYaml(ctx context.Context, app *AppIdentifier) (*ReleaseInfo, error)
6150
GetDesiredManifest(ctx context.Context, app *AppIdentifier, resource *openapi.ResourceIdentifier) (*openapi.DesiredManifestResponse, error)
6251
DeleteApplication(ctx context.Context, app *AppIdentifier) (*openapi.UninstallReleaseResponse, error)
63-
UpdateApplication(ctx context.Context, app *AppIdentifier, request *openapi.UpdateReleaseRequest, apiCallerAppType ApiCallerAppType) (*openapi.UpdateReleaseResponse, error)
52+
UpdateApplication(ctx context.Context, app *AppIdentifier, request *UpdateApplicationRequestDto) (*openapi.UpdateReleaseResponse, error)
6453
GetDeploymentDetail(ctx context.Context, app *AppIdentifier, version int32) (*openapi.HelmAppDeploymentManifestDetail, error)
6554
InstallRelease(ctx context.Context, clusterId int, installReleaseRequest *InstallReleaseRequest) (*InstallReleaseResponse, error)
66-
UpdateApplicationWithChartInfo(ctx context.Context, clusterId int, updateReleaseRequest *InstallReleaseRequest, apiCallerAppType ApiCallerAppType) (*openapi.UpdateReleaseResponse, error)
55+
UpdateApplicationWithChartInfo(ctx context.Context, clusterId int, request *UpdateApplicationWithChartInfoRequestDto) (*openapi.UpdateReleaseResponse, error)
6756
IsReleaseInstalled(ctx context.Context, app *AppIdentifier) (bool, error)
6857
RollbackRelease(ctx context.Context, app *AppIdentifier, version int32) (bool, error)
6958
GetClusterConf(clusterId int) (*ClusterConfig, error)
7059
GetDevtronHelmAppIdentifier() *AppIdentifier
7160
UpdateApplicationWithChartInfoWithExtraValues(ctx context.Context, appIdentifier *AppIdentifier, chartRepository *ChartRepository, extraValues map[string]interface{}, extraValuesYamlUrl string, useLatestChartVersion bool) (*openapi.UpdateReleaseResponse, error)
7261
TemplateChart(ctx context.Context, templateChartRequest *openapi2.TemplateChartRequest) (*openapi2.TemplateChartResponse, error)
7362
GetNotes(ctx context.Context, request *InstallReleaseRequest) (string, error)
74-
GetRevisionHistoryMaxValue(appType ApiCallerAppType) int32
63+
GetRevisionHistoryMaxValue(appType SourceAppType) int32
7564
}
7665

7766
type HelmAppServiceImpl struct {
@@ -439,7 +428,7 @@ func (impl *HelmAppServiceImpl) DeleteApplication(ctx context.Context, app *AppI
439428
return response, nil
440429
}
441430

442-
func (impl *HelmAppServiceImpl) UpdateApplication(ctx context.Context, app *AppIdentifier, request *openapi.UpdateReleaseRequest, apiCallerAppType ApiCallerAppType) (*openapi.UpdateReleaseResponse, error) {
431+
func (impl *HelmAppServiceImpl) UpdateApplication(ctx context.Context, app *AppIdentifier, request *UpdateApplicationRequestDto) (*openapi.UpdateReleaseResponse, error) {
443432
config, err := impl.GetClusterConf(app.ClusterId)
444433
if err != nil {
445434
impl.logger.Errorw("error in fetching cluster detail", "clusterId", app.ClusterId, "err", err)
@@ -453,7 +442,7 @@ func (impl *HelmAppServiceImpl) UpdateApplication(ctx context.Context, app *AppI
453442
ReleaseNamespace: app.Namespace,
454443
},
455444
ValuesYaml: request.GetValuesYaml(),
456-
HistoryMax: impl.GetRevisionHistoryMaxValue(apiCallerAppType),
445+
HistoryMax: impl.GetRevisionHistoryMaxValue(request.SourceAppType),
457446
}
458447

459448
updateApplicationResponse, err := impl.helmAppClient.UpdateApplication(ctx, req)
@@ -517,16 +506,16 @@ func (impl *HelmAppServiceImpl) InstallRelease(ctx context.Context, clusterId in
517506
}
518507

519508
func (impl *HelmAppServiceImpl) UpdateApplicationWithChartInfo(ctx context.Context, clusterId int,
520-
updateReleaseRequest *InstallReleaseRequest, apiCallerAppType ApiCallerAppType) (*openapi.UpdateReleaseResponse, error) {
509+
request *UpdateApplicationWithChartInfoRequestDto) (*openapi.UpdateReleaseResponse, error) {
521510
config, err := impl.GetClusterConf(clusterId)
522511
if err != nil {
523512
impl.logger.Errorw("error in fetching cluster detail", "clusterId", clusterId, "err", err)
524513
return nil, err
525514
}
526-
updateReleaseRequest.HistoryMax = impl.GetRevisionHistoryMaxValue(apiCallerAppType)
527-
updateReleaseRequest.ReleaseIdentifier.ClusterConfig = config
515+
request.HistoryMax = impl.GetRevisionHistoryMaxValue(request.SourceAppType)
516+
request.ReleaseIdentifier.ClusterConfig = config
528517

529-
updateReleaseResponse, err := impl.helmAppClient.UpdateApplicationWithChartInfo(ctx, updateReleaseRequest)
518+
updateReleaseResponse, err := impl.helmAppClient.UpdateApplicationWithChartInfo(ctx, request.InstallReleaseRequest)
530519
if err != nil {
531520
impl.logger.Errorw("error in installing release", "err", err)
532521
return nil, err
@@ -668,20 +657,24 @@ func (impl *HelmAppServiceImpl) UpdateApplicationWithChartInfoWithExtraValues(ct
668657
}
669658

670659
// update in helm
671-
updateReleaseRequest := &InstallReleaseRequest{
672-
ReleaseIdentifier: &ReleaseIdentifier{
673-
ReleaseName: appIdentifier.ReleaseName,
674-
ReleaseNamespace: appIdentifier.Namespace,
660+
661+
updateReleaseRequest := &UpdateApplicationWithChartInfoRequestDto{
662+
InstallReleaseRequest: &InstallReleaseRequest{
663+
ReleaseIdentifier: &ReleaseIdentifier{
664+
ReleaseName: appIdentifier.ReleaseName,
665+
ReleaseNamespace: appIdentifier.Namespace,
666+
},
667+
ChartName: releaseInfo.DeployedAppDetail.ChartName,
668+
ValuesYaml: string(mergedValuesYamlByteArr),
669+
ChartRepository: chartRepository,
675670
},
676-
ChartName: releaseInfo.DeployedAppDetail.ChartName,
677-
ValuesYaml: string(mergedValuesYamlByteArr),
678-
ChartRepository: chartRepository,
671+
SourceAppType: SOURCE_UNKNOWN,
679672
}
680673
if !useLatestChartVersion {
681674
updateReleaseRequest.ChartVersion = releaseInfo.DeployedAppDetail.ChartVersion
682675
}
683676

684-
updateResponse, err := impl.UpdateApplicationWithChartInfo(ctx, appIdentifier.ClusterId, updateReleaseRequest, API_CALLER_UNKNOWN)
677+
updateResponse, err := impl.UpdateApplicationWithChartInfo(ctx, appIdentifier.ClusterId, updateReleaseRequest)
685678
if err != nil {
686679
impl.logger.Errorw("error in upgrading release", "err", err)
687680
return nil, err
@@ -885,13 +878,13 @@ func (impl *HelmAppServiceImpl) appListRespProtoTransformer(deployedApps *Deploy
885878
return appList
886879
}
887880

888-
func (impl *HelmAppServiceImpl) GetRevisionHistoryMaxValue(appType ApiCallerAppType) int32 {
881+
func (impl *HelmAppServiceImpl) GetRevisionHistoryMaxValue(appType SourceAppType) int32 {
889882
switch appType {
890-
case API_CALLER_DEVTRON_APP:
883+
case SOURCE_DEVTRON_APP:
891884
return int32(impl.helmReleaseConfig.RevisionHistoryLimitDevtronApp)
892-
case API_CALLER_HELM_APP:
885+
case SOURCE_HELM_APP:
893886
return int32(impl.helmReleaseConfig.RevisionHistoryLimitHelmApp)
894-
case API_CALLER_EXTERNAL_HELM_APP:
887+
case SOURCE_EXTERNAL_HELM_APP:
895888
return int32(impl.helmReleaseConfig.RevisionHistoryLimitExternalHelmApp)
896889
default:
897890
return 0

api/helm-app/bean.go

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
package client
2+
3+
import openapi "github.com/devtron-labs/devtron/api/helm-app/openapiClient"
4+
5+
const (
6+
DEFAULT_CLUSTER = "default_cluster"
7+
DEFAULT_CLUSTER_ID = 1
8+
SOURCE_DEVTRON_APP SourceAppType = "devtron-app"
9+
SOURCE_HELM_APP SourceAppType = "helm-app"
10+
SOURCE_EXTERNAL_HELM_APP SourceAppType = "external-helm-app"
11+
SOURCE_UNKNOWN SourceAppType = "unknown"
12+
)
13+
14+
type SourceAppType string
15+
16+
type UpdateApplicationRequestDto struct {
17+
*openapi.UpdateReleaseRequest
18+
SourceAppType SourceAppType `json:"-"`
19+
}
20+
21+
type UpdateApplicationWithChartInfoRequestDto struct {
22+
*InstallReleaseRequest
23+
SourceAppType SourceAppType `json:"-"`
24+
}

api/restHandler/CoreAppRestHandler.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1271,6 +1271,7 @@ func (handler CoreAppRestHandlerImpl) createDockerConfig(appId int, dockerConfig
12711271
DockerBuildOptions: dockerBuildConfig.DockerBuildOptions,
12721272
Args: dockerBuildConfig.Args,
12731273
TargetPlatform: dockerBuildConfig.TargetPlatform,
1274+
BuildContext: dockerBuildConfig.BuildContext,
12741275
},
12751276
}
12761277
}

api/restHandler/app/BuildPipelineRestHandler.go

Lines changed: 80 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,7 @@ type DevtronAppBuildMaterialRestHandler interface {
5252
CreateMaterial(w http.ResponseWriter, r *http.Request)
5353
UpdateMaterial(w http.ResponseWriter, r *http.Request)
5454
FetchMaterials(w http.ResponseWriter, r *http.Request)
55+
FetchMaterialsByMaterialId(w http.ResponseWriter, r *http.Request)
5556
RefreshMaterials(w http.ResponseWriter, r *http.Request)
5657
FetchMaterialInfo(w http.ResponseWriter, r *http.Request)
5758
FetchChanges(w http.ResponseWriter, r *http.Request)
@@ -196,7 +197,8 @@ func (handler PipelineConfigRestHandlerImpl) UpdateBranchCiPipelinesWithRegex(w
196197
common.WriteJsonResp(w, err, nil, http.StatusInternalServerError)
197198
return
198199
}
199-
resp, err := handler.ciHandler.FetchMaterialsByPipelineId(patchRequest.Id)
200+
//if include/exclude configured showAll will include excluded materials also in list, if not configured it will ignore this flag
201+
resp, err := handler.ciHandler.FetchMaterialsByPipelineId(patchRequest.Id, false)
200202
if err != nil {
201203
handler.Logger.Errorw("service err, FetchMaterials", "err", err, "pipelineId", patchRequest.Id)
202204
common.WriteJsonResp(w, err, resp, http.StatusInternalServerError)
@@ -459,6 +461,7 @@ func (handler PipelineConfigRestHandlerImpl) TriggerCiPipeline(w http.ResponseWr
459461
response["apiResponse"] = strconv.Itoa(resp)
460462
common.WriteJsonResp(w, err, response, http.StatusOK)
461463
}
464+
462465
func (handler PipelineConfigRestHandlerImpl) FetchMaterials(w http.ResponseWriter, r *http.Request) {
463466
userId, err := handler.userAuthService.GetLoggedInUser(r)
464467
if userId == 0 || err != nil {
@@ -471,6 +474,69 @@ func (handler PipelineConfigRestHandlerImpl) FetchMaterials(w http.ResponseWrite
471474
common.WriteJsonResp(w, err, nil, http.StatusBadRequest)
472475
return
473476
}
477+
v := r.URL.Query()
478+
showAll := false
479+
show := v.Get("showAll")
480+
if len(show) > 0 {
481+
showAll, err = strconv.ParseBool(show)
482+
if err != nil {
483+
showAll = true
484+
err = nil
485+
//ignore error, apply rbac by default
486+
}
487+
}
488+
handler.Logger.Infow("request payload, FetchMaterials", "pipelineId", pipelineId)
489+
ciPipeline, err := handler.ciPipelineRepository.FindById(pipelineId)
490+
if err != nil {
491+
handler.Logger.Errorw("service err, UpdateCiTemplate", "err", err, "pipelineId", pipelineId)
492+
common.WriteJsonResp(w, err, nil, http.StatusInternalServerError)
493+
return
494+
}
495+
//RBAC
496+
token := r.Header.Get("token")
497+
object := handler.enforcerUtil.GetAppRBACNameByAppId(ciPipeline.AppId)
498+
if ok := handler.enforcer.Enforce(token, casbin.ResourceApplications, casbin.ActionGet, object); !ok {
499+
common.WriteJsonResp(w, err, "Unauthorized User", http.StatusForbidden)
500+
return
501+
}
502+
//RBAC
503+
resp, err := handler.ciHandler.FetchMaterialsByPipelineId(pipelineId, showAll)
504+
if err != nil {
505+
handler.Logger.Errorw("service err, FetchMaterials", "err", err, "pipelineId", pipelineId)
506+
common.WriteJsonResp(w, err, resp, http.StatusInternalServerError)
507+
return
508+
}
509+
common.WriteJsonResp(w, err, resp, http.StatusOK)
510+
}
511+
512+
func (handler PipelineConfigRestHandlerImpl) FetchMaterialsByMaterialId(w http.ResponseWriter, r *http.Request) {
513+
userId, err := handler.userAuthService.GetLoggedInUser(r)
514+
if userId == 0 || err != nil {
515+
common.WriteJsonResp(w, err, "Unauthorized User", http.StatusUnauthorized)
516+
return
517+
}
518+
vars := mux.Vars(r)
519+
pipelineId, err := strconv.Atoi(vars["pipelineId"])
520+
if err != nil {
521+
common.WriteJsonResp(w, err, nil, http.StatusBadRequest)
522+
return
523+
}
524+
gitMaterialId, err := strconv.Atoi(vars["gitMaterialId"])
525+
if err != nil {
526+
common.WriteJsonResp(w, err, nil, http.StatusBadRequest)
527+
return
528+
}
529+
v := r.URL.Query()
530+
showAll := false
531+
show := v.Get("showAll")
532+
if len(show) > 0 {
533+
showAll, err = strconv.ParseBool(show)
534+
if err != nil {
535+
showAll = true
536+
err = nil
537+
//ignore error, apply rbac by default
538+
}
539+
}
474540
handler.Logger.Infow("request payload, FetchMaterials", "pipelineId", pipelineId)
475541
ciPipeline, err := handler.ciPipelineRepository.FindById(pipelineId)
476542
if err != nil {
@@ -486,7 +552,7 @@ func (handler PipelineConfigRestHandlerImpl) FetchMaterials(w http.ResponseWrite
486552
return
487553
}
488554
//RBAC
489-
resp, err := handler.ciHandler.FetchMaterialsByPipelineId(pipelineId)
555+
resp, err := handler.ciHandler.FetchMaterialsByPipelineIdAndGitMaterialId(pipelineId, gitMaterialId, showAll)
490556
if err != nil {
491557
handler.Logger.Errorw("service err, FetchMaterials", "err", err, "pipelineId", pipelineId)
492558
common.WriteJsonResp(w, err, resp, http.StatusInternalServerError)
@@ -1196,6 +1262,17 @@ func (handler PipelineConfigRestHandlerImpl) FetchChanges(w http.ResponseWriter,
11961262
common.WriteJsonResp(w, err, nil, http.StatusBadRequest)
11971263
return
11981264
}
1265+
showAll := false
1266+
v := r.URL.Query()
1267+
show := v.Get("showAll")
1268+
if len(show) > 0 {
1269+
showAll, err = strconv.ParseBool(show)
1270+
if err != nil {
1271+
showAll = true
1272+
err = nil
1273+
//ignore error, apply rbac by default
1274+
}
1275+
}
11991276
handler.Logger.Infow("request payload, FetchChanges", "ciMaterialId", ciMaterialId, "pipelineId", pipelineId)
12001277
ciPipeline, err := handler.ciPipelineRepository.FindById(pipelineId)
12011278
if err != nil {
@@ -1214,6 +1291,7 @@ func (handler PipelineConfigRestHandlerImpl) FetchChanges(w http.ResponseWriter,
12141291

12151292
changeRequest := &gitSensor.FetchScmChangesRequest{
12161293
PipelineMaterialId: ciMaterialId,
1294+
ShowAll: showAll,
12171295
}
12181296
changes, err := handler.gitSensorClient.FetchChanges(context.Background(), changeRequest)
12191297
if err != nil {

0 commit comments

Comments
 (0)