Skip to content

Commit 036fe37

Browse files
authored
Merge pull request #100 from SivanShl/reuse_group_name
Reuse group name added command line argument that SmartConnector should use reuse the group by name instead of creating a new group. --reuse-group-name', default="false"
2 parents 2e4d172 + 4d08fa0 commit 036fe37

File tree

8 files changed

+55
-137
lines changed

8 files changed

+55
-137
lines changed

CheckPointObjects/RuleBaseOptimizer.cs

Lines changed: 6 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -15,13 +15,12 @@ You may obtain a copy of the License at
1515
limitations under the License.
1616
********************************************************************/
1717

18-
using System;
1918
using System.Collections.Generic;
2019
using System.Linq;
2120
using System.Text;
2221
using System.Text.RegularExpressions;
2322
using CommonUtils;
24-
23+
2524
namespace CheckPointObjects
2625
{
2726
/// <summary>
@@ -35,13 +34,9 @@ namespace CheckPointObjects
3534
/// 5.1. both the source and destination columns match
3635
/// 5.2. both the source and service columns match
3736
/// 5.3. both the destination and service columns match
38-
/// for CiscoASA and FirePower vendors there is an option to optimize by comments -
39-
/// two rules can be merged if they have the same comments and in addition they up to the above criteria.
4037
/// </summary>
4138
public static class RuleBaseOptimizer
4239
{
43-
44-
public static bool IsOptimizeByComments = false;
4540
public static CheckPoint_Layer Optimize(CheckPoint_Layer originalLayer, string newName)
4641
{
4742
CheckPoint_Layer curLayer = originalLayer;
@@ -72,7 +67,7 @@ public static CheckPoint_Layer Optimize(CheckPoint_Layer originalLayer, string n
7267

7368
return newLayer;
7469
}
75-
70+
7671
private static void AddRule(CheckPoint_Layer layer, CheckPoint_Rule newRule)
7772
{
7873
bool match = false;
@@ -95,7 +90,7 @@ private static void AddRule(CheckPoint_Layer layer, CheckPoint_Rule newRule)
9590
{
9691
CheckPoint_Rule rule = newRule.Clone();
9792
rule.Layer = layer.Name;
98-
rule.Comments = IsOptimizeByComments ? rule.Comments : "";
93+
rule.Comments = "";
9994
rule.ConversionComments = newRule.ConversionComments;
10095
layer.Rules.Add(rule);
10196
}
@@ -136,7 +131,7 @@ private static CheckPoint_Rule MergeRules(CheckPoint_Rule rule1, CheckPoint_Rule
136131
mergedRule.Track = rule1.Track;
137132
mergedRule.SourceNegated = rule1.SourceNegated;
138133
mergedRule.DestinationNegated = rule1.DestinationNegated;
139-
mergedRule.Comments = IsOptimizeByComments ? rule1.Comments : ""; // adding or not adding comments by the user request
134+
mergedRule.Comments = "";
140135
mergedRule.ConversionComments = rule1.ConversionComments + " | " + rule2.ConversionComments;
141136
mergedRule.ConvertedCommandId = rule1.ConvertedCommandId;
142137
mergedRule.ConversionIncidentType = ConversionIncidentType.None;
@@ -183,15 +178,9 @@ private static int GetFirstRuleWithSameAction(CheckPoint_Layer layer, CheckPoint
183178

184179
return (matchedRules == 0) ? -1 : (pos + 1);
185180
}
186-
181+
187182
private static bool IsRuleSimilarToRule(CheckPoint_Rule rule1, CheckPoint_Rule rule2)
188183
{
189-
// Optimizing by comments - checks if comments of the two rules are matched and not empty
190-
if (IsOptimizeByComments && rule1.Comments != rule2.Comments || IsOptimizeByComments && string.IsNullOrEmpty(rule1.Comments))
191-
{
192-
return false;
193-
}
194-
195184
if (rule1.Action != rule2.Action)
196185
{
197186
return false;
@@ -289,7 +278,7 @@ private static string OptimizeConverstionComments(string commentToProcess)
289278

290279

291280
}
292-
else
281+
else
293282
return commentToProcess.Trim();
294283

295284
}

CiscoMigration/CiscoCommands.cs

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -19,9 +19,7 @@ limitations under the License.
1919
using System.Collections.Generic;
2020
using System.Linq;
2121
using System.Text.RegularExpressions;
22-
using CheckPointObjects;
2322
using CommonUtils;
24-
using MigrationBase;
2523

2624
namespace CiscoMigration
2725
{
@@ -126,7 +124,7 @@ public string FirstWord
126124
public ConversionIncidentType ConversionIncidentType { get; set; }
127125
public string ConversionIncidentMessage { get; set; }
128126
public List<CiscoCommand> Children { get; set; }
129-
127+
130128
public CiscoCommand()
131129
{
132130
CiscoId = "";
@@ -2233,11 +2231,11 @@ public override void Parse(CiscoCommand command, CiscoCommand prevCommand, Dicti
22332231

22342232
return;
22352233
}
2236-
2234+
22372235
if (prevAclCommand != null && ACLName.Equals(prevAclCommand.ACLName) && !string.IsNullOrEmpty(prevAclCommand.DataForNextElement))
22382236
{
22392237
Remark = prevAclCommand.DataForNextElement;
2240-
2238+
22412239
if (CiscoParser.SpreadAclRemarks)
22422240
{
22432241
DataForNextElement = Remark;

CiscoMigration/CiscoConverter.cs

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,6 @@ limitations under the License.
2424
using CheckPointObjects;
2525
using MigrationBase;
2626
using System.Globalization;
27-
using System.Runtime.InteropServices;
2827
using System.Threading;
2928
using CiscoMigration.CiscoMigration;
3029
using static CheckPointObjects.CheckPoint_Rule;
@@ -48,7 +47,7 @@ public class CiscoConverter : VendorConverter
4847
#region GUI params
4948

5049
public bool SkipUnusedObjects { get; set; } //check if Optimized configuration is requested
51-
50+
5251
#endregion
5352

5453
#region Helper Classes
@@ -5739,7 +5738,7 @@ private void Add_Optimized_Package()
57395738
foreach (CheckPoint_Layer layer in regularPackage.SubPolicies)
57405739
{
57415740
string optimizedSubPolicyName = layer.Name + "_opt";
5742-
5741+
57435742
CheckPoint_Layer optimizedLayer = RuleBaseOptimizer.Optimize(layer, optimizedSubPolicyName);
57445743
foreach (CheckPoint_Rule subSubRule in optimizedLayer.Rules)
57455744
{

CiscoMigration/CiscoParser.cs

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -35,8 +35,6 @@ public class CiscoParser : VendorParser
3535
//if we are using cisco code for fire power vendor we need set this flag to true value
3636
public bool isUsingForFirePower { get; set; } = false;
3737

38-
#region Private Members
39-
4038
#region Helper Classes
4139

4240
private class Indentation
@@ -53,14 +51,14 @@ public Indentation(int? id, int spaces)
5351

5452
#endregion
5553

56-
54+
#region Private Members
5755

5856
private IList<CiscoCommand> _ciscoCommands = new List<CiscoCommand>();
5957
private Dictionary<string, CiscoCommand> _ciscoIds = new Dictionary<string, CiscoCommand>();
6058
private Dictionary<string, string> _ciscoAliases = new Dictionary<string, string>();
6159

6260
public static bool SpreadAclRemarks = false;
63-
61+
6462
#endregion
6563

6664
#region Public Methods

SmartMove/CommandLine.cs

Lines changed: 2 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,6 @@
1313
using System.Text.RegularExpressions;
1414
using CommonUtils;
1515
using System.Threading;
16-
using CheckPointObjects;
1716

1817
namespace SmartMove
1918
{
@@ -111,7 +110,6 @@ public bool IsAnalyze
111110
private bool _isInteractive = true;
112111

113112
private bool _isCiscoSpreadAclRemarks = false;
114-
private bool _isOptimizeByComments;
115113
#endregion
116114

117115
public int DisplayHelp()
@@ -131,7 +129,6 @@ public int DisplayHelp()
131129
Console.WriteLine("\t" + "-f | --format" + "\t\t" + "format of the output file (JSON[default], TEXT)");
132130
Console.WriteLine("\t" + "-i | --interactive" + "\t" + @"-i false | -i true [default] Interactive mode provides a better user experience.Disable when automation is required[enabled by default]");
133131
Console.WriteLine("\t" + "-a | --analyzer" + "\t\t" + @"mode for analyze package");
134-
Console.WriteLine("\t" + "-obc | --optimize-by-comments" + "\t" + @"(""-obc false"" | ""-obc true"" [default]) create optimized policy by comment and spread acl remarks - only for CiscoASA, FirePower");
135132
Console.WriteLine();
136133
Console.WriteLine("Example:");
137134
Console.WriteLine("\t" + "SmartMove.exe –s \"D:\\SmartMove\\Content\\config.txt\" –v CiscoASA - t \"D:\\SmartMove\\Content\" –n true -k false -f json -a");
@@ -462,23 +459,6 @@ public CommandLine Parse(string[] args)
462459
this.isAnalyze = true;
463460
break;
464461
}
465-
case "-obc":
466-
case "--optimize-by-comments": // adding flag to optimize by comments option
467-
{
468-
if (args[i] == args.Last())
469-
{
470-
_successCommands = false;
471-
Console.WriteLine("Value for option --optimize-by-comments is not specified! ", MessageTypes.Error);
472-
}
473-
else if (bool.TryParse(args[i + 1].ToLower(), out _isOptimizeByComments))
474-
break;
475-
else
476-
{
477-
_successCommands = false;
478-
Console.WriteLine("Value for option format is not corrected! Allow only 'true' or 'false' ", MessageTypes.Error);
479-
}
480-
break;
481-
}
482462
}
483463
}
484464
return this;
@@ -553,17 +533,10 @@ public void DoAnalyze(CommandLine commandLine)
553533
switch (commandLine.Vendor)
554534
{
555535
case "CiscoASA":
556-
CiscoParser.SpreadAclRemarks = _isOptimizeByComments;
557-
RuleBaseOptimizer.IsOptimizeByComments = _isOptimizeByComments;
558-
// verifying that the user or the default option won't reverse the flag to false if asking optimize by comments option
559-
CiscoParser.SpreadAclRemarks = _isOptimizeByComments ? true : _isCiscoSpreadAclRemarks;
536+
CiscoParser.SpreadAclRemarks = _isCiscoSpreadAclRemarks;
560537
vendorParser = new CiscoParser();
561538
break;
562539
case "FirePower":
563-
CiscoParser.SpreadAclRemarks = _isOptimizeByComments;
564-
RuleBaseOptimizer.IsOptimizeByComments = _isOptimizeByComments;
565-
// verifying that the user or the default option won't reverse the flag to false if asking optimize by comments option
566-
CiscoParser.SpreadAclRemarks = _isOptimizeByComments ? true : _isCiscoSpreadAclRemarks;
567540
vendorParser = new CiscoParser()
568541
{
569542
isUsingForFirePower = true
@@ -995,15 +968,10 @@ public void DoMigration(CommandLine commandLine)
995968
switch (commandLine.Vendor)
996969
{
997970
case "CiscoASA":
998-
CiscoParser.SpreadAclRemarks = _isOptimizeByComments;
999-
RuleBaseOptimizer.IsOptimizeByComments = _isOptimizeByComments;
1000-
CiscoParser.SpreadAclRemarks = _isOptimizeByComments ? true : _isCiscoSpreadAclRemarks;
971+
CiscoParser.SpreadAclRemarks = _isCiscoSpreadAclRemarks;
1001972
vendorParser = new CiscoParser();
1002973
break;
1003974
case "FirePower":
1004-
CiscoParser.SpreadAclRemarks = _isOptimizeByComments;
1005-
RuleBaseOptimizer.IsOptimizeByComments = _isOptimizeByComments;
1006-
CiscoParser.SpreadAclRemarks = _isOptimizeByComments ? true : _isCiscoSpreadAclRemarks;
1007975
vendorParser = new CiscoParser()
1008976
{
1009977
isUsingForFirePower = true

SmartMove/MainWindow.xaml

Lines changed: 2 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -226,23 +226,16 @@
226226
<CheckBox x:Name="SkipUnusedObjects" Grid.Row="13" Content="Do not import unused objects"
227227
IsChecked="{Binding RelativeSource={RelativeSource FindAncestor, AncestorType={x:Type Window}}, Path=SkipUnusedObjectsConversion, Mode=TwoWay}"
228228
Margin="0,15,0,0" Background="Transparent" Focusable="False"/>
229-
<CheckBox x:Name="OptimizeByComments" Grid.Row="14" Content="Optimize by comments"
230-
IsChecked="{Binding RelativeSource={RelativeSource FindAncestor, AncestorType={x:Type Window}}, Path=OptimizeByCommentsConversion, Mode=TwoWay}"
231-
Margin="0,15,0,0" Background="Transparent" Focusable="False" Checked="OptimizeByComments_Checked" Unchecked="OptimizeByComments_Checked"/>
232229
<CheckBox x:Name="CreateServiceGroupsConf" Grid.Row="14" Content="Import service groups"
233230
IsChecked="{Binding RelativeSource={RelativeSource FindAncestor, AncestorType={x:Type Window}}, Path=CreateServiceGroupsConfiguration, Mode=TwoWay}"
234231
Margin="0,15,0,0" Background="Transparent" Focusable="False" Visibility="Collapsed"/>
235232
<Grid Grid.Row="15" Margin="0,30,0,0" Background="Transparent" Focusable="False">
236233
<Grid.ColumnDefinitions>
237-
<ColumnDefinition Width="8*"/>
238-
<ColumnDefinition Width="8*"/>
239-
<ColumnDefinition Width="84*"/>
240-
<ColumnDefinition Width="401*"/>
234+
<ColumnDefinition/>
241235
</Grid.ColumnDefinitions>
242236
<Button x:Name="Go" Style="{StaticResource GoButtonControlStyle}" HorizontalAlignment="Right"
243-
Click="Go_OnClick" Grid.Column="3" Margin="0,0,-0.2,2.4"/>
237+
Click="Go_OnClick"/>
244238
</Grid>
245-
246239
</Grid>
247240
</Grid>
248241
<Grid x:Name="OutputPanel" Grid.Row="1" Background="Transparent" Focusable="False" Visibility="Collapsed">

0 commit comments

Comments
 (0)