Skip to content

Commit 8535716

Browse files
authored
Merge pull request #102 from CheckPointSW/staging
version 9.40 Added a pre-commit code Formating: dot net format Added new logic to optimize policy based on comments SmartConnector : Adding the option to reuse a group name rather than creating a new one so all the data will be added to the existing name slicing custom-fields.field-1 in case exceeded 250 chars
2 parents 731ce99 + e427e87 commit 8535716

File tree

82 files changed

+922
-840
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

82 files changed

+922
-840
lines changed

.github/contributing.md

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,10 @@
11
## Code and testing requirements:
2-
- The tool is developed using Microsoft C# language and .NET framework version 4.5 (WPF application).
2+
- The tool is developed using Microsoft C# language and .NET framework version 4.5 (WPF application).
33
- The project solution file is configured for Microsoft Visual Studio 2012 (C# v5).
44
- Do not add new external libraries or any 3rd party code (open source or commercial).
5-
- The code will be implemented with high quality standards. It should be designed well, refactored for easy reuse and easy maintenance, efficient as possible, readable and well documented.
5+
- The code will be implemented with high quality standards. It should be designed well, refactored for easy reuse and easy maintenance, efficient as possible, readable and well documented.
66
- Verify functionality and correctness of the tool, including end-to-end testing & QA.
7-
7+
88
## Committing code to GitHub:
99
- Commit/PR name needs to be meaningful and explain the change and not the issue it solves. For example: User is suffering from failure due to host name collision – commit name would be: “Handle host creation in case of name duplications”.
1010
- Commit/PR description needs to contain more details about the issue and the solution.

.gitignore

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
1+
build.bat
22
SmartMove/SmartConnector/*.pyc
33
SmartMove/SmartConnector/.idea
44
SmartMove/compressors/*.exe

.pre-commit-config.yaml

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
repos:
2+
- repo: https://github.com/pre-commit/pre-commit-hooks
3+
rev: v4.3.0
4+
hooks:
5+
- id: trailing-whitespace
6+
- id: mixed-line-ending
7+
- id: check-merge-conflict
8+
- id: check-case-conflict
9+
- id: check-ast
10+
- id: check-docstring-first
11+
- id: end-of-file-fixer
12+
- id: check-builtin-literals
13+
- id: debug-statements
14+
- id: forbid-new-submodules
15+
- repo: https://github.com/asottile/pyupgrade
16+
rev: v3.1.0
17+
hooks:
18+
- id: pyupgrade
19+
args: [--py37-plus]
20+
- repo: https://github.com/zricethezav/gitleaks
21+
rev: v7.6.1
22+
hooks:
23+
- id: gitleaks
24+
name: Detect hardcoded secrets
25+
description: Detect hardcoded secrets using Gitleaks
26+
args: [--debug, --verbose, --repo-url, .]

CheckPointObjects/CP_KnownServiceGroups.csv

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -49,4 +49,4 @@
4949
"time"
5050
"Trojan_Services"
5151
"Yahoo_Messenger"
52-
"Mail"
52+
"Mail"

CheckPointObjects/CheckPointObjects.cs

Lines changed: 7 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -202,7 +202,7 @@ public class CheckPoint_Domain : CheckPointObject
202202
public override string ToCLIScript()
203203
{
204204
return "add dns-domain " + WriteParam("name", SafeName(), "") + WriteParam("comments", Comments, "")
205-
+ WriteParam("is-sub-domain", IsSubDomain, !IsSubDomain) //"is-sub-domain" is a required field by documentation
205+
+ WriteParam("is-sub-domain", IsSubDomain, !IsSubDomain) //"is-sub-domain" is a required field by documentation
206206
+ WriteListParam("tags", Tags, true);
207207
}
208208

@@ -303,7 +303,7 @@ public class CheckPoint_NetworkGroup : CheckPointObject
303303
public bool IsPanoramaDeviceGroup = false;
304304

305305
/// <summary>
306-
/// This property is used to overcome the problematic order of objects creation for
306+
/// This property is used to overcome the problematic order of objects creation for
307307
/// GroupWithExclusion and NetworkGroup types cross-referencing each other.
308308
/// </summary>
309309
public bool CreateAfterGroupsWithExclusion { get; set; }
@@ -491,7 +491,7 @@ public class CheckPoint_OtherService : CheckPointObject
491491
public string IpProtocol { get; set; }
492492

493493
public CheckPoint_OtherService() : base() { }
494-
public CheckPoint_OtherService (string name, string ipprotocol, string comments, List<string> tags) : base()
494+
public CheckPoint_OtherService(string name, string ipprotocol, string comments, List<string> tags) : base()
495495
{
496496
Name = name;
497497
IpProtocol = ipprotocol;
@@ -517,7 +517,7 @@ public class CheckPoint_ServiceGroup : CheckPointObject
517517
{
518518
public List<string> Members = new List<string>();
519519
public int MembersPublishIndex { get; set; }
520-
public int MembersMaxPublishSize { get; set; }
520+
public int MembersMaxPublishSize { get; set; }
521521

522522
public CheckPoint_ServiceGroup() : base()
523523
{
@@ -538,7 +538,7 @@ public override string ToCLIScriptInstruction()
538538
int index = ((MembersPublishIndex + MembersMaxPublishSize) > Members.Count) ? Members.Count : MembersPublishIndex + MembersMaxPublishSize;
539539
return (MembersPublishIndex == 0 ? "create " : "update ") + "service group [" + Name + "]: " + index + "/" + Members.Count + " members";
540540
}
541-
541+
542542
}
543543

544544
public class CheckPoint_ApplicationGroup : CheckPointObject
@@ -787,7 +787,7 @@ public override string ToCLIScript()
787787
+ WriteParam("inline-layer", SubPolicyName, "")
788788
+ WriteParam("name", Name, "")
789789
+ WriteListParam("install-on", (from o in Target select o).ToList(), true)
790-
+ WriteParam("custom-fields.field-1", ConversionComments.Substring(0, Math.Min(ConversionComments.Length, 150)), "");
790+
+ WriteParam("custom-fields.field-1", ConversionComments.Substring(0, Math.Min(ConversionComments.Length, 250)), "");
791791
}
792792

793793
public override string ToCLIScriptInstruction()
@@ -866,7 +866,7 @@ public bool IsCleanupRule()
866866
{
867867
return true; // sub-policy's automatic cleanup rule
868868
}
869-
return checkRuleType(ActionType.Drop);// user defined cleanup rule
869+
return checkRuleType(ActionType.Drop);// user defined cleanup rule
870870
}
871871

872872
/// <summary>
@@ -1106,4 +1106,3 @@ public int TotalRules()
11061106
}
11071107
}
11081108
}
1109-

CheckPointObjects/CheckPointObjects.csproj

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -73,11 +73,11 @@
7373
</None>
7474
</ItemGroup>
7575
<Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />
76-
<!-- To modify your build process, add your task inside one of the targets below and uncomment it.
76+
<!-- To modify your build process, add your task inside one of the targets below and uncomment it.
7777
Other similar extension points exist, see Microsoft.Common.targets.
7878
<Target Name="BeforeBuild">
7979
</Target>
8080
<Target Name="AfterBuild">
8181
</Target>
8282
-->
83-
</Project>
83+
</Project>

CheckPointObjects/CheckPointObjectsRepository.cs

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ limitations under the License.
2222
namespace CheckPointObjects
2323
{
2424
/// <summary>
25-
/// Repository for Check Point objects created during the convertion from 3rd party configuration and
25+
/// Repository for Check Point objects created during the convertion from 3rd party configuration and
2626
/// predefined Check Point objects.
2727
/// Objects are identified by their names.
2828
/// </summary>
@@ -32,8 +32,8 @@ public class CheckPointObjectsRepository
3232

3333
private class ObjectInfo
3434
{
35-
public CheckPointObject Object { get; private set; }
36-
public bool IsPredefined { get; private set; }
35+
public CheckPointObject Object { get; private set; }
36+
public bool IsPredefined { get; private set; }
3737

3838
public ObjectInfo(CheckPointObject cpObject, bool isPredefined)
3939
{
@@ -157,7 +157,8 @@ public bool HasObject(string objectName)
157157
return (!string.IsNullOrEmpty(objectName) && _repository.ContainsKey(objectName));
158158
}
159159

160-
public bool IsPredefinedOrKnownService(string name) {
160+
public bool IsPredefinedOrKnownService(string name)
161+
{
161162
return HasObject(name) || IsKnownService(name);
162163
}
163164

CheckPointObjects/Properties/AssemblyInfo.cs

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
using System.Runtime.CompilerServices;
33
using System.Runtime.InteropServices;
44

5-
// General Information about an assembly is controlled through the following
5+
// General Information about an assembly is controlled through the following
66
// set of attributes. Change these attribute values to modify the information
77
// associated with an assembly.
88
[assembly: AssemblyTitle("CheckPointObjects")]
@@ -14,8 +14,8 @@
1414
[assembly: AssemblyTrademark("")]
1515
[assembly: AssemblyCulture("")]
1616

17-
// Setting ComVisible to false makes the types in this assembly not visible
18-
// to COM components. If you need to access a type in this assembly from
17+
// Setting ComVisible to false makes the types in this assembly not visible
18+
// to COM components. If you need to access a type in this assembly from
1919
// COM, set the ComVisible attribute to true on that type.
2020
[assembly: ComVisible(false)]
2121

@@ -25,11 +25,11 @@
2525
// Version information for an assembly consists of the following four values:
2626
//
2727
// Major Version
28-
// Minor Version
28+
// Minor Version
2929
// Build Number
3030
// Revision
3131
//
32-
// You can specify all the values or you can default the Build and Revision Numbers
32+
// You can specify all the values or you can default the Build and Revision Numbers
3333
// by using the '*' as shown below:
3434
// [assembly: AssemblyVersion("1.0.*")]
3535
[assembly: AssemblyVersion("1.0.0.0")]

CheckPointObjects/RuleBaseOptimizer.cs

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ namespace CheckPointObjects
2929
/// 1. both rules have the same action, and
3030
/// 2. both rules are enabled or disabled, and
3131
/// 3. both rules have source and destination columns negated or not, and
32-
/// 4. both rules have the same time objects, and
32+
/// 4. both rules have the same time objects, and
3333
/// 5. either one of the following is true:
3434
/// 5.1. both the source and destination columns match
3535
/// 5.2. both the source and service columns match
@@ -196,7 +196,7 @@ private static bool IsRuleSimilarToRule(CheckPoint_Rule rule1, CheckPoint_Rule r
196196
return false;
197197
}
198198

199-
if ((rule1.Time.Count != rule2.Time.Count) ||
199+
if ((rule1.Time.Count != rule2.Time.Count) ||
200200
(rule1.Time.Count > 0 && rule2.Time.Count > 0 && rule1.Time[0].Name != rule2.Time[0].Name))
201201
{
202202
return false;
@@ -238,8 +238,9 @@ private static string OptimizeConverstionComments(string commentToProcess)
238238
//if there is nothing to merge return empty comment
239239
if (comments_parts.Count == 0)
240240
return "";
241-
242-
if (comments_parts.Count > 0) {
241+
242+
if (comments_parts.Count > 0)
243+
{
243244

244245
if (regex.IsMatch(comments_parts[0]))
245246
foreach (string part in comments_parts)
@@ -275,9 +276,11 @@ private static string OptimizeConverstionComments(string commentToProcess)
275276
commentBuilder += ", " + comments_parts[i];
276277
}
277278

279+
278280
}
279281
else
280282
return commentToProcess.Trim();
283+
281284
}
282285

283286
return commentBuilder == "Matched rule(s)" ? "" : commentBuilder;

CiscoMigration/CiscoAnalizStatistic.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,7 @@ public override void CalculateNetworks(List<CheckPoint_Network> _cpNetworks,
4848
}
4949
foreach (var item in _cpHosts)
5050
{
51-
if (_cpHosts.Where(nt => nt.IpAddress == item.IpAddress ).Count() > 1) { _duplicateServicesObjectsCount++; }
51+
if (_cpHosts.Where(nt => nt.IpAddress == item.IpAddress).Count() > 1) { _duplicateServicesObjectsCount++; }
5252
}
5353
foreach (var item in _cpRanges)
5454
{
@@ -188,4 +188,4 @@ public override void CalculateServices(List<CheckPoint_TcpService> _cpTcpService
188188
}
189189
}
190190

191-
}
191+
}

0 commit comments

Comments
 (0)