Skip to content

Commit ac14817

Browse files
committed
Update cookstyle to v8
Signed-off-by: Dan Webb <[email protected]>
1 parent 6f8a993 commit ac14817

File tree

12 files changed

+100
-95
lines changed

12 files changed

+100
-95
lines changed

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@ _Store
2525
.rvmrc
2626
Gemfile.lock
2727
.bundle
28+
/bin/
2829
*.gem
2930
coverage
3031
spec/reports

.mise.toml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
[env]
2+
_.path = ["{{config_root}}/bin", "/opt/chef-workstation/bin"]

.tool-versions

Lines changed: 0 additions & 1 deletion
This file was deleted.

Gemfile

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
source 'https://rubygems.org'
2+
3+
gem 'cookstyle'

libraries/helpers_network.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ def ip_address_from_container_networks(container)
1515
# It might also not match the new_resource value
1616
if container.info['NetworkSettings'] &&
1717
container.info['NetworkSettings']['Networks'] &&
18-
container.info['NetworkSettings']['Networks'].values[0] &&
18+
container.info['NetworkSettings']['Networks'].values.first &&
1919
container.info['NetworkSettings']['Networks'].values[0]['IPAMConfig'] &&
2020
container.info['NetworkSettings']['Networks'].values[0]['IPAMConfig']['IPv4Address']
2121
# Return the ip address listed

libraries/helpers_service.rb

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -117,10 +117,10 @@ def coerce_daemon_labels(v)
117117
Array(v).each_with_object([]) do |label, a|
118118
if label =~ /:/
119119
parts = label.split(':')
120-
a << "#{parts[0]}=\"#{parts[1]}\""
120+
a << "#{parts.first}=\"#{parts[1]}\""
121121
elsif label =~ /=/
122122
parts = label.split('=')
123-
a << "#{parts[0]}=#{parts[1]}"
123+
a << "#{parts.first}=#{parts[1]}"
124124
else
125125
Chef::Log.info("WARNING: docker_service label #{label} not valid")
126126
end

resources/container.rb

Lines changed: 74 additions & 74 deletions
Original file line numberDiff line numberDiff line change
@@ -73,7 +73,7 @@
7373
property :sysctls, Hash, default: {}
7474
property :timeout, Integer, desired_state: false
7575
property :tmpfs, [Hash, Array], default: {}, coerce: proc { |v| coerce_tmpfs(v) },
76-
description: 'A hash or array of tmpfs mounts to add to the container. Hash format: { "/path" => "size=100M,uid=1000" }. Array format: ["/path", "/path2"]. See https://docs.docker.com/storage/tmpfs/'
76+
description: 'A hash or array of tmpfs mounts to add to the container. Hash format: { "/path" => "size=100M,uid=1000" }. Array format: ["/path", "/path2"]. See https://docs.docker.com/storage/tmpfs/'
7777
property :tty, [true, false], default: false
7878
property :ulimits, [Array, nil], coerce: proc { |v| coerce_ulimits(v) }
7979
property :user, String
@@ -87,7 +87,7 @@
8787
property :gpu_driver, String, default: 'nvidia', description: 'GPU driver to use for container (e.g., nvidia)'
8888

8989
# Used to store the bind property since binds is an alias to volumes
90-
property :volumes_binds, Array, coerce: proc { |v| v.sort }
90+
property :volumes_binds, Array, coerce: proc(&:sort)
9191

