YunoHost-Apps / Experimental_helpers

6 stars 12 forks source link

Create ynh_sanitize_name #48

Closed yalh76 closed 5 years ago

yalh76 commented 5 years ago

As now with YunoHost 3.6 we are able to create users with yunohost user create without providing the admin password

And as some applications need to have a dedicated ldap users to configure ldap connexions for authentication

The best way to create that dedicated user would be to use the $app. For example dedicated username could be ${app}ldap or ldap$app

But if you install twice the same application, in the second installation $app value would be something like example__2 for the example application

But yunohost user create has some limitations regarding username, firstname and lastname : https://github.com/YunoHost/yunohost/blob/ac7102a0caee9c6d2d8808ef4b345edfbdbb54e8/data/actionsmap/yunohost.yml#L75-L108

So the best is to sanitize the name to have something like:

ldap_user=$(ynh_sanitize_name --name="${app}ldap")
ldap_password=$(ynh_string_random --length=8)

yunohost user create $ldap_user --firstname $ldap_user --lastname $ldap_user --mail ${ldap_user}@$domain --password $ldap_password -q 0
maniackcrudelis commented 5 years ago

Not sure we'll really need that, as app is already sanitize with similar rules. But anyway, as an experimental helper, let's try it and we'll see.