Skip to content

Commit

Permalink
Delete and Create vpn connection if profile changed instead of using …
Browse files Browse the repository at this point in the history
…Session.ModifyInstance().
  • Loading branch information
rinrab committed Jan 6, 2024
1 parent 23e4502 commit 345d01c
Show file tree
Hide file tree
Showing 7 changed files with 12 additions and 37 deletions.
6 changes: 4 additions & 2 deletions AOVpnManager.Tests/GpUpdateProcessorTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -39,10 +39,12 @@ public void Test()
mocks.BackToRecordAll();

vpnManager.Expect(x => x.EnumarateVpnConnections()).Return(new VpnConnectionInfo[] { new VpnConnectionInfo("Name 1", "Profile 1") });
vpnManager.Expect(x => x.UpdateVpnConnection("Name 1", "Profile 2"));
vpnManager.Expect(x => x.DeleteVpnConnection("Name 1"));
vpnManager.Expect(x => x.CreateVpnConnection("Name 1", "Profile 2"));
policyProvider.Expect(x => x.ReadSettings()).Return(new GroupPolicySettings("Profile 2", "Name 1"));
logger.Expect(x => x.Trace(null)).Repeat.Any().IgnoreArguments();
logger.Expect(x => x.VpnConnectionUpdated("Name 1"));
logger.Expect(x => x.VpnConnectionDeleted("Name 1"));
logger.Expect(x => x.VpnConnectionCreated("Name 1"));

mocks.ReplayAll();

Expand Down
5 changes: 0 additions & 5 deletions AOVpnManager/ConsoleLogger.cs
Original file line number Diff line number Diff line change
Expand Up @@ -24,11 +24,6 @@ public void VpnConnectionCreated(string connectionName)
Console.WriteLine("Vpn connection \"{0}\" created.", connectionName);
}

public void VpnConnectionUpdated(string connectionName)
{
Console.WriteLine("Vpn connection \"{0}\" updated.", connectionName);
}

public void VpnConnectionDeleted(string connectionName)
{
Console.WriteLine("Vpn connection \"{0}\" deleted.", connectionName);
Expand Down
6 changes: 0 additions & 6 deletions AOVpnManager/EventSourceLogger.cs
Original file line number Diff line number Diff line change
Expand Up @@ -29,12 +29,6 @@ public void VpnConnectionCreated(string connectionName)
WriteEvent(4, connectionName);
}

[Event(5, Level = EventLevel.Informational, Channel = EventChannel.Operational, Message = "Vpn connection \"{0}\" updated.")]
public void VpnConnectionUpdated(string connectionName)
{
WriteEvent(5, connectionName);
}

[Event(6, Level = EventLevel.Informational, Channel = EventChannel.Operational, Message = "Vpn connection \"{0}\" deleted.")]
public void VpnConnectionDeleted(string connectionName)
{
Expand Down
12 changes: 8 additions & 4 deletions AOVpnManager/GpUpdateProcessor.cs
Original file line number Diff line number Diff line change
Expand Up @@ -58,16 +58,20 @@ public void Run()

if (oldConnection == null)
{
stateManager.SetLastConnectionName(settings.VpnConnectionName);
vpnManager.CreateVpnConnection(settings.VpnConnectionName, settings.VpnProfileXml);
logger.VpnConnectionCreated(settings.VpnConnectionName);
}
else
{
vpnManager.UpdateVpnConnection(settings.VpnConnectionName, settings.VpnProfileXml);
logger.VpnConnectionUpdated(settings.VpnConnectionName);
}
stateManager.SetLastConnectionName(null);
vpnManager.DeleteVpnConnection(lastConnectionName);
logger.VpnConnectionDeleted(lastConnectionName);

stateManager.SetLastConnectionName(settings.VpnConnectionName);
stateManager.SetLastConnectionName(settings.VpnConnectionName);
vpnManager.CreateVpnConnection(settings.VpnConnectionName, settings.VpnProfileXml);
logger.VpnConnectionCreated(settings.VpnConnectionName);
}
}
}

Expand Down
1 change: 0 additions & 1 deletion AOVpnManager/ILogger.cs
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@ public interface ILogger
void Finished(int code);
void Started();
void VpnConnectionCreated(string connectionName);
void VpnConnectionUpdated(string connectionName);
void Trace(string message);
void VpnConnectionDeleted(string connectionName);
}
Expand Down
1 change: 0 additions & 1 deletion AOVpnManager/IVpnManager.cs
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,5 @@ public interface IVpnManager : IDisposable
void CreateVpnConnection(string connectionName, string profile);
void DeleteVpnConnection(string connectionName);
IEnumerable<VpnConnectionInfo> EnumarateVpnConnections();
void UpdateVpnConnection(string connectionName, string profile);
}
}
18 changes: 0 additions & 18 deletions AOVpnManager/VpnManager.cs
Original file line number Diff line number Diff line change
Expand Up @@ -46,24 +46,6 @@ public void CreateVpnConnection(string connectionName, string profile)
}
}


public void UpdateVpnConnection(string connectionName, string profile)
{
try
{
using (CimInstance newInstance = new CimInstance(ClassName, NamespaceName))
{
AddKeyPropertiesToVpnConnection(newInstance, connectionName);
AddValuePropertiesToVpnConnection(newInstance, profile);
session.ModifyInstance(NamespaceName, newInstance);
}
}
catch (CimException ex)
{
throw ConvertCimException(ex);
}
}

public void DeleteVpnConnection(string connectionName)
{
try
Expand Down

0 comments on commit 345d01c

Please sign in to comment.