Skip to content
This repository was archived by the owner on Aug 4, 2022. It is now read-only.

Commit 87c739c

Browse files
faixAntonstockmarr
andauthored
Enable updating the allowlisted apps after importing a db (#135)
* Enable updating the whitelisted apps after importing a db (#135) * Change setup step to update table instead of inserting The AADApp step can now be used in isolation after importing a database to update the whitelisted apps, both for scale units and the interAOS app. * Rename whitelisting to applylisting Complying with diversity policies * Throw exception if user does not exist No longer tries to identify old records based on the appName. If the appId is not in the table, then a new entry is created. * Change location of error handling Co-authored-by: Antonstockmarr <43210147+Antonstockmarr@users.noreply.github.com>
1 parent 3295015 commit 87c739c

4 files changed

Lines changed: 128 additions & 42 deletions

File tree

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
using System;
2+
using ScaleUnitManagement.Utilities;
3+
4+
namespace ScaleUnitManagement.DatabaseManager
5+
{
6+
public class AADAppAllowListing
7+
{
8+
public void UpdateAADAppClientTable(string dbName, string userName, string appName, string appId)
9+
{
10+
string sqlQuery = $@"
11+
USE {dbName};
12+
13+
IF NOT EXISTS (SELECT TOP 1 1 FROM USERINFO WHERE ID = '{userName}')
14+
THROW 51000, 'No user exists named {userName}', 1
15+
ELSE
16+
IF NOT EXISTS (SELECT TOP 1 1 FROM SysAADClientTable WHERE AADClientId = '{appId}')
17+
INSERT INTO SysAADClientTable (AADClientId, UserId, Name) VALUES ('{appId}', '{userName}', '{appName}');
18+
";
19+
20+
var sqlQueryExecutor = new SqlQueryExecutor();
21+
22+
try
23+
{
24+
sqlQueryExecutor.Execute(sqlQuery);
25+
}
26+
catch (Exception ex)
27+
{
28+
if (ex.Message.Contains($"No user exists named {userName}"))
29+
{
30+
Console.WriteLine($"\nUser \"{userName}\" does not exist, run Deployment.Setup.exe fullall sync to create it\n");
31+
}
32+
throw;
33+
}
34+
35+
36+
}
37+
}
38+
}

src/ScaleUnitManagement/ScaleUnitFeatureManager/Common/AddToolClientToSysAADClientTable.cs

Lines changed: 0 additions & 42 deletions
This file was deleted.
Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
1+
using System;
2+
using System.Threading.Tasks;
3+
using ScaleUnitManagement.DatabaseManager;
4+
using ScaleUnitManagement.Utilities;
5+
6+
namespace ScaleUnitManagement.ScaleUnitFeatureManager.Hub
7+
{
8+
public sealed class AddToolToHubSysAADClientTable : IHubStep
9+
{
10+
public string Label()
11+
{
12+
return "Add CLI tool App to SysAADClientTable";
13+
}
14+
15+
public float Priority()
16+
{
17+
return 6F;
18+
}
19+
20+
public Task Run()
21+
{
22+
const string UserName = "ScaleUnitManagement";
23+
string hubDb = Config.HubScaleUnit().AxDbName;
24+
var allowListing = new AADAppAllowListing();
25+
26+
try
27+
{
28+
string interAOSAppId = Config.InterAOSAppId();
29+
const string InterAOSAppName = "ScaleUnits";
30+
allowListing.UpdateAADAppClientTable(hubDb, UserName, InterAOSAppName, interAOSAppId);
31+
32+
const string ScaleUnitAppName = "Scale Unit Management Tool";
33+
ScaleUnitInstance scaleUnit = Config.FindScaleUnitWithId(ScaleUnitContext.GetScaleUnitId());
34+
string scaleUnitAppId = scaleUnit.AuthConfiguration.AppId;
35+
allowListing.UpdateAADAppClientTable(hubDb, UserName, ScaleUnitAppName, scaleUnitAppId);
36+
}
37+
catch (Exception ex)
38+
{
39+
Console.WriteLine(ex);
40+
Console.WriteLine("\nFailed to add CLI tool App to SysAADClientTable.");
41+
}
42+
43+
return Task.CompletedTask;
44+
}
45+
}
46+
}
Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
using System;
2+
using System.Threading.Tasks;
3+
using ScaleUnitManagement.DatabaseManager;
4+
using ScaleUnitManagement.Utilities;
5+
6+
namespace ScaleUnitManagement.ScaleUnitFeatureManager.ScaleUnit
7+
{
8+
public sealed class AddToolToScaleUnitSysAADClientTable : IScaleUnitStep
9+
{
10+
public string Label()
11+
{
12+
return "Add CLI tool App to SysAADClientTable";
13+
}
14+
15+
public float Priority()
16+
{
17+
return 6F;
18+
}
19+
20+
public Task Run()
21+
{
22+
const string UserName = "ScaleUnitManagement";
23+
const string ScaleUnitAppName = "Scale Unit Management Tool";
24+
25+
ScaleUnitInstance scaleUnit = Config.FindScaleUnitWithId(ScaleUnitContext.GetScaleUnitId());
26+
string scaleUnitAppId = scaleUnit.AuthConfiguration.AppId;
27+
string dbName = scaleUnit.AxDbName;
28+
29+
var allowListing = new AADAppAllowListing();
30+
31+
try
32+
{
33+
allowListing.UpdateAADAppClientTable(dbName, UserName, ScaleUnitAppName, scaleUnitAppId);
34+
}
35+
catch (Exception ex)
36+
{
37+
Console.WriteLine(ex);
38+
Console.WriteLine("\nFailed to add CLI tool App to SysAADClientTable.");
39+
}
40+
41+
return Task.CompletedTask;
42+
}
43+
}
44+
}

0 commit comments

Comments
 (0)