Skip to content
Draft
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
45 changes: 45 additions & 0 deletions api/helm-app/HelmAppRestHandler.go
Original file line number Diff line number Diff line change
Expand Up @@ -231,6 +231,13 @@ func (handler *HelmAppRestHandlerImpl) handleFluxApplicationHibernate(r *http.Re
return nil, err
}

// Validate confirmation name if provided
if hibernateRequest.ConfirmationName != nil {
if *hibernateRequest.ConfirmationName != appIdentifier.AppName {
return nil, errors.New("confirmation name does not match application name")
}
}

if !handler.enforcer.Enforce(token, casbin.ResourceGlobal, casbin.ActionUpdate, "*") {
return nil, errors.New("unauthorized")
}
Expand All @@ -243,6 +250,13 @@ func (handler *HelmAppRestHandlerImpl) handleArgoApplicationHibernate(r *http.Re
return nil, err
}

// Validate confirmation name if provided
if hibernateRequest.ConfirmationName != nil {
if *hibernateRequest.ConfirmationName != appIdentifier.AppName {
return nil, errors.New("confirmation name does not match application name")
}
}

if !handler.enforcer.Enforce(token, casbin.ResourceGlobal, casbin.ActionUpdate, "*") {
return nil, errors.New("unauthorized")
}
Expand All @@ -255,6 +269,14 @@ func (handler *HelmAppRestHandlerImpl) handleHelmApplicationHibernate(r *http.Re
if err != nil {
return nil, err
}

// Validate confirmation name if provided
if hibernateRequest.ConfirmationName != nil {
if *hibernateRequest.ConfirmationName != appIdentifier.ReleaseName {
return nil, errors.New("confirmation name does not match application name")
}
}

rbacObject, rbacObject2 := handler.enforcerUtil.GetHelmObjectByClusterIdNamespaceAndAppName(
appIdentifier.ClusterId,
appIdentifier.Namespace,
Expand Down Expand Up @@ -317,6 +339,14 @@ func (handler *HelmAppRestHandlerImpl) handleFluxApplicationUnHibernate(r *http.
if err != nil {
return nil, err
}

// Validate confirmation name if provided
if hibernateRequest.ConfirmationName != nil {
if *hibernateRequest.ConfirmationName != appIdentifier.AppName {
return nil, errors.New("confirmation name does not match application name")
}
}

if !handler.enforcer.Enforce(token, casbin.ResourceGlobal, casbin.ActionUpdate, "*") {
return nil, errors.New("unauthorized")
}
Expand All @@ -327,6 +357,14 @@ func (handler *HelmAppRestHandlerImpl) handleArgoApplicationUnHibernate(r *http.
if err != nil {
return nil, err
}

// Validate confirmation name if provided
if hibernateRequest.ConfirmationName != nil {
if *hibernateRequest.ConfirmationName != appIdentifier.AppName {
return nil, errors.New("confirmation name does not match application name")
}
}

if !handler.enforcer.Enforce(token, casbin.ResourceGlobal, casbin.ActionUpdate, "*") {
return nil, errors.New("unauthorized")
}
Expand All @@ -339,6 +377,13 @@ func (handler *HelmAppRestHandlerImpl) handleHelmApplicationUnHibernate(r *http.
return nil, err
}

// Validate confirmation name if provided
if hibernateRequest.ConfirmationName != nil {
if *hibernateRequest.ConfirmationName != appIdentifier.ReleaseName {
return nil, errors.New("confirmation name does not match application name")
}
}

rbacObject, rbacObject2 := handler.enforcerUtil.GetHelmObjectByClusterIdNamespaceAndAppName(
appIdentifier.ClusterId,
appIdentifier.Namespace,
Expand Down
37 changes: 37 additions & 0 deletions api/helm-app/openapiClient/model_hibernate_request.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 2 additions & 0 deletions pkg/bulkAction/bean/bean.go
Original file line number Diff line number Diff line change
Expand Up @@ -106,6 +106,8 @@ type BulkApplicationForEnvironmentPayload struct {
AppNamesExcludes []string `json:"appNamesExcludes,omitempty"`
UserId int32 `json:"-"`
InvalidateCache bool `json:"invalidateCache"`
// confirmation name - should match environment name for additional confirmation
ConfirmationName *string `json:"confirmationName,omitempty"`
}

type BulkApplicationForEnvironmentResponse struct {
Expand Down
40 changes: 40 additions & 0 deletions pkg/bulkAction/service/BulkUpdateService.go
Original file line number Diff line number Diff line change
Expand Up @@ -1108,6 +1108,26 @@ type stopAppFunc func(ctx context.Context, req *bean5.StopAppRequest, userMetada

// bulkHibernateCommon contains the common bulk-hibernate logic.
func (impl BulkUpdateServiceImpl) bulkHibernateCommon(request *bean4.BulkApplicationForEnvironmentPayload, ctx context.Context, token string, checkAuthForBulkActions func(token, appObject, envObject string) bool, stopApp stopAppFunc, userMetadata *bean6.UserMetadata) (*bean4.BulkApplicationHibernateUnhibernateForEnvironmentResponse, error) {
// Validate confirmation name if provided
if request.ConfirmationName != nil {
var envName string
if len(request.EnvName) > 0 {
envName = request.EnvName
} else if request.EnvId != 0 {
// Fetch environment name by ID
env, err := impl.environmentRepository.FindById(request.EnvId)
if err != nil {
impl.logger.Errorw("error in fetching environment by id", "envId", request.EnvId, "err", err)
return nil, fmt.Errorf("error fetching environment details: %v", err)
}
envName = env.Name
}

if envName != "" && *request.ConfirmationName != envName {
return nil, fmt.Errorf("confirmation name does not match environment name")
}
}

// Fetch pipelines based on filters.
var pipelines []*pipelineConfig.Pipeline
var err error
Expand Down Expand Up @@ -1279,6 +1299,26 @@ func (impl BulkUpdateServiceImpl) buildHibernateUnHibernateRequestForHelmPipelin

func (impl BulkUpdateServiceImpl) BulkUnHibernate(ctx context.Context, request *bean4.BulkApplicationForEnvironmentPayload, checkAuthForBulkActions func(token string, appObject string, envObject string) bool,
userMetadata *bean6.UserMetadata) (*bean4.BulkApplicationHibernateUnhibernateForEnvironmentResponse, error) {
// Validate confirmation name if provided
if request.ConfirmationName != nil {
var envName string
if len(request.EnvName) > 0 {
envName = request.EnvName
} else if request.EnvId != 0 {
// Fetch environment name by ID
env, err := impl.environmentRepository.FindById(request.EnvId)
if err != nil {
impl.logger.Errorw("error in fetching environment by id", "envId", request.EnvId, "err", err)
return nil, fmt.Errorf("error fetching environment details: %v", err)
}
envName = env.Name
}

if envName != "" && *request.ConfirmationName != envName {
return nil, fmt.Errorf("confirmation name does not match environment name")
}
}

var pipelines []*pipelineConfig.Pipeline
var err error
if len(request.AppIdIncludes) > 0 {
Expand Down
Loading