Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
31 changes: 30 additions & 1 deletion resources/server.rb
Original file line number Diff line number Diff line change
Expand Up @@ -143,6 +143,34 @@
default: lazy { platform_family?('rhel', 'fedora', 'amazon', 'suse') ? %w(smb nmb) : %w(smbd nmbd) },
description: 'An array of services to start'

action_class do
def share_options(resource)
{
'comment' => resource.comment,
'path' => resource.path,
'guest ok' => resource.guest_ok,
'printable' => resource.printable,
'write list' => resource.write_list,
'create mask' => resource.create_mask,
'directory mask' => resource.directory_mask,
'read only' => resource.read_only,
'valid users' => resource.valid_users,
'force user' => resource.force_user,
'force group' => resource.force_group,
'browseable' => resource.browseable,
}.merge(resource.options)
end

def declared_shares
run_context.resource_collection.each_with_object({}) do |resource, shares|
next unless resource.resource_name == :samba_share
next unless resource.config_file == new_resource.config_file

shares[resource.share_name] = share_options(resource)
end
end
end

action :create do
package 'samba'

Expand Down Expand Up @@ -174,7 +202,8 @@
samba_options: new_resource.options,
log_level: new_resource.log_level,
max_log_size: new_resource.max_log_size,
bind_interfaces_only: new_resource.bind_interfaces_only
bind_interfaces_only: new_resource.bind_interfaces_only,
shares: declared_shares
)
new_resource.samba_services.each do |samba_service|
notifies :restart, "service[#{samba_service}]", :delayed
Expand Down
24 changes: 0 additions & 24 deletions resources/share.rb
Original file line number Diff line number Diff line change
Expand Up @@ -104,30 +104,6 @@
description: 'Path to the samba configuration file'

action :add do
# We need to force both the server template and the
# share templates into the root context to find each other
with_run_context :root do
edit_resource(:template, new_resource.config_file) do |new_resource|
variables[:shares] ||= {}
variables[:shares][new_resource.share_name] ||= {}
variables[:shares][new_resource.share_name]['comment'] = new_resource.comment
variables[:shares][new_resource.share_name]['path'] = new_resource.path
variables[:shares][new_resource.share_name]['guest ok'] = new_resource.guest_ok
variables[:shares][new_resource.share_name]['printable'] = new_resource.printable
variables[:shares][new_resource.share_name]['write list'] = new_resource.write_list
variables[:shares][new_resource.share_name]['create mask'] = new_resource.create_mask
variables[:shares][new_resource.share_name]['directory mask'] = new_resource.directory_mask
variables[:shares][new_resource.share_name]['read only'] = new_resource.read_only
variables[:shares][new_resource.share_name]['valid users'] = new_resource.valid_users
variables[:shares][new_resource.share_name]['force user'] = new_resource.force_user
variables[:shares][new_resource.share_name]['force group'] = new_resource.force_group
variables[:shares][new_resource.share_name]['browseable'] = new_resource.browseable
new_resource.options.each do |key, value|
variables[:shares][new_resource.share_name][key] = value
end
end
end

if new_resource.create_directory
directory new_resource.path do
recursive true
Expand Down
20 changes: 20 additions & 0 deletions spec/resources/server_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -18,4 +18,24 @@
it { is_expected.to install_package('samba') }
it { is_expected.to create_template('/etc/samba/smb.conf') }
end

context 'when shares are declared separately' do
recipe do
samba_server 'test-server'

samba_share 'homes' do
comment 'Home Directories'
guest_ok 'no'
read_only 'no'
browseable 'no'
create_directory false
end
end

it 'renders the share into smb.conf' do
expect(chef_run).to render_file('/etc/samba/smb.conf').with_content('[homes]')
expect(chef_run).to render_file('/etc/samba/smb.conf').with_content('comment = Home Directories')
expect(chef_run).to render_file('/etc/samba/smb.conf').with_content('browseable = no')
end
end
end
Loading