def get_rest_api(client, module, swagger_spec):
rest_api = None
info_title = None
rest_api_id = module.params['rest_api_id']
try:
info_title = swagger_spec['info']['title']
except KeyError:
module.fail_json(msg="Missing required value in swagger spec: info.title")
if rest_api_id == '*':
try:
rest_apis = client.get_rest_apis(limit=500)['items']
choices = [api for api in rest_apis if api['name'] == info_title]
except ClientError as e:
choices = None
module.fail_json(msg="Error retrieving REST APIs: {0}".format(e))
if len(choices) > 1:
module.fail_json(msg="More than one API found: {0}".format(choices))
elif len(choices) > 0:
try:
rest_api_id = choices[0]['id']
rest_api = client.get_rest_api(restApiId=rest_api_id)
except (ClientError, ParamValidationError, MissingParametersError) as e:
if not e.response['Error']['Code'] == 'NotFoundException':
module.fail_json(msg='Error retrieving REST API: {0}'.format(e))
return rest_api
评论列表
文章目录