Skip to content

Commit

Permalink
Merge pull request #2357 from abarz722/develop
Browse files Browse the repository at this point in the history
connections report first throw
  • Loading branch information
tpurschke committed Mar 19, 2024
2 parents c4df3e7 + ca73457 commit 00b1827
Show file tree
Hide file tree
Showing 106 changed files with 4,283 additions and 1,993 deletions.
302 changes: 302 additions & 0 deletions roles/api/files/replace_metadata.json

Large diffs are not rendered by default.

1 change: 1 addition & 0 deletions roles/database/files/sql/creation/fworch-fill-stm.sql
Original file line number Diff line number Diff line change
Expand Up @@ -81,6 +81,7 @@ insert into config (config_key, config_value, config_user) VALUES ('importSubnet
insert into config (config_key, config_value, config_user) VALUES ('importAppDataPath', '[]', 0);
insert into config (config_key, config_value, config_user) VALUES ('importSubnetDataPath', '', 0);
insert into config (config_key, config_value, config_user) VALUES ('modNamingConvention', '{"networkAreaRequired":false,"useAppPart":false,"fixedPartLength":0,"freePartLength":0,"networkAreaPattern":"","appRolePattern":""}', 0);
insert into config (config_key, config_value, config_user) VALUES ('modCommonAreas', '[]', 0);
insert into config (config_key, config_value, config_user) VALUES ('modIconify', 'True', 0);
insert into config (config_key, config_value, config_user) VALUES ('reducedProtocolSet', 'True', 0);
insert into config (config_key, config_value, config_user) VALUES ('overviewDisplayLines', '3', 0);
Expand Down
74 changes: 62 additions & 12 deletions roles/database/files/sql/idempotent/fworch-texts.sql

Large diffs are not rendered by default.

Original file line number Diff line number Diff line change
Expand Up @@ -8,4 +8,9 @@ fragment appRoleDetails on modelling_nwgroup {
is_deleted
creator
creation_date
nwobjects: nwobject_nwgroups{
owner_network{
...appServerDetails
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -6,4 +6,9 @@ fragment serviceGroupDetails on modelling_service_group {
comment
creator
creation_date
services: service_service_groups{
service{
...serviceDetails
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
query getCommonServices{
modelling_connection (where: { common_service: { _eq: true } } order_by: { name: asc }){
...connectionDetails
owner{
name
}
}
}
71 changes: 0 additions & 71 deletions roles/lib/files/FWO.Api.Client/Data/Device.cs
Original file line number Diff line number Diff line change
Expand Up @@ -35,15 +35,6 @@ public class Device
[JsonProperty("comment"), JsonPropertyName("comment")]
public string? Comment { get; set; }

[JsonProperty("rules"), JsonPropertyName("rules")]
public Rule[]? Rules { get; set; }

[JsonProperty("changelog_rules"), JsonPropertyName("changelog_rules")]
public RuleChange[]? RuleChanges { get; set; }

[JsonProperty("rules_aggregate"), JsonPropertyName("rules_aggregate")]
public ObjectStatistics RuleStatistics { get; set; } = new ObjectStatistics();

public bool Selected { get; set; } = false;
public bool Relevant { get; set; }
public bool AwaitMgmt { get; set; }
Expand Down Expand Up @@ -71,22 +62,6 @@ public Device(Device device)
ActionId = device.ActionId;
}

public void AssignRuleNumbers()
{
if (Rules != null)
{
int ruleNumber = 1;

foreach (Rule rule in Rules)
{
if (string.IsNullOrEmpty(rule.SectionHeader)) // Not a section header
{
rule.DisplayOrderNumber = ruleNumber++;
}
}
}
}

public bool Sanitize()
{
bool shortened = false;
Expand All @@ -97,51 +72,5 @@ public bool Sanitize()
Comment = Sanitizer.SanitizeCommentOpt(Comment, ref shortened);
return shortened;
}

public bool ContainsRules()
{
return (Rules != null && Rules.Count()>0);
}
}


public static class DeviceUtility
{
// adding rules fetched in slices
public static bool Merge(this Device[] devices, Device[] devicesToMerge)
{
bool newObjects = false;

for (int i = 0; i < devices.Length && i < devicesToMerge.Length; i++)
{
if (devices[i].Id == devicesToMerge[i].Id)
{
try
{
if (devices[i].Rules != null && devicesToMerge[i].Rules != null && devicesToMerge[i].Rules?.Length > 0)
{
devices[i].Rules = devices[i].Rules?.Concat(devicesToMerge[i].Rules!).ToArray();
newObjects = true;
}
if (devices[i].RuleChanges != null && devicesToMerge[i].RuleChanges != null && devicesToMerge[i].RuleChanges?.Length > 0)
{
devices[i].RuleChanges = devices[i].RuleChanges!.Concat(devicesToMerge[i].RuleChanges!).ToArray();
newObjects = true;
}
if (devices[i].RuleStatistics != null && devicesToMerge[i].RuleStatistics != null)
devices[i].RuleStatistics.ObjectAggregate.ObjectCount += devicesToMerge[i].RuleStatistics.ObjectAggregate.ObjectCount; // correct ??
}
catch (NullReferenceException)
{
throw new ArgumentNullException("Rules is null");
}
}
else
{
throw new NotSupportedException("Devices have to be in the same order in oder to merge.");
}
}
return newObjects;
}
}
}
16 changes: 10 additions & 6 deletions roles/lib/files/FWO.Api.Client/Data/DisplayBase.cs
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,10 @@ public static StringBuilder DisplayService(NetworkService service, bool isTechRe
{
result.Append($" ({ports}/{service.Protocol?.Name})");
}
else if (service.Protocol?.Name != null)
{
result.Append($" ({service.Protocol?.Name})");
}
}
return result;
}
Expand Down Expand Up @@ -65,7 +69,7 @@ public static string DisplayIp(string ip1, string ip2, string nwObjType, bool in
IPAddressRange IpRange;
string IpStart;
string IpEnd;
if (nwObjType != "group")
if (nwObjType != ObjectType.Group)
{
if (ip2 == null)
{
Expand Down Expand Up @@ -96,14 +100,14 @@ public static string DisplayIp(string ip1, string ip2, string nwObjType, bool in
if (IpRange != null)
{
result = inBrackets ? " (" : "";
if (nwObjType == "network")
if (nwObjType == ObjectType.Network)
{
result += IpRange.ToCidrString();
}
else
{
result += IpStart;
if (nwObjType.Contains("range"))
if (nwObjType.Contains(ObjectType.IPRange))
{
result += $"-{IpEnd}";
}
Expand Down Expand Up @@ -152,13 +156,13 @@ private static string AutoDetectType(string ip1, string ip2)
{
if (ip1 == ip2)
{
return "host";
return ObjectType.Host;
}
if (SpanSingleNetwork(ip1, ip2))
{
return "network";
return ObjectType.Network;
}
return "iprange";
return ObjectType.IPRange;
}

private static bool isV6Address(string ip)
Expand Down
8 changes: 8 additions & 0 deletions roles/lib/files/FWO.Api.Client/Data/GlobalConstants.cs
Original file line number Diff line number Diff line change
Expand Up @@ -32,4 +32,12 @@ public struct GlobalConst
public const string kLdapInternalPostfix = "dc=fworch,dc=internal";

}

public struct ObjectType
{
public const string Group = "group";
public const string Host = "host";
public const string Network = "network";
public const string IPRange = "ip_range";
}
}
1 change: 1 addition & 0 deletions roles/lib/files/FWO.Api.Client/Data/Icons.cs
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ public struct Icons
public const string Edit = "oi oi-wrench";
public const string Delete = "oi oi-trash";
public const string Search = "oi oi-magnifying-glass";
public const string Display = "oi oi-eye";
public const string Use = "oi oi-arrow-thick-right";
public const string Unuse = "oi oi-arrow-thick-left";
public const string Close = "oi oi-x";
Expand Down
149 changes: 10 additions & 139 deletions roles/lib/files/FWO.Api.Client/Data/Management.cs
Original file line number Diff line number Diff line change
Expand Up @@ -56,24 +56,6 @@ public class Management
[JsonProperty("devices"), JsonPropertyName("devices")]
public Device[] Devices { get; set; } = new Device[]{};

[JsonProperty("networkObjects"), JsonPropertyName("networkObjects")]
public NetworkObject[] Objects { get; set; } = new NetworkObject[]{};

[JsonProperty("serviceObjects"), JsonPropertyName("serviceObjects")]
public NetworkService[] Services { get; set; } = new NetworkService[]{};

[JsonProperty("userObjects"), JsonPropertyName("userObjects")]
public NetworkUser[] Users { get; set; } = new NetworkUser[]{};

[JsonProperty("reportNetworkObjects"), JsonPropertyName("reportNetworkObjects")]
public NetworkObject[] ReportObjects { get; set; } = new NetworkObject[]{};

[JsonProperty("reportServiceObjects"), JsonPropertyName("reportServiceObjects")]
public NetworkService[] ReportServices { get; set; } = new NetworkService[]{};

[JsonProperty("reportUserObjects"), JsonPropertyName("reportUserObjects")]
public NetworkUser[] ReportUsers { get; set; } = new NetworkUser[]{};

[JsonProperty("deviceType"), JsonPropertyName("deviceType")]
public DeviceType DeviceType { get; set; } = new DeviceType();

Expand All @@ -86,21 +68,6 @@ public class Management
public bool Delete { get; set; }
public long ActionId { get; set; }

//[JsonProperty("rule_id"), JsonPropertyName("rule_id")]
public List<long> ReportedRuleIds { get; set; } = new List<long>();
public List<long> ReportedNetworkServiceIds { get; set; } = new List<long>();

[JsonProperty("objects_aggregate"), JsonPropertyName("objects_aggregate")]
public ObjectStatistics NetworkObjectStatistics { get; set; } = new ObjectStatistics();

[JsonProperty("services_aggregate"), JsonPropertyName("services_aggregate")]
public ObjectStatistics ServiceObjectStatistics { get; set; } = new ObjectStatistics();

[JsonProperty("usrs_aggregate"), JsonPropertyName("usrs_aggregate")]
public ObjectStatistics UserObjectStatistics { get; set; } = new ObjectStatistics();

[JsonProperty("rules_aggregate"), JsonPropertyName("rules_aggregate")]
public ObjectStatistics RuleStatistics { get; set; } = new ObjectStatistics();

public Management()
{}
Expand All @@ -118,6 +85,7 @@ public Management(Management management)
DomainUid = management.DomainUid;
CloudSubscriptionId = management.CloudSubscriptionId;
CloudTenantId = management.CloudTenantId;
SuperManagerId = management.SuperManagerId;
ImporterHostname = management.ImporterHostname;
Port = management.Port;
ImportDisabled = management.ImportDisabled;
Expand All @@ -126,44 +94,27 @@ public Management(Management management)
Comment = management.Comment;
DebugLevel = management.DebugLevel;
Devices = management.Devices;
Objects = management.Objects;
Services = management.Services;
Users = management.Users;
ReportObjects = management.ReportObjects;
ReportServices = management.ReportServices;
ReportUsers = management.ReportUsers;
DeviceType = management.DeviceType;
if (management.DeviceType != null)
DeviceType = new DeviceType(management.DeviceType);
Import = management.Import;
Ignore = management.Ignore;
AwaitDevice = management.AwaitDevice;
Delete = management.Delete;
ActionId = management.ActionId;
ReportedRuleIds = management.ReportedRuleIds;
SuperManagerId = management.SuperManagerId;
ReportedNetworkServiceIds = management.ReportedNetworkServiceIds;
if (management.Import != null && management.Import.ImportAggregate != null &&
management.Import.ImportAggregate.ImportAggregateMax != null &&
management.Import.ImportAggregate.ImportAggregateMax.RelevantImportId != null)
{
RelevantImportId = management.Import.ImportAggregate.ImportAggregateMax.RelevantImportId;

if (management.DeviceType != null)
DeviceType = new DeviceType(management.DeviceType);
}
Ignore = management.Ignore;
AwaitDevice = management.AwaitDevice;
Delete = management.Delete;
ActionId = management.ActionId;
}

public string Host()
{
return Hostname + ":" + Port;
}

public void AssignRuleNumbers()
{
foreach (Device device in Devices)
{
device.AssignRuleNumbers();
}
}

public bool Sanitize()
public virtual bool Sanitize()
{
bool shortened = false;
Name = Sanitizer.SanitizeMand(Name, ref shortened);
Expand All @@ -177,84 +128,4 @@ public bool Sanitize()
return shortened;
}
}

public static class ManagementUtility
{
public static bool Merge(this Management[] managements, Management[] managementsToMerge)
{
bool newObjects = false;

for (int i = 0; i < managementsToMerge.Length; i++)
newObjects |= managements[i].Merge(managementsToMerge[i]);

return newObjects;
}

public static bool Merge(this Management management, Management managementToMerge)
{
bool newObjects = false;

if (management.Objects != null && managementToMerge.Objects != null && managementToMerge.Objects.Length > 0)
{
management.Objects = management.Objects.Concat(managementToMerge.Objects).ToArray();
newObjects = true;
}

if (management.Services != null && managementToMerge.Services != null && managementToMerge.Services.Length > 0)
{
management.Services = management.Services.Concat(managementToMerge.Services).ToArray();
newObjects = true;
}

if (management.Users != null && managementToMerge.Users != null && managementToMerge.Users.Length > 0)
{
management.Users = management.Users.Concat(managementToMerge.Users).ToArray();
newObjects = true;
}

if (management.Devices != null && managementToMerge.Devices != null && managementToMerge.Devices.Length > 0)
{
// important: if any management still returns rules, newObjects is set to true
if (management.Devices.Merge(managementToMerge.Devices) == true)
newObjects = true;
}
return newObjects;
}

public static bool MergeReportObjects(this Management management, Management managementToMerge)
{
bool newObjects = false;

if (management.ReportObjects != null && managementToMerge.ReportObjects != null && managementToMerge.ReportObjects.Length > 0)
{
management.ReportObjects = management.ReportObjects.Concat(managementToMerge.ReportObjects).ToArray();
newObjects = true;
}

if (management.ReportServices != null && managementToMerge.ReportServices != null && managementToMerge.ReportServices.Length > 0)
{
management.ReportServices = management.ReportServices.Concat(managementToMerge.ReportServices).ToArray();
newObjects = true;
}

if (management.ReportUsers != null && managementToMerge.ReportUsers != null && managementToMerge.ReportUsers.Length > 0)
{
management.ReportUsers = management.ReportUsers.Concat(managementToMerge.ReportUsers).ToArray();
newObjects = true;
}

if (management.Devices != null && managementToMerge.Devices != null && managementToMerge.Devices.Length > 0)
{
// important: if any management still returns rules, newObjects is set to true
if (management.Devices.Merge(managementToMerge.Devices) == true)
newObjects = true;
}
return newObjects;
}

public static string NameAndDeviceNames(this Management management, string separator = ", ")
{
return $"{management.Name} [{string.Join(separator, Array.ConvertAll(management.Devices, device => device.Name))}]";
}
}
}
Loading

0 comments on commit 00b1827

Please sign in to comment.