Skip to content

Commit

Permalink
Merge pull request #932 from Checkmarx/feature/MiryamFoifer/ProjectCr…
Browse files Browse the repository at this point in the history
…eationWithGroups

Project Creation Flow With AM Phase-2 (AST-72966)
  • Loading branch information
miryamfoiferCX authored Nov 14, 2024
2 parents e6d08e0 + 3e38269 commit be94344
Show file tree
Hide file tree
Showing 5 changed files with 15 additions and 50 deletions.
17 changes: 8 additions & 9 deletions internal/commands/groups.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,25 +3,24 @@ package commands
import (
"encoding/json"

featureFlagsConstants "github.com/checkmarx/ast-cli/internal/constants/feature-flags"
commonParams "github.com/checkmarx/ast-cli/internal/params"
"github.com/checkmarx/ast-cli/internal/services"
"github.com/checkmarx/ast-cli/internal/wrappers"
"github.com/spf13/cobra"
)

func updateGroupValues(input *[]byte, cmd *cobra.Command, groupsWrapper wrappers.GroupsWrapper, featureFlagsWrapper wrappers.FeatureFlagsWrapper) ([]*wrappers.Group, error) {
func updateGroupValues(input *[]byte, cmd *cobra.Command, groupsWrapper wrappers.GroupsWrapper) ([]*wrappers.Group, error) {
groupListStr, _ := cmd.Flags().GetString(commonParams.GroupList)
groups, err := services.CreateGroupsMap(groupListStr, groupsWrapper)
if err != nil {
return groups, err
}
flagResponse, _ := wrappers.GetSpecificFeatureFlag(featureFlagsWrapper, featureFlagsConstants.AccessManagementEnabled)
if !flagResponse.Status {
var info map[string]interface{}
_ = json.Unmarshal(*input, &info)
info["groups"] = services.GetGroupIds(groups)
*input, _ = json.Marshal(info)
}

// we're not checking here status of the feature flag, because of refactoring in AM
var info map[string]interface{}
_ = json.Unmarshal(*input, &info)
info["groups"] = services.GetGroupIds(groups)
*input, _ = json.Marshal(info)

return groups, nil
}
2 changes: 1 addition & 1 deletion internal/commands/project.go
Original file line number Diff line number Diff line change
Expand Up @@ -248,7 +248,7 @@ func runCreateProjectCommand(
if err != nil {
return err
}
groups, err := updateGroupValues(&input, cmd, groupsWrapper, featureFlagsWrapper)
groups, err := updateGroupValues(&input, cmd, groupsWrapper)
if err != nil {
return err
}
Expand Down
17 changes: 5 additions & 12 deletions internal/services/groups.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,15 +8,16 @@ import (
"github.com/pkg/errors"
)

func GetGroupMap(groupsWrapper wrappers.GroupsWrapper, projectGroups string, projModelResp *wrappers.ProjectResponseModel,
featureFlagsWrapper wrappers.FeatureFlagsWrapper) ([]*wrappers.Group, []string, error) {
func GetGroupMap(groupsWrapper wrappers.GroupsWrapper, projectGroups string, projModelResp *wrappers.ProjectResponseModel) ([]*wrappers.Group, []string, error) {
groupsMap, groupErr := CreateGroupsMap(projectGroups, groupsWrapper)
if groupErr != nil {
return nil, nil, errors.Errorf("%s: %v", failedUpdatingProj, groupErr)
}
groups := getGroupsForRequest(groupsMap, featureFlagsWrapper)
// we're not checking here status of the feature flag, because of refactoring in AM
groups := GetGroupIds(groupsMap)
if projModelResp != nil {
groups = append(getGroupsForRequest(groupsMap, featureFlagsWrapper), projModelResp.Groups...)
// we're not checking here status of the feature flag, because of refactoring in AM
groups = append(GetGroupIds(groupsMap), projModelResp.Groups...)
return groupsMap, groups, nil
}
return groupsMap, groups, nil
Expand Down Expand Up @@ -47,14 +48,6 @@ func CreateGroupsMap(groupsStr string, groupsWrapper wrappers.GroupsWrapper) ([]
return groupsMap, nil
}

func getGroupsForRequest(groups []*wrappers.Group, featureFlagsWrapper wrappers.FeatureFlagsWrapper) []string {
flagResponse, _ := wrappers.GetSpecificFeatureFlag(featureFlagsWrapper, featureFlagsConstants.AccessManagementEnabled)
if !flagResponse.Status {
return GetGroupIds(groups)
}
return nil
}

func AssignGroupsToProjectNewAccessManagement(projectID string, projectName string, groups []*wrappers.Group,
accessManagement wrappers.AccessManagementWrapper, featureFlagsWrapper wrappers.FeatureFlagsWrapper) error {
flagResponse, _ := wrappers.GetSpecificFeatureFlag(featureFlagsWrapper, featureFlagsConstants.AccessManagementEnabled)
Expand Down
27 changes: 0 additions & 27 deletions internal/services/groups_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -173,33 +173,6 @@ func Test_findGroupByName(t *testing.T) {
}
}

func Test_getGroupsForRequest(t *testing.T) {
setup() // Clear the map before starting this test
type args struct {
groups []*wrappers.Group
}
tests := []struct {
name string
args args
want []string
}{
{
name: "When access management is disabled, return group IDs of the groups",
args: args{groups: []*wrappers.Group{{ID: "group-id-1", Name: "group-name-1"}, {ID: "group-id-2", Name: "group-name-2"}}},
want: []string{"group-id-1", "group-id-2"},
},
}
for _, tt := range tests {
ttt := tt
t.Run(tt.name, func(t *testing.T) {
mock.Flag = wrappers.FeatureFlagResponseModel{Name: featureFlagsConstants.AccessManagementEnabled, Status: false}
if got := getGroupsForRequest(ttt.args.groups, &mock.FeatureFlagsMockWrapper{}); !reflect.DeepEqual(got, ttt.want) {
t.Errorf("getGroupsForRequest() = %v, want %v", got, ttt.want)
}
})
}
}

func Test_getGroupsToAssign(t *testing.T) {
type args struct {
receivedGroups []*wrappers.Group
Expand Down
2 changes: 1 addition & 1 deletion internal/services/projects.go
Original file line number Diff line number Diff line change
Expand Up @@ -110,7 +110,7 @@ func createProject(
if projectGroups != "" {
var groups []string
var groupErr error
groupsMap, groups, groupErr = GetGroupMap(groupsWrapper, projectGroups, nil, featureFlagsWrapper)
groupsMap, groups, groupErr = GetGroupMap(groupsWrapper, projectGroups, nil)
if groupErr != nil {
return "", groupErr
}
Expand Down

0 comments on commit be94344

Please sign in to comment.