This class represents a port that needs to be opened in the firewall.
예제 #1
0
        private IList <Firewall.AllowedData> EnablePort(FirewallPort port)
        {
            var allowedData = new Firewall.AllowedData
            {
                IPProtocol = port.ProtocolString,
                Ports      = new List <string> {
                    port.Port.ToString()
                },
            };

            return(new List <Firewall.AllowedData> {
                allowedData
            });
        }
예제 #2
0
        /// <summary>
        /// Creates a firewall rule with the given name that opens up the given port, targetting the very same
        /// name as the target tag. GCE instances with that tag will be affected by this rule.
        /// </summary>
        /// <param name="port">The port to open.</param>
        /// <returns>The task that will be fulfilled once the operation is completed.</returns>
        public async Task CreateFirewall(FirewallPort port)
        {
            try
            {
                var newFirewall = new Firewall
                {
                    Name       = port.Name,
                    Allowed    = EnablePort(port),
                    TargetTags = new List <string> {
                        port.Name
                    },
                };

                var operation = await Service.Firewalls.Insert(newFirewall, ProjectId).ExecuteAsync();
                await WaitAsync(operation);
            }
            catch (GoogleApiException ex)
            {
                Debug.WriteLine($"Failed to create firewall: {ex.Message}");
                throw new DataSourceException(ex.Message, ex);
            }
        }
        private void OnOkCommand()
        {
            var portsToEnable = new List<FirewallPort>();
            var portsToDisable = new List<FirewallPort>();

            foreach (var entry in Ports.Where(x => x.Changed))
            {
                var firewallPort = new FirewallPort(entry.PortInfo.GetTag(_instance), entry.PortInfo.Port);
                if (entry.IsEnabled)
                {
                    portsToEnable.Add(firewallPort);
                }
                else
                {
                    portsToDisable.Add(firewallPort);
                }
            }

            Result = new PortChanges(portsToEnable: portsToEnable, portsToDisable: portsToDisable);

            _owner.Close();
        }