Puppet Function: docker_secrets_flags

Defined in:
lib/puppet/parser/functions/docker_secrets_flags.rb
Function type:
Ruby 3.x API

Overview

docker_secrets_flags()Any

Transforms a hash into a string of docker swarm init flags

Returns:

  • (Any)


7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
# File 'lib/puppet/parser/functions/docker_secrets_flags.rb', line 7

newfunction(:docker_secrets_flags, :type => :rvalue) do |args|
  opts = args[0] || {}
  flags = []

  if opts['ensure'].to_s == 'present'
    flags << 'create'
  end

  if opts['secret_name'].to_s != 'undef'
    flags << "'#{opts['secret_name']}'"
  end

  if opts['secret_path'].to_s != 'undef'
    flags << "'#{opts['secret_path']}'"
  end

  multi_flags = lambda { |values, format|
    filtered = [values].flatten.compact
    filtered.map { |val| sprintf(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