From 45fcc5bed810c105fea029ead4d3aeb455ef77a1 Mon Sep 17 00:00:00 2001 From: Kloadut Date: Wed, 10 Oct 2012 19:47:57 +0200 Subject: [PATCH] Domain arguments et actions list --- lib/yunohost.py | 54 ++++++++++++++++----------------- lib/yunohost_user.py | 6 ++-- yunohost | 72 ++++++++++++++++++++++++++++++++++++++++---- 3 files changed, 96 insertions(+), 36 deletions(-) diff --git a/lib/yunohost.py b/lib/yunohost.py index 43707e76..8b461061 100644 --- a/lib/yunohost.py +++ b/lib/yunohost.py @@ -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 diff --git a/lib/yunohost_user.py b/lib/yunohost_user.py index 8837944d..6b7a9d35 100644 --- a/lib/yunohost_user.py +++ b/lib/yunohost_user.py @@ -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}$' }) diff --git a/yunohost b/yunohost index 24ab7c44..7638977f 100755 --- a/yunohost +++ b/yunohost @@ -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"),