Example #1
0
        public override void Execute()
        {
            base.Execute();

            PSP2SVpnGateway existingP2SVpnGateway = null;

            if (ParameterSetName.Equals(CortexParameterSetNames.ByP2SVpnGatewayObject, StringComparison.OrdinalIgnoreCase))
            {
                existingP2SVpnGateway  = this.InputObject;
                this.ResourceGroupName = this.InputObject.ResourceGroupName;
                this.Name = this.InputObject.Name;
            }
            else
            {
                if (ParameterSetName.Equals(CortexParameterSetNames.ByP2SVpnGatewayResourceId, StringComparison.OrdinalIgnoreCase))
                {
                    var parsedResourceId = new ResourceIdentifier(ResourceId);
                    Name = parsedResourceId.ResourceName;
                    ResourceGroupName = parsedResourceId.ResourceGroupName;
                }

                existingP2SVpnGateway = this.GetP2SVpnGateway(this.ResourceGroupName, this.Name);
            }

            if (existingP2SVpnGateway == null)
            {
                throw new PSArgumentException(Properties.Resources.P2SVpnGatewayNotFound);
            }

            PSP2SVpnProfileParameters p2sVpnProfileParams = new PSP2SVpnProfileParameters();

            p2sVpnProfileParams.AuthenticationMethod = string.IsNullOrWhiteSpace(this.AuthenticationMethod)
                ? MNM.AuthenticationMethod.EAPTLS.ToString()
                : this.AuthenticationMethod;

            var p2sVpnProfileParametersModel = NetworkResourceManagerProfile.Mapper.Map <MNM.P2SVpnProfileParameters>(p2sVpnProfileParams);

            // There may be a required Json serialize for the package URL to conform to REST-API
            // The try-catch below handles the case till the change is made and deployed to PROD
            string serializedPackageUrl = this.NetworkClient.GenerateP2SVpnGatewayVpnProfile(this.ResourceGroupName, this.Name, p2sVpnProfileParametersModel);

            MNM.VpnProfileResponse p2sVpnGatewayVpnProfile = new MNM.VpnProfileResponse();
            try
            {
                p2sVpnGatewayVpnProfile = JsonConvert.DeserializeObject <MNM.VpnProfileResponse>(serializedPackageUrl);
            }
            catch (Exception e)
            {
                Console.WriteLine(e.Message);
            }

            PSVpnProfileResponse vpnProfileResponse = new PSVpnProfileResponse()
            {
                ProfileUrl = p2sVpnGatewayVpnProfile?.ProfileUrl
            };

            WriteObject(vpnProfileResponse);
        }
Example #2
0
        public override void Execute()
        {
            base.Execute();

            PSVirtualWan virtualWan = null;

            if (ParameterSetName.Contains(CortexParameterSetNames.ByVirtualWanObject))
            {
                virtualWan             = this.VirtualWanObject;
                this.ResourceGroupName = this.VirtualWanObject.ResourceGroupName;
                this.Name = this.VirtualWanObject.Name;
            }
            else
            {
                if (ParameterSetName.Contains(CortexParameterSetNames.ByVirtualWanResourceId))
                {
                    var parsedResourceId = new ResourceIdentifier(this.ResourceId);
                    this.Name = parsedResourceId.ResourceName;
                    this.ResourceGroupName = parsedResourceId.ResourceGroupName;
                }

                virtualWan = GetVirtualWan(this.ResourceGroupName, this.Name);
            }

            if (virtualWan == null)
            {
                throw new PSArgumentException(Properties.Resources.VirtualWanNotFound);
            }

            PSVirtualWanVpnProfileParameters virtualWanVpnProfileParams = new PSVirtualWanVpnProfileParameters();

            virtualWanVpnProfileParams.AuthenticationMethod = string.IsNullOrWhiteSpace(this.AuthenticationMethod)
                ? MNM.AuthenticationMethod.EAPTLS.ToString()
                : this.AuthenticationMethod;

            if (this.VpnServerConfiguration != null)
            {
                virtualWanVpnProfileParams.VpnServerConfigurationResourceId = this.VpnServerConfiguration.Id;
            }

            var virtualWanVpnProfileParametersModel = NetworkResourceManagerProfile.Mapper.Map <MNM.VirtualWanVpnProfileParameters>(virtualWanVpnProfileParams);

            // There may be a required Json serialize for the package URL to conform to REST-API
            // The try-catch below handles the case till the change is made and deployed to PROD
            string serializedPackageUrl = this.NetworkClient.GenerateVirtualWanVpnProfile(this.ResourceGroupName, this.Name, virtualWanVpnProfileParametersModel);

            MNM.VpnProfileResponse vpnProfile = new MNM.VpnProfileResponse();
            try
            {
                vpnProfile = JsonConvert.DeserializeObject <MNM.VpnProfileResponse>(serializedPackageUrl);
            }
            catch (Exception e)
            {
                Console.WriteLine(e.Message);
            }

            PSVpnProfileResponse vpnProfileResponse = new PSVpnProfileResponse()
            {
                ProfileUrl = vpnProfile.ProfileUrl
            };

            WriteObject(vpnProfileResponse);
        }