forked from CactuseSecurity/firewall-orchestrator
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[+] Create App Zones(WIP) CactuseSecurity#2597
- Loading branch information
1 parent
210579c
commit 901a1f2
Showing
6 changed files
with
138 additions
and
2 deletions.
There are no files selected for viewing
16 changes: 16 additions & 0 deletions
16
roles/lib/files/FWO.Api.Client/APIcalls/modelling/addNwAppZone.graphql
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
mutation newAppZone( | ||
$name: String | ||
$idString: String | ||
$creator: String | ||
) { | ||
insert_modelling_nwgroup(objects: { | ||
name: $name | ||
id_string: $idString | ||
creator: $creator | ||
group_type: 21 | ||
}) { | ||
returning { | ||
newId: id | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
using FWO.Api.Data; | ||
|
||
namespace FWO.Api.Client.Data | ||
{ | ||
public class ModellingAppZone : ModellingAppRole | ||
{ | ||
public ModellingAppZone() | ||
{ | ||
|
||
} | ||
|
||
public ModellingAppZone(ModellingAppZone appZone) : base(appZone) | ||
{ | ||
Comment = appZone.Comment; | ||
Creator = appZone.Creator; | ||
CreationDate = appZone.CreationDate; | ||
AppServers = appZone.AppServers; | ||
Area = appZone.Area; | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,77 @@ | ||
using FWO.Api.Client; | ||
using FWO.Api.Data; | ||
using FWO.Config.Api; | ||
using FWO.Api.Client.Data; | ||
using FWO.Api.Client.Queries; | ||
using System.Text.Json; | ||
|
||
namespace FWO.Services | ||
{ | ||
public class ModellingAppZoneHandler : ModellingHandlerBase | ||
{ | ||
public ModellingNamingConvention NamingConvention = new(); | ||
public List<ModellingAppZone> AppZones { get; set; } = []; | ||
|
||
public ModellingAppZoneHandler(ApiConnection apiConnection, UserConfig userConfig) : base(apiConnection, userConfig) | ||
{ | ||
|
||
} | ||
public async Task CreateAppZones(int appId) | ||
{ | ||
List<ModellingAppServer> appServers = await apiConnection.SendQueryAsync<List<ModellingAppServer>>(ModellingQueries.getAppServers, new { appId = appId }); | ||
List<FwoOwner> owners = await apiConnection.SendQueryAsync<List<FwoOwner>>(OwnerQueries.getOwners); | ||
|
||
FwoOwner? owner = owners.FirstOrDefault(_ => _.Id == appId); | ||
|
||
foreach (ModellingAppServer appServer in appServers) | ||
{ | ||
ModellingAppZone appZone = new(); | ||
appZone.AppServers.Add(new ModellingAppServerWrapper() { Content = appServer }); | ||
ApplyNamingConvention(owner.ExtAppId.ToUpper(), appZone); | ||
await AddAppZoneToDb(appZone); | ||
} | ||
} | ||
|
||
private void ApplyNamingConvention(string extAppId, ModellingAppZone appZone) | ||
{ | ||
NamingConvention = JsonSerializer.Deserialize<ModellingNamingConvention>(userConfig.ModNamingConvention) ?? new(); | ||
appZone.ManagedIdString.NamingConvention = NamingConvention; | ||
appZone.ManagedIdString.SetAppPartFromExtId(extAppId); | ||
appZone.Name = $"{NamingConvention.AppZone}{appZone.ManagedIdString.AppPart}"; | ||
} | ||
|
||
private async Task AddAppZoneToDb(ModellingAppZone appZone) | ||
{ | ||
var azVars = new | ||
{ | ||
name = appZone.Name, | ||
idString = appZone.IdString, | ||
creator = "CreateAZObjects" | ||
}; | ||
|
||
ReturnId[]? returnIds = ( await apiConnection.SendQueryAsync<NewReturning>(ModellingQueries.newAppZone, azVars) ).ReturnIds; | ||
|
||
if (returnIds != null) | ||
{ | ||
appZone.Id = returnIds[0].NewId; | ||
|
||
await LogChange(ModellingTypes.ChangeType.Insert, ModellingTypes.ModObjectType.AppZone, appZone.Id, | ||
$"New App Zone: {appZone.Display()}", appZone.AppId); | ||
|
||
foreach (var appServer in appZone.AppServers) | ||
{ | ||
var nwobject_nwgroupVars = new | ||
{ | ||
nwObjectId = appServer.Content.Id, | ||
nwGroupId = appZone.Id | ||
}; | ||
|
||
await apiConnection.SendQueryAsync<ReturnId>(ModellingQueries.addNwObjectToNwGroup, nwobject_nwgroupVars); | ||
|
||
await LogChange(ModellingTypes.ChangeType.Assign, ModellingTypes.ModObjectType.AppRole, appZone.Id, | ||
$"Added App Server {appServer.Content.Display()} to App Role: {appZone.Display()}", Application.Id); | ||
} | ||
} | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters