Skip to content

Commit 9a52a06

Browse files
Merge pull request #5837 from devtron-labs/config-diff-3-oss
feat: Config diff 3 oss
2 parents 73ad83e + 0078d80 commit 9a52a06

23 files changed

+1279
-96
lines changed

api/restHandler/DeploymentConfigurationRestHandler.go

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,20 @@
11
package restHandler
22

33
import (
4+
"context"
45
"fmt"
56
"github.com/devtron-labs/devtron/api/restHandler/common"
67
"github.com/devtron-labs/devtron/pkg/auth/authorisation/casbin"
78
"github.com/devtron-labs/devtron/pkg/auth/user"
89
"github.com/devtron-labs/devtron/pkg/configDiff"
910
"github.com/devtron-labs/devtron/pkg/configDiff/bean"
11+
util2 "github.com/devtron-labs/devtron/util"
1012
"github.com/devtron-labs/devtron/util/rbac"
1113
"github.com/gorilla/schema"
1214
"go.uber.org/zap"
1315
"gopkg.in/go-playground/validator.v9"
1416
"net/http"
17+
"time"
1518
)
1619

1720
type DeploymentConfigurationRestHandler interface {
@@ -88,6 +91,7 @@ func (handler *DeploymentConfigurationRestHandlerImpl) GetConfigData(w http.Resp
8891
return
8992
}
9093

94+
configDataQueryParams.UserId = userId
9195
//RBAC START
9296
token := r.Header.Get(common.TokenHeaderKey)
9397
object := handler.enforcerUtil.GetAppRBACName(configDataQueryParams.AppName)
@@ -97,8 +101,12 @@ func (handler *DeploymentConfigurationRestHandlerImpl) GetConfigData(w http.Resp
97101
return
98102
}
99103
//RBAC END
100-
101-
res, err := handler.deploymentConfigurationService.GetAllConfigData(r.Context(), configDataQueryParams)
104+
isSuperAdmin := handler.enforcer.Enforce(token, casbin.ResourceGlobal, casbin.ActionGet, "*")
105+
userHasAdminAccess := handler.enforcer.Enforce(token, casbin.ResourceApplications, casbin.ActionUpdate, object)
106+
ctx, cancel := context.WithTimeout(r.Context(), 60*time.Second)
107+
defer cancel()
108+
ctx = util2.SetSuperAdminInContext(ctx, isSuperAdmin)
109+
res, err := handler.deploymentConfigurationService.GetAllConfigData(ctx, configDataQueryParams, userHasAdminAccess)
102110
if err != nil {
103111
handler.logger.Errorw("service err, GetAllConfigData ", "err", err)
104112
common.WriteJsonResp(w, err, nil, http.StatusInternalServerError)

internal/sql/repository/DeploymentTemplateRepository.go

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,7 @@ type DeploymentTemplateComparisonMetadata struct {
3838
EnvironmentId int `json:"environmentId,omitempty"`
3939
EnvironmentName string `json:"environmentName,omitempty"`
4040
DeploymentTemplateHistoryId int `json:"deploymentTemplateHistoryId,omitempty"`
41+
WfrId int `json:"wfrId,omitempty"`
4142
StartedOn *time.Time `json:"startedOn,omitempty"`
4243
FinishedOn *time.Time `json:"finishedOn,omitempty"`
4344
Status string `json:"status,omitempty"`
@@ -69,7 +70,7 @@ func (impl DeploymentTemplateRepositoryImpl) FetchDeploymentHistoryWithChartRefs
6970
limit := 15
7071

7172
query := "select p.id as pipeline_id, dth.id as deployment_template_history_id," +
72-
" wfr.finished_on, wfr.status, c.chart_ref_id, c.chart_version FROM cd_workflow_runner wfr" +
73+
" wfr.id as wfr_id, wfr.finished_on, wfr.status, c.chart_ref_id, c.chart_version FROM cd_workflow_runner wfr" +
7374
" JOIN cd_workflow wf ON wf.id = wfr.cd_workflow_id JOIN pipeline p ON p.id = wf.pipeline_id" +
7475
" JOIN deployment_template_history dth ON dth.deployed_on = wfr.started_on " +
7576
"JOIN pipeline_config_override pco ON pco.cd_workflow_id = wf.id " +

pkg/bean/configSecretData.go

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,8 @@ type SecretList struct {
3030
ConfigData []*ConfigData `json:"secrets"`
3131
}
3232

33+
// there is an adapter written in pkg/bean folder to convert below ConfigData struct to pipeline/bean's ConfigData
34+
3335
// TODO refactoring: duplicate struct of ConfigData in ConfigMapBean.go
3436
type ConfigData struct {
3537
Name string `json:"name"`
@@ -49,6 +51,7 @@ type ConfigData struct {
4951
SubPath bool `json:"subPath"`
5052
ESOSubPath []string `json:"esoSubPath"`
5153
FilePermission string `json:"filePermission"`
54+
Overridden bool `json:"overridden"`
5255
}
5356

5457
func (c *ConfigData) IsESOExternalSecretType() bool {

pkg/cluster/repository/EnvironmentRepository.go

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -80,6 +80,7 @@ type EnvironmentRepository interface {
8080
FindAllActiveWithFilter() ([]*Environment, error)
8181
FindEnvClusterInfosByIds([]int) ([]*EnvCluserInfo, error)
8282
FindEnvLinkedWithCiPipelines(externalCi bool, ciPipelineIds []int) ([]*Environment, error)
83+
FindEnvByNameWithClusterDetails(envName string) (*Environment, error)
8384
}
8485

8586
func NewEnvironmentRepositoryImpl(dbConnection *pg.DB, logger *zap.SugaredLogger, appStatusRepository appStatus.AppStatusRepository) *EnvironmentRepositoryImpl {
@@ -160,6 +161,17 @@ func (repositoryImpl EnvironmentRepositoryImpl) FindByName(name string) (*Enviro
160161
return environment, err
161162
}
162163

164+
func (repositoryImpl EnvironmentRepositoryImpl) FindEnvByNameWithClusterDetails(envName string) (*Environment, error) {
165+
environment := &Environment{}
166+
err := repositoryImpl.dbConnection.
167+
Model(environment).
168+
Column("environment.*", "Cluster").
169+
Where("environment.environment_name = ?", envName).
170+
Where("environment.active = ?", true).
171+
Select()
172+
return environment, err
173+
}
174+
163175
func (repositoryImpl EnvironmentRepositoryImpl) FindIdByName(name string) (int, error) {
164176
environment := &Environment{}
165177
err := repositoryImpl.dbConnection.

0 commit comments

Comments
 (0)