From 40c91126e54657cae7b12369e5450457858deeab Mon Sep 17 00:00:00 2001 From: OrShamirCM Date: Thu, 25 Apr 2024 11:13:45 +0300 Subject: [PATCH] SAP Application association Issue - Workaround --- go.sum | 1 + internal/commands/groups.go | 2 +- internal/commands/project.go | 2 +- internal/commands/scan.go | 59 +++++++++++++++++++++++++----------- 4 files changed, 45 insertions(+), 19 deletions(-) diff --git a/go.sum b/go.sum index ff06ec542..a13052d1f 100644 --- a/go.sum +++ b/go.sum @@ -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= diff --git a/internal/commands/groups.go b/internal/commands/groups.go index 67dfd24c0..74d82ccfb 100644 --- a/internal/commands/groups.go +++ b/internal/commands/groups.go @@ -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 diff --git a/internal/commands/project.go b/internal/commands/project.go index d95638499..2d222cdbb 100644 --- a/internal/commands/project.go +++ b/internal/commands/project.go @@ -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 } diff --git a/internal/commands/scan.go b/internal/commands/scan.go index 464549c49..c0f1ddb30 100644 --- a/internal/commands/scan.go +++ b/internal/commands/scan.go @@ -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 != "" { @@ -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 } @@ -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) @@ -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 }