def get_rbac_resources(resource: str = None): """Get the RBAC resources from the catalog Parameters ---------- resource : str Show the information of the specified resource. Ex: agent:id Returns ------- dict RBAC resources """ if not resource: return WazuhResult({'data': load_spec()['x-rbac-catalog']['resources']}) else: if resource not in load_spec()['x-rbac-catalog']['resources'].keys(): raise WazuhError(4019) return WazuhResult({'data': {resource: load_spec()['x-rbac-catalog']['resources'][resource]}})
def get_api_endpoints(): """Get a list with all API endpoints Returns ------- list API endpoints """ info_data = load_spec() endpoints_list = list() for path, path_info in info_data['paths'].items(): for method in path_info.keys(): endpoints_list.append(f'{method.upper()} {path}') return endpoints_list
def get_rbac_actions(endpoint: str = None): """Get the RBAC actions from the catalog Parameters ---------- endpoint : str Show actions and resources for the specified endpoint. Ex: GET /agents Returns ------- dict RBAC resources """ endpoints_list = get_api_endpoints() if endpoint and endpoint not in endpoints_list: raise WazuhError(4020, extra_remediation=endpoints_list) info_data = load_spec() data = dict() for path, path_info in info_data['paths'].items(): for method, payload in path_info.items(): try: for ref in payload['x-rbac-actions']: action = list(ref.values())[0].split('/')[-1] if endpoint and \ f'{method.upper()} {path}'.encode('ascii', 'ignore') != endpoint.encode('ascii', 'ignore'): continue if action not in data.keys(): data[action] = deepcopy( info_data['x-rbac-catalog']['actions'][action]) for index, resource in enumerate( info_data['x-rbac-catalog']['actions'][action] ['resources']): data[action]['resources'][index] = list( resource.values())[0].split('/')[-1] if 'related_endpoints' not in data[action].keys(): data[action]['related_endpoints'] = list() data[action]['related_endpoints'].append( f'{method.upper()} {path}') except KeyError: pass return WazuhResult({'data': data})
async def default_info(pretty=False): """Get basicinfo :param pretty: Show results in human-readable format Returns various basic information about the API """ info_data = load_spec() data = { 'title': info_data['info']['title'], 'api_version': info_data['info']['version'], 'revision': info_data['info']['x-revision'], 'license_name': info_data['info']['license']['name'], 'license_url': info_data['info']['license']['url'], 'hostname': socket.gethostname(), 'timestamp': datetime.utcnow().strftime(date_format) } response = WazuhResult({'data': BasicInfo.from_dict(data)}) return web.json_response(data=response, status=200, dumps=prettify if pretty else dumps)
async def default_info(pretty=False): """Get basicinfo :param pretty: Show results in human-readable format Returns various basic information about the API """ info_data = load_spec() timestamp = time.strftime("%Y-%m-%dT%H:%M:%S%z", time.gmtime()) data = { 'title': info_data['info']['title'], 'api_version': info_data['info']['version'], 'revision': info_data['info']['x-revision'], 'license_name': info_data['info']['license']['name'], 'license_url': info_data['info']['license']['url'], 'hostname': socket.gethostname(), 'timestamp': timestamp } response = BasicInfo.from_dict(data) return web.json_response(data=response, status=200, dumps=prettify if pretty else dumps)