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

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

Add new controller, feeds, to centralise all feed creation code. Add
new template, feed_creator, to allow input form to directly create
atom feed entry. Add general feed to discovery search page - tieing
this to the feed created by feed_creator. Add icons for feed and
include these in the config set up.

Line 
1'''
2Class defining the config params for the milk server
3'''
4from paste.deploy import CONFIG
5from ndg.common.src.models.myconfig import myConfig
6from ndg.common.src.lib.atomvalidator import AtomValidator
7from ndg.common.src.clients.http.vocabserverclient import VocabServerClient
8import milk_server.lib.helpers as h
9import milk_server.lib.constants as constants
10
11class NDGConfigError(Exception): 
12    '''Errors related to reading from ndg config file'''
13     
14class milkMiddleware:
15   
16    def __init__(self, app, g, app_conf):
17       
18        #this is the next application in the wsgi stack
19        self.app=app
20       
21        #set up the ndg configuration file
22        cf= CONFIG['app_conf']['configfile']
23        cf=myConfig(cf)
24     
25        self.globals=g
26        self.globals.htdocs=cf.get('DEFAULT','htdocs',None)
27        self.globals.localLink=cf.get('layout','localLink',None)
28        self.globals.ndgLink=cf.get('layout','ndgLink','http://ndg.nerc.ac.uk')
29        self.globals.ndgImage=cf.get('layout','ndgImage',None)
30        self.globals.ndgAlt=cf.get('layout','ndgAlt','Visit NDG')
31        self.globals.stfcLink=cf.get('layout','stfcLink')
32        self.globals.stfcImage=cf.get('layout','stfcImage')
33        self.globals.helpIcon=cf.get('layout','helpIcon')
34        self.globals.navPlus=cf.get('layout','navPlus')
35        self.globals.loadingIcon=cf.get('layout','loadingIcon')
36        self.globals.navMinus=cf.get('layout','navMinus')
37        self.globals.LeftAlt=cf.get('layout','HdrLeftAlt')
38        self.globals.LeftLogo=cf.get('layout','HdrLeftLogo')
39        self.globals.icons_xml=cf.get('layout','Xicon')
40        self.globals.icons_plot=cf.get('layout','plot')
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')
44        self.globals.icons_D=cf.get('DISCOVERY','icon')
45        self.globals.icons_R=cf.get('RELATED','icon')
46        self.globals.icons_key=cf.get('layout','key')
47        self.globals.feedIcon = cf.get('layout','feedIcon')
48       
49        self.globals.debugModeOn = \
50            self.__getTrueFalseValue(cf.get('DEFAULT','debug')) 
51       
52        self.globals.atomEditorEnabled = \
53            self.__getTrueFalseValue(cf.get('MILK_SERVER','editorOn')) 
54
55        self.globals.browseEnabled = \
56            self.__getTrueFalseValue(cf.get('MILK_SERVER','browseOn')) 
57
58        self.globals.discoveryEnabled = \
59            self.__getTrueFalseValue(cf.get('MILK_SERVER','discoveryOn')) 
60
61        self.globals.wmcClientURL = cf.get('WMC_CLIENT','url')
62       
63        self.globals.disclaimer=cf.get('default','disclaimer')
64       
65        self.globals.discoveryURL=cf.get('SEARCH','discoveryURL')
66       
67        self.globals.server=cf.get('DEFAULT','server','')
68
69        self.globals.proxyServer = cf.get('DEFAULT','proxyServer')
70
71        self.globals.mailServer = cf.get('DEFAULT','mailServer')
72        self.globals.tbRecipient = cf.get('DEFAULT', 'tbrecipient')
73        self.globals.metadataMaintainer = cf.get('DEFAULT','metadataMaintainer')
74               
75        # for standalone discovery
76        self.globals.standalone = cf.config.getboolean('DISCOVERY','standalone')
77
78        # NB, without this set, the default host on ndg.badc.rl.ac.uk will be
79        # used by discoveryServiceClient
80        self.globals.discoveryServiceURL = cf.get('DISCOVERY', 'discoveryServiceURL')
81               
82        self.globals.pwFile = cf.get('NDG_EXIST','passwordFile')
83        self.globals.localEXist = cf.get('NDG_EXIST','local')
84        # set up the validator for atoms - to allow re-use across the app
85        self.globals.validator = AtomValidator(None,
86                                               localMILKServer = self.globals.server, 
87                                               dbConfigFile = self.globals.pwFile, 
88                                               dbHostName = self.globals.localEXist,
89                                               newLineChar="<br/>",
90                                               isDebug = self.globals.debugModeOn,
91                                               loadAllCollections = False)
92
93        # initialise client to vocab server - to do vocab term searches
94        self.globals.vocabServerClient = VocabServerClient(proxyServer = self.globals.proxyServer)
95
96        # initialise collection to store re-usable connections to the eXist DB
97        self.globals.eXistDBCons = {}
98       
99        self.globals.orderByList = h.options_for_select(constants.ORDER_BY_LIST)
100
101        # Security Related
102
103        # Single Sign On settings - check for mode of operation:
104        # 1) act as a client to a separate Single Sign On Service
105        # or
106        # 2) Single Sign On service is integrated into THIS service
107        securityEnabled = not self.globals.standalone
108        isSSOClient = cf.config.has_section('NDG_SECURITY.ssoClient') and \
109            securityEnabled
110           
111        isSSOService = cf.config.has_section('NDG_SECURITY.ssoService') and \
112            securityEnabled
113           
114        if isSSOClient and isSSOService:
115            raise NDGConfigError(\
116                "NDG_SECURITY.ssoClient and NDG_SECURITY.ssoService " + \
117                "sections are present in the NDG Config file: " + \
118                "only one or the other may be set")
119 
120        if isSSOClient:
121            try:
122                from \
123            ndg.security.client.ssoclient.ssoclient.config.ssoClientMiddleware\
124                    import SSOMiddleware
125            except ImportError, e:
126                # If standalone flag is not present security must be enabled
127                raise NDGConfigError(\
128                    '%s: importing Single Sign On Client SSOMiddleware: %s' % \
129                        (__name__, e))
130                       
131               
132            self.app = SSOMiddleware(app, cf.config, g, app_conf,
133                                     defSection='NDG_SECURITY.ssoClient')
134           
135            self.globals.sslServer = g.ndg.security.common.sso.cfg.sslServer
136            self.globals.wayfuri=g.ndg.security.common.sso.cfg.wayfuri
137            self.globals.logout=g.ndg.security.common.sso.cfg.logoutURI
138           
139        elif isSSOService:
140            try:
141                from ndg.security.server.sso.sso.config.ssoServiceMiddleware \
142                    import SSOMiddleware
143            except ImportError, e:
144                # If standalone flag is not present security must be enabled
145                raise NDGConfigError(\
146                    '%s: importing Single Sign On Service SSOMiddleware: %s' %\
147                        (__name__, e))
148                       
149               
150            self.app = SSOMiddleware(app, g, app_conf,
151                                     defSection='NDG_SECURITY.ssoService',
152                                     wssSection='NDG_SECURITY.wssecurity')
153           
154            self.globals.sslServer=g.ndg.security.server.sso.cfg.sslServer
155            self.globals.wayfuri=g.ndg.security.server.sso.cfg.wayfuri
156            self.globals.logout=g.ndg.security.server.sso.cfg.logoutURI
157            self.globals.getCredentials=g.ndg.security.server.sso.cfg.getCredentials
158
159        # Policy Enforcement Point initialisation
160        if securityEnabled:
161            try:
162                from ndg.security.common.authz.pep import PEP
163            except ImportError, e:
164                # If standalone flag is not present security must be enabled
165                raise NDGConfigError('%s: expecting standalone config ' % \
166                        __name__ + 
167                        'flag set to False for Policy Enforcement Point ' + \
168                        'import: %s' % e)
169           
170            self.globals.pep = PEP(cfg=cf.config, 
171                                   cfgSection='NDG_SECURITY.gatekeeper')
172           
173        self.config=cf
174       
175        self.__setUpHelpText(g)
176
177    def __getTrueFalseValue(self, val):
178        '''
179        Check for config values that could be true/false in a consistent manner
180        @param val: value read from config object
181        @return True, if val is some form of 'true'
182        '''
183        if val and val.lower() == 'true':
184            return True
185        return False
186
187    def __setUpHelpText(self, g):
188       
189        cf = CONFIG['app_conf']['helpConfigfile']
190        cf = myConfig(cf)
191        # NB, the cf.config class lowercases everything.
192        for (section, val) in cf.config.items('ATOM_EDITOR'):
193            setattr(g, section, val)
194           
195        # extend the granulite example link - to add a valid location
196        g.example_granulite = g.example_granulite.replace('HREF', \
197            h.url_for('example'))
198       
199       
200    def __call__(self,environ,start_response):
201       
202        environ['ndgConfig']=self.config
203        return self.app(environ,start_response)
204   
Note: See TracBrowser for help on using the repository browser.