Skip to content

Commit

Permalink
Merge pull request #28 from webalexeu/cleaning
Browse files Browse the repository at this point in the history
Cleaning code
  • Loading branch information
webalexeu authored Jan 22, 2023
2 parents d54dfe2 + 9afc246 commit 737b272
Show file tree
Hide file tree
Showing 16 changed files with 768 additions and 777 deletions.
4 changes: 4 additions & 0 deletions .rubocop.yml
Original file line number Diff line number Diff line change
Expand Up @@ -517,3 +517,7 @@ Style/RedundantArgument:
Enabled: false
Style/SwapValues:
Enabled: false

# Discard multi-line chains of blocks
Style/MultilineBlockChain:
Enabled: false
12 changes: 12 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,18 @@

All notable changes to this project will be documented in this file.

## Release 1.4.2 (2023-01-22)

[Full Changelog](https://github.com/webalexeu/puppet-windows_firewall/compare/v1.4.1...v1.4.2)

**Features**

- Bug fixes and performance improvements

**Bugfixes**

**Known Issues**

## Release 1.4.1 (2022-12-14)

[Full Changelog](https://github.com/webalexeu/puppet-windows_firewall/compare/v1.4.0...v1.4.1)
Expand Down
52 changes: 27 additions & 25 deletions REFERENCE.md
Original file line number Diff line number Diff line change
Expand Up @@ -104,16 +104,16 @@ Configures how CRL checking is enforced

The following parameters are available in the `windows_firewall_global` type.

* [`name`](#name)
* [`provider`](#provider)
* [`name`](#-windows_firewall_global--name)
* [`provider`](#-windows_firewall_global--provider)

##### <a name="name"></a>`name`
##### <a name="-windows_firewall_global--name"></a>`name`

namevar

Not used (reference only)

##### <a name="provider"></a>`provider`
##### <a name="-windows_firewall_global--provider"></a>`provider`

The specific backend to use for this `windows_firewall_global` resource. You will seldom need to specify this --- Puppet
will usually discover the appropriate provider for your platform.
Expand All @@ -128,7 +128,7 @@ The following properties are available in the `windows_firewall_group` type.

##### `enabled`

Valid values: ``true``, ``false``
Valid values: `true`, `false`

Whether the rule group is enabled (`true` or `false`)

Expand All @@ -138,16 +138,16 @@ Default value: `true`

The following parameters are available in the `windows_firewall_group` type.

* [`name`](#name)
* [`provider`](#provider)
* [`name`](#-windows_firewall_group--name)
* [`provider`](#-windows_firewall_group--provider)

##### <a name="name"></a>`name`
##### <a name="-windows_firewall_group--name"></a>`name`

namevar

Name of the rule group to enable/disable

##### <a name="provider"></a>`provider`
##### <a name="-windows_firewall_group--provider"></a>`provider`

The specific backend to use for this `windows_firewall_group` resource. You will seldom need to specify this --- Puppet
will usually discover the appropriate provider for your platform.
Expand Down Expand Up @@ -176,7 +176,7 @@ Specifies the localized, user-facing name of the firewall rule being created

##### `enabled`

Valid values: ``true``, ``false``
Valid values: `true`, `false`

This parameter specifies that the rule object is administratively enabled or administratively disabled (`true` or `false`)

Expand Down Expand Up @@ -276,16 +276,16 @@ Default value: `any`

The following parameters are available in the `windows_firewall_ipsec_rule` type.

* [`name`](#name)
* [`provider`](#provider)
* [`name`](#-windows_firewall_ipsec_rule--name)
* [`provider`](#-windows_firewall_ipsec_rule--provider)

##### <a name="name"></a>`name`
##### <a name="-windows_firewall_ipsec_rule--name"></a>`name`

namevar

Name of this rule

##### <a name="provider"></a>`provider`
##### <a name="-windows_firewall_ipsec_rule--provider"></a>`provider`

The specific backend to use for this `windows_firewall_ipsec_rule` resource. You will seldom need to specify this ---
Puppet will usually discover the appropriate provider for your platform.
Expand Down Expand Up @@ -348,7 +348,7 @@ Allow remote management of Windows Firewall

##### `state`

Valid values: `on`, `off`, ``true``, ``false``
Valid values: `on`, `off`, `true`, `false`

State of this firewall profile

Expand All @@ -362,16 +362,16 @@ Control stateful unicast response to multicast

The following parameters are available in the `windows_firewall_profile` type.

* [`name`](#name)
* [`provider`](#provider)
* [`name`](#-windows_firewall_profile--name)
* [`provider`](#-windows_firewall_profile--provider)

##### <a name="name"></a>`name`
##### <a name="-windows_firewall_profile--name"></a>`name`

namevar

Name of the profile to work on

##### <a name="provider"></a>`provider`
##### <a name="-windows_firewall_profile--provider"></a>`provider`

The specific backend to use for this `windows_firewall_profile` resource. You will seldom need to specify this ---
Puppet will usually discover the appropriate provider for your platform.
Expand Down Expand Up @@ -428,7 +428,7 @@ Default value: `block`

##### `enabled`

Valid values: ``true``, ``false``
Valid values: `true`, `false`

Whether the rule is enabled (`true` or `false`)

Expand Down Expand Up @@ -499,10 +499,12 @@ Default value: `any`

##### `protocol`

Valid values: `tcp`, `udp`, `icmpv4`, `icmpv6`, `/^(25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)$/`
Valid values: `any`, `tcp`, `udp`, `icmpv4`, `icmpv6`, `/^(25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)$/`

the protocol the rule targets

Default value: `any`

##### `remote_address`

the remote IP the rule targets (hostname not allowed), use an array to pass more then one
Expand Down Expand Up @@ -537,16 +539,16 @@ Default value: `any`

The following parameters are available in the `windows_firewall_rule` type.

* [`name`](#name)
* [`provider`](#provider)
* [`name`](#-windows_firewall_rule--name)
* [`provider`](#-windows_firewall_rule--provider)

##### <a name="name"></a>`name`
##### <a name="-windows_firewall_rule--name"></a>`name`

namevar

Name of this rule

##### <a name="provider"></a>`provider`
##### <a name="-windows_firewall_rule--provider"></a>`provider`

The specific backend to use for this `windows_firewall_rule` resource. You will seldom need to specify this --- Puppet
will usually discover the appropriate provider for your platform.
Expand Down
18 changes: 8 additions & 10 deletions lib/puppet/provider/windows_firewall_global/ruby.rb
Original file line number Diff line number Diff line change
@@ -1,16 +1,16 @@
require 'puppet_x'
require_relative '../../../puppet_x/windows_firewall'

Puppet::Type.type(:windows_firewall_global).provide(:windows_firewall_global, :parent => Puppet::Provider) do
confine :osfamily => :windows
Puppet::Type.type(:windows_firewall_global).provide(:windows_firewall_global, parent: Puppet::Provider) do
confine osfamily: :windows
mk_resource_methods
desc 'Windows Firewall global settings'

commands :cmd => 'netsh'
commands cmd: 'netsh'

def self.prefetch(resources)
instances.each do |prov|
if resource = resources[prov.name]
if (resource = resources[prov.name])
resource.provider = prov
end
end
Expand All @@ -28,7 +28,7 @@ def create; end
def destroy; end

def self.instances
PuppetX::WindowsFirewall.globals(command(:cmd)).collect { |hash| new(hash) }
PuppetX::WindowsFirewall.globals(command(:cmd)).map { |hash| new(hash) }
end

def flush
Expand All @@ -41,9 +41,8 @@ def flush
:boottimerulecategory,
:firewallrulecategory,
:stealthrulecategory,
:consecrulecategory
].include?(property.name)
}.each { |property|
:consecrulecategory].include?(property.name)
}.each do |property|
property_name = PuppetX::WindowsFirewall.global_argument_lookup(property.name)
property_value = property.value.instance_of?(Array) ? property.value.join(',') : property.value

Expand All @@ -53,7 +52,6 @@ def flush
cmd = "#{command(:cmd)} advfirewall set global #{arg}"
output = execute(cmd).to_s
Puppet.debug("...#{output}")
}
end
end

end
13 changes: 6 additions & 7 deletions lib/puppet/provider/windows_firewall_group/ruby.rb
Original file line number Diff line number Diff line change
@@ -1,16 +1,16 @@
require 'puppet_x'
require_relative '../../../puppet_x/windows_firewall'

Puppet::Type.type(:windows_firewall_group).provide(:windows_firewall_group, :parent => Puppet::Provider) do
confine :osfamily => :windows
Puppet::Type.type(:windows_firewall_group).provide(:windows_firewall_group, parent: Puppet::Provider) do
confine osfamily: :windows
mk_resource_methods
desc 'Windows Firewall group'

commands :cmd => 'netsh'
commands cmd: 'netsh'

def self.prefetch(resources)
instances.each do |prov|
if resource = resources[prov.name]
if (resource = resources[prov.name])
resource.provider = prov
end
end
Expand All @@ -28,7 +28,7 @@ def create; end
def destroy; end

def self.instances
PuppetX::WindowsFirewall.groups.collect { |hash| new(hash) }
PuppetX::WindowsFirewall.groups.map { |hash| new(hash) }
end

def flush
Expand All @@ -37,12 +37,11 @@ def flush
# to inspect @resource instead

# careful its a label not a boolean...
netsh_enabled = (@resource[:enabled] == :true)? 'yes': 'no'
netsh_enabled = (@resource[:enabled] == :true) ? 'yes' : 'no'

Puppet.notice("(windows_firewall) group '#{@resource[:name]}' enabled: #{@resource[:enabled]}")
cmd = "#{command(:cmd)} advfirewall firewall set rule group=\"#{@resource[:name]}\" new enable=\"#{netsh_enabled}\""
output = execute(cmd).to_s
Puppet.debug("...#{output}")
end

end
14 changes: 6 additions & 8 deletions lib/puppet/provider/windows_firewall_ipsec_rule/ruby.rb
Original file line number Diff line number Diff line change
@@ -1,14 +1,14 @@
require 'puppet_x'
require_relative '../../../puppet_x/windows_firewall_ipsec'

Puppet::Type.type(:windows_firewall_ipsec_rule).provide(:windows_firewall_ipsec_rule, :parent => Puppet::Provider) do
confine :osfamily => :windows
Puppet::Type.type(:windows_firewall_ipsec_rule).provide(:windows_firewall_ipsec_rule, parent: Puppet::Provider) do
confine osfamily: :windows
mk_resource_methods
desc 'Windows Firewall'

def self.prefetch(resources)
instances.each do |prov|
if resource = resources[prov.name]
if (resource = resources[prov.name])
resource.provider = prov
end
end
Expand All @@ -27,16 +27,14 @@ def destroy
end

def self.instances
PuppetX::WindowsFirewallIPSec.rules.collect { |hash| new(hash) }
PuppetX::WindowsFirewallIPSec.rules.map { |hash| new(hash) }
end

def flush
# Update rule
# Only if IS value ensure == SHOULD value ensure
# @property_hash contains the IS values (thanks Gary!). For new rules there is no IS, there is only the SHOULD
if @property_hash[:ensure] == @resource[:ensure]
PuppetX::WindowsFirewallIPSec.update_rule @resource
end
return unless @property_hash[:ensure] == @resource[:ensure]
PuppetX::WindowsFirewallIPSec.update_rule @resource
end

end
16 changes: 7 additions & 9 deletions lib/puppet/provider/windows_firewall_profile/ruby.rb
Original file line number Diff line number Diff line change
@@ -1,16 +1,16 @@
require 'puppet_x'
require_relative '../../../puppet_x/windows_firewall'

Puppet::Type.type(:windows_firewall_profile).provide(:windows_firewall_profile, :parent => Puppet::Provider) do
confine :osfamily => :windows
Puppet::Type.type(:windows_firewall_profile).provide(:windows_firewall_profile, parent: Puppet::Provider) do
confine osfamily: :windows
mk_resource_methods
desc 'Windows Firewall profile'

commands :cmd => 'netsh'
commands cmd: 'netsh'

def self.prefetch(resources)
instances.each do |prov|
if resource = resources[prov.name]
if (resource = resources[prov.name])
resource.provider = prov
end
end
Expand All @@ -27,16 +27,15 @@ def create; end
# all work done in `flush()` method
def destroy; end


def self.instances
PuppetX::WindowsFirewall.profiles(command(:cmd)).collect { |hash| new(hash) }
PuppetX::WindowsFirewall.profiles(command(:cmd)).map { |hash| new(hash) }
end

def flush
# @property_hash contains the `IS` values (thanks Gary!)... For new rules there is no `IS`, there is only the
# `SHOULD`. The setter methods from `mk_resource_methods` (or manually created) won't be called either. You have
# to inspect @resource instead
@resource.properties.each { |property|
@resource.properties.each do |property|
property_name = PuppetX::WindowsFirewall.profile_argument_lookup(property.name)
property_value = property.value

Expand All @@ -45,7 +44,6 @@ def flush
cmd = "#{command(:cmd)} advfirewall set #{@resource[:name]}profile #{arg}"
output = execute(cmd).to_s
Puppet.debug("...#{output}")
}
end
end

end
Loading

0 comments on commit 737b272

Please sign in to comment.