Skip to content

Commit

Permalink
refectoring: simplify code (#4580)
Browse files Browse the repository at this point in the history
- some conditional expressions have been simplified.

Signed-off-by: Youngjun <yj.yoo@okestro.com>
Co-authored-by: Namkyu Park <53862866+namkyu1999@users.noreply.github.com>
  • Loading branch information
yj-yoo and namkyu1999 authored May 9, 2024
1 parent f10f5a6 commit 99ea826
Show file tree
Hide file tree
Showing 4 changed files with 9 additions and 11 deletions.
2 changes: 1 addition & 1 deletion chaoscenter/authentication/pkg/project/repository.go
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@ func (r repository) GetProjectsByUserID(userID string, isOwner bool) ([]*entitie
var projects []*entities.Project
query := bson.D{}

if isOwner == true {
if isOwner {
query = bson.D{
{"members", bson.D{
{"$elemMatch", bson.D{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,10 +31,8 @@ func (r repository) IsTokenRevoked(encodedToken string) bool {
err := r.Collection.FindOne(context.TODO(), bson.M{
"token": encodedToken,
}).Decode(&result)
if err != nil {
return false
}
return true

return err == nil
}

// NewRevokedTokenRepo creates a new instance of this repository
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -115,11 +115,11 @@ func ManifestParser(infra dbChaosInfra.ChaosInfra, rootPath string, config *Subs
)

// Checking if the agent namespace does not exist and its scope of installation is not namespaced
if *infra.InfraNsExists == false && infra.InfraScope != "namespace" {
if !*infra.InfraNsExists && infra.InfraScope != "namespace" {
generatedYAML = append(generatedYAML, fmt.Sprintf(namespaceConfig))
}

if *infra.InfraSaExists == false {
if !*infra.InfraSaExists {
generatedYAML = append(generatedYAML, fmt.Sprintf(serviceAccountStr))
}

Expand Down Expand Up @@ -202,7 +202,7 @@ func ManifestParser(infra dbChaosInfra.ChaosInfra, rootPath string, config *Subs
newContent = strings.Replace(newContent, "#{CUSTOM_TLS_CERT}", config.TLSCert, -1)

newContent = strings.Replace(newContent, "#{START_TIME}", "\""+infra.StartTime+"\"", -1)
if infra.IsInfraConfirmed == true {
if infra.IsInfraConfirmed {
newContent = strings.Replace(newContent, "#{IS_INFRA_CONFIRMED}", "\""+"true"+"\"", -1)
} else {
newContent = strings.Replace(newContent, "#{IS_INFRA_CONFIRMED}", "\""+"false"+"\"", -1)
Expand Down
6 changes: 3 additions & 3 deletions chaoscenter/graphql/server/pkg/chaoshub/service.go
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ func NewService(chaosHubOperator *dbSchemaChaosHub.Operator) Service {
func (c *chaosHubService) AddChaosHub(ctx context.Context, chaosHub model.CreateChaosHubRequest, projectID string) (*model.ChaosHub, error) {
if IsExist, err := c.IsChaosHubAvailable(ctx, chaosHub.Name, projectID); err != nil {
return nil, err
} else if IsExist == true {
} else if IsExist {
return nil, errors.New("Name Already exists")
}
currentTime := time.Now()
Expand Down Expand Up @@ -136,7 +136,7 @@ func (c *chaosHubService) AddRemoteChaosHub(ctx context.Context, chaosHub model.
if err != nil {
return nil, err
}
if IsExist == true {
if IsExist {
return nil, errors.New("Name Already exists")
}
description := ""
Expand Down Expand Up @@ -205,7 +205,7 @@ func (c *chaosHubService) SaveChaosHub(ctx context.Context, chaosHub model.Creat
if err != nil {
return nil, err
}
if IsExist == true {
if IsExist {
return nil, errors.New("Name Already exists")
}

Expand Down

0 comments on commit 99ea826

Please sign in to comment.