mirror of
https://github.com/YunoHost/moulinette.git
synced 2024-09-03 20:06:31 +02:00
Domain arguments et actions list
This commit is contained in:
parent
df2a8d9ad1
commit
45fcc5bed8
3 changed files with 96 additions and 36 deletions
|
@ -63,6 +63,7 @@ def str_to_func(astr):
|
||||||
Function
|
Function
|
||||||
|
|
||||||
"""
|
"""
|
||||||
|
try:
|
||||||
module, _, function = astr.rpartition('.')
|
module, _, function = astr.rpartition('.')
|
||||||
if module:
|
if module:
|
||||||
__import__(module)
|
__import__(module)
|
||||||
|
@ -70,15 +71,33 @@ def str_to_func(astr):
|
||||||
else:
|
else:
|
||||||
mod = sys.modules['__main__'] # default module
|
mod = sys.modules['__main__'] # default module
|
||||||
|
|
||||||
try:
|
|
||||||
func = getattr(mod, function)
|
func = getattr(mod, function)
|
||||||
except AttributeError:
|
except (AttributeError, ImportError):
|
||||||
#raise YunoHostError(168, _('Function is not defined'))
|
#raise YunoHostError(168, _('Function is not defined'))
|
||||||
return None
|
return None
|
||||||
else:
|
else:
|
||||||
return func
|
return func
|
||||||
|
|
||||||
|
|
||||||
|
def validate(regex_dict):
|
||||||
|
"""
|
||||||
|
Validate attributes with a pattern
|
||||||
|
|
||||||
|
Keyword arguments:
|
||||||
|
regex_dict -- Dictionnary of values/pattern to check
|
||||||
|
|
||||||
|
Returns:
|
||||||
|
Boolean | YunoHostError
|
||||||
|
|
||||||
|
"""
|
||||||
|
for attr, pattern in regex_dict.items():
|
||||||
|
if re.match(pattern, attr):
|
||||||
|
continue
|
||||||
|
else:
|
||||||
|
raise YunoHostError(22, _('Invalid attribute') + ' ' + attr)
|
||||||
|
return True
|
||||||
|
|
||||||
|
|
||||||
class YunoHostError(Exception):
|
class YunoHostError(Exception):
|
||||||
"""
|
"""
|
||||||
Custom exception
|
Custom exception
|
||||||
|
@ -200,25 +219,6 @@ class YunoHostLDAP:
|
||||||
return True
|
return True
|
||||||
|
|
||||||
|
|
||||||
def validate(self, regex_dict):
|
|
||||||
"""
|
|
||||||
Validate attributes with a pattern
|
|
||||||
|
|
||||||
Keyword arguments:
|
|
||||||
regex_dict -- Dictionnary of values/pattern to check
|
|
||||||
|
|
||||||
Returns:
|
|
||||||
Boolean | YunoHostError
|
|
||||||
|
|
||||||
"""
|
|
||||||
for attr, pattern in regex_dict.items():
|
|
||||||
if re.match(pattern, attr):
|
|
||||||
continue
|
|
||||||
else:
|
|
||||||
raise YunoHostError(22, _('Invalid attribute') + ' ' + attr)
|
|
||||||
return True
|
|
||||||
|
|
||||||
|
|
||||||
def validate_uniqueness(self, value_dict):
|
def validate_uniqueness(self, value_dict):
|
||||||
"""
|
"""
|
||||||
Check uniqueness of values
|
Check uniqueness of values
|
||||||
|
|
|
@ -7,7 +7,7 @@ import crypt
|
||||||
import random
|
import random
|
||||||
import string
|
import string
|
||||||
import getpass
|
import getpass
|
||||||
from yunohost import YunoHostError, win_msg, colorize
|
from yunohost import YunoHostError, win_msg, colorize, validate
|
||||||
|
|
||||||
|
|
||||||
def user_list(args, yldap): # TODO : fix
|
def user_list(args, yldap): # TODO : fix
|
||||||
|
@ -15,7 +15,7 @@ def user_list(args, yldap): # TODO : fix
|
||||||
#print(result)
|
#print(result)
|
||||||
|
|
||||||
|
|
||||||
def user_add(args, yldap):
|
def user_create(args, yldap):
|
||||||
"""
|
"""
|
||||||
Add user to LDAP
|
Add user to LDAP
|
||||||
|
|
||||||
|
@ -66,7 +66,7 @@ def user_add(args, yldap):
|
||||||
}
|
}
|
||||||
|
|
||||||
# Validate values
|
# Validate values
|
||||||
yldap.validate({
|
validate({
|
||||||
args['username'] : r'^[a-z0-9_]+$',
|
args['username'] : r'^[a-z0-9_]+$',
|
||||||
args['mail'] : r'^[\w.-]+@[\w.-]+\.[a-zA-Z]{2,6}$'
|
args['mail'] : r'^[\w.-]+@[\w.-]+\.[a-zA-Z]{2,6}$'
|
||||||
})
|
})
|
||||||
|
|
66
yunohost
66
yunohost
|
@ -108,8 +108,8 @@ action_dict = {
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
### user_add()
|
### user_create()
|
||||||
'add' : {
|
'create' : {
|
||||||
'action_help' : _("Create user"),
|
'action_help' : _("Create user"),
|
||||||
'ldap' : True,
|
'ldap' : True,
|
||||||
'arguments' : {
|
'arguments' : {
|
||||||
|
@ -205,9 +205,69 @@ action_dict = {
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
#############################
|
||||||
|
# Domain #
|
||||||
|
#############################
|
||||||
'domain' : {
|
'domain' : {
|
||||||
'category_help' : _("Manage domains"),
|
'category_help' : _("Manage domains"),
|
||||||
'actions' : {}
|
'actions' : {
|
||||||
|
### domain_list()
|
||||||
|
'list' : {
|
||||||
|
'action_help' : _("List domains"),
|
||||||
|
'ldap' : True,
|
||||||
|
'arguments' : {
|
||||||
|
'-f' : {
|
||||||
|
'full' : '--filter',
|
||||||
|
'help' : _("LDAP filter used to search"),
|
||||||
|
},
|
||||||
|
'-l' : {
|
||||||
|
'full' : '--limit',
|
||||||
|
'help' : _("Maximum number of users fetched"),
|
||||||
|
},
|
||||||
|
'-o' : {
|
||||||
|
'full' : '--offset',
|
||||||
|
'help' : _("Starting number for user fetching"),
|
||||||
|
},
|
||||||
|
}
|
||||||
|
},
|
||||||
|
### domain_create()
|
||||||
|
'create' : {
|
||||||
|
'action_help' : _("Create a custom domain"),
|
||||||
|
'ldap' : True,
|
||||||
|
'arguments' : {
|
||||||
|
'domain name' : {
|
||||||
|
'help' : _("Domain name to create"),
|
||||||
|
}
|
||||||
|
}
|
||||||
|
},
|
||||||
|
### domain_delete()
|
||||||
|
'delete' : {
|
||||||
|
'action_help' : _("Delete domains"),
|
||||||
|
'ldap' : True,
|
||||||
|
'arguments' : {
|
||||||
|
'domains' : {
|
||||||
|
'help' : _("Domain names to delete"),
|
||||||
|
'nargs' : '+',
|
||||||
|
},
|
||||||
|
}
|
||||||
|
},
|
||||||
|
### domain_info()
|
||||||
|
'info' : {
|
||||||
|
'action_help' : _("Get domain informations"),
|
||||||
|
'ldap' : True,
|
||||||
|
'arguments' : {
|
||||||
|
'domain-name' : {}
|
||||||
|
}
|
||||||
|
},
|
||||||
|
### domain_renewcert()
|
||||||
|
'renewcert' : {
|
||||||
|
'action_help' : _("Renew domain certificate"),
|
||||||
|
'ldap' : True,
|
||||||
|
'arguments' : {
|
||||||
|
'domain-name' : {}
|
||||||
|
}
|
||||||
|
},
|
||||||
|
}
|
||||||
},
|
},
|
||||||
'app' : {
|
'app' : {
|
||||||
'category_help' : _("Manage apps"),
|
'category_help' : _("Manage apps"),
|
||||||
|
|
Loading…
Add table
Reference in a new issue