Skip to content

Commit

Permalink
Change Group Logic
Browse files Browse the repository at this point in the history
  • Loading branch information
OrShamirCM committed Apr 25, 2024
1 parent 91c09f0 commit 9275a2c
Showing 1 changed file with 38 additions and 26 deletions.
64 changes: 38 additions & 26 deletions internal/commands/scan.go
Original file line number Diff line number Diff line change
Expand Up @@ -637,13 +637,6 @@ func createProject(

var projModel = wrappers.Project{}
projModel.Name = projectName
/* if !wrappers.FeatureFlags[accessManagementEnabled] {
groupsMap, err := createGroupsMap(projectGroups, groupsWrapper)
if err != nil {
return "", err
}
projModel.Groups = getGroupsForRequest(groupsMap)
}*/
projModel.ApplicationIds = applicationID

if projectPrivatePackage != "" {
Expand All @@ -657,16 +650,30 @@ func createProject(
}
if err == nil {
projectID = resp.ID
if applicationID != nil {
//todo: replace with a pooling mechanize that check if the application associated with application(only when assign application)

//todo: replace with a pooling mechanize that check if the application associated with application(only when assign application)
if applicationID != nil && len(applicationID) > 0 {

Check failure on line 655 in internal/commands/scan.go

View workflow job for this annotation

GitHub Actions / lint

S1009: should omit nil check; len() for []string is defined as zero (gosimple)
time.Sleep(35 * time.Second)

Check failure on line 656 in internal/commands/scan.go

View workflow job for this annotation

GitHub Actions / lint

mnd: Magic number: 35, in <argument> detected (gomnd)
logger.PrintIfVerbose("slept 35")
}

if projectGroups != "" {
groupsMap, err := createGroupsMap(projectGroups, groupsWrapper)

Check failure on line 661 in internal/commands/scan.go

View workflow job for this annotation

GitHub Actions / lint

shadow: declaration of "err" shadows declaration at line 646 (govet)
if err != nil {
return projectID, err
}
err = assignGroupsToProjectNewAccessManagement(projectID, projectName, groupsMap, accessManagementWrapper)
if err != nil {
return projectID, err
if !wrappers.FeatureFlags[accessManagementEnabled] {
projModel.Groups = getGroupsForRequest(groupsMap)
logger.PrintIfVerbose("Updating project groups")
err = projectsWrapper.Update(projectID, &projModel)
if err != nil {
return "", errors.Errorf("%s: %v", failedUpdatingProj, err)
}
} else {
err = assignGroupsToProjectNewAccessManagement(projectID, projectName, groupsMap, accessManagementWrapper)
if err != nil {
return projectID, err
}
}
}
}
Expand Down Expand Up @@ -717,16 +724,7 @@ func updateProject(
projModel.Groups = projModelResp.Groups
projModel.Tags = projModelResp.Tags
projModel.ApplicationIds = projModelResp.ApplicationIds
/* if !wrappers.FeatureFlags[accessManagementEnabled] {
if projectGroups != "" {
groupsMap, groupErr := createGroupsMap(projectGroups, groupsWrapper)
if groupErr != nil {
return "", errors.Errorf("%s: %v", failedUpdatingProj, groupErr)
}
logger.PrintIfVerbose("Updating project groups")
projModel.Groups = getGroupsForRequest(groupsMap)
}
}*/

if projectTags != "" {
logger.PrintIfVerbose("Updating project tags")
projModel.Tags = createTagMap(projectTags)
Expand All @@ -740,16 +738,30 @@ func updateProject(
return "", errors.Errorf("%s: %v", failedUpdatingProj, err)
}

time.Sleep(35 * time.Second)
if applicationID != nil && len(applicationID) > 0 {

Check failure on line 741 in internal/commands/scan.go

View workflow job for this annotation

GitHub Actions / lint

S1009: should omit nil check; len() for []string is defined as zero (gosimple)
//todo: replace with a pooling mechanize that check if the application associated with application(only when assign application)
time.Sleep(35 * time.Second)

Check failure on line 743 in internal/commands/scan.go

View workflow job for this annotation

GitHub Actions / lint

mnd: Magic number: 35, in <argument> detected (gomnd)
logger.PrintIfVerbose("slept 35")
}

if projectGroups != "" {
groupsMap, groupErr := createGroupsMap(projectGroups, groupsWrapper)
if groupErr != nil {
return "", errors.Errorf("%s: %v", failedUpdatingProj, groupErr)
}
err = assignGroupsToProjectNewAccessManagement(projectID, projectName, groupsMap, accessManagementWrapper)
if err != nil {
return "", err
groups := append(getGroupsForRequest(groupsMap), projModelResp.Groups...)
if !wrappers.FeatureFlags[accessManagementEnabled] {
projModel.Groups = groups
logger.PrintIfVerbose("Updating project groups")
err = projectsWrapper.Update(projectID, &projModel)
if err != nil {
return "", errors.Errorf("%s: %v", failedUpdatingProj, err)
}
} else {
err = assignGroupsToProjectNewAccessManagement(projectID, projectName, groupsMap, accessManagementWrapper)
if err != nil {
return projectID, err
}
}
}
return projectID, nil
Expand Down

0 comments on commit 9275a2c

Please sign in to comment.