9292
# Used to store the state of the Docker container
9393
property :container, Docker::Container, desired_state: false
@@ -206,7 +206,7 @@ def coerce_volumes(v)
206206
PartialHash[v]
207207
else
208208
b = []
209-
v = Array(v).to_a # in case v.is_A?(Chef::Node::ImmutableArray)
209+
v = Array(v) # in case v.is_A?(Chef::Node::ImmutableArray)
210210
v.delete_if do |x|
211211
parts = x.split(':')
212212
b << x if parts.length > 1
@@ -260,27 +260,27 @@ def parse_port(v)
260260
parts = v.split(':')
261261
case parts.length
262262
when 3
263-
host_ip = parts[0]
263+
host_ip = parts.first
264264
host_port = parts[1].split('-')
265265
container_port = parts[2].split('-')
266266
when 2
267267
host_ip = '0.0.0.0'
268-
host_port = parts[0].split('-')
268+
host_port = parts.first.split('-')
269269
container_port = parts[1].split('-')
270270
when 1
271271
host_ip = ''
272272
host_port = ['']
273-
container_port = parts[0].split('-')
273+
container_port = parts.first.split('-')
274274
end
275275
host_port.map!(&:to_i) unless host_port == ['']
276276
container_port.map!(&:to_i)
277277
if host_port.count > 1
278-
Chef::Log.fatal("FATAL: Invalid port range! #{host_port}") if host_port[0] > host_port[1]
279-
host_port = (host_port[0]..host_port[1]).to_a
278+
Chef::Log.fatal("FATAL: Invalid port range! #{host_port}") if host_port.first > host_port[1]
279+
host_port = (host_port.first..host_port[1]).to_a
280280
end
281281
if container_port.count > 1
282-
Chef::Log.fatal("FATAL: Invalid port range! #{container_port}") if container_port[0] > container_port[1]
283-
container_port = (container_port[0]..container_port[1]).to_a
282+
Chef::Log.fatal("FATAL: Invalid port range! #{container_port}") if container_port.first > container_port[1]
283+
container_port = (container_port.first..container_port[1]).to_a
284284
end
285285
Chef::Log.fatal('FATAL: Port range size does not match!') if host_port.count > 1 && host_port.count != container_port.count
286286
# qualify the port-binding protocol even when it is implicitly tcp #427.
@@ -408,7 +408,7 @@ def to_snake_case(name)
408408

409409
# reload_signal is not persisted elsewhere, and will cause container
410410
# to restart if different from the default value
411-
public_send('reload_signal', new_resource.reload_signal)
411+
reload_signal(new_resource.reload_signal)
412412

413413
# Go through everything in the container and set corresponding properties:
414414
# c.info['Config']['ExposedPorts'] -> exposed_ports
@@ -461,7 +461,7 @@ def load_container_labels
461461
engine_labels.any? { |k, v| k == key && v == val }
462462
end
463463

464-
public_send(:labels, labels)
464+
labels(labels)
465465
end
466466

467467
action :run do
@@ -479,71 +479,71 @@ def load_container_labels
479479

