source: MILK/trunk/milk_server/milk_server/config/milkMiddleware.py @ 4845

Subversion URL: http://proj.badc.rl.ac.uk/svn/ndg/MILK/trunk/milk_server/milk_server/config/milkMiddleware.py@4845
Revision 4845, 7.3 KB checked in by cbyrom, 11 years ago (diff)

Add improved error handling when doing document ingests + add
additional help sections for this purpose.

RevLine 
[4485]1'''
2Class defining the config params for the milk server
3'''
[2615]4from paste.deploy import CONFIG
[4798]5from ndg.common.src.models.myconfig import myConfig
6from ndg.common.src.lib.atomvalidator import AtomValidator
[4599]7import milk_server.lib.helpers as h
[2929]8
[3893]9class NDGConfigError(Exception): 
10    '''Errors related to reading from ndg config file'''
11     
[4485]12class milkMiddleware:
[2615]13   
[3919]14    def __init__(self, app, g, app_conf):
[2615]15       
16        #this is the next application in the wsgi stack
17        self.app=app
18       
19        #set up the ndg configuration file
[2736]20        cf= CONFIG['app_conf']['configfile']
[2616]21        cf=myConfig(cf)
22     
23        self.globals=g
[3137]24        self.globals.htdocs=cf.get('DEFAULT','htdocs',None)
[2616]25        self.globals.localLink=cf.get('layout','localLink',None)
[3893]26        self.globals.localAlt=cf.get('layout','localAlt','Visit Local Site')
27        self.globals.ndgLink=cf.get('layout','ndgLink','http://ndg.nerc.ac.uk')
28        self.globals.ndgImage=cf.get('layout','ndgImage',None)
29        self.globals.ndgAlt=cf.get('layout','ndgAlt','Visit NDG')
[2672]30        self.globals.stfcLink=cf.get('layout','stfcLink')
31        self.globals.stfcImage=cf.get('layout','stfcImage')
32        self.globals.helpIcon=cf.get('layout','helpIcon')
[4211]33        self.globals.navPlus=cf.get('layout','navPlus')
[4579]34        self.globals.loadingIcon=cf.get('layout','loadingIcon')
[4211]35        self.globals.navMinus=cf.get('layout','navMinus')
[2672]36        self.globals.LeftAlt=cf.get('layout','HdrLeftAlt')
37        self.globals.LeftLogo=cf.get('layout','HdrLeftLogo')
38        self.globals.pageLogo="bodcHdr"
[2688]39        self.globals.icons_xml=cf.get('layout','Xicon')
[3418]40        self.globals.icons_plot=cf.get('layout','plot')
[2688]41        self.globals.icons_prn=cf.get('layout','printer')
42        self.globals.icons_A=cf.get('NDG_A_SERVICE','icon')
43        self.globals.icons_B=cf.get('NDG_B_SERVICE','icon')
[2703]44        self.globals.icons_D=cf.get('DISCOVERY','icon')
45        self.globals.icons_R=cf.get('RELATED','icon')
[2791]46        self.globals.icons_key=cf.get('layout','key')
[4477]47       
48        self.globals.atomEditorEnabled = cf.get('ATOM_EDITOR','enabled')
[4594]49        self.globals.debugAtomEditor = cf.get('ATOM_EDITOR','debug') or False
[4482]50
51        self.globals.wmcClientURL = cf.get('WMC_CLIENT','url')
[3120]52       
[3119]53        self.globals.disclaimer=cf.get('default','disclaimer')
[2626]54       
[2672]55        self.globals.discoveryURL=cf.get('SEARCH','discoveryURL')
56       
[2626]57        self.globals.server=cf.get('DEFAULT','server','')
[2929]58
[3120]59        # for standalone discovery
[4259]60        self.globals.standalone=cf.config.getboolean('DISCOVERY','standalone')
[3893]61
[4259]62        # NB, without this set, the default host on ndg.badc.rl.ac.uk will be used by ndgSearch
63        if cf.config.has_option('DISCOVERY', 'discoveryServiceURL'):
64            self.globals.discoveryServiceURL = \
[4491]65                cf.config.get('DISCOVERY', 'discoveryServiceURL')
66               
67        self.globals.pwFile = cf.get('NDG_EXIST','passwordFile')
68        # set up the validator for atoms - to allow re-use across the app
[4506]69        self.globals.validator = AtomValidator(None, self.globals.pwFile, \
[4625]70                                       newLineChar="<br/>",
[4845]71                                       isDebug = self.globals.debugAtomEditor, \
72                                       loadAllCollections = True)
[4259]73
[4504]74        # initialise collection to store re-usable connections to the eXist DB
75        self.globals.eXistDBCons = {}
76       
[3893]77        # Security Related
78
79        # Single Sign On settings - check for mode of operation:
80        # 1) act as a client to a separate Single Sign On Service
81        # or
82        # 2) Single Sign On service is integrated into THIS service
83        securityEnabled = not self.globals.standalone
84        isSSOClient = cf.config.has_section('NDG_SECURITY.ssoClient') and \
85            securityEnabled
86           
87        isSSOService = cf.config.has_section('NDG_SECURITY.ssoService') and \
88            securityEnabled
89           
90        if isSSOClient and isSSOService:
91            raise NDGConfigError(\
92                "NDG_SECURITY.ssoClient and NDG_SECURITY.ssoService " + \
93                "sections are present in the NDG Config file: " + \
94                "only one or the other may be set")
95 
96        if isSSOClient:
97            try:
98                from \
99            ndg.security.client.ssoclient.ssoclient.config.ssoClientMiddleware\
100                    import SSOMiddleware
101            except ImportError, e:
102                # If standalone flag is not present security must be enabled
103                raise NDGConfigError(\
104                    '%s: importing Single Sign On Client SSOMiddleware: %s' % \
105                        (__name__, e))
106                       
107               
[3919]108            self.app = SSOMiddleware(app, cf.config, g, app_conf,
109                                     defSection='NDG_SECURITY.ssoClient')
[3893]110           
[3919]111            self.globals.sslServer = g.ndg.security.common.sso.cfg.sslServer
112            self.globals.wayfuri=g.ndg.security.common.sso.cfg.wayfuri
113            self.globals.logout=g.ndg.security.common.sso.cfg.logoutURI
[3893]114           
115        elif isSSOService:
116            try:
117                from ndg.security.server.sso.sso.config.ssoServiceMiddleware \
118                    import SSOMiddleware
119            except ImportError, e:
120                # If standalone flag is not present security must be enabled
121                raise NDGConfigError(\
122                    '%s: importing Single Sign On Service SSOMiddleware: %s' %\
123                        (__name__, e))
124                       
125               
[3919]126            self.app = SSOMiddleware(app, g, app_conf,
127                                     defSection='NDG_SECURITY.ssoService',
128                                     wssSection='NDG_SECURITY.wssecurity')
[3893]129           
[3919]130            self.globals.sslServer=g.ndg.security.server.sso.cfg.sslServer
131            self.globals.wayfuri=g.ndg.security.server.sso.cfg.wayfuri
132            self.globals.logout=g.ndg.security.server.sso.cfg.logoutURI
133            self.globals.getCredentials=g.ndg.security.server.sso.cfg.getCredentials
[3901]134
135        # Policy Enforcement Point initialisation
136        if securityEnabled:
137            try:
138                from ndg.security.common.authz.pep import PEP
139            except ImportError, e:
140                # If standalone flag is not present security must be enabled
141                raise NDGConfigError('%s: expecting standalone config ' % \
142                        __name__ + 
143                        'flag set to False for Policy Enforcement Point ' + \
144                        'import: %s' % e)
145           
146            self.globals.pep = PEP(cfg=cf.config, 
147                                   cfgSection='NDG_SECURITY.gatekeeper')
148           
[2616]149        self.config=cf
[2615]150       
[4599]151        self.__setUpHelpText(g)
152
153
154    def __setUpHelpText(self, g):
[2616]155       
[4599]156        cf = CONFIG['app_conf']['helpConfigfile']
157        cf = myConfig(cf)
158        # NB, the cf.config class lowercases everything.
159        for (section, val) in cf.config.items('ATOM_EDITOR'):
160            setattr(g, section, val)
161           
162        # extend the granulite example link - to add a valid location
163        g.example_granulite = g.example_granulite.replace('HREF', \
[4724]164            h.url_for('example'))
[4599]165       
166       
[2615]167    def __call__(self,environ,start_response):
168       
169        environ['ndgConfig']=self.config
170        return self.app(environ,start_response)
171   
Note: See TracBrowser for help on using the repository browser.