Puppet Function: docker_secrets_flags
- Defined in:
- lib/puppet/parser/functions/docker_secrets_flags.rb
- Function type:
- Ruby 3.x API
Overview
Transforms a hash into a string of docker swarm init flags
9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 |
# File 'lib/puppet/parser/functions/docker_secrets_flags.rb', line 9 newfunction(:docker_secrets_flags, type: :rvalue) do |args| opts = args[0] || {} flags = [] flags << 'create' if opts['ensure'].to_s == 'present' flags << "'#{opts['secret_name']}'" if opts['secret_name'] && opts['secret_name'].to_s != 'undef' flags << "'#{opts['secret_path']}'" if opts['secret_path'] && opts['secret_path'].to_s != 'undef' multi_flags = ->(values, format) { filtered = [values].flatten.compact filtered.map { |val| format + (" \\\n" % val) } } [ ['-l %s', 'label'], ].each do |(format, key)| values = opts[key] new_flags = multi_flags.call(values, format) flags.concat(new_flags) end flags.flatten.join(' ') end |