File: validate_tempauth_account.rb

package info (click to toggle)
puppet-module-swift 25.0.0-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid, trixie
  • size: 2,400 kB
  • sloc: ruby: 9,593; python: 38; sh: 10; makefile: 10
file content (44 lines) | stat: -rw-r--r-- 1,238 bytes parent folder | download
1
2
3
4
5
6
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
37
38
39
40
41
42
43
44
Puppet::Functions.create_function(:validate_tempauth_account) do
  def validate_tempauth_account(*args)
    if args.size > 1
      raise Puppet::Error, "validate_tempauth_account takes only a single argument, #{args.size} provided"
    end
    arg = args[0]

    if not arg.kind_of?(Hash)
      raise Puppet::Error, "non-hash argument provided to validate_tempauth_account"
    end

    ['user', 'account', 'key'].each do |key|
      if arg.has_key?(key)
        key_real = key
      elsif arg.has_key?(key.to_sym)
        key_real = key.to_sym
      else
        raise Puppet::Error, "The required key #{key} is missing"
      end

      if not arg[key_real].kind_of?(String)
        raise Puppet::Error, "The key #{key} is not a string value"
      end

      if arg[key_real].length == 0
        raise Puppet::Error, "The key #{key} is empty"
      end
    end

    ['groups'].each do |key|
      if arg.has_key?(key)
        key_real = key
      elsif arg.has_key?(key.to_sym)
        key_real = key.to_sym
      else
        raise Puppet::Error, "The required key #{key} is missing"
      end

      if not arg[key_real].kind_of?(Array)
        raise Puppet::Error, "The key #{key} is not an array value"
      end
    end
  end
end