|
| 1 | +# |
| 2 | +# Cookbook:: fb_sasl |
| 3 | +# Recipe:: default |
| 4 | +# |
| 5 | +# Copyright (c) 2025-present, Meta Platforms, Inc. |
| 6 | +# Copyright (c) 2025-present, Phil Dibowitz |
| 7 | +# All rights reserved. |
| 8 | +# |
| 9 | +# Licensed under the Apache License, Version 2.0 (the "License"); |
| 10 | +# you may not use this file except in compliance with the License. |
| 11 | +# You may obtain a copy of the License at |
| 12 | +# |
| 13 | +# http://www.apache.org/licenses/LICENSE-2.0 |
| 14 | +# |
| 15 | +# Unless required by applicable law or agreed to in writing, software |
| 16 | +# distributed under the License is distributed on an "AS IS" BASIS, |
| 17 | +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 18 | +# See the License for the specific language governing permissions and |
| 19 | +# limitations under the License. |
| 20 | +# |
| 21 | + |
| 22 | +if fedora_derived? |
| 23 | + packages = %w{cyrus-sasl} |
| 24 | + modules_package_prefix = 'cyrus-sasl' |
| 25 | + sysconfig_path = '/etc/sysconfig/saslauthd' |
| 26 | +elsif debian? |
| 27 | + packages = %w{sasl2-bin} |
| 28 | + modules_package_prefix = 'libsasl2-modules' |
| 29 | + sysconfig_path = '/etc/default/saslauthd' |
| 30 | +else |
| 31 | + fail "fb_sasl: Unknown platform_family: #{node['platform_family']}" |
| 32 | +end |
| 33 | + |
| 34 | +package 'sasl packages' do |
| 35 | + only_if { node['fb_sasl']['manage_packages'] } |
| 36 | + package_name lazy { |
| 37 | + packages + node['fb_sasl']['modules'].map do |mod| |
| 38 | + "#{modules_package_prefix}-#{mod}" |
| 39 | + end |
| 40 | + } |
| 41 | + action :upgrade |
| 42 | + notifies :restart, 'service[saslauthd]' |
| 43 | +end |
| 44 | + |
| 45 | +whyrun_safe_ruby_block 'validate config' do |
| 46 | + block do |
| 47 | + node['fb_sasl']['sysconfig'].each_key do |key| |
| 48 | + if key != key.downcase |
| 49 | + fail "fb_sasl: invalid casing for key #{key} - please use downcase" |
| 50 | + end |
| 51 | + if key == 'start' |
| 52 | + fail 'fb_sasl: do not specify "start" in sysconfig, use ' + |
| 53 | + 'enable_saslauthd instead' |
| 54 | + end |
| 55 | + end |
| 56 | + end |
| 57 | +end |
| 58 | + |
| 59 | +template sysconfig_path do |
| 60 | + source 'sysconfig.erb' |
| 61 | + owner node.root_user |
| 62 | + group node.root_group |
| 63 | + mode '0644' |
| 64 | + notifies :restart, 'service[saslauthd]' |
| 65 | +end |
| 66 | + |
| 67 | +service 'saslauthd' do |
| 68 | + only_if { node['fb_sasl']['enable_saslauthd'] } |
| 69 | + action [:enable, :start] |
| 70 | +end |
| 71 | + |
| 72 | +service 'disable saslauthd' do |
| 73 | + not_if { node['fb_sasl']['enable_saslauthd'] } |
| 74 | + service_name 'saslauthd' |
| 75 | + action [:stop, :disable] |
| 76 | +end |
0 commit comments