#-*- coding: utf-8 -*-

# Copyright 2008-2012 Calculate Ltd. 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.

from calculate.lib.datavars import Variables
from calculate.lib.encrypt import getHash
from calculate.lib.utils.common import genpassword

#class LDAP(Variables):
#    vars = ['ld_base_dn', 'ld_bind_dn', 'ld_bind_login', 'ld_bind_hash',
#            'ld_bind_pw', 'ld_encrypt', 'ld_base_root', 'ld_admin_dn',
#            'ld_admin_login', 'ld_admin_hash', 'ld_admin_pw', 'ld_services',
#            'ld_services_dn']
#    addDn = lambda x,*y: ",".join(y)
#    genDn = lambda x,*y: "=".join(y)
#
#    # base DN LDAP
#    ld_base_dn = {'hide':True}
#
#    # bind суффикс LDAP
#    ld_bind_dn = {'hide':True}
#
#    # bind name
#    ld_bind_login = {'hide':True,
#                     'value':'proxyuser'}
#
#    # bind hash
#    ld_bind_hash = {'hide':True}
#
#    # bind password
#    ld_bind_pw = {'hide':True,
#                  'type':'password',
#                  'value':'calculate'}
#
#    # hash crypto algoritm
#    ld_encrypt = {'hide':True,
#                  'value':'ssha'}
#
#    # base name LDAP
#    ld_base_root = {'hide':True,
#                    'value':'calculate'}
#
#    # admin DN
#    ld_admin_dn = {'hide':True}
#
#    # admin name LDAP
#    ld_admin_login = {'hide':True,
#                      'value':'ldapadmin'}
#
#    # admin hash
#    ld_admin_hash = {'hide':True}
#
#    # admin password
#    ld_admin_pw = {'hide':True,
#                   'type':'password'}
#
#    # name from all services
#    ld_services= {'hide':True,
#                  'value':'Services'}
#
#    # DN from all services
#    ld_services_dn =  {'hide':True}
#
#    def get_ld_base_dn(self):
#        """base DN LDAP"""
#        return self.genDn("dc", self.Get('ld_base_root'))
#
#    def get_ld_bind_dn(self):
#        """bind DN LDAP"""
#        return self.addDn(self.genDn("cn", self.Get('ld_bind_login')),
#                          self.Get('ld_base_dn'))
#
#    def get_ld_bind_hash(self):
#        """hash bind"""
#        return getHash(self.Get('ld_bind_pw'), self.Get('ld_encrypt'))
#
#    def get_ld_admin_dn(self):
#        """root DN"""
#        return self.addDn(self.genDn("cn", self.Get('ld_admin_login')), 
#                          self.Get('ld_base_dn'))
#
#    def get_ld_admin_hash(self):
#        """root hash"""
#        return getHash(self.Get('ld_admin_pw'), self.Get('ld_encrypt'))
#
#    def get_ld_admin_pw(self):
#        """password root"""
#        return genpassword()
#
#    def get_ld_services_dn(self):
#        """DN from all services"""
#        return self.addDn(self.genDn("ou", self.Get('ld_services')), 
#                          self.Get('ld_base_dn'))
