summaryrefslogtreecommitdiff
path: root/manifests/init.pp
blob: 00a22854c78e3868cdb8d657212267f09691fb01 (plain)
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
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
define webdav_server (
  String $nginx_server,
  String $file_path,
  String $location = $name,
  String $passwd_file = "${file_path}/.htpasswd",
  String $owner  = 'http',
  String $group = 'share',
  Array[Array[String,2,2]] $users = [],
  Array[String] $dav_methods = ['PUT', 'DELETE', 'MKCOL', 'COPY', 'MOVE'],
  Array[String] $dav_ext_methods = ['PROPFIND', 'OPTIONS'],
  Hash[String,String] $dav_access = {
    'user'  => 'rw',
    'group' => 'rw',
  }
) {

  # ensure_packages(['nginx-mainline-mod-dav-ext'])

  require ::nginx

  $modname = 'ngx_http_dav_ext_module'
  # This assumes that the directory exists, and that
  # nginx::include_modules_enabled => true
  file { "/etc/nginx/modules-enabled/${modname}.conf":
    ensure  => file,
    content => @("EOF")
    load_module /usr/lib/nginx/modules/${modname}.so;
    | EOF
  }

  $lines = $users.map |$pair| { $pair.join(':') }.join("\n")

  file {
    default:
      owner   => $owner,
      group   => $group,
      ;
    $file_path:
      ensure  => 'directory',
      mode    => '0770',
      recurse => 'false',
      ;
    $passwd_file:
      ensure  => 'file',
      mode    => '0660',
      content => @("EOF")
        # File managed by puppet
        ${lines}
        | EOF
      ;
  }

  nginx::resource::location { $location:
    server         => $nginx_server,
    location_alias => $file_path,
    ssl            => true,
    ssl_only       => true,

    auth_basic           => 'Enter password for dav access',
    auth_basic_user_file => $passwd_file,

    location_cfg_append       => {
      'dav_methods'           => $dav_methods.join(' '),
      'dav_ext_methods'       => $dav_ext_methods.join(' '),
      'dav_access'            => $dav_access.map |$k, $v| { "${k}:${v}" }.join(' '),
      'client_body_temp_path' => "${file_path}/tmp",
      'create_full_put_path'  => 'on',
      'autoindex'             => 'on',
      'allow'                 => 'all',
    }
  }
}