def getPackage(self, pkgFilename, *args): """ Get rpm package. """ log_debug(3, pkgFilename) if args: pkg_spec = [pkgFilename] + list(args) else: pkg_spec = pkgFilename redirectsSupported = 0 # If we are talking to a proxy, determine whether it's a version that # supports redirects. proxyVersionString = rhnFlags.get('x-rhn-proxy-version') if proxyVersionString: redirectsSupported = 1 else: # Must be a client. We'll determine the redirect capability via # the x-rhn-transport-capability header instead. transport_cap = rhnFlags.get('x-rhn-transport-capability') if transport_cap: transport_cap_list = transport_cap.split('=') redirectsSupported = transport_cap_list[ 0] == 'follow-redirects' and transport_cap_list[1] >= 2 if redirectsSupported: log_debug(3, "Client supports redirects.") filePath = self.getPackagePath(pkg_spec, 1) else: #older clients just return the hosted url and download the package filePath = self.getPackagePath(pkg_spec) return self._getFile(filePath)
def getPackage(self, pkgFilename, *args): """ Get rpm package. """ log_debug(3, pkgFilename) if args: pkg_spec = [pkgFilename] + list(args) else: pkg_spec = pkgFilename redirectsSupported = 0 # If we are talking to a proxy, determine whether it's a version that # supports redirects. proxyVersionString = rhnFlags.get('x-rhn-proxy-version') if proxyVersionString: redirectsSupported = 1 else: # Must be a client. We'll determine the redirect capability via # the x-rhn-transport-capability header instead. transport_cap = rhnFlags.get('x-rhn-transport-capability') if transport_cap : transport_cap_list = transport_cap.split('=') redirectsSupported = transport_cap_list[0] == 'follow-redirects' and transport_cap_list[1] >= 2 if redirectsSupported: log_debug(3, "Client supports redirects.") filePath = self.getPackagePath(pkg_spec, 1) else: #older clients just return the hosted url and download the package filePath = self.getPackagePath(pkg_spec) return self._getFile(filePath)
def getxml(self): # see if there were any template strings loaded from the db, # {label:value} templateOverrides = rhnFlags.get('templateOverrides') # update the templateValues in the module if templateOverrides: for label in templateOverrides.keys(): # only care about values we've defined defaults for... if templateValues.has_key(label): templateValues[label] = templateOverrides[label] s = StringIO() s.write("\n") if self.text: s.write(_("Error Message:\n %s\n") % self.text.strip()) if self.code: s.write(_("Error Class Code: %s\n") % self.code) if self.arrayText: cinfo = self.arrayText % templateValues s.write(_("Error Class Info: %s\n") % cinfo.rstrip()) if self.explain: s.write(_("Explanation: %s") % Explain) if not self.code: return xmlrpclib.Fault(1, s.getvalue()) return xmlrpclib.Fault(-self.code, s.getvalue())
def __init__(self): # We store the security list in the global flags. This way, we don't # have to worry about clearing it up. if rhnFlags.test(self._flag_string): self.sec = rhnFlags.get(self._flag_string) else: self.sec = [] rhnFlags.set(self._flag_string, self.sec)
def _set_proxy_info(self, req): """ Spacewalk Proxy stuff. """ proxyVersion = "X-RHN-Proxy-Version" if req.headers_in.has_key(proxyVersion): self.proxyVersion = req.headers_in[proxyVersion] # Make sure the proxy version gets set in the headers. rhnFlags.get("outputTransportOptions")[proxyVersion] = str(self.proxyVersion) # Make sure the proxy auth-token gets set in global flags. if req.headers_in.has_key("X-RHN-Proxy-Auth"): rhnFlags.set("X-RHN-Proxy-Auth", req.headers_in["X-RHN-Proxy-Auth"]) return apache.OK
def getPackage(self, pkgFilename, *args): """ Get rpm package. """ log_debug(3, pkgFilename) if args: pkg_spec = [pkgFilename] + list(args) else: pkg_spec = pkgFilename redirectsSupported = 0 # If we are talking to a proxy, determine whether it's a version that # supports redirects. proxyVersionString = rhnFlags.get('x-rhn-proxy-version') if proxyVersionString: # Convert the version string to a number format that we can compare. versionParts = proxyVersionString.split('.') proxyVersionStringBaked = \ "%s.%s" % (versionParts[0], string.join(versionParts[1:], '')) # Check the proxy version. To maintain backward compatibility, we # won't redirect to proxies < v4.1.0. log_debug(3, "Detected proxy version " + proxyVersionStringBaked) if float(proxyVersionStringBaked) >= 4.1: redirectsSupported = 1 else: # Must be a client. We'll determine the redirect capability via # the x-rhn-transport-capability header instead. transport_cap = rhnFlags.get('x-rhn-transport-capability') if transport_cap : transport_cap_list = transport_cap.split('=') redirectsSupported = transport_cap_list[0] == 'follow-redirects' and transport_cap_list[1] >= 2 if redirectsSupported: log_debug(3, "Client supports redirects.") filePath = self.getPackagePath(pkg_spec, 1) else: #older clients just return the hosted url and download the package filePath = self.getPackagePath(pkg_spec) return self._getFile(filePath)
def _set_proxy_info(self, req): """ RHN Proxy stuff. """ proxyVersion = 'X-RHN-Proxy-Version' if req.headers_in.has_key(proxyVersion): self.proxyVersion = req.headers_in[proxyVersion] # Make sure the proxy version gets set in the headers. rhnFlags.get('outputTransportOptions')[proxyVersion] = str( self.proxyVersion) # Make sure the proxy auth-token gets set in global flags. if req.headers_in.has_key('X-RHN-Proxy-Auth'): rhnFlags.set('X-RHN-Proxy-Auth', req.headers_in['X-RHN-Proxy-Auth']) return apache.OK
def _set_proxy_info(self, req): """ Spacewalk Proxy stuff. """ proxyVersion = 'X-RHN-Proxy-Version' if req.headers_in.has_key(proxyVersion): self.proxyVersion = req.headers_in[proxyVersion] # Make sure the proxy version gets set in the headers. rhnFlags.get('outputTransportOptions')[proxyVersion] = str( self.proxyVersion) # Make sure the proxy auth-token gets set in global flags. if req.headers_in.has_key('X-RHN-Proxy-Auth'): rhnFlags.set('X-RHN-Proxy-Auth', req.headers_in['X-RHN-Proxy-Auth']) return apache.OK
def _set_last_modified(self, last_modified, extra_headers={}): log_debug(4, last_modified) if not last_modified: return None # Set a field with the name of the header transport = rhnFlags.get('outputTransportOptions') if last_modified: # Put the last-modified info too if type(last_modified) in (types.IntType, types.FloatType): last_modified = rfc822time(last_modified) transport['Last-Modified'] = last_modified for k, v in extra_headers.items(): transport[str(k)] = str(v) return transport
def headerParserHandler(self, req): """ after a request has been received, first thing we do is to create the input object """ # pylint: disable=R0911 log_setreq(req) log_debug(3) self.start_time = time.time() # Decline if this is a subrequest: if req.main: return apache.DECLINED log_debug(4, req.method, req.path_info, req.headers_in) # Clear the global flags. rhnFlags.reset() # Init the transport options. rhnFlags.set('outputTransportOptions', UserDictCase()) # Init the session token dictionary. rhnFlags.set("AUTH_SESSION_TOKEN", UserDictCase()) ret = self._init_request_processor(req) if ret != apache.OK: return ret ret = self._set_client_info(req) if ret != apache.OK: return ret # Check the protocol version if req.proto_num < 1001: # HTTP protocols prior to 1.1 close the connection rhnFlags.get('outputTransportOptions')["Connection"] = "close" ret = self._set_proxy_info(req) if ret != apache.OK: return ret # Need to run _set_other first, since _set_lang needs RoodDir set ret = self._set_other(req) if ret != apache.OK: return ret ret = self._set_lang(req) if ret != apache.OK: return ret return apache.OK
def _set_last_modified(last_modified, extra_headers=None): log_debug(4, last_modified) if not last_modified: return None # Set a field with the name of the header transport = rhnFlags.get('outputTransportOptions') if last_modified: # Put the last-modified info too if type(last_modified) in (types.IntType, types.FloatType): last_modified = rfc822time(last_modified) transport['Last-Modified'] = last_modified if extra_headers: for k, v in extra_headers.items(): transport[str(k)] = str(v) return transport
def _set_client_info(self, req): # Figure out the client version clientVersionHeader = "X-RHN-Client-Version" if req.headers_in.has_key(clientVersionHeader): # Useful to have it as a separate variable, to see it in a # traceback report clientVersion = req.headers_in[clientVersionHeader] self.clientVersion = int(clientVersion) # NOTE: x-client-version is really the cgiwrap xmlrpc API version # NOT the RHN client version... but it works if nothing else # does. elif req.headers_in.has_key("X-Client-Version"): clientVersion = req.headers_in["X-Client-Version"] self.clientVersion = int(clientVersion) else: self.clientVersion = 0 # Make sure the client version gets set in the headers. rhnFlags.get("outputTransportOptions")[clientVersionHeader] = str(self.clientVersion) return apache.OK
def _set_client_info(self, req): # Figure out the client version clientVersionHeader = 'X-RHN-Client-Version' if req.headers_in.has_key(clientVersionHeader): # Useful to have it as a separate variable, to see it in a # traceback report clientVersion = req.headers_in[clientVersionHeader] self.clientVersion = int(clientVersion) # NOTE: x-client-version is really the cgiwrap xmlrpc API version # NOT the RHN client version... but it works if nothing else # does. elif req.headers_in.has_key('X-Client-Version'): clientVersion = req.headers_in['X-Client-Version'] self.clientVersion = int(clientVersion) else: self.clientVersion = 0 # Make sure the client version gets set in the headers. rhnFlags.get('outputTransportOptions')[clientVersionHeader] = str( self.clientVersion) return apache.OK