class ServerInfo(Resource): def __init__(self, **kwargs): # Configure utils utils_conf_keys = ('PREFIX', 'PERPAGE_DEFAULT', 'LIMIT_DEFAULT') self.utils_confs = { k: kwargs[k] for k in utils_conf_keys if k in kwargs } self.utils = Utils(**self.utils_confs) def get(self): """ It returns the general info about the REST API :return: returns current AiiDA version defined in aiida/__init__.py """ ## Decode url parts path = unquote(request.path) query_string = unquote(request.query_string) url = unquote(request.url) url_root = unquote(request.url_root) pathlist = self.utils.split_path(self.utils.strip_prefix(path)) if len(pathlist) > 1: resource_type = pathlist.pop(1) else: resource_type = "info" response = {} import aiida.restapi.common.config as conf from aiida import __version__ if resource_type == "info": response = [] # Add Rest API version response.append("REST API version: " + conf.PREFIX.split("/")[-1]) # Add Rest API prefix response.append("REST API Prefix: " + conf.PREFIX) # Add AiiDA version response.append("AiiDA==" + __version__) elif resource_type == "endpoints": from aiida.restapi.common.utils import list_routes response["available_endpoints"] = list_routes() headers = self.utils.build_headers(url=request.url, total_count=1) ## Build response and return it data = dict(method=request.method, url=url, url_root=url_root, path=path, query_string=query_string, resource_type="Info", data=response) return self.utils.build_response(status=200, headers=headers, data=data)
class ServerInfo(Resource): """Endpoint to return general server info""" def __init__(self, **kwargs): # Configure utils utils_conf_keys = ('PREFIX', 'PERPAGE_DEFAULT', 'LIMIT_DEFAULT') self.utils_confs = { k: kwargs[k] for k in utils_conf_keys if k in kwargs } self.utils = Utils(**self.utils_confs) def get(self): """ It returns the general info about the REST API :return: returns current AiiDA version defined in aiida/__init__.py """ # Decode url parts path = unquote(request.path) url = unquote(request.url) url_root = unquote(request.url_root) subpath = self.utils.strip_api_prefix(path).strip('/') pathlist = self.utils.split_path(subpath) if subpath == '': resource_type = 'endpoints' elif len(pathlist) > 1: resource_type = pathlist.pop(1) else: resource_type = 'info' response = {} from aiida.restapi.common.config import API_CONFIG from aiida import __version__ if resource_type == 'info': response = {} # Add Rest API version api_version = API_CONFIG['VERSION'].split('.') response['API_major_version'] = api_version[0] response['API_minor_version'] = api_version[1] response['API_revision_version'] = api_version[2] # Add Rest API prefix response['API_prefix'] = API_CONFIG['PREFIX'] # Add AiiDA version response['AiiDA_version'] = __version__ elif resource_type == 'endpoints': from aiida.restapi.common.utils import list_routes response['available_endpoints'] = list_routes() headers = self.utils.build_headers(url=request.url, total_count=1) ## Build response and return it data = dict(method=request.method, url=url, url_root=url_root, path=path, query_string=request.query_string.decode('utf-8'), resource_type='Info', data=response) return self.utils.build_response(status=200, headers=headers, data=data)