Skip to content

Commit

Permalink
SAP Application association Issue - Workaround
Browse files Browse the repository at this point in the history
  • Loading branch information
OrShamirCM committed Apr 25, 2024
1 parent e446185 commit 40c9112
Show file tree
Hide file tree
Showing 4 changed files with 45 additions and 19 deletions.
1 change: 1 addition & 0 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -85,6 +85,7 @@ golang.org/x/crypto v0.22.0 h1:g1v0xeRhjcugydODzvb3mEM9SQ0HGp9s/nh3COQ/C30=
golang.org/x/crypto v0.22.0/go.mod h1:vr6Su+7cTlO45qkww3VDJlzDn0ctJvRgYbC2NvXHt+M=
golang.org/x/exp v0.0.0-20230905200255-921286631fa9 h1:GoHiUyI/Tp2nVkLI2mCxVkOjsbSXD66ic0XW0js0R9g=
golang.org/x/exp v0.0.0-20230905200255-921286631fa9/go.mod h1:S2oDrQGGwySpoQPVqRShND87VCbxmc6bL1Yd2oYrm6k=
golang.org/x/net v0.23.0/go.mod h1:JKghWKKOSdJwpW2GEx0Ja7fmaKnMsbu+MWVZTokSYmg=
golang.org/x/sys v0.19.0 h1:q5f1RH2jigJ1MoAWp2KTp3gm5zAGFUTarQZ5U386+4o=
golang.org/x/sys v0.19.0/go.mod h1:/VUhepiaJMQUp4+oa/7Zr1D23ma6VTLIYjOOTFZPUcA=
golang.org/x/text v0.14.0 h1:ScX5w1eTa3QqT8oi6+ziP7dTV1S2+ALU0bI+0zXKWiQ=
Expand Down
2 changes: 1 addition & 1 deletion internal/commands/groups.go
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,7 @@ func getGroupIds(groups []*wrappers.Group) []string {
return groupIds
}

func assignGroupsToProject(projectID string, projectName string, groups []*wrappers.Group,
func assignGroupsToProjectNewAccessManagement(projectID string, projectName string, groups []*wrappers.Group,
accessManagement wrappers.AccessManagementWrapper) error {
if !wrappers.FeatureFlags[accessManagementEnabled] {
return nil
Expand Down
2 changes: 1 addition & 1 deletion internal/commands/project.go
Original file line number Diff line number Diff line change
Expand Up @@ -291,7 +291,7 @@ func runCreateProjectCommand(
return errors.Wrapf(err, "%s", failedCreatingProj)
}
}
err = assignGroupsToProject(projResponseModel.ID, projResponseModel.Name, groups, accessManagementWrapper)
err = assignGroupsToProjectNewAccessManagement(projResponseModel.ID, projResponseModel.Name, groups, accessManagementWrapper)
if err != nil {
return err
}
Expand Down
59 changes: 42 additions & 17 deletions internal/commands/scan.go
Original file line number Diff line number Diff line change
Expand Up @@ -634,13 +634,16 @@ func createProject(
projectGroups, _ := cmd.Flags().GetString(commonParams.ProjectGroupList)
projectTags, _ := cmd.Flags().GetString(commonParams.ProjectTagList)
projectPrivatePackage, _ := cmd.Flags().GetString(commonParams.ProjecPrivatePackageFlag)
groupsMap, err := createGroupsMap(projectGroups, groupsWrapper)
if err != nil {
return "", err
}

var projModel = wrappers.Project{}
projModel.Name = projectName
projModel.Groups = getGroupsForRequest(groupsMap)
/* 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 @@ -654,7 +657,18 @@ func createProject(
}
if err == nil {
projectID = resp.ID
err = assignGroupsToProject(projectID, projectName, groupsMap, accessManagementWrapper)
if applicationID != nil {
//todo: replace with a pooling mechanize that check if the application associated with application(only when assign application)
time.Sleep(35 * time.Second)
groupsMap, err := createGroupsMap(projectGroups, groupsWrapper)
if err != nil {
return projectID, err
}
err = assignGroupsToProjectNewAccessManagement(projectID, projectName, groupsMap, accessManagementWrapper)
if err != nil {
return projectID, err
}
}
}
return projectID, err
}
Expand Down Expand Up @@ -703,18 +717,16 @@ func updateProject(
projModel.Groups = projModelResp.Groups
projModel.Tags = projModelResp.Tags
projModel.ApplicationIds = projModelResp.ApplicationIds
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)
err = assignGroupsToProject(projectID, projectName, groupsMap, accessManagementWrapper)
if err != nil {
return "", err
/* 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 @@ -727,6 +739,19 @@ func updateProject(
if err != nil {
return "", errors.Errorf("%s: %v", failedUpdatingProj, err)
}

time.Sleep(35 * time.Second)

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
}
}
return projectID, nil
}

Expand Down

0 comments on commit 40c9112

Please sign in to comment.