def test_ordered_set(self): set1 = OrderedSet([1, 2, 3, 3, 4, 2, 1, 5]) self.assertEqual(set1, [1, 2, 3, 4, 5]) set2 = OrderedSet([5, 4, 3, 2, 1]) self.assertEqual(set2, [5, 4, 3, 2, 1]) set3 = OrderedSet([1, 2, 3, 4, 5, 5, 4, 3, 2, 1]) self.assertEqual(set3, [1, 2, 3, 4, 5]) set4 = OrderedSet([1, 1, 1, 1, 4, 4, 4, 9]) self.assertEqual(set4, [1, 4, 9])
def custom_start_response(status, headers, exc_info=None): headers = ResponseHeaders(headers) origin = request.headers.get("Origin") origins = OrderedSet(cfg.CONF.api.allow_origin) # Build a list of the default allowed origins public_api_url = cfg.CONF.auth.api_url # Default gulp development server WebUI URL origins.add("http://127.0.0.1:3000") # By default WebUI simple http server listens on 8080 origins.add("http://localhost:8080") origins.add("http://127.0.0.1:8080") if public_api_url: # Public API URL origins.add(public_api_url) origins = list(origins) if origin: if "*" in origins: origin_allowed = origin else: # See http://www.w3.org/TR/cors/#access-control-allow-origin-response-header origin_allowed = origin if origin in origins else list( origins)[0] else: origin_allowed = list(origins)[0] methods_allowed = ["GET", "POST", "PUT", "DELETE", "OPTIONS"] request_headers_allowed = [ "Content-Type", "Authorization", HEADER_ATTRIBUTE_NAME, HEADER_API_KEY_ATTRIBUTE_NAME, REQUEST_ID_HEADER, ] response_headers_allowed = [ "Content-Type", "X-Limit", "X-Total-Count", REQUEST_ID_HEADER, ] headers["Access-Control-Allow-Origin"] = origin_allowed headers["Access-Control-Allow-Methods"] = ",".join(methods_allowed) headers["Access-Control-Allow-Headers"] = ",".join( request_headers_allowed) headers["Access-Control-Allow-Credentials"] = "true" headers["Access-Control-Expose-Headers"] = ",".join( response_headers_allowed) return start_response(status, headers._items, exc_info)
def custom_start_response(status, headers, exc_info=None): headers = ResponseHeaders(headers) origin = request.headers.get('Origin') origins = OrderedSet(cfg.CONF.api.allow_origin) # Build a list of the default allowed origins public_api_url = cfg.CONF.auth.api_url # Default gulp development server WebUI URL origins.add('http://127.0.0.1:3000') # By default WebUI simple http server listens on 8080 origins.add('http://localhost:8080') origins.add('http://127.0.0.1:8080') if public_api_url: # Public API URL origins.add(public_api_url) origins = list(origins) if origin: if '*' in origins: origin_allowed = origin else: # See http://www.w3.org/TR/cors/#access-control-allow-origin-response-header origin_allowed = origin if origin in origins else list( origins)[0] else: origin_allowed = list(origins)[0] methods_allowed = ['GET', 'POST', 'PUT', 'DELETE', 'OPTIONS'] request_headers_allowed = [ 'Content-Type', 'Authorization', HEADER_ATTRIBUTE_NAME, HEADER_API_KEY_ATTRIBUTE_NAME, REQUEST_ID_HEADER ] response_headers_allowed = [ 'Content-Type', 'X-Limit', 'X-Total-Count', REQUEST_ID_HEADER ] headers['Access-Control-Allow-Origin'] = origin_allowed headers['Access-Control-Allow-Methods'] = ','.join(methods_allowed) headers['Access-Control-Allow-Headers'] = ','.join( request_headers_allowed) headers['Access-Control-Allow-Credentials'] = 'true' headers['Access-Control-Expose-Headers'] = ','.join( response_headers_allowed) return start_response(status, headers._items, exc_info)
def custom_start_response(status, headers, exc_info=None): headers = ResponseHeaders(headers) origin = request.headers.get('Origin') origins = OrderedSet(cfg.CONF.api.allow_origin) # Build a list of the default allowed origins public_api_url = cfg.CONF.auth.api_url # Default gulp development server WebUI URL origins.add('http://127.0.0.1:3000') # By default WebUI simple http server listens on 8080 origins.add('http://localhost:8080') origins.add('http://127.0.0.1:8080') if public_api_url: # Public API URL origins.add(public_api_url) origins = list(origins) if origin: if '*' in origins: origin_allowed = origin else: # See http://www.w3.org/TR/cors/#access-control-allow-origin-response-header origin_allowed = origin if origin in origins else list(origins)[0] else: origin_allowed = list(origins)[0] methods_allowed = ['GET', 'POST', 'PUT', 'DELETE', 'OPTIONS'] request_headers_allowed = ['Content-Type', 'Authorization', HEADER_ATTRIBUTE_NAME, HEADER_API_KEY_ATTRIBUTE_NAME, REQUEST_ID_HEADER] response_headers_allowed = ['Content-Type', 'X-Limit', 'X-Total-Count', REQUEST_ID_HEADER] headers['Access-Control-Allow-Origin'] = origin_allowed headers['Access-Control-Allow-Methods'] = ','.join(methods_allowed) headers['Access-Control-Allow-Headers'] = ','.join(request_headers_allowed) headers['Access-Control-Allow-Credentials'] = 'true' headers['Access-Control-Expose-Headers'] = ','.join(response_headers_allowed) return start_response(status, headers._items, exc_info)
def get_aliases_base_paths(): """ Return a list of base paths which are searched for action aliases. :rtype: ``list`` """ aliases_base_paths = cfg.CONF.content.aliases_base_paths or '' # Remove trailing colon (if present) if aliases_base_paths.endswith(':'): aliases_base_paths = aliases_base_paths[:-1] result = [] aliases_base_paths = aliases_base_paths.split(':') result = aliases_base_paths result = [path for path in result if path] result = list(OrderedSet(result)) return result
def get_packs_base_paths(): """ Return a list of base paths which are searched for integration packs. :rtype: ``list`` """ system_packs_base_path = get_system_packs_base_path() packs_base_paths = cfg.CONF.content.packs_base_paths or '' # Remove trailing colon (if present) if packs_base_paths.endswith(':'): packs_base_paths = packs_base_paths[:-1] result = [] # System path is always first if system_packs_base_path: result.append(system_packs_base_path) packs_base_paths = packs_base_paths.split(':') result = result + packs_base_paths result = [path for path in result if path] result = list(OrderedSet(result)) return result