def api_resources(): """Print the supported API resources""" environment = get_config('environment') endpoints = get_endpoint(environment) resources = _get_resources_from_client(endpoints) resources = _get_resource_alias(resources) _print_api_resources(resources)
def _execute_api(service, resource, verb, params={}, api_version='v1', output='yaml', parser=None): config = get_config() _check_api_permissions(service, resource, verb) client = _get_client(service, api_version) response = _call_api(client, resource, verb, params, config=config) if verb == 'list' and parser: results = [] try: for result in response.get('results', []): results.append(parser.parse_data(result)) except Exception: raise Exception( f'{service}.{resource} template format is invalid.') response['results'] = results if verb in ['list', 'stat']: options = {'root_key': 'results'} if 'total_count' in response: options['total_count'] = response['total_count'] print_data(response, output, **options) else: print_data(response, output)
def _execute_api(service, resource, verb, params={}, api_version='v1', output='yaml', parser=None, silent=False): config = get_config() _check_api_permissions(service, resource, verb) client = _get_client(service, api_version) # _call_api can change some data of params so need deepcopy # e.g. credential of identity.Token response_stream = _call_api(client, resource, verb, copy.deepcopy(params), config=config) for response in response_stream: if verb in ['list', 'stat', 'analyze']: results = response.get('results', []) if len(results) == 0: return [] elif len(results) > 0: return results else: Exception() elif verb == 'create': return response elif verb == 'update': return response else: echo("[INFO] Non-standard verb: " + verb, flag=not silent) return response
def _get_user_name(self): api_key = get_config().get('api_key', '') user_name = JWTUtil.unverified_decode(api_key).get('aud', '') return user_name