tiredofit / docker-self-service-password

Dockerized Self Service Password Changer with many customizable options
MIT License
135 stars 63 forks source link

[Suggestion] Use gomplate instead of sed #5

Open zicklag opened 6 years ago

zicklag commented 6 years ago

Hi @tiredofit,

I was trying out your container and I noticed that you use sed to substitute the environment variables into the SSP config template file. I just wanted to let you know about an awesome tool called Gomplate that could make that process a whole lot cleaner and more elegant IMHO.

You can use the Go template format for your config template then substitute the values straight from the container environment variables with a single command, using Gomplate ( a 4.51MB binary ). It is very nice. I just used it in my own SSP container:

config.inc.local.php.template:

...
# LDAP
$ldap_url = "{{.Env.LDAP_URL}}";
$ldap_starttls = {{.Env.LDAP_STARTTLS}};
$ldap_binddn = "{{.Env.LDAP_BINDDN}}";
$ldap_bindpw = "{{.Env.LDAP_BINDPW}}";
$ldap_base = "{{.Env.LDAP_BASE}}";
$ldap_login_attribute = "{{.Env.LDAP_LOGIN_ATTRIBUTE}}";
$ldap_fullname_attribute = "{{.Env.LDAP_FULLNAME_ATTRIBUTE}}";
{{if not .Env.LDAP_FILTER}}
$ldap_filter = "(&(objectClass={{.Env.LDAP_OBJECT_CLASS}})($ldap_login_attribute={login}}))";
{{else}}
$ldap_filter = "{{.Env.LDAP_FILTER}}";
{{end}}
...

Having if statements and other functions lets you add logic like I did with the LDAP_FILTER variable. Very cool.

Anyway, that's just my tip from one Docker geek to another. Hope you enjoy. :smiley:

fbartels commented 5 years ago

An alternative to gomplate could be https://github.com/jwilder/dockerize