480480
with_retries do
481481
config = {
482-
'name' => new_resource.container_name,
483-
'Image' => new_resource.tag.to_s.start_with?('sha256:') ? "#{new_resource.repo}@#{new_resource.tag}" : "#{new_resource.repo}:#{new_resource.tag}",
484-
'Labels' => new_resource.labels,
485-
'Cmd' => to_shellwords(new_resource.command),
486-
'AttachStderr' => new_resource.attach_stderr,
487-
'AttachStdin' => new_resource.attach_stdin,
488-
'AttachStdout' => new_resource.attach_stdout,
489-
'Domainname' => new_resource.domain_name,
490-
'Entrypoint' => to_shellwords(new_resource.entrypoint),
491-
'Env' => new_resource.env + read_env_file,
492-
'ExposedPorts' => new_resource.exposed_ports,
493-
'Healthcheck' => new_resource.health_check,
494-
'Hostname' => parsed_hostname,
495-
'MacAddress' => new_resource.mac_address,
482+
'name' => new_resource.container_name,
483+
'Image' => new_resource.tag.to_s.start_with?('sha256:') ? "#{new_resource.repo}@#{new_resource.tag}" : "#{new_resource.repo}:#{new_resource.tag}",
484+
'Labels' => new_resource.labels,
485+
'Cmd' => to_shellwords(new_resource.command),
486+
'AttachStderr' => new_resource.attach_stderr,
487+
'AttachStdin' => new_resource.attach_stdin,
488+
'AttachStdout' => new_resource.attach_stdout,
489+
'Domainname' => new_resource.domain_name,
490+
'Entrypoint' => to_shellwords(new_resource.entrypoint),
491+
'Env' => new_resource.env + read_env_file,
492+
'ExposedPorts' => new_resource.exposed_ports,
493+
'Healthcheck' => new_resource.health_check,
494+
'Hostname' => parsed_hostname,
495+
'MacAddress' => new_resource.mac_address,
496496
'NetworkDisabled' => new_resource.network_disabled,
497-
'OpenStdin' => new_resource.open_stdin,
498-
'StdinOnce' => new_resource.stdin_once,
499-
'Tty' => new_resource.tty,
500-
'User' => new_resource.user,
501-
'Volumes' => new_resource.volumes,
502-
'WorkingDir' => new_resource.working_dir,
503-
'HostConfig' => {
504-
'Binds' => new_resource.volumes_binds,
505-
'CapAdd' => new_resource.cap_add,
506-
'CapDrop' => new_resource.cap_drop,
507-
'CgroupParent' => new_resource.cgroup_parent,
508-
'CgroupnsMode' => new_resource.cgroup_ns,
509-
'CpuShares' => new_resource.cpu_shares,
510-
'CpusetCpus' => new_resource.cpuset_cpus,
511-
'Devices' => new_resource.devices,
512-
'Dns' => new_resource.dns,
513-
'DnsSearch' => new_resource.dns_search,
514-
'ExtraHosts' => new_resource.extra_hosts,
515-
'IpcMode' => new_resource.ipc_mode,
516-
'Init' => new_resource.init,
517-
'KernelMemory' => new_resource.kernel_memory,
518-
'Links' => new_resource.links,
519-
'LogConfig' => log_config,
520-
'Memory' => new_resource.memory,
521-
'MemorySwap' => new_resource.memory_swap,
497+
'OpenStdin' => new_resource.open_stdin,
498+
'StdinOnce' => new_resource.stdin_once,
499+
'Tty' => new_resource.tty,
500+
'User' => new_resource.user,
501+
'Volumes' => new_resource.volumes,
502+
'WorkingDir' => new_resource.working_dir,
503+
'HostConfig' => {
504+
'Binds' => new_resource.volumes_binds,
505+
'CapAdd' => new_resource.cap_add,
506+
'CapDrop' => new_resource.cap_drop,
507+
'CgroupParent' => new_resource.cgroup_parent,
508+
'CgroupnsMode' => new_resource.cgroup_ns,
509+
'CpuShares' => new_resource.cpu_shares,
510+
'CpusetCpus' => new_resource.cpuset_cpus,
511+
'Devices' => new_resource.devices,
512+
'Dns' => new_resource.dns,
513+
'DnsSearch' => new_resource.dns_search,
514+
'ExtraHosts' => new_resource.extra_hosts,
515+
'IpcMode' => new_resource.ipc_mode,
516+
'Init' => new_resource.init,
517+
'KernelMemory' => new_resource.kernel_memory,
518+
'Links' => new_resource.links,
519+
'LogConfig' => log_config,
520+
'Memory' => new_resource.memory,
521+
'MemorySwap' => new_resource.memory_swap,
522522
'MemorySwappiness' => new_resource.memory_swappiness,
523523
'MemoryReservation' => new_resource.memory_reservation,
524-
'NanoCpus' => new_resource.cpus,
525-
'NetworkMode' => normalize_container_network_mode(new_resource.network_mode),
526-
'OomKillDisable' => new_resource.oom_kill_disable,
527-
'OomScoreAdj' => new_resource.oom_score_adj,
528-
'Privileged' => new_resource.privileged,
529-
'PidMode' => new_resource.pid_mode,
530-
'PortBindings' => new_resource.port_bindings,
524+
'NanoCpus' => new_resource.cpus,
525+
'NetworkMode' => normalize_container_network_mode(new_resource.network_mode),
526+
'OomKillDisable' => new_resource.oom_kill_disable,
527+
'OomScoreAdj' => new_resource.oom_score_adj,
528+
'Privileged' => new_resource.privileged,
529+
'PidMode' => new_resource.pid_mode,
530+
'PortBindings' => new_resource.port_bindings,
531531
'PublishAllPorts' => new_resource.publish_all_ports,
532-
'RestartPolicy' => {
533-
'Name' => new_resource.restart_policy,
532+
'RestartPolicy' => {
533+
'Name' => new_resource.restart_policy,
534534
'MaximumRetryCount' => new_resource.restart_maximum_retry_count,
535535
},
536-
'ReadonlyRootfs' => new_resource.ro_rootfs,
537-
'Runtime' => new_resource.runtime,
538-
'SecurityOpt' => new_resource.security_opt,
539-
'ShmSize' => new_resource.shm_size,
540-
'Sysctls' => new_resource.sysctls,
541-
'Tmpfs' => new_resource.tmpfs,
542-
'Ulimits' => ulimits_to_hash,
543-
'UsernsMode' => new_resource.userns_mode,
544-
'UTSMode' => new_resource.uts_mode,
545-
'VolumesFrom' => new_resource.volumes_from,
546-
'VolumeDriver' => new_resource.volume_driver,
536+
'ReadonlyRootfs' => new_resource.ro_rootfs,
537+
'Runtime' => new_resource.runtime,
538+
'SecurityOpt' => new_resource.security_opt,
539+
'ShmSize' => new_resource.shm_size,
540+
'Sysctls' => new_resource.sysctls,
541+
'Tmpfs' => new_resource.tmpfs,
542+
'Ulimits' => ulimits_to_hash,
543+
'UsernsMode' => new_resource.userns_mode,
544+
'UTSMode' => new_resource.uts_mode,
545+
'VolumesFrom' => new_resource.volumes_from,
546+
'VolumeDriver' => new_resource.volume_driver,
547547
},
548548
}
549549
net_config = {
@@ -699,7 +699,7 @@ def validate_container_create
699699
raise Chef::Exceptions::ValidationFailed, 'restart_policy must be either no, always, unless-stopped, or on-failure.'
700700
end
701701

702-
if new_resource.autoremove == true && (new_resource.property_is_set?(:restart_policy) && new_resource.restart_policy != 'no')
702+
if new_resource.autoremove == true && new_resource.property_is_set?(:restart_policy) && new_resource.restart_policy != 'no'
703703
raise Chef::Exceptions::ValidationFailed, 'Conflicting options restart_policy and autoremove.'
704704
end
705705

@@ -754,8 +754,8 @@ def state
754754
def ulimits_to_hash
755755
return if new_resource.ulimits.nil?
756756
new_resource.ulimits.map do |u|
757-
name = u.split('=')[0]
758-
soft = u.split('=')[1].split(':')[0]
757+
name = u.split('=').first
758+
soft = u.split('=')[1].split(':').first
759759
hard = u.split('=')[1].split(':')[1]
760760
{ 'Name' => name, 'Soft' => soft.to_i, 'Hard' => hard.to_i }
761761
end

resources/exec.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@
1212
property :timeout, Numeric, default: 60, desired_state: false
1313
property :container_obj, Docker::Container, desired_state: false
1414
property :returns, [ Integer, Array ], coerce: proc { |v| Array(v) }, default: [0],
15-
description: 'The return value for a command. This may be an array of accepted values. An exception is raised when the return value(s) do not match.'
15+
description: 'The return value for a command. This may be an array of accepted values. An exception is raised when the return value(s) do not match.'
1616

1717
alias_method :cmd, :command
1818

resources/installation_package.rb

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -95,7 +95,7 @@ def version_string(v)
9595
"5:#{v}-1~ubuntu.#{node['platform_version']}~#{codename}"
9696
elsif v.to_f >= 18.09 && debuntu?
9797
return "5:#{v}~#{test_version}-0~debian-#{codename}" if debian?
98-
return "5:#{v}~#{test_version}-0~ubuntu-#{codename}" if ubuntu?
98+
"5:#{v}~#{test_version}-0~ubuntu-#{codename}" if ubuntu?
9999
else
100100
return "#{v}~ce~#{test_version}-0~debian" if debian?
101101
return "#{v}~ce~#{test_version}-0~ubuntu" if ubuntu?
@@ -162,7 +162,7 @@ def version_string(v)
162162
# TODO: This eventually should go away once Debian 12 and Ubuntu 24.04 go EOL
163163
if (debian? && node['platform_version'].to_i < 13) || (ubuntu? && node['platform_version'].to_f <= 24.04)
164164
signed_by false
165-
end if Chef::VERSION >= Gem::Version.new('18.7.10')
165+
end if Gem::Version.new('18.7.10') <= Chef::VERSION
166166
action :add
167167
end
168168

resources/network.rb

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -41,25 +41,25 @@ def coerce_auxiliary_addresses(v)
4141
e.each { |key, val| ray << "#{key}=#{val}" }
4242
end
4343
end
44-
ray.length == 1 ? ray[0] : ray
44+
ray.length == 1 ? ray.first : ray
4545
end
4646

4747
def coerce_gateway(v)
4848
case v
4949
when String
50-
v.split('/')[0]
50+
v.split('/').first
5151
when Array
52-
ray = Array(v).map { |a| a.split('/')[0] }
53-
ray.length == 1 ? ray[0] : ray
52+
ray = Array(v).map { |a| a.split('/').first }
53+
ray.length == 1 ? ray.first : ray
5454
end
5555
end
5656

5757
def coerce_subnet(v)
58-
Array(v).length == 1 ? Array(v)[0] : v
58+
Array(v).length == 1 ? Array(v).first : v
5959
end
6060

6161
def coerce_ip_range(v)
62-
Array(v).length == 1 ? Array(v)[0] : v
62+
Array(v).length == 1 ? Array(v).first : v
6363
end
6464

6565
####################
@@ -224,7 +224,7 @@ def consolidate_ipam(subnets, ranges, gateways, auxaddrs)
224224

225225
# Check overlapping subnets
226226
subnets.each do |s|
227-
data.each do |k, _|
227+
data.each_key do |k|
228228
if subnet_matches(s, k) || subnet_matches(k, s)
229229
raise 'multiple overlapping subnet configuration is not supported'
230230
end

0 commit comments

Comments
 (0)