[buildout]
parts =
  publish-connection-parameter

eggs-directory = ${buildout:eggs-directory}
develop-eggs-directory = ${buildout:develop-eggs-directory}
offline = true


[publish-connection-parameter]
recipe = slapos.cookbook:publish
url = https://[$${galene-wrapper:ip}]:$${galene-wrapper:port}
admin-user = $${admin-password:username}
admin-password = $${admin-password:passwd}

[slap-configuration]
recipe = slapos.cookbook:slapconfiguration
computer = $${slap-connection:computer-id}
partition = $${slap-connection:partition-id}
url = $${slap-connection:server-url}
key = $${slap-connection:key-file}
cert = $${slap-connection:cert-file}
configuration.ice-servers.json = [{"urls":["stun:turn-paris-rapidspace.api.nexedi.net:443"]}]

[directory]
recipe = slapos.cookbook:mkdirectory
etc = $${buildout:directory}/etc
var = $${buildout:directory}/var
srv = $${buildout:directory}/srv
bin = $${buildout:directory}/bin
tmp = $${buildout:directory}/tmp
run = $${:var}/run

services   = $${:etc}/service
data       = $${:srv}/data
groups     = $${:srv}/groups
recordings = $${:srv}/recordings

[galene-ssl]
recipe = plone.recipe.command
cert-file = $${directory:data}/cert.pem
key-file = $${directory:data}/key.pem
command = ${openssl:location}/bin/openssl req -newkey rsa:2048 -batch -new -x509  -days 3650 -nodes -keyout "$${:key-file}" -out "$${:cert-file}"
update-command =
stop-on-error = true

[admin-password]
recipe = slapos.cookbook:generate.password
storage-path = $${directory:data}/.passwd
username = admin

[ice-servers.json]
recipe = slapos.recipe.template:jinja2
template = inline:
  $${slap-configuration:configuration.ice-servers.json}
rendered = $${directory:data}/ice-servers.json

[groups-json]
recipe = slapos.recipe.template:jinja2
template = inline:{
    "public":true,
    "op": [{"username":"$${admin-password:username}","password":"$${admin-password:passwd}"}],
    "other": [],
    "presenter": [{"username": "", "password": "nexedi"}],
    "max-users":100
  }
rendered = $${directory:groups}/public.json

[galene-wrapper]
recipe = slapos.recipe.template:jinja2
port = 8443
ip = $${slap-configuration:ipv6-random}
template =
  inline:#!/bin/sh
  
  ulimit -n $(ulimit -Hn)
  exec ${galene:location}/bin/galene \
    -static ${galene-repository:location}/static \
    -recordings $${directory:recordings} \
    -groups $${directory:groups} \
    -data $${directory:data} \
    -http [$${:ip}]:$${:port} \
    -turn ""
rendered = $${directory:services}/galene
depends =
  $${ice-servers.json:recipe}
  $${groups-json:recipe}
  $${galene-ssl:recipe}

