def _get_streamer_url(catalog_entry, signing_key): """ Build a URL that can be used to retrieve the file in the catalog entry from the lazy streamer. :param catalog_entry: The catalog entry to get the URL for. :type catalog_entry: pulp.server.db.model.LazyCatalogEntry :param signing_key: The server private RSA key to sign the url with. :type signing_key: M2Crypto.RSA.RSA :return: The signed streamer URL which corresponds to the catalog entry. :rtype: str """ try: https_retrieval = parse_bool(pulp_conf.get('lazy', 'https_retrieval')) except Unparsable: raise PulpCodedTaskException(error_codes.PLP1014, section='lazy', key='https_retrieval', reason=_('The value is not boolean')) retrieval_scheme = 'https' if https_retrieval else 'http' host = pulp_conf.get('lazy', 'redirect_host') port = pulp_conf.get('lazy', 'redirect_port') path_prefix = pulp_conf.get('lazy', 'redirect_path') netloc = (host + ':' + port) if port else host path = os.path.join(path_prefix, catalog_entry.path.lstrip('/')) unsigned_url = urlunsplit((retrieval_scheme, netloc, path, None, None)) # Sign the URL for a year to avoid the URL expiring before the task completes return str(URL(unsigned_url).sign(signing_key, expiration=31536000))
def pulp_bindings(): """ Get a pulp bindings object for this node. Properties defined in the pulp server configuration are used when not defined in the node configuration. :return: A pulp bindings object. :rtype: Bindings """ node_conf = read_config() oauth = node_conf.oauth verify_ssl = parse_bool(node_conf.main.verify_ssl) ca_path = node_conf.main.ca_path host = pulp_conf.get('server', 'server_name') key = pulp_conf.get('oauth', 'oauth_key') secret = pulp_conf.get('oauth', 'oauth_secret') connection = PulpConnection( host=host, port=443, oauth_key=key, oauth_secret=secret, oauth_user=oauth.user_id, verify_ssl=verify_ssl, ca_path=ca_path) bindings = Bindings(connection) return bindings
def get(self, request): """ Process the GET content request. :param request: The WSGI request object. :type request: django.core.handlers.wsgi.WSGIRequest :return: An appropriate HTTP reply :rtype: django.http.HttpResponse """ host = request.get_host() path = os.path.realpath(request.path_info) lazy_enabled = parse_bool(pulp_conf.get('lazy', 'enabled')) # Authorization if not allow_access(request.environ, host): # Not Authorized return HttpResponseForbidden() # Already downloaded if os.path.exists(path): return self.x_send(path) # Redirect if lazy_enabled: return self.redirect(request, self.key) # NotFound return HttpResponseNotFound(request.path_info)
def get(self, request): """ Process the GET content request. :param request: The WSGI request object. :type request: django.core.handlers.wsgi.WSGIRequest :return: An appropriate HTTP reply :rtype: django.http.HttpResponse """ host = request.get_host() path = os.path.realpath(request.path_info) lazy_enabled = parse_bool(pulp_conf.get('lazy', 'enabled')) # Authorization if not allow_access(request.environ, host): # Not Authorized return HttpResponseForbidden() # Immediately 404 if the symbolic link doesn't even exist if not os.path.lexists(request.path_info): return HttpResponseNotFound(request.path_info) # Already downloaded if os.path.exists(path): return self.x_send(path) # Redirect if lazy is on if lazy_enabled: return self.redirect(request, self.key) # NotFound return HttpResponseNotFound(request.path_info)
def __init__(self): host = cfg.server.host port = int(cfg.server.port) verify_ssl = parse_bool(cfg.server.verify_ssl) ca_path = cfg.server.ca_path cert = os.path.join(cfg.filesystem.id_cert_dir, cfg.filesystem.id_cert_filename) connection = PulpConnection(host, port, cert_filename=cert, verify_ssl=verify_ssl, ca_path=ca_path) Bindings.__init__(self, connection)
def parent_bindings(host, port=443): """ Get a pulp bindings object for the parent node. :param host: The hostname of IP of the parent server. :type host: str :param port: The TCP port number. :type port: int :return: A pulp bindings object. :rtype: Bindings """ node_conf = read_config() oauth = node_conf.parent_oauth verify_ssl = parse_bool(node_conf.main.verify_ssl) ca_path = node_conf.main.ca_path connection = PulpConnection( host=host, port=port, oauth_key=oauth.key, oauth_secret=oauth.secret, oauth_user=oauth.user_id, verify_ssl=verify_ssl, ca_path=ca_path) bindings = Bindings(connection) return bindings
def test_util(self): cfg = self.read(VALID).graph(True) # getbool() v = parse_bool(cfg.limits.posix) self.assertTrue(isinstance(v, bool))
def __init__(self): self.rsa_key = None self.enabled = parse_bool(pulp_conf.get('messaging', 'auth_enabled'))