public override void Execute()
        {
            base.Execute();
            var vnetGateway = this.GetVirtualNetworkGateway(this.ResourceGroupName, this.VirtualNetworkGatewayName);

            if (vnetGateway.VpnClientConfiguration == null)
            {
                throw new ArgumentException(string.Format(Properties.Resources.VirtualNetworkGatewayNoRootCertificate, VirtualNetworkGatewayName));
            }

            if (!string.IsNullOrEmpty(this.VpnClientRootCertificateName))
            {
                PSVpnClientRootCertificate rootCertificate = vnetGateway.VpnClientConfiguration.VpnClientRootCertificates.Find(cert => cert.Name.Equals(VpnClientRootCertificateName));
                if (rootCertificate == null)
                {
                    throw new ArgumentException(string.Format(Properties.Resources.ResourceNotFound, VpnClientRootCertificateName));
                }
                else
                {
                    WriteObject(rootCertificate);
                }
            }
            else
            {
                WriteObject(vnetGateway.VpnClientConfiguration.VpnClientRootCertificates, true);
            }
        }
Exemplo n.º 2
0
        public override void Execute()
        {
            base.Execute();
            var vpnClientRootCertificate = new PSVpnClientRootCertificate();

            vpnClientRootCertificate.Name           = this.Name;
            vpnClientRootCertificate.PublicCertData = this.PublicCertData;

            WriteObject(vpnClientRootCertificate);
        }
        public override void ExecuteCmdlet()
        {
            base.ExecuteCmdlet();

            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.VpnClientRootCertificates == null)
            {
                vnetGateway.VpnClientConfiguration.VpnClientRootCertificates = new List <PSVpnClientRootCertificate>();
            }
            else
            {
                // Make sure the same client Root certificate is not already added on Gateway
                PSVpnClientRootCertificate vpnClientRootCertificate = vnetGateway.VpnClientConfiguration.VpnClientRootCertificates.Find(cert => cert.Name.Equals(VpnClientRootCertificateName) &&
                                                                                                                                        cert.PublicCertData.Equals(PublicCertData));
                if (vpnClientRootCertificate != null)
                {
                    throw new ArgumentException("Same vpn client root client certificate:" + VpnClientRootCertificateName + " PublicCertData:" + PublicCertData +
                                                " is already added on Gateway! No need to add again!");
                }
            }

            PSVpnClientRootCertificate newVpnClientRootCertToAdd = new PSVpnClientRootCertificate()
            {
                Name           = VpnClientRootCertificateName,
                PublicCertData = PublicCertData
            };

            vnetGateway.VpnClientConfiguration.VpnClientRootCertificates.Add(newVpnClientRootCertToAdd);

            // 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.VpnClientRootCertificates, true);
        }
Exemplo n.º 4
0
        public override void ExecuteCmdlet()
        {
            base.ExecuteCmdlet();

            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.VpnClientRootCertificates == null)
            {
                throw new ArgumentException("There are no any vpn client root certificates on Gateway!");
            }

            // Make sure the vpn client root certificate is present on Gateway before calling to Remove it.
            PSVpnClientRootCertificate vpnClientRootCertificate = vnetGateway.VpnClientConfiguration.VpnClientRootCertificates.Find(cert => cert.Name.Equals(VpnClientRootCertificateName) &&
                                                                                                                                    cert.PublicCertData.Equals(PublicCertData));

            if (vpnClientRootCertificate == null)
            {
                throw new ArgumentException("No Vpn client root certificate:" + VpnClientRootCertificateName + " PublicCertData:" + PublicCertData +
                                            " found on Gateway! So, can not proceed with removing it!");
            }

            vnetGateway.VpnClientConfiguration.VpnClientRootCertificates.Remove(vpnClientRootCertificate);

            // 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);

            WriteObject(true);
        }