Domain arguments et actions list

This commit is contained in:
Kloadut 2012-10-10 19:47:57 +02:00
parent df2a8d9ad1
commit 45fcc5bed8
3 changed files with 96 additions and 36 deletions

View file

@ -63,22 +63,41 @@ def str_to_func(astr):
Function
"""
module, _, function = astr.rpartition('.')
if module:
__import__(module)
mod = sys.modules[module]
else:
mod = sys.modules['__main__'] # default module
try:
module, _, function = astr.rpartition('.')
if module:
__import__(module)
mod = sys.modules[module]
else:
mod = sys.modules['__main__'] # default module
func = getattr(mod, function)
except AttributeError:
except (AttributeError, ImportError):
#raise YunoHostError(168, _('Function is not defined'))
return None
else:
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):
"""
Custom exception
@ -200,25 +219,6 @@ class YunoHostLDAP:
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):
"""
Check uniqueness of values

View file

@ -7,7 +7,7 @@ import crypt
import random
import string
import getpass
from yunohost import YunoHostError, win_msg, colorize
from yunohost import YunoHostError, win_msg, colorize, validate
def user_list(args, yldap): # TODO : fix
@ -15,7 +15,7 @@ def user_list(args, yldap): # TODO : fix
#print(result)
def user_add(args, yldap):
def user_create(args, yldap):
"""
Add user to LDAP
@ -66,7 +66,7 @@ def user_add(args, yldap):
}
# Validate values
yldap.validate({
validate({
args['username'] : r'^[a-z0-9_]+$',
args['mail'] : r'^[\w.-]+@[\w.-]+\.[a-zA-Z]{2,6}$'
})

View file

@ -86,7 +86,7 @@ action_dict = {
'category_help' : _("Manage users"),
'actions' : {
### user_list()
'list' : {
'list' : {
'action_help' : _("List users"),
'ldap' : True,
'arguments' : {
@ -108,8 +108,8 @@ action_dict = {
},
}
},
### user_add()
'add' : {
### user_create()
'create' : {
'action_help' : _("Create user"),
'ldap' : True,
'arguments' : {
@ -133,7 +133,7 @@ action_dict = {
}
},
### user_delete()
'delete' : {
'delete' : {
'action_help' : _("Delete user"),
'ldap' : True,
'arguments' : {
@ -144,7 +144,7 @@ action_dict = {
}
},
### user_update()
'update' : {
'update' : {
'action_help' : _("Update user informations"),
'ldap' : True,
'arguments' : {
@ -205,9 +205,69 @@ action_dict = {
},
}
},
#############################
# Domain #
#############################
'domain' : {
'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' : {
'category_help' : _("Manage apps"),