Package backend :: Package server :: Module basePackageUpload
[hide private]
[frames] | no frames]

Source Code for Module backend.server.basePackageUpload

  1  # 
  2  # Copyright (c) 2008--2016 Red Hat, Inc. 
  3  # 
  4  # This software is licensed to you under the GNU General Public License, 
  5  # version 2 (GPLv2). There is NO WARRANTY for this software, express or 
  6  # implied, including the implied warranties of MERCHANTABILITY or FITNESS 
  7  # FOR A PARTICULAR PURPOSE. You should have received a copy of GPLv2 
  8  # along with this software; if not, see 
  9  # http://www.gnu.org/licenses/old-licenses/gpl-2.0.txt. 
 10  # 
 11  # Red Hat trademarks are not licensed under GPLv2. No permission is 
 12  # granted to use or replicate Red Hat trademarks that are incorporated 
 13  # in this software or its documentation. 
 14  # 
 15   
 16  from rhn.UserDictCase import UserDictCase 
 17  from spacewalk.common import apache 
 18   
 19  from spacewalk.common.rhnLog import log_debug 
 20  from spacewalk.common.rhnException import rhnFault 
 21   
 22   
23 -class BasePackageUpload:
24
25 - def __init__(self, req):
26 self.header_prefix = "X-RHN-Upload" 27 self.error_header_prefix = 'X-RHN-Upload-Error' 28 self.prefix = 'rhn/repository' 29 self.is_source = 0 30 self.rel_package_path = None 31 self.package_path = None 32 self.required_fields = [ 33 "Package-Name", 34 "Package-Version", 35 "Package-Release", 36 "Package-Arch", 37 "File-Checksum", 38 "File-Checksum-Type", 39 ] 40 self.field_data = UserDictCase() 41 self.org_id = None
42
43 - def headerParserHandler(self, req):
44 """ This whole function is ugly as hell. The Auth field in the header used to be required, but now 45 it must have either the Auth field or the Auth-Session field. 46 """ 47 # Initialize the logging 48 log_debug(3, "Method", req.method) 49 50 # Header string. This is what the Auth-Session field will look like in the header. 51 session_header = "%s-%s" % (self.header_prefix, "Auth-Session") 52 53 # legacy rhnpush sends File-MD5sum; translate it into File-Checksum 54 md5sum_header = "%s-%s" % (self.header_prefix, "File-MD5sum") 55 if md5sum_header in req.headers_in: 56 req.headers_in["%s-%s" % (self.header_prefix, "File-Checksum-Type")] = 'md5' 57 req.headers_in["%s-%s" % (self.header_prefix, "File-Checksum")] = \ 58 req.headers_in[md5sum_header] 59 60 for f in self.required_fields: 61 hf = "%s-%s" % (self.header_prefix, f) 62 if hf not in req.headers_in: 63 # If the current field is Auth and Auth-Session field isn't present, something is wrong. 64 if f == "Auth" and (session_header not in req.headers_in): 65 log_debug(4, "Required field %s missing" % f) 66 raise rhnFault(500, f) 67 68 # The current field is Auth and the Auth-Session field is present, so everything is good. 69 elif f == "Auth" and (session_header in req.headers_in): 70 self.field_data["Auth-Session"] = req.headers_in[session_header] 71 continue 72 73 # The current field being looked for isn't the Auth field and it's missing, so something is wrong. 74 else: 75 log_debug(4, "Required field %s missing" % f) 76 raise rhnFault(500, f) 77 78 if not (f == "Auth" and (hf not in req.headers_in)): 79 self.field_data[f] = req.headers_in[hf] 80 else: 81 if session_header in req.headers_in: 82 self.field_data[f] = req.headers_in[hf] 83 84 self.package_name = self.field_data["Package-Name"] 85 self.package_version = self.field_data["Package-Version"] 86 self.package_release = self.field_data["Package-Release"] 87 self.package_arch = self.field_data["Package-Arch"] 88 self.file_checksum_type = self.field_data["File-Checksum-Type"] 89 self.file_checksum = self.field_data["File-Checksum"] 90 # 4/18/05 wregglej. if 1051 is in the header's keys, then it's a nosrc package. 91 self.is_source = (self.package_arch == 'src' or self.package_arch == 'nosrc') 92 return apache.OK
93
94 - def handler(self, req):
95 log_debug(3, "Method", req.method) 96 return apache.OK
97
98 - def cleanupHandler(self, req):
99 return apache.OK
100
101 - def logHandler(self, req):
102 return apache.OK
103