You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
calculate-utils-3-ldap/pym/ldap/utils/cl_ldap_setup.py

150 lines
5.0 KiB

# -*- coding: utf-8 -*-
# Copyright 2016 Mir Calculate. http://www.calculate-linux.org
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
import sys
from calculate.core.server.func import Action, Tasks
from calculate.lib.cl_lang import setLocalTranslate, getLazyLocalTranslate
from calculate.lib.cl_template import TemplatesError
from calculate.lib.utils.files import FilesError
from calculate.lib.datavars import VariableError
from calculate.server.variables.action import Actions
from ..ldap import LdapError, Ldap
from calculate.server.server import ServerError
_ = lambda x: x
setLocalTranslate('cl_ldap3', sys.modules[__name__])
__ = getLazyLocalTranslate(_)
class MetaTasks(object):
def __init__(self, obj):
self.obj = obj
def ldif_task(self, ldap_params, action):
return [
{'name': 'set_ldif',
'method': '%s.set_ldap_connection(%s)' % (self.obj, ldap_params)
},
{'name': 'ldif_action',
'method': '%s.set_server_action("%s")' % (self.obj, Actions.Ldif),
},
{'name': 'ldif',
'method': '%s.applyTemplates(install.cl_source,'
'False,True,None,False,True)' % self.obj,
},
{'name': 'ldif_action',
'method': '%s.set_server_action("%s")' % (self.obj, action),
},
]
class ClLdapSetupAction(Action):
"""
Действие обновление конфигурационных файлов
"""
# ошибки, которые отображаются без подробностей
native_error = (FilesError,
TemplatesError,
VariableError,
ServerError,
LdapError)
successMessage = __("LDAP server configured!")
failedMessage = __("Failed to configure LDAP server!")
interruptMessage = __("LDAP configuration manually interrupted")
meta_tasks = MetaTasks("Ldap")
# список задач для удаления сервера
uninstall_tasks = [
{'name': 'clear_creds',
'method': 'Server.clear_service_data("all")',
'condition': lambda Get: Get('server.sr_ldap_set') == 'on'
},
{'name': 'unset_ldap',
'method': 'Server.service_uninstall("ldap")',
'condition': lambda Get: Get('server.sr_ldap_set') == 'on'
},
]
stop_tasks = [
{'name': 'noautorun',
'method': 'Server.autorun_disable("%s")' % Ldap.Service.LDAP,
},
{'name': 'stop_slapd',
'message': __("Stopping LDAP service"),
'method': 'Server.stop_service("%s")' % Ldap.Service.LDAP,
},
]
# список задач для конфигурирования сервера
configure_task = [
]
# список задач для действия
tasks = [
{'name': 'uninstall',
'tasks': uninstall_tasks,
},
{'name': 'stop',
'tasks': stop_tasks,
},
{'name': 'preconfigure',
'message': __("Pre-configure LDAP"),
'method': 'Ldap.preconfigureTemplates()',
},
{'name': 'remove_old_db',
'method': 'Ldap.remove_ldap_db(ld_database_path)'
},
{'name': 'start_slapd',
'message': __("Starting LDAP service"),
'method': 'Server.start_service("%s")' % Ldap.Service.LDAP,
},
{'name': 'apply_ldif',
'tasks': meta_tasks.ldif_task("ld_temp_dn,ld_temp_pw", Actions.Setup)
},
{'name': 'templates',
'message': __("Configure LDAP"),
'method': 'Server.applyTemplates(install.cl_source,'
'False,True,None,True,True)',
},
{'name': 'restart_slapd',
'message': __("Restarting LDAP service"),
'method': 'Server.restart_service("%s")' % Ldap.Service.LDAP,
},
{'name': 'save_creds',
'method': 'Server.save_service_data("admin",ld_admin_dn,ld_admin_pw)'
},
{'name': 'autorun',
'method': 'Server.autorun_enable("%s")' % Ldap.Service.LDAP,
},
{'name': 'set_ldap',
'method': 'Server.service_install("ldap")'
},
{'name': 'save_data',
'method': 'Ldap.save_variables()'
}
]
@classmethod
def register_stop(cls, stop_tasks):
cls.stop_tasks.extend(stop_tasks)
@classmethod
def register_uninstall(cls, uninstall_tasks):
cls.uninstall_tasks.extend(uninstall_tasks)