public override void Execute()
{
base.Execute();
if (!this.IsVirtualNetworkGatewayPresent(ResourceGroupName, VirtualNetworkGatewayName))
{
throw new ArgumentException(Microsoft.Azure.Commands.Network.Properties.Resources.ResourceNotFound);
}
var vnetGateway = this.GetVirtualNetworkGateway(this.ResourceGroupName, this.VirtualNetworkGatewayName);
if (vnetGateway.VpnClientConfiguration == null)
{
vnetGateway.VpnClientConfiguration = new PSVpnClientConfiguration();
}
if (vnetGateway.VpnClientConfiguration.VpnClientRevokedCertificates == null)
{
vnetGateway.VpnClientConfiguration.VpnClientRevokedCertificates = new List<PSVpnClientRevokedCertificate>();
}
else
{
// Make sure the same vpn client certificate is not already in the Revoked certificates list on Gateway
PSVpnClientRevokedCertificate vpnClientRevokedCertificate = vnetGateway.VpnClientConfiguration.VpnClientRevokedCertificates.Find(cert => cert.Name.Equals(VpnClientRevokedCertificateName)
&& cert.Thumbprint.Equals(Thumbprint));
if (vpnClientRevokedCertificate != null)
{
throw new ArgumentException("Same vpn client certificate:" + VpnClientRevokedCertificateName + " Thumbprint:" + Thumbprint +
" is already in Revoked certificates list on Gateway! No need to revoke again!");
}
}
PSVpnClientRevokedCertificate newVpnClientCertToRevoke = new PSVpnClientRevokedCertificate()
{
Name = VpnClientRevokedCertificateName,
Thumbprint = Thumbprint
};
vnetGateway.VpnClientConfiguration.VpnClientRevokedCertificates.Add(newVpnClientCertToRevoke);
// Map to the sdk object
var virtualnetGatewayModel = Mapper.Map<MNM.VirtualNetworkGateway>(vnetGateway);
virtualnetGatewayModel.Tags = TagsConversionHelper.CreateTagDictionary(vnetGateway.Tag, validate: true);
this.VirtualNetworkGatewayClient.CreateOrUpdate(ResourceGroupName, VirtualNetworkGatewayName, virtualnetGatewayModel);
var getvirtualnetGateway = this.GetVirtualNetworkGateway(ResourceGroupName, VirtualNetworkGatewayName);
WriteObject(getvirtualnetGateway.VpnClientConfiguration.VpnClientRevokedCertificates, true);
}
}