Skip to content

Commit

Permalink
Apply cookstyle
Browse files Browse the repository at this point in the history
  • Loading branch information
Annih committed Jul 30, 2024
1 parent e154ca9 commit aed413e
Show file tree
Hide file tree
Showing 20 changed files with 63 additions and 84 deletions.
2 changes: 1 addition & 1 deletion attributes/configure.rb
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
#
# Author:: Baptiste Courtois (<[email protected]>)
# Cookbook Name:: wsus-server
# Cookbook:: wsus-server
# Attribute:: server_configuration
#
# Copyright:: Copyright (c) 2014 Criteo.
Expand Down
2 changes: 1 addition & 1 deletion attributes/freeze.rb
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
#
# Author:: Baptiste Courtois (<[email protected]>)
# Cookbook Name:: wsus-server
# Cookbook:: wsus-server
# Attribute:: freeze
#
# Copyright:: Copyright (c) 2014 Criteo.
Expand Down
2 changes: 1 addition & 1 deletion attributes/install.rb
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
#
# Author:: Baptiste Courtois (<[email protected]>)
# Cookbook Name:: wsus-server
# Cookbook:: wsus-server
# Attribute:: install
#
# Copyright:: Copyright (c) 2014 Criteo.
Expand Down
2 changes: 1 addition & 1 deletion attributes/report_viewer.rb
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
#
# Author:: Baptiste Courtois (<[email protected]>)
# Cookbook Name:: wsus-server
# Cookbook:: wsus-server
# Attribute:: report_viewer
#
# Copyright:: Copyright (c) 2014 Criteo.
Expand Down
2 changes: 1 addition & 1 deletion attributes/synchronize.rb
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
#
# Author:: Baptiste Courtois (<[email protected]>)
# Cookbook Name:: wsus-server
# Cookbook:: wsus-server
# Attribute:: synchronize
#
# Copyright:: Copyright (c) 2014 Criteo.
Expand Down
10 changes: 3 additions & 7 deletions libraries/base_provider.rb
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
#
# Author:: Baptiste Courtois (<[email protected]>)
# Cookbook Name:: wsus-server
# Cookbook:: wsus-server
# Library:: base_provider
#
# Copyright:: Copyright (c) 2014 Criteo.
Expand All @@ -26,10 +26,6 @@ module BaseProvider
include Chef::Mixin::ShellOut
include Windows::Helper

def whyrun_supported?
true
end

def self.uri_to_wsus_endpoint_params(uri)
uri = URI uri
"'#{uri.host}', #{'https'.casecmp(uri.scheme).zero?}, #{uri.port}"
Expand All @@ -54,7 +50,7 @@ def powershell
locate_sysnative_cmd('powershell.exe')
end

def powershell_out64(cmd, timeout=300)
def powershell_out64(cmd, timeout = 300)
flags = [
# Hides the copyright banner at startup.
'-NoLogo',
Expand All @@ -76,7 +72,7 @@ def powershell_out64(cmd, timeout=300)
# => https://msdn.microsoft.com/en-us/library/windows/desktop/aa384187.aspx
cmd = shell_out "#{powershell} #{flags.join(' ')} -EncodedCommand #{encoded_command}", timeout: timeout
cmd.error!
fail 'Invalid syntax in PowershellScript' if cmd.stderr && cmd.stderr.include?('ParserError')
raise 'Invalid syntax in PowershellScript' if cmd.stderr && cmd.stderr.include?('ParserError')
cmd
end

Expand Down
21 changes: 6 additions & 15 deletions libraries/base_resource.rb
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
#
# Author:: Baptiste Courtois (<[email protected]>)
# Cookbook Name:: wsus-server
# Cookbook:: wsus-server
# Library:: base_resource
#
# Copyright:: Copyright (c) 2014 Criteo.
Expand All @@ -22,15 +22,6 @@ module WsusServer
module BaseResource
require 'uri'

def initialize(name, run_context = nil)
super(name, run_context)

@action = :configure
@allowed_actions.push(:configure)

@properties = {}
end

def endpoint(uri = nil)
@endpoint = validate_http_uri('endpoint', uri) unless uri.nil?
@endpoint
Expand All @@ -43,7 +34,7 @@ def properties(arg = nil)

def validate_string(name, value, values)
unless values.include? value
fail RangeError, "Invalid value for '#{name}', accepted values are '#{values.join('\', \'')}'"
raise RangeError, "Invalid value for '#{name}', accepted values are '#{values.join('\', \'')}'"
end
value
end
Expand All @@ -52,29 +43,29 @@ def validate_http_uri(name, value)
uri = URI value
uri = URI 'http://' + value unless uri.scheme # also validate the emptyness of the host
unless %w(http https).include? uri.scheme.to_s.downcase
fail ArgumentError, "Invalid scheme for '#{name}' URI, accepted schemes are 'http' and 'https'"
raise ArgumentError, "Invalid scheme for '#{name}' URI, accepted schemes are 'http' and 'https'"
end
uri
end

def validate_boolean(name, value)
unless value.is_a?(TrueClass) || value.is_a?(FalseClass)
fail TypeError, "Invalid value for '#{name}' expecting 'True' or 'False'"
raise TypeError, "Invalid value for '#{name}' expecting 'True' or 'False'"
end
value
end

def validate_time(name, value)
unless value =~ /^([01]?[0-9]|2[0-3])(\:[0-5][0-9]){1,2}$/
fail ArgumentError, "Invalid value for '#{name}', format is: 'HH:MM:SS'"
raise ArgumentError, "Invalid value for '#{name}', format is: 'HH:MM:SS'"
end
value
end

def validate_integer(name, value, min, max)
i = value.to_i
unless i >= min && i <= max && value.to_s =~ /^\d+$/
fail ArgumentError, "Invalid value for '#{name}', value must be between #{min} and #{max}"
raise ArgumentError, "Invalid value for '#{name}', value must be between #{min} and #{max}"
end
i
end
Expand Down
7 changes: 3 additions & 4 deletions metadata.rb
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,10 @@
maintainer_email '[email protected]'
license 'Apache-2.0'
description 'Installs wsus server'
long_description IO.read(File.join(File.dirname(__FILE__), 'README.md'))
version '2.3.2'
supports 'windows'
depends 'windows'

chef_version '>= 12.1' if respond_to?(:chef_version)
source_url 'https://github.com/criteo-cookbooks/wsus-server' if respond_to?(:source_url)
issues_url 'https://github.com/criteo-cookbooks/wsus-server/issues' if respond_to?(:issues_url)
chef_version '>= 12.1'
source_url 'https://github.com/criteo-cookbooks/wsus-server'
issues_url 'https://github.com/criteo-cookbooks/wsus-server/issues'
3 changes: 1 addition & 2 deletions providers/configuration.rb
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
#
# Author:: Baptiste Courtois (<[email protected]>)
# Cookbook Name:: wsus-server
# Cookbook:: wsus-server
# Provider:: configuration
#
# Copyright:: Copyright (c) 2014 Criteo.
Expand All @@ -17,7 +17,6 @@
# See the License for the specific language governing permissions and
# limitations under the License.
#
use_inline_resources

include WsusServer::BaseProvider

Expand Down
3 changes: 1 addition & 2 deletions providers/notification.rb
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
#
# Author:: Baptiste Courtois (<[email protected]>)
# Cookbook Name:: wsus-server
# Cookbook:: wsus-server
# Provider:: notification
#
# Copyright:: Copyright (c) 2014 Criteo.
Expand All @@ -17,7 +17,6 @@
# See the License for the specific language governing permissions and
# limitations under the License.
#
use_inline_resources

include WsusServer::BaseProvider

Expand Down
3 changes: 1 addition & 2 deletions providers/subscription.rb
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
#
# Author:: Baptiste Courtois (<[email protected]>)
# Cookbook Name:: wsus-server
# Cookbook:: wsus-server
# Provider:: subscription
#
# Copyright:: Copyright (c) 2014 Criteo.
Expand All @@ -17,7 +17,6 @@
# See the License for the specific language governing permissions and
# limitations under the License.
#
use_inline_resources

include WsusServer::BaseProvider

Expand Down
2 changes: 1 addition & 1 deletion recipes/configure.rb
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
#
# Author:: Baptiste Courtois (<[email protected]>)
# Cookbook Name:: wsus-server
# Cookbook:: wsus-server
# Recipe:: configure
#
# Copyright:: Copyright (c) 2014 Criteo.
Expand Down
2 changes: 1 addition & 1 deletion recipes/default.rb
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
#
# Author:: Baptiste Courtois (<[email protected]>)
# Cookbook Name:: wsus-server
# Cookbook:: wsus-server
# Recipe:: default
#
# Copyright:: Copyright (c) 2014 Criteo.
Expand Down
6 changes: 2 additions & 4 deletions recipes/freeze.rb
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
#
# Author:: Baptiste Courtois (<[email protected]>)
# Cookbook Name:: wsus
# Cookbook:: wsus
# Attribute:: server_freeze
#
# Copyright:: Copyright (c) 2014 Criteo.
Expand All @@ -22,10 +22,9 @@

include_recipe 'wsus-server::install'


freeze = node['wsus_server']['freeze']['name']

powershell_script 'WSUS Update Freeze' do # ~FC009
powershell_script 'WSUS Update Freeze' do
code <<-EOH
[Reflection.Assembly]::LoadWithPartialName('Microsoft.UpdateServices.Administration') | Out-Null
$wsus = [Microsoft.UpdateServices.Administration.AdminProxy]::GetUpdateServer()
Expand All @@ -51,7 +50,6 @@
}
}
EOH
guard_interpreter :powershell_script
only_if <<-EOH
[Reflection.Assembly]::LoadWithPartialName('Microsoft.UpdateServices.Administration') | Out-Null
$wsus = [Microsoft.UpdateServices.Administration.AdminProxy]::GetUpdateServer()
Expand Down
14 changes: 7 additions & 7 deletions recipes/install.rb
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
#
# Author:: Baptiste Courtois (<[email protected]>)
# Cookbook Name:: wsus-server
# Cookbook:: wsus-server
# Recipe:: install
#
# Copyright:: Copyright (c) 2014 Criteo.
Expand All @@ -24,11 +24,11 @@

setup_options = ''
if setup_conf['sqlinstance_name']
if node['platform_version'].to_f >= 6.2
setup_options << " SQL_INSTANCE_NAME=\"#{setup_conf['sqlinstance_name']}\""
else
setup_options << " SQLINSTANCE_NAME=\"#{setup_conf['sqlinstance_name']}\""
end
setup_options << if node['platform_version'].to_f >= 6.2
" SQL_INSTANCE_NAME=\"#{setup_conf['sqlinstance_name']}\""
else
" SQLINSTANCE_NAME=\"#{setup_conf['sqlinstance_name']}\""
end
end

if setup_conf['content_dir']
Expand Down Expand Up @@ -130,4 +130,4 @@
end

# Wsus does not need configuration when setup as frontend server
include_recipe 'wsus-server::configure' unless setup_conf['frontend_setup']
include_recipe 'wsus-server::configure' unless setup_conf['frontend_setup']
2 changes: 1 addition & 1 deletion recipes/report_viewer.rb
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
#
# Author:: Baptiste Courtois (<[email protected]>)
# Cookbook Name:: wsus-server
# Cookbook:: wsus-server
# Recipe:: report_viewer
#
# Copyright:: Copyright (c) 2014 Criteo.
Expand Down
2 changes: 1 addition & 1 deletion recipes/synchronize.rb
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
#
# Author:: Baptiste Courtois (<[email protected]>)
# Cookbook Name:: wsus-server
# Cookbook:: wsus-server
# Attribute:: synchronize
#
# Copyright:: Copyright (c) 2014 Criteo.
Expand Down
15 changes: 6 additions & 9 deletions resources/configuration.rb
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
#
# Author:: Baptiste Courtois (<[email protected]>)
# Cookbook Name:: wsus-server
# Cookbook:: wsus-server
# Resource:: configuration
#
# Copyright:: Copyright (c) 2014 Criteo.
Expand All @@ -20,10 +20,15 @@
include WsusServer::BaseResource

default_action :configure
unified_mode true

property :proxy_password, String
property :update_languages, Array

def initialize(name, run_context = nil)
super(name, run_context)

@properties = {}
# Default computed value for master_server is nil
@properties['UpstreamWsusServerName'] = nil
@properties['SyncFromMicrosoftUpdate'] = true
Expand All @@ -50,11 +55,3 @@ def master_server(arg = nil)
@properties['IsReplicaServer'] = true
end
end

def proxy_password(arg = nil)
set_or_return(:proxy_password, arg, kind_of: String)
end

def update_languages(arg = nil)
set_or_return(:update_languages, arg, kind_of: Array)
end
17 changes: 11 additions & 6 deletions resources/notification.rb
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
#
# Author:: Baptiste Courtois (<[email protected]>)
# Cookbook Name:: wsus-server
# Cookbook:: wsus-server
# Resource:: notification
#
# Copyright:: Copyright (c) 2014 Criteo.
Expand All @@ -20,8 +20,17 @@
include WsusServer::BaseResource

default_action :configure
unified_mode true

FREQUENCY_VALUES = %w(Daily Weekly)
FREQUENCY_VALUES = %w(Daily Weekly).freeze

property :smtp_password, String

def initialize(name, run_context = nil)
super(name, run_context)

@properties = {}
end

def enable_sync_notification(arg = nil)
if arg.nil?
Expand Down Expand Up @@ -79,10 +88,6 @@ def smtp_host(arg = nil)
end
end

def smtp_password(arg = nil)
set_or_return(:smtp_password, arg, kind_of: String)
end

def smtp_port(arg = nil)
if arg.nil?
@properties['SmtpPort']
Expand Down
Loading

0 comments on commit aed413e

Please sign in to comment.