source: TI05-delivery/ows_framework/trunk/ows_server/ows_server/controllers/fetch.py @ 2782

Subversion URL: http://proj.badc.rl.ac.uk/svn/ndg/TI05-delivery/ows_framework/trunk/ows_server/ows_server/controllers/fetch.py@2782
Revision 2782, 1.7 KB checked in by domlowe, 12 years ago (diff)

integrating Trajectory subsetting into pylons wcs

Line 
1from ows_server.lib.base import *
2import os
3
4class FetchController(BaseController):
5    def _getMimeType(self, file):
6        if os.path.splitext(file)[1]=='.nc':
7            return 'application/cf-netcdf'
8        else:
9            return 'application/unknown'
10       
11       
12    def fetchFile(self, file):
13        ''' returns a file from the filestore. Used for the wcs store parameter, but could be used for other services.
14        checks the security information in the text file that accompanies the file and checks ndg security'''
15       
16        #given the filename, these are the paths to the file, and to the accompanying text file
17        filePath=request.environ['paste.config']['app_conf']['publish_dir'] + '/' + file
18        textFilePath=request.environ['paste.config']['app_conf']['publish_dir']+'/'+os.path.splitext(os.path.basename(file))[0]+'.txt'
19   
20        #open the text file and read security credentials
21        input =open(textFilePath, 'r')
22        sec=input.read()
23       
24        #check current users credentials
25        #if they match, return the file
26        #TODO, check this properly
27        if sec=='No Security':
28            match=True #allow       
29        elif 'ndgSec' in session:
30            if sec == str(session['ndgSec']):
31                match=True #allow         
32            else:
33                match=False #deny
34        else:
35             match=False  #deny     
36        if match:
37            #return the file (netcdf)
38            fileToReturn=open(filePath, 'r')
39            mType=self._getMimeType(file)
40            return Response(content=fileToReturn, mimetype=mType)
41        else:
42            #return access denied message
43            return render_response('wcs_accessDenied', mimetype ='text/html')
44
Note: See TracBrowser for help on using the repository browser.