Changeset 2418

Show
Ignore:
Timestamp:
09/03/05 14:20:30 (19 years ago)
Author:
jerome
Message:

Allow PyKota admins and users to use different database backends
or locations depending on their permissions.
Severity : minor, but with great possibilities :)

Location:
pykota/trunk
Files:
6 modified

Legend:

Unmodified
Added
Removed
  • pykota/trunk/conf/pykotadmin.conf.sample

    r2303 r2418  
    5151 
    5252# 
    53 # THIS FILE CAN ONLY CONTAIN A [global] SECTION AND TWO FIELDS 
    54 # NAMED storageadmin AND storageadminpw 
     53# THIS FILE CAN ONLY CONTAIN A [global] SECTION AND ONE MANDATORY 
     54# FIELD NAMED storageadmin, ALONG WITH THE FOLLOWING FOUR OPTIONAL 
     55# FIELDS : storageadminpw, storagebackend, storageserver, storagename. 
    5556# 
    5657 
     
    6162# storageadminpw: Comment out if unused, or set to Quota Storage admin password 
    6263 
     64# storagebackend: ldapstorage 
     65# storageserver: ldap://ldapmaster.example.com:389 
     66# storagename: dc=example,dc=com 
     67 
  • pykota/trunk/NEWS

    r2414 r2418  
    2222PyKota NEWS : 
    2323        
     24    - 1.23alpha24 : 
     25     
     26        - Allows different databases to be used depending on the 
     27          user's rights. This allows PyKota admins to directly 
     28          use a master LDAP server for read+write, while letting 
     29          normal users using the replicas for readonly access. 
     30          NB : using different storage backends is also possible, 
     31          but you're on your own there. 
     32           
    2433    - 1.23alpha23 : 
    2534     
  • pykota/trunk/pykota/config.py

    r2405 r2418  
    4343        self.directory = directory 
    4444        self.filename = os.path.join(directory, "pykota.conf") 
     45        self.adminfilename = os.path.join(directory, "pykotadmin.conf") 
    4546        if not os.path.isfile(self.filename) : 
    4647            raise PyKotaConfigError, _("Configuration file %s not found.") % self.filename 
     48        if not os.path.isfile(self.adminfilename) : 
     49            raise PyKotaConfigError, _("Configuration file %s not found.") % self.adminfilename 
     50        if os.access(self.adminfilename, os.R_OK) :     
     51            self.isAdmin = 1 
    4752        self.config = ConfigParser.ConfigParser() 
    4853        self.config.read([self.filename]) 
     
    97102        backendinfo["storageadmin"] = None 
    98103        backendinfo["storageadminpw"] = None 
    99         adminconf = ConfigParser.ConfigParser() 
    100         filename = os.path.join(self.directory, "pykotadmin.conf") 
    101         adminconf.read([filename]) 
    102         if adminconf.sections() : # were we able to read the file ? 
    103             try : 
    104                 backendinfo["storageadmin"] = adminconf.get("global", "storageadmin", raw=1) 
    105             except (ConfigParser.NoSectionError, ConfigParser.NoOptionError) :     
    106                 raise PyKotaConfigError, _("Option %s not found in section global of %s") % ("storageadmin", filename) 
    107             else :     
    108                 self.isAdmin = 1 # We are a PyKota administrator 
    109             try : 
    110                 backendinfo["storageadminpw"] = adminconf.get("global", "storageadminpw", raw=1) 
    111             except (ConfigParser.NoSectionError, ConfigParser.NoOptionError) :     
    112                 pass # Password is optional 
     104        if self.isAdmin : 
     105            adminconf = ConfigParser.ConfigParser() 
     106            adminconf.read([self.adminfilename]) 
     107            if adminconf.sections() : # were we able to read the file ? 
     108                try : 
     109                    backendinfo["storageadmin"] = adminconf.get("global", "storageadmin", raw=1) 
     110                except (ConfigParser.NoSectionError, ConfigParser.NoOptionError) :     
     111                    raise PyKotaConfigError, _("Option %s not found in section global of %s") % ("storageadmin", self.adminfilename) 
     112                try : 
     113                    backendinfo["storageadminpw"] = adminconf.get("global", "storageadminpw", raw=1) 
     114                except (ConfigParser.NoSectionError, ConfigParser.NoOptionError) :     
     115                    pass # Password is optional 
     116                # Now try to overwrite the storagebackend, storageserver  
     117                # and storagename. This allows admins to use the master LDAP 
     118                # server directly and users to use the replicas transparently. 
     119                try : 
     120                    backendinfo["storagebackend"] = adminconf.get("global", "storagebackend", raw=1) 
     121                except ConfigParser.NoOptionError : 
     122                    pass 
     123                try : 
     124                    backendinfo["storageserver"] = adminconf.get("global", "storageserver", raw=1) 
     125                except ConfigParser.NoOptionError : 
     126                    pass 
     127                try : 
     128                    backendinfo["storagename"] = adminconf.get("global", "storagename", raw=1) 
     129                except ConfigParser.NoOptionError : 
     130                    pass 
    113131        return backendinfo 
    114132         
  • pykota/trunk/pykota/storages/ldapstorage.py

    r2388 r2418  
    7272        for tryit in range(3) : 
    7373            try : 
     74                self.tool.logdebug("Trying to open database (host=%s, dbname=%s, user=%s)..." % (self.savedhost, self.saveddbname, self.saveduser)) 
    7475                self.database = ldap.initialize(self.savedhost)  
    7576                if self.info["ldaptls"] : 
  • pykota/trunk/pykota/storages/pgstorage.py

    r2302 r2418  
    4848            port = -1         # Use PostgreSQL's default tcp/ip port (5432). 
    4949         
     50        self.tool.logdebug("Trying to open database (host=%s, port=%s, dbname=%s, user=%s)..." % (host, port, dbname, user)) 
    5051        self.database = pg.connect(host=host, port=port, dbname=dbname, user=user, passwd=passwd) 
    5152        self.closed = 0 
  • pykota/trunk/pykota/version.py

    r2413 r2418  
    2222# 
    2323 
    24 __version__ = "1.23alpha23_unofficial" 
     24__version__ = "1.23alpha24_unofficial" 
    2525 
    2626__doc__ = "PyKota : a complete Printing Quota Solution for CUPS and LPRng."