in tools/mconnect/commands/groups/groups.go [82:127]
func (gc *mcGroupCreator) create(ctx context.Context, groups []string, ignoreExist bool) error {
var errors []string
label := map[string]string{LabelKey: labelValue}
for _, group := range groups {
// Prepare group details -
groupDetails := &migrationcenterpb.Group{
Name: group,
DisplayName: group,
Description: fmt.Sprintf("%v application group. Created using mconnect.", group),
Labels: label,
}
// Migration Center groups need to be lower and without spaces.
groupID, diff := format(group)
if diff {
fmt.Printf("Spaces or underscores were found for application '%v', groupID '%v' will be used.\n", group, groupID)
}
req := &migrationcenterpb.CreateGroupRequest{Parent: gc.pal.Path(), GroupId: groupID, Group: groupDetails}
op, err := gc.client.CreateGroup(ctx, req)
if err != nil {
if alreadyExist(err) {
if !ignoreExist {
errors = append(errors, fmt.Sprintf("Group %q already exists, use the --ignore-existing-groups flag if you would like to update it with the MConnect label.", group))
} else if err := gc.updateLabel(ctx, groupID); err != nil {
return err
}
continue
}
errors = append(errors, fmt.Sprintf("Group: %q, err: %v", group, err))
continue
}
_, err = op.Wait(ctx)
if err != nil {
errors = append(errors, fmt.Sprintf("Group: %q, err: %v", group, err))
}
fmt.Println(messages.GroupCreated{Group: groupID})
}
if errors != nil {
return fmt.Errorf("%s", formatMultipleErrors(errors))
}
return nil
}