mirror of
https://github.com/valitydev/salt.git
synced 2024-11-07 17:09:03 +00:00
lint warnings/errors.
This commit is contained in:
parent
7df27fe0c9
commit
824960503c
@ -73,7 +73,7 @@ Connection module for Amazon APIGateway
|
|||||||
|
|
||||||
'''
|
'''
|
||||||
# keep lint from choking on _get_conn and _cache_id
|
# keep lint from choking on _get_conn and _cache_id
|
||||||
#pylint: disable=E0602
|
# pylint: disable=E0602
|
||||||
|
|
||||||
# Import Python libs
|
# Import Python libs
|
||||||
from __future__ import absolute_import
|
from __future__ import absolute_import
|
||||||
@ -86,19 +86,17 @@ from distutils.version import LooseVersion as _LooseVersion # pylint: disable=i
|
|||||||
# Import Salt libs
|
# Import Salt libs
|
||||||
import salt.utils.boto3
|
import salt.utils.boto3
|
||||||
import salt.utils.compat
|
import salt.utils.compat
|
||||||
from salt.exceptions import SaltInvocationError, CommandExecutionError
|
|
||||||
import salt.ext.six as six
|
|
||||||
|
|
||||||
log = logging.getLogger(__name__)
|
log = logging.getLogger(__name__)
|
||||||
|
|
||||||
# Import third party libs
|
# Import third party libs
|
||||||
|
|
||||||
#pylint: disable=import-error
|
# pylint: disable=import-error
|
||||||
try:
|
try:
|
||||||
#pylint: disable=unused-import
|
# pylint: disable=unused-import
|
||||||
import boto
|
import boto
|
||||||
import boto3
|
import boto3
|
||||||
#pylint: enable=unused-import
|
# pylint: enable=unused-import
|
||||||
from botocore.exceptions import ClientError
|
from botocore.exceptions import ClientError
|
||||||
logging.getLogger('boto').setLevel(logging.CRITICAL)
|
logging.getLogger('boto').setLevel(logging.CRITICAL)
|
||||||
logging.getLogger('boto3').setLevel(logging.CRITICAL)
|
logging.getLogger('boto3').setLevel(logging.CRITICAL)
|
||||||
@ -107,6 +105,7 @@ except ImportError:
|
|||||||
HAS_BOTO = False
|
HAS_BOTO = False
|
||||||
# pylint: enable=import-error
|
# pylint: enable=import-error
|
||||||
|
|
||||||
|
|
||||||
def __virtual__():
|
def __virtual__():
|
||||||
'''
|
'''
|
||||||
Only load if boto libraries exist and if boto libraries are greater than
|
Only load if boto libraries exist and if boto libraries are greater than
|
||||||
@ -144,18 +143,21 @@ def _convert_datetime_str(response):
|
|||||||
return dict([(k, '{0}'.format(v)) if isinstance(v, datetime.date) else (k, v) for k, v in response.iteritems()])
|
return dict([(k, '{0}'.format(v)) if isinstance(v, datetime.date) else (k, v) for k, v in response.iteritems()])
|
||||||
return None
|
return None
|
||||||
|
|
||||||
|
|
||||||
def _filter_apis(name, apis):
|
def _filter_apis(name, apis):
|
||||||
'''
|
'''
|
||||||
Return list of api items matching the given name.
|
Return list of api items matching the given name.
|
||||||
'''
|
'''
|
||||||
return [api for api in apis if api['name'] == name]
|
return [api for api in apis if api['name'] == name]
|
||||||
|
|
||||||
|
|
||||||
def _filter_apis_desc(desc, apis):
|
def _filter_apis_desc(desc, apis):
|
||||||
'''
|
'''
|
||||||
Return list of api items matching the given description.
|
Return list of api items matching the given description.
|
||||||
'''
|
'''
|
||||||
return [api for api in apis if api['description'] == desc]
|
return [api for api in apis if api['description'] == desc]
|
||||||
|
|
||||||
|
|
||||||
def _multi_call(function, contentkey, *args, **kwargs):
|
def _multi_call(function, contentkey, *args, **kwargs):
|
||||||
'''
|
'''
|
||||||
Retrieve full list of values for the contentkey from a boto3 ApiGateway
|
Retrieve full list of values for the contentkey from a boto3 ApiGateway
|
||||||
@ -170,6 +172,7 @@ def _multi_call(function, contentkey, *args, **kwargs):
|
|||||||
position = more.get('position')
|
position = more.get('position')
|
||||||
return ret.get(contentkey)
|
return ret.get(contentkey)
|
||||||
|
|
||||||
|
|
||||||
def _find_apis_by_name(name, description=None,
|
def _find_apis_by_name(name, description=None,
|
||||||
region=None, key=None, keyid=None, profile=None):
|
region=None, key=None, keyid=None, profile=None):
|
||||||
|
|
||||||
@ -182,12 +185,13 @@ def _find_apis_by_name(name, description=None,
|
|||||||
apis = _multi_call(conn.get_rest_apis, 'items')
|
apis = _multi_call(conn.get_rest_apis, 'items')
|
||||||
if name:
|
if name:
|
||||||
apis = _filter_apis(name, apis)
|
apis = _filter_apis(name, apis)
|
||||||
if description != None:
|
if description is not None:
|
||||||
apis = _filter_apis_desc(description, apis)
|
apis = _filter_apis_desc(description, apis)
|
||||||
return {'restapi': [_convert_datetime_str(api) for api in apis]}
|
return {'restapi': [_convert_datetime_str(api) for api in apis]}
|
||||||
except ClientError as e:
|
except ClientError as e:
|
||||||
return {'error': salt.utils.boto3.get_error(e)}
|
return {'error': salt.utils.boto3.get_error(e)}
|
||||||
|
|
||||||
|
|
||||||
def describe_apis(name=None, description=None, region=None, key=None, keyid=None, profile=None):
|
def describe_apis(name=None, description=None, region=None, key=None, keyid=None, profile=None):
|
||||||
|
|
||||||
'''
|
'''
|
||||||
@ -213,6 +217,7 @@ def describe_apis(name=None, description=None, region=None, key=None, keyid=None
|
|||||||
return _find_apis_by_name('', description=description,
|
return _find_apis_by_name('', description=description,
|
||||||
region=region, key=key, keyid=keyid, profile=profile)
|
region=region, key=key, keyid=keyid, profile=profile)
|
||||||
|
|
||||||
|
|
||||||
def api_exists(name, description=None, region=None, key=None, keyid=None, profile=None):
|
def api_exists(name, description=None, region=None, key=None, keyid=None, profile=None):
|
||||||
'''
|
'''
|
||||||
Check to see if the given Rest API Name and optionlly description exists.
|
Check to see if the given Rest API Name and optionlly description exists.
|
||||||
@ -273,11 +278,11 @@ def delete_api(name, description=None, region=None, key=None, keyid=None, profil
|
|||||||
|
|
||||||
'''
|
'''
|
||||||
try:
|
try:
|
||||||
r = _find_apis_by_name(name, description=description,
|
conn_params = dict(region=region, key=key, keyid=keyid, profile=profile)
|
||||||
region=region, key=key, keyid=keyid, profile=profile)
|
r = _find_apis_by_name(name, description=description, **conn_params)
|
||||||
apis = r.get('restapi')
|
apis = r.get('restapi')
|
||||||
if apis:
|
if apis:
|
||||||
conn = _get_conn(region=region, key=key, keyid=keyid, profile=profile)
|
conn = _get_conn(**conn_params)
|
||||||
for api in apis:
|
for api in apis:
|
||||||
conn.delete_rest_api(restApiId=api['id'])
|
conn.delete_rest_api(restApiId=api['id'])
|
||||||
return {'deleted': True, 'count': len(apis)}
|
return {'deleted': True, 'count': len(apis)}
|
||||||
@ -286,7 +291,7 @@ def delete_api(name, description=None, region=None, key=None, keyid=None, profil
|
|||||||
except ClientError as e:
|
except ClientError as e:
|
||||||
return {'deleted': False, 'error': salt.utils.boto3.get_error(e)}
|
return {'deleted': False, 'error': salt.utils.boto3.get_error(e)}
|
||||||
|
|
||||||
# rest api resource
|
|
||||||
def describe_api_resources(restApiId, region=None, key=None, keyid=None, profile=None):
|
def describe_api_resources(restApiId, region=None, key=None, keyid=None, profile=None):
|
||||||
'''
|
'''
|
||||||
Given rest api id, return all resources for this api.
|
Given rest api id, return all resources for this api.
|
||||||
@ -307,6 +312,7 @@ def describe_api_resources(restApiId, region=None, key=None, keyid=None, profile
|
|||||||
except ClientError as e:
|
except ClientError as e:
|
||||||
return {'error': salt.utils.boto3.get_error(e)}
|
return {'error': salt.utils.boto3.get_error(e)}
|
||||||
|
|
||||||
|
|
||||||
def describe_api_resource(restApiId, path,
|
def describe_api_resource(restApiId, path,
|
||||||
region=None, key=None, keyid=None, profile=None):
|
region=None, key=None, keyid=None, profile=None):
|
||||||
'''
|
'''
|
||||||
@ -329,6 +335,7 @@ def describe_api_resource(restApiId, path,
|
|||||||
return {'resource': resource}
|
return {'resource': resource}
|
||||||
return {'resource': None}
|
return {'resource': None}
|
||||||
|
|
||||||
|
|
||||||
def create_api_resources(restApiId, path,
|
def create_api_resources(restApiId, path,
|
||||||
region=None, key=None, keyid=None, profile=None):
|
region=None, key=None, keyid=None, profile=None):
|
||||||
'''
|
'''
|
||||||
@ -396,7 +403,6 @@ def delete_api_resources(restApiId, path,
|
|||||||
return {'created': False, 'error': salt.utils.boto3.get_error(e)}
|
return {'created': False, 'error': salt.utils.boto3.get_error(e)}
|
||||||
|
|
||||||
|
|
||||||
# resource method
|
|
||||||
def describe_api_resource_method(restApiId, resourcepath, httpMethod,
|
def describe_api_resource_method(restApiId, resourcepath, httpMethod,
|
||||||
region=None, key=None, keyid=None, profile=None):
|
region=None, key=None, keyid=None, profile=None):
|
||||||
'''
|
'''
|
||||||
@ -425,7 +431,6 @@ def describe_api_resource_method(restApiId, resourcepath, httpMethod,
|
|||||||
return {'error': salt.utils.boto3.get_error(e)}
|
return {'error': salt.utils.boto3.get_error(e)}
|
||||||
|
|
||||||
|
|
||||||
# API Keys
|
|
||||||
def describe_api_key(apiKey, region=None, key=None, keyid=None, profile=None):
|
def describe_api_key(apiKey, region=None, key=None, keyid=None, profile=None):
|
||||||
'''
|
'''
|
||||||
Gets info about the given api key
|
Gets info about the given api key
|
||||||
@ -444,6 +449,7 @@ def describe_api_key(apiKey, region=None, key=None, keyid=None, profile=None):
|
|||||||
except ClientError as e:
|
except ClientError as e:
|
||||||
return {'error': salt.utils.boto3.get_error(e)}
|
return {'error': salt.utils.boto3.get_error(e)}
|
||||||
|
|
||||||
|
|
||||||
def describe_api_keys(region=None, key=None, keyid=None, profile=None):
|
def describe_api_keys(region=None, key=None, keyid=None, profile=None):
|
||||||
'''
|
'''
|
||||||
Gets information about the defined API Keys. Return list of apiKeys.
|
Gets information about the defined API Keys. Return list of apiKeys.
|
||||||
@ -501,6 +507,7 @@ def create_api_key(name, description, enabled=True, stageKeys=None,
|
|||||||
except ClientError as e:
|
except ClientError as e:
|
||||||
return {'created': False, 'error': salt.utils.boto3.get_error(e)}
|
return {'created': False, 'error': salt.utils.boto3.get_error(e)}
|
||||||
|
|
||||||
|
|
||||||
def delete_api_key(apiKey, region=None, key=None, keyid=None, profile=None):
|
def delete_api_key(apiKey, region=None, key=None, keyid=None, profile=None):
|
||||||
'''
|
'''
|
||||||
Deletes a given apiKey
|
Deletes a given apiKey
|
||||||
@ -519,6 +526,7 @@ def delete_api_key(apiKey, region=None, key=None, keyid=None, profile=None):
|
|||||||
except ClientError as e:
|
except ClientError as e:
|
||||||
return {'deleted': False, 'error': salt.utils.boto3.get_error(e)}
|
return {'deleted': False, 'error': salt.utils.boto3.get_error(e)}
|
||||||
|
|
||||||
|
|
||||||
def _api_key_patch_replace(conn, apiKey, path, value):
|
def _api_key_patch_replace(conn, apiKey, path, value):
|
||||||
'''
|
'''
|
||||||
the replace patch operation on an ApiKey resource
|
the replace patch operation on an ApiKey resource
|
||||||
@ -527,12 +535,14 @@ def _api_key_patch_replace(conn, apiKey, path, value):
|
|||||||
patchOperations=[{'op': 'replace', 'path': path, 'value': value}])
|
patchOperations=[{'op': 'replace', 'path': path, 'value': value}])
|
||||||
return response
|
return response
|
||||||
|
|
||||||
|
|
||||||
def _api_key_patchops(op, pvlist):
|
def _api_key_patchops(op, pvlist):
|
||||||
'''
|
'''
|
||||||
helper function to return patchOperations object
|
helper function to return patchOperations object
|
||||||
'''
|
'''
|
||||||
return [{'op': op, 'path': p, 'value': v} for (p, v) in pvlist]
|
return [{'op': op, 'path': p, 'value': v} for (p, v) in pvlist]
|
||||||
|
|
||||||
|
|
||||||
def _api_key_patch_add(conn, apiKey, pvlist):
|
def _api_key_patch_add(conn, apiKey, pvlist):
|
||||||
'''
|
'''
|
||||||
the add patch operation for a list of (path, value) tuples on an ApiKey resource list path
|
the add patch operation for a list of (path, value) tuples on an ApiKey resource list path
|
||||||
@ -541,6 +551,7 @@ def _api_key_patch_add(conn, apiKey, pvlist):
|
|||||||
patchOperations=_api_key_patchops('add', pvlist))
|
patchOperations=_api_key_patchops('add', pvlist))
|
||||||
return response
|
return response
|
||||||
|
|
||||||
|
|
||||||
def _api_key_patch_remove(conn, apiKey, pvlist):
|
def _api_key_patch_remove(conn, apiKey, pvlist):
|
||||||
'''
|
'''
|
||||||
the remove patch operation for a list of (path, value) tuples on an ApiKey resource list path
|
the remove patch operation for a list of (path, value) tuples on an ApiKey resource list path
|
||||||
@ -568,6 +579,7 @@ def update_api_key_description(apiKey, description, region=None, key=None, keyid
|
|||||||
except ClientError as e:
|
except ClientError as e:
|
||||||
return {'updated': False, 'error': salt.utils.boto3.get_error(e)}
|
return {'updated': False, 'error': salt.utils.boto3.get_error(e)}
|
||||||
|
|
||||||
|
|
||||||
def enable_api_key(apiKey, region=None, key=None, keyid=None, profile=None):
|
def enable_api_key(apiKey, region=None, key=None, keyid=None, profile=None):
|
||||||
'''
|
'''
|
||||||
enable the given apiKey.
|
enable the given apiKey.
|
||||||
@ -586,6 +598,7 @@ def enable_api_key(apiKey, region=None, key=None, keyid=None, profile=None):
|
|||||||
except ClientError as e:
|
except ClientError as e:
|
||||||
return {'error': salt.utils.boto3.get_error(e)}
|
return {'error': salt.utils.boto3.get_error(e)}
|
||||||
|
|
||||||
|
|
||||||
def disable_api_key(apiKey, region=None, key=None, keyid=None, profile=None):
|
def disable_api_key(apiKey, region=None, key=None, keyid=None, profile=None):
|
||||||
'''
|
'''
|
||||||
disable the given apiKey.
|
disable the given apiKey.
|
||||||
@ -624,6 +637,7 @@ def associate_api_key_stagekeys(apiKey, stagekeyslist, region=None, key=None, ke
|
|||||||
except ClientError as e:
|
except ClientError as e:
|
||||||
return {'associated': False, 'error': salt.utils.boto3.get_error(e)}
|
return {'associated': False, 'error': salt.utils.boto3.get_error(e)}
|
||||||
|
|
||||||
|
|
||||||
def disassociate_api_key_stagekeys(apiKey, stagekeyslist, region=None, key=None, keyid=None, profile=None):
|
def disassociate_api_key_stagekeys(apiKey, stagekeyslist, region=None, key=None, keyid=None, profile=None):
|
||||||
'''
|
'''
|
||||||
disassociate the given stagekeyslist to the given apiKey.
|
disassociate the given stagekeyslist to the given apiKey.
|
||||||
@ -644,9 +658,6 @@ def disassociate_api_key_stagekeys(apiKey, stagekeyslist, region=None, key=None,
|
|||||||
return {'disassociated': False, 'error': salt.utils.boto3.get_error(e)}
|
return {'disassociated': False, 'error': salt.utils.boto3.get_error(e)}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
# API Deployments
|
|
||||||
|
|
||||||
def describe_api_deployments(restApiId, region=None, key=None, keyid=None, profile=None):
|
def describe_api_deployments(restApiId, region=None, key=None, keyid=None, profile=None):
|
||||||
'''
|
'''
|
||||||
Gets information about the defined API Deployments. Return list of api deployments.
|
Gets information about the defined API Deployments. Return list of api deployments.
|
||||||
@ -666,7 +677,7 @@ def describe_api_deployments(restApiId, region=None, key=None, keyid=None, profi
|
|||||||
while True:
|
while True:
|
||||||
if _deployments:
|
if _deployments:
|
||||||
deployments = deployments + _deployments['items']
|
deployments = deployments + _deployments['items']
|
||||||
if not _deployments.has_key('position'):
|
if 'position' not in _deployments:
|
||||||
break
|
break
|
||||||
_deployments = conn.get_deployments(restApiId=restApiId, position=_deployments['position'])
|
_deployments = conn.get_deployments(restApiId=restApiId, position=_deployments['position'])
|
||||||
|
|
||||||
@ -674,6 +685,7 @@ def describe_api_deployments(restApiId, region=None, key=None, keyid=None, profi
|
|||||||
except ClientError as e:
|
except ClientError as e:
|
||||||
return {'error': salt.utils.boto3.get_error(e)}
|
return {'error': salt.utils.boto3.get_error(e)}
|
||||||
|
|
||||||
|
|
||||||
def describe_api_deployment(restApiId, deploymentId, region=None, key=None, keyid=None, profile=None):
|
def describe_api_deployment(restApiId, deploymentId, region=None, key=None, keyid=None, profile=None):
|
||||||
'''
|
'''
|
||||||
Get API deployment for a given restApiId and deploymentId.
|
Get API deployment for a given restApiId and deploymentId.
|
||||||
@ -715,6 +727,7 @@ def activate_api_deployment(restApiId, stageName, deploymentId,
|
|||||||
except ClientError as e:
|
except ClientError as e:
|
||||||
return {'set': False, 'error': salt.utils.boto3.get_error(e)}
|
return {'set': False, 'error': salt.utils.boto3.get_error(e)}
|
||||||
|
|
||||||
|
|
||||||
def create_api_deployment(restApiId, stageName, stageDescription='', description='', cacheClusterEnabled=False,
|
def create_api_deployment(restApiId, stageName, stageDescription='', description='', cacheClusterEnabled=False,
|
||||||
cacheClusterSize='0.5', variables=None,
|
cacheClusterSize='0.5', variables=None,
|
||||||
region=None, key=None, keyid=None, profile=None):
|
region=None, key=None, keyid=None, profile=None):
|
||||||
@ -741,6 +754,7 @@ def create_api_deployment(restApiId, stageName, stageDescription='', description
|
|||||||
except ClientError as e:
|
except ClientError as e:
|
||||||
return {'created': False, 'error': salt.utils.boto3.get_error(e)}
|
return {'created': False, 'error': salt.utils.boto3.get_error(e)}
|
||||||
|
|
||||||
|
|
||||||
def delete_api_deployment(restApiId, deploymentId, region=None, key=None, keyid=None, profile=None):
|
def delete_api_deployment(restApiId, deploymentId, region=None, key=None, keyid=None, profile=None):
|
||||||
'''
|
'''
|
||||||
Deletes API deployment for a given restApiId and deploymentID
|
Deletes API deployment for a given restApiId and deploymentID
|
||||||
@ -754,12 +768,11 @@ def delete_api_deployment(restApiId, deploymentId, region=None, key=None, keyid=
|
|||||||
'''
|
'''
|
||||||
try:
|
try:
|
||||||
conn = _get_conn(region=region, key=key, keyid=keyid, profile=profile)
|
conn = _get_conn(region=region, key=key, keyid=keyid, profile=profile)
|
||||||
response = conn.delete_deployment(restApiId=restApiId, deploymentId=deploymentId)
|
conn.delete_deployment(restApiId=restApiId, deploymentId=deploymentId)
|
||||||
return {'deleted': True}
|
return {'deleted': True}
|
||||||
except ClientError as e:
|
except ClientError as e:
|
||||||
return {'deleted': False, 'error': salt.utils.boto3.get_error(e)}
|
return {'deleted': False, 'error': salt.utils.boto3.get_error(e)}
|
||||||
|
|
||||||
# API Stages
|
|
||||||
|
|
||||||
def overwrite_api_stage_variables(restApiId, stageName, variables, region=None, key=None, keyid=None, profile=None):
|
def overwrite_api_stage_variables(restApiId, stageName, variables, region=None, key=None, keyid=None, profile=None):
|
||||||
'''
|
'''
|
||||||
@ -782,7 +795,7 @@ def overwrite_api_stage_variables(restApiId, stageName, variables, region=None,
|
|||||||
|
|
||||||
conn = _get_conn(region=region, key=key, keyid=keyid, profile=profile)
|
conn = _get_conn(region=region, key=key, keyid=keyid, profile=profile)
|
||||||
|
|
||||||
# remove all existing variables that are not in the given variables,
|
# remove all existing variables that are not in the given variables,
|
||||||
# followed by adding of the variables
|
# followed by adding of the variables
|
||||||
stage = res.get('stage')
|
stage = res.get('stage')
|
||||||
old_vars = stage.get('variables', {})
|
old_vars = stage.get('variables', {})
|
||||||
@ -806,6 +819,7 @@ def overwrite_api_stage_variables(restApiId, stageName, variables, region=None,
|
|||||||
except ClientError as e:
|
except ClientError as e:
|
||||||
return {'overwrite': False, 'error': salt.utils.boto3.get_error(e)}
|
return {'overwrite': False, 'error': salt.utils.boto3.get_error(e)}
|
||||||
|
|
||||||
|
|
||||||
def describe_api_stage(restApiId, stageName, region=None, key=None, keyid=None, profile=None):
|
def describe_api_stage(restApiId, stageName, region=None, key=None, keyid=None, profile=None):
|
||||||
'''
|
'''
|
||||||
Get API stage for a given apiID and stage name
|
Get API stage for a given apiID and stage name
|
||||||
@ -824,6 +838,7 @@ def describe_api_stage(restApiId, stageName, region=None, key=None, keyid=None,
|
|||||||
except ClientError as e:
|
except ClientError as e:
|
||||||
return {'error': salt.utils.boto3.get_error(e)}
|
return {'error': salt.utils.boto3.get_error(e)}
|
||||||
|
|
||||||
|
|
||||||
def describe_api_stages(restApiId, deploymentId, region=None, key=None, keyid=None, profile=None):
|
def describe_api_stages(restApiId, deploymentId, region=None, key=None, keyid=None, profile=None):
|
||||||
'''
|
'''
|
||||||
Get all API stages for a given apiID and deploymentID
|
Get all API stages for a given apiID and deploymentID
|
||||||
@ -842,6 +857,7 @@ def describe_api_stages(restApiId, deploymentId, region=None, key=None, keyid=No
|
|||||||
except ClientError as e:
|
except ClientError as e:
|
||||||
return {'error': salt.utils.boto3.get_error(e)}
|
return {'error': salt.utils.boto3.get_error(e)}
|
||||||
|
|
||||||
|
|
||||||
def create_api_stage(restApiId, stageName, deploymentId, description='',
|
def create_api_stage(restApiId, stageName, deploymentId, description='',
|
||||||
cacheClusterEnabled=False, cacheClusterSize='0.5', variables=None,
|
cacheClusterEnabled=False, cacheClusterSize='0.5', variables=None,
|
||||||
region=None, key=None, keyid=None, profile=None):
|
region=None, key=None, keyid=None, profile=None):
|
||||||
@ -867,6 +883,7 @@ def create_api_stage(restApiId, stageName, deploymentId, description='',
|
|||||||
except ClientError as e:
|
except ClientError as e:
|
||||||
return {'created': False, 'error': salt.utils.boto3.get_error(e)}
|
return {'created': False, 'error': salt.utils.boto3.get_error(e)}
|
||||||
|
|
||||||
|
|
||||||
def delete_api_stage(restApiId, stageName, region=None, key=None, keyid=None, profile=None):
|
def delete_api_stage(restApiId, stageName, region=None, key=None, keyid=None, profile=None):
|
||||||
'''
|
'''
|
||||||
Deletes stage identified by stageName from API identified by restApiId
|
Deletes stage identified by stageName from API identified by restApiId
|
||||||
@ -885,6 +902,7 @@ def delete_api_stage(restApiId, stageName, region=None, key=None, keyid=None, pr
|
|||||||
except ClientError as e:
|
except ClientError as e:
|
||||||
return {'deleted': False, 'error': salt.utils.boto3.get_error(e)}
|
return {'deleted': False, 'error': salt.utils.boto3.get_error(e)}
|
||||||
|
|
||||||
|
|
||||||
def flush_api_stage_cache(restApiId, stageName, region=None, key=None, keyid=None, profile=None):
|
def flush_api_stage_cache(restApiId, stageName, region=None, key=None, keyid=None, profile=None):
|
||||||
'''
|
'''
|
||||||
Flushes cache for the stage identified by stageName from API identified by restApiId
|
Flushes cache for the stage identified by stageName from API identified by restApiId
|
||||||
@ -904,8 +922,6 @@ def flush_api_stage_cache(restApiId, stageName, region=None, key=None, keyid=Non
|
|||||||
return {'flushed': False, 'error': salt.utils.boto3.get_error(e)}
|
return {'flushed': False, 'error': salt.utils.boto3.get_error(e)}
|
||||||
|
|
||||||
|
|
||||||
# API Methods
|
|
||||||
|
|
||||||
def create_api_method(restApiId, resourcePath, httpMethod, authorizationType,
|
def create_api_method(restApiId, resourcePath, httpMethod, authorizationType,
|
||||||
apiKeyRequired=False, requestParameters=None, requestModels=None,
|
apiKeyRequired=False, requestParameters=None, requestModels=None,
|
||||||
region=None, key=None, keyid=None, profile=None):
|
region=None, key=None, keyid=None, profile=None):
|
||||||
@ -937,6 +953,7 @@ def create_api_method(restApiId, resourcePath, httpMethod, authorizationType,
|
|||||||
except ClientError as e:
|
except ClientError as e:
|
||||||
return {'created': False, 'error': salt.utils.boto3.get_error(e)}
|
return {'created': False, 'error': salt.utils.boto3.get_error(e)}
|
||||||
|
|
||||||
|
|
||||||
def describe_api_method(restApiId, resourcePath, httpMethod, region=None, key=None, keyid=None, profile=None):
|
def describe_api_method(restApiId, resourcePath, httpMethod, region=None, key=None, keyid=None, profile=None):
|
||||||
'''
|
'''
|
||||||
Get API method for a resource in the given API
|
Get API method for a resource in the given API
|
||||||
@ -959,6 +976,7 @@ def describe_api_method(restApiId, resourcePath, httpMethod, region=None, key=No
|
|||||||
except ClientError as e:
|
except ClientError as e:
|
||||||
return {'error': salt.utils.boto3.get_error(e)}
|
return {'error': salt.utils.boto3.get_error(e)}
|
||||||
|
|
||||||
|
|
||||||
def delete_api_method(restApiId, resourcePath, httpMethod, region=None, key=None, keyid=None, profile=None):
|
def delete_api_method(restApiId, resourcePath, httpMethod, region=None, key=None, keyid=None, profile=None):
|
||||||
'''
|
'''
|
||||||
Delete API method for a resource in the given API
|
Delete API method for a resource in the given API
|
||||||
@ -975,12 +993,13 @@ def delete_api_method(restApiId, resourcePath, httpMethod, region=None, key=None
|
|||||||
key=key, keyid=keyid, profile=profile).get('resource')
|
key=key, keyid=keyid, profile=profile).get('resource')
|
||||||
if resource:
|
if resource:
|
||||||
conn = _get_conn(region=region, key=key, keyid=keyid, profile=profile)
|
conn = _get_conn(region=region, key=key, keyid=keyid, profile=profile)
|
||||||
method = conn.delete_method(restApiId=restApiId, resourceId=resource['id'], httpMethod=httpMethod)
|
conn.delete_method(restApiId=restApiId, resourceId=resource['id'], httpMethod=httpMethod)
|
||||||
return {'deleted': True}
|
return {'deleted': True}
|
||||||
return {'deleted': False, 'error': 'get API method failed: no such resource'}
|
return {'deleted': False, 'error': 'get API method failed: no such resource'}
|
||||||
except ClientError as e:
|
except ClientError as e:
|
||||||
return {'deleted': False, 'error': salt.utils.boto3.get_error(e)}
|
return {'deleted': False, 'error': salt.utils.boto3.get_error(e)}
|
||||||
|
|
||||||
|
|
||||||
def create_api_method_response(restApiId, resourcePath, httpMethod, statusCode, responseParameters=None,
|
def create_api_method_response(restApiId, resourcePath, httpMethod, statusCode, responseParameters=None,
|
||||||
responseModels=None, region=None, key=None, keyid=None, profile=None):
|
responseModels=None, region=None, key=None, keyid=None, profile=None):
|
||||||
'''
|
'''
|
||||||
@ -1035,6 +1054,7 @@ def delete_api_method_response(restApiId, resourcePath, httpMethod, statusCode,
|
|||||||
except ClientError as e:
|
except ClientError as e:
|
||||||
return {'deleted': False, 'error': salt.utils.boto3.get_error(e)}
|
return {'deleted': False, 'error': salt.utils.boto3.get_error(e)}
|
||||||
|
|
||||||
|
|
||||||
def describe_api_method_response(restApiId, resourcePath, httpMethod, statusCode,
|
def describe_api_method_response(restApiId, resourcePath, httpMethod, statusCode,
|
||||||
region=None, key=None, keyid=None, profile=None):
|
region=None, key=None, keyid=None, profile=None):
|
||||||
'''
|
'''
|
||||||
@ -1060,8 +1080,6 @@ def describe_api_method_response(restApiId, resourcePath, httpMethod, statusCode
|
|||||||
return {'error': salt.utils.boto3.get_error(e)}
|
return {'error': salt.utils.boto3.get_error(e)}
|
||||||
|
|
||||||
|
|
||||||
# API Model
|
|
||||||
|
|
||||||
def describe_api_models(restApiId, region=None, key=None, keyid=None, profile=None):
|
def describe_api_models(restApiId, region=None, key=None, keyid=None, profile=None):
|
||||||
'''
|
'''
|
||||||
Get all models for a given API
|
Get all models for a given API
|
||||||
@ -1099,6 +1117,7 @@ def describe_api_model(restApiId, modelName, flatten=True, region=None, key=None
|
|||||||
except ClientError as e:
|
except ClientError as e:
|
||||||
return {'error': salt.utils.boto3.get_error(e)}
|
return {'error': salt.utils.boto3.get_error(e)}
|
||||||
|
|
||||||
|
|
||||||
def api_model_exists(restApiId, modelName, region=None, key=None, keyid=None, profile=None):
|
def api_model_exists(restApiId, modelName, region=None, key=None, keyid=None, profile=None):
|
||||||
'''
|
'''
|
||||||
Check to see if the given modelName exists in the given restApiId
|
Check to see if the given modelName exists in the given restApiId
|
||||||
@ -1113,6 +1132,7 @@ def api_model_exists(restApiId, modelName, region=None, key=None, keyid=None, pr
|
|||||||
|
|
||||||
return {'exists': bool(r.get('model'))}
|
return {'exists': bool(r.get('model'))}
|
||||||
|
|
||||||
|
|
||||||
def _api_model_patch_replace(conn, restApiId, modelName, path, value):
|
def _api_model_patch_replace(conn, restApiId, modelName, path, value):
|
||||||
'''
|
'''
|
||||||
the replace patch operation on a Model resource
|
the replace patch operation on a Model resource
|
||||||
@ -1121,6 +1141,7 @@ def _api_model_patch_replace(conn, restApiId, modelName, path, value):
|
|||||||
patchOperations=[{'op': 'replace', 'path': path, 'value': value}])
|
patchOperations=[{'op': 'replace', 'path': path, 'value': value}])
|
||||||
return response
|
return response
|
||||||
|
|
||||||
|
|
||||||
def update_api_model_schema(restApiId, modelName, schema, region=None, key=None, keyid=None, profile=None):
|
def update_api_model_schema(restApiId, modelName, schema, region=None, key=None, keyid=None, profile=None):
|
||||||
'''
|
'''
|
||||||
update the schema (in python dictionary format) for the given model in the given restApiId
|
update the schema (in python dictionary format) for the given model in the given restApiId
|
||||||
@ -1159,6 +1180,7 @@ def delete_api_model(restApiId, modelName, region=None, key=None, keyid=None, pr
|
|||||||
except ClientError as e:
|
except ClientError as e:
|
||||||
return {'deleted': False, 'error': salt.utils.boto3.get_error(e)}
|
return {'deleted': False, 'error': salt.utils.boto3.get_error(e)}
|
||||||
|
|
||||||
|
|
||||||
def create_api_model(restApiId, modelName, modelDescription, schema, contentType='application/json',
|
def create_api_model(restApiId, modelName, modelDescription, schema, contentType='application/json',
|
||||||
region=None, key=None, keyid=None, profile=None):
|
region=None, key=None, keyid=None, profile=None):
|
||||||
'''
|
'''
|
||||||
@ -1181,7 +1203,6 @@ def create_api_model(restApiId, modelName, modelDescription, schema, contentType
|
|||||||
except ClientError as e:
|
except ClientError as e:
|
||||||
return {'created': False, 'error': salt.utils.boto3.get_error(e)}
|
return {'created': False, 'error': salt.utils.boto3.get_error(e)}
|
||||||
|
|
||||||
# API Integrations
|
|
||||||
|
|
||||||
def describe_api_integration(restApiId, resourcePath, httpMethod, region=None, key=None, keyid=None, profile=None):
|
def describe_api_integration(restApiId, resourcePath, httpMethod, region=None, key=None, keyid=None, profile=None):
|
||||||
'''
|
'''
|
||||||
@ -1230,6 +1251,7 @@ def describe_api_integration_response(restApiId, resourcePath, httpMethod, statu
|
|||||||
except ClientError as e:
|
except ClientError as e:
|
||||||
return {'error': salt.utils.boto3.get_error(e)}
|
return {'error': salt.utils.boto3.get_error(e)}
|
||||||
|
|
||||||
|
|
||||||
def delete_api_integration(restApiId, resourcePath, httpMethod, region=None, key=None, keyid=None, profile=None):
|
def delete_api_integration(restApiId, resourcePath, httpMethod, region=None, key=None, keyid=None, profile=None):
|
||||||
'''
|
'''
|
||||||
Deletes an integration for a given method in a given API
|
Deletes an integration for a given method in a given API
|
||||||
@ -1252,6 +1274,7 @@ def delete_api_integration(restApiId, resourcePath, httpMethod, region=None, key
|
|||||||
except ClientError as e:
|
except ClientError as e:
|
||||||
return {'deleted': False, 'error': salt.utils.boto3.get_error(e)}
|
return {'deleted': False, 'error': salt.utils.boto3.get_error(e)}
|
||||||
|
|
||||||
|
|
||||||
def delete_api_integration_response(restApiId, resourcePath, httpMethod, statusCode,
|
def delete_api_integration_response(restApiId, resourcePath, httpMethod, statusCode,
|
||||||
region=None, key=None, keyid=None, profile=None):
|
region=None, key=None, keyid=None, profile=None):
|
||||||
'''
|
'''
|
||||||
@ -1278,6 +1301,9 @@ def delete_api_integration_response(restApiId, resourcePath, httpMethod, statusC
|
|||||||
|
|
||||||
|
|
||||||
def _get_role_arn(name, region=None, key=None, keyid=None, profile=None):
|
def _get_role_arn(name, region=None, key=None, keyid=None, profile=None):
|
||||||
|
'''
|
||||||
|
Helper function to get an ARN if name does not look like an ARN.
|
||||||
|
'''
|
||||||
if name.startswith('arn:aws:iam:'):
|
if name.startswith('arn:aws:iam:'):
|
||||||
return name
|
return name
|
||||||
|
|
||||||
|
@ -48,7 +48,6 @@ config:
|
|||||||
|
|
||||||
# Import Python Libs
|
# Import Python Libs
|
||||||
from __future__ import absolute_import
|
from __future__ import absolute_import
|
||||||
from six import string_types
|
|
||||||
import logging
|
import logging
|
||||||
import os
|
import os
|
||||||
import os.path
|
import os.path
|
||||||
@ -57,10 +56,9 @@ import re
|
|||||||
import json
|
import json
|
||||||
import yaml
|
import yaml
|
||||||
|
|
||||||
|
|
||||||
# Import Salt Libs
|
# Import Salt Libs
|
||||||
import salt.utils.dictupdate as dictupdate
|
|
||||||
import salt.utils
|
import salt.utils
|
||||||
|
from salt.ext.six import string_types
|
||||||
|
|
||||||
# Import 3rd Party Libs
|
# Import 3rd Party Libs
|
||||||
|
|
||||||
@ -270,6 +268,7 @@ def present(name, api_name, swagger_file, stage_name, api_key_required, lambda_i
|
|||||||
|
|
||||||
return ret
|
return ret
|
||||||
|
|
||||||
|
|
||||||
def _get_stage_variables(stage_variables):
|
def _get_stage_variables(stage_variables):
|
||||||
'''
|
'''
|
||||||
Helper function to retrieve stage variables from pillars/options, if the
|
Helper function to retrieve stage variables from pillars/options, if the
|
||||||
@ -295,6 +294,7 @@ def _get_stage_variables(stage_variables):
|
|||||||
|
|
||||||
return ret
|
return ret
|
||||||
|
|
||||||
|
|
||||||
def absent(name, api_name, stage_name, nuke_api=False, region=None, key=None, keyid=None, profile=None):
|
def absent(name, api_name, stage_name, nuke_api=False, region=None, key=None, keyid=None, profile=None):
|
||||||
'''
|
'''
|
||||||
Ensure the stage_name associated with the given api_name deployed by boto_apigateway's
|
Ensure the stage_name associated with the given api_name deployed by boto_apigateway's
|
||||||
@ -384,12 +384,14 @@ def _gen_md5_filehash(fname):
|
|||||||
_hash.update(chunk)
|
_hash.update(chunk)
|
||||||
return _hash.hexdigest()
|
return _hash.hexdigest()
|
||||||
|
|
||||||
|
|
||||||
def _dict_to_json_pretty(d, sort_keys=True):
|
def _dict_to_json_pretty(d, sort_keys=True):
|
||||||
'''
|
'''
|
||||||
helper function to generate pretty printed json output
|
helper function to generate pretty printed json output
|
||||||
'''
|
'''
|
||||||
return json.dumps(d, indent=4, separators=(',', ': '), sort_keys=sort_keys)
|
return json.dumps(d, indent=4, separators=(',', ': '), sort_keys=sort_keys)
|
||||||
|
|
||||||
|
|
||||||
# Heuristic on whether or not the property name loosely matches given set of 'interesting' factors
|
# Heuristic on whether or not the property name loosely matches given set of 'interesting' factors
|
||||||
# If you are interested in IDs for example, 'id', 'blah_id', 'blahId' would all match
|
# If you are interested in IDs for example, 'id', 'blah_id', 'blahId' would all match
|
||||||
def _name_matches(name, matches):
|
def _name_matches(name, matches):
|
||||||
@ -405,6 +407,7 @@ def _name_matches(name, matches):
|
|||||||
return True
|
return True
|
||||||
return False
|
return False
|
||||||
|
|
||||||
|
|
||||||
def _object_reducer(o, names=('id', 'name', 'path', 'httpMethod',
|
def _object_reducer(o, names=('id', 'name', 'path', 'httpMethod',
|
||||||
'statusCode', 'Created', 'Deleted',
|
'statusCode', 'Created', 'Deleted',
|
||||||
'Updated', 'Flushed', 'Associated', 'Disassociated')):
|
'Updated', 'Flushed', 'Associated', 'Disassociated')):
|
||||||
@ -442,6 +445,7 @@ def _log_changes(ret, changekey, changevalue):
|
|||||||
ret['changes']['new'] = cl
|
ret['changes']['new'] = cl
|
||||||
return ret
|
return ret
|
||||||
|
|
||||||
|
|
||||||
def _log_error_and_abort(ret, obj):
|
def _log_error_and_abort(ret, obj):
|
||||||
'''
|
'''
|
||||||
helper function to update errors in the return structure
|
helper function to update errors in the return structure
|
||||||
@ -452,6 +456,7 @@ def _log_error_and_abort(ret, obj):
|
|||||||
ret['comment'] = '{0}'.format(obj.get('error'))
|
ret['comment'] = '{0}'.format(obj.get('error'))
|
||||||
return ret
|
return ret
|
||||||
|
|
||||||
|
|
||||||
class _Swagger(object):
|
class _Swagger(object):
|
||||||
'''
|
'''
|
||||||
this is a helper class that holds the swagger definition file and the associated logic
|
this is a helper class that holds the swagger definition file and the associated logic
|
||||||
@ -462,8 +467,8 @@ class _Swagger(object):
|
|||||||
'''
|
'''
|
||||||
|
|
||||||
SWAGGER_OBJ_V2_FIELDS = ('swagger', 'info', 'host', 'basePath', 'schemes', 'consumes', 'produces',
|
SWAGGER_OBJ_V2_FIELDS = ('swagger', 'info', 'host', 'basePath', 'schemes', 'consumes', 'produces',
|
||||||
'paths', 'definitions', 'parameters', 'responses', 'securityDefinitions',
|
'paths', 'definitions', 'parameters', 'responses', 'securityDefinitions',
|
||||||
'security', 'tags', 'externalDocs')
|
'security', 'tags', 'externalDocs')
|
||||||
# SWAGGER OBJECT V2 Fields that are required by boto apigateway states.
|
# SWAGGER OBJECT V2 Fields that are required by boto apigateway states.
|
||||||
SWAGGER_OBJ_V2_FIELDS_REQUIRED = ('swagger', 'info', 'basePath', 'schemes', 'paths', 'definitions')
|
SWAGGER_OBJ_V2_FIELDS_REQUIRED = ('swagger', 'info', 'basePath', 'schemes', 'paths', 'definitions')
|
||||||
# SWAGGER OPERATION NAMES
|
# SWAGGER OPERATION NAMES
|
||||||
@ -478,43 +483,43 @@ class _Swagger(object):
|
|||||||
|
|
||||||
# AWS integration templates for normal and options methods
|
# AWS integration templates for normal and options methods
|
||||||
REQUEST_TEMPLATE = {'application/json':
|
REQUEST_TEMPLATE = {'application/json':
|
||||||
'#set($inputRoot = $input.path(\'$\'))\n'
|
'#set($inputRoot = $input.path(\'$\'))\n'
|
||||||
'{\n'
|
'{\n'
|
||||||
'"header_params" : {\n'
|
'"header_params" : {\n'
|
||||||
'#set ($map = $input.params().header)\n'
|
'#set ($map = $input.params().header)\n'
|
||||||
'#foreach( $param in $map.entrySet() )\n'
|
'#foreach( $param in $map.entrySet() )\n'
|
||||||
'"$param.key" : "$param.value" #if( $foreach.hasNext ), #end\n'
|
'"$param.key" : "$param.value" #if( $foreach.hasNext ), #end\n'
|
||||||
'#end\n'
|
'#end\n'
|
||||||
'},\n'
|
'},\n'
|
||||||
'"query_params" : {\n'
|
'"query_params" : {\n'
|
||||||
'#set ($map = $input.params().querystring)\n'
|
'#set ($map = $input.params().querystring)\n'
|
||||||
'#foreach( $param in $map.entrySet() )\n'
|
'#foreach( $param in $map.entrySet() )\n'
|
||||||
'"$param.key" : "$param.value" #if( $foreach.hasNext ), #end\n'
|
'"$param.key" : "$param.value" #if( $foreach.hasNext ), #end\n'
|
||||||
'#end\n'
|
'#end\n'
|
||||||
'},\n'
|
'},\n'
|
||||||
'"path_params" : {\n'
|
'"path_params" : {\n'
|
||||||
'#set ($map = $input.params().path)\n'
|
'#set ($map = $input.params().path)\n'
|
||||||
'#foreach( $param in $map.entrySet() )\n'
|
'#foreach( $param in $map.entrySet() )\n'
|
||||||
'"$param.key" : "$param.value" #if( $foreach.hasNext ), #end\n'
|
'"$param.key" : "$param.value" #if( $foreach.hasNext ), #end\n'
|
||||||
'#end\n'
|
'#end\n'
|
||||||
'},\n'
|
'},\n'
|
||||||
'"apigw_context" : {\n'
|
'"apigw_context" : {\n'
|
||||||
'"apiId": "$context.apiId",\n'
|
'"apiId": "$context.apiId",\n'
|
||||||
'"httpMethod": "$context.httpMethod",\n'
|
'"httpMethod": "$context.httpMethod",\n'
|
||||||
'"requestId": "$context.requestId",\n'
|
'"requestId": "$context.requestId",\n'
|
||||||
'"resourceId": "$context.resourceId",\n'
|
'"resourceId": "$context.resourceId",\n'
|
||||||
'"resourcePath": "$context.resourcePath",\n'
|
'"resourcePath": "$context.resourcePath",\n'
|
||||||
'"stage": "$context.stage",\n'
|
'"stage": "$context.stage",\n'
|
||||||
'"identity": {\n'
|
'"identity": {\n'
|
||||||
'#set ($map = $context.identity)\n'
|
'#set ($map = $context.identity)\n'
|
||||||
'#foreach( $param in $map.entrySet() )\n'
|
'#foreach( $param in $map.entrySet() )\n'
|
||||||
'"$param.key" : "$param.value" #if( $foreach.hasNext ), #end\n'
|
'"$param.key" : "$param.value" #if( $foreach.hasNext ), #end\n'
|
||||||
'#end\n'
|
'#end\n'
|
||||||
'}\n'
|
'}\n'
|
||||||
'},\n'
|
'},\n'
|
||||||
'"body_params" : $input.json(\'$\'),\n'
|
'"body_params" : $input.json(\'$\'),\n'
|
||||||
'"stage_variables" : "$stageVariables"\n'
|
'"stage_variables" : "$stageVariables"\n'
|
||||||
'}'}
|
'}'}
|
||||||
REQUEST_OPTION_TEMPLATE = {'application/json': '{"statusCode": 200}'}
|
REQUEST_OPTION_TEMPLATE = {'application/json': '{"statusCode": 200}'}
|
||||||
|
|
||||||
# AWS integration response template mapping to convert stackTrace part or the error
|
# AWS integration response template mapping to convert stackTrace part or the error
|
||||||
@ -522,22 +527,22 @@ class _Swagger(object):
|
|||||||
# an array of non-uniform types, to it is not possible to create error model to match
|
# an array of non-uniform types, to it is not possible to create error model to match
|
||||||
# exactly what comes out of lambda functions in case of error.
|
# exactly what comes out of lambda functions in case of error.
|
||||||
RESPONSE_TEMPLATE = {'application/json':
|
RESPONSE_TEMPLATE = {'application/json':
|
||||||
'#set($inputRoot = $input.path(\'$\'))\n'
|
'#set($inputRoot = $input.path(\'$\'))\n'
|
||||||
'{\n'
|
'{\n'
|
||||||
' "errorMessage" : "$inputRoot.errorMessage",\n'
|
' "errorMessage" : "$inputRoot.errorMessage",\n'
|
||||||
' "errorType" : "$inputRoot.errorType",\n'
|
' "errorType" : "$inputRoot.errorType",\n'
|
||||||
' "stackTrace" : [\n'
|
' "stackTrace" : [\n'
|
||||||
'#foreach($stackTrace in $inputRoot.stackTrace)\n'
|
'#foreach($stackTrace in $inputRoot.stackTrace)\n'
|
||||||
' [\n'
|
' [\n'
|
||||||
'#foreach($elem in $stackTrace)\n'
|
'#foreach($elem in $stackTrace)\n'
|
||||||
' "$elem"\n'
|
' "$elem"\n'
|
||||||
'#if($foreach.hasNext),#end\n'
|
'#if($foreach.hasNext),#end\n'
|
||||||
'#end\n'
|
'#end\n'
|
||||||
' ]\n'
|
' ]\n'
|
||||||
'#if($foreach.hasNext),#end\n'
|
'#if($foreach.hasNext),#end\n'
|
||||||
'#end\n'
|
'#end\n'
|
||||||
' ]\n'
|
' ]\n'
|
||||||
'}'}
|
'}'}
|
||||||
RESPONSE_OPTION_TEMPLATE = {}
|
RESPONSE_OPTION_TEMPLATE = {}
|
||||||
|
|
||||||
# This string should not be modified, every API created by this state will carry the description
|
# This string should not be modified, every API created by this state will carry the description
|
||||||
@ -695,7 +700,6 @@ class _Swagger(object):
|
|||||||
'match AWS convention. If pattern is not set, .+ will '
|
'match AWS convention. If pattern is not set, .+ will '
|
||||||
'be used'.format(modelname))
|
'be used'.format(modelname))
|
||||||
|
|
||||||
|
|
||||||
def _validate_swagger_file(self):
|
def _validate_swagger_file(self):
|
||||||
'''
|
'''
|
||||||
High level check/validation of the input swagger file based on
|
High level check/validation of the input swagger file based on
|
||||||
@ -709,7 +713,7 @@ class _Swagger(object):
|
|||||||
# check for any invalid fields for Swagger Object V2
|
# check for any invalid fields for Swagger Object V2
|
||||||
for field in self._cfg:
|
for field in self._cfg:
|
||||||
if (field not in _Swagger.SWAGGER_OBJ_V2_FIELDS and
|
if (field not in _Swagger.SWAGGER_OBJ_V2_FIELDS and
|
||||||
not _Swagger.VENDOR_EXT_PATTERN.match(field)):
|
not _Swagger.VENDOR_EXT_PATTERN.match(field)):
|
||||||
raise ValueError('Invalid Swagger Object Field: {0}'.format(field))
|
raise ValueError('Invalid Swagger Object Field: {0}'.format(field))
|
||||||
|
|
||||||
# check for Required Swagger fields by Saltstack boto apigateway state
|
# check for Required Swagger fields by Saltstack boto apigateway state
|
||||||
@ -790,7 +794,6 @@ class _Swagger(object):
|
|||||||
break
|
break
|
||||||
yield (model, self._models().get(model))
|
yield (model, self._models().get(model))
|
||||||
|
|
||||||
|
|
||||||
@property
|
@property
|
||||||
def paths(self):
|
def paths(self):
|
||||||
'''
|
'''
|
||||||
@ -1203,7 +1206,7 @@ class _Swagger(object):
|
|||||||
# need to walk each property object
|
# need to walk each property object
|
||||||
properties = obj_schema.get('properties')
|
properties = obj_schema.get('properties')
|
||||||
if properties:
|
if properties:
|
||||||
for prop_obj, prop_obj_schema in properties.iteritems():
|
for _, prop_obj_schema in properties.iteritems():
|
||||||
dep_models_list.extend(self._build_dependent_model_list(prop_obj_schema))
|
dep_models_list.extend(self._build_dependent_model_list(prop_obj_schema))
|
||||||
return list(set(dep_models_list))
|
return list(set(dep_models_list))
|
||||||
|
|
||||||
@ -1250,9 +1253,9 @@ class _Swagger(object):
|
|||||||
a dictionary for returning status to Saltstack
|
a dictionary for returning status to Saltstack
|
||||||
'''
|
'''
|
||||||
|
|
||||||
for model, schema in self.models():
|
for model, schema in self.models():
|
||||||
# add in a few attributes into the model schema that AWS expects
|
# add in a few attributes into the model schema that AWS expects
|
||||||
#_schema = schema.copy()
|
# _schema = schema.copy()
|
||||||
_schema = self._update_schema_to_aws_notation(schema)
|
_schema = self._update_schema_to_aws_notation(schema)
|
||||||
_schema.update({'$schema': _Swagger.JSON_SCHEMA_DRAFT_4,
|
_schema.update({'$schema': _Swagger.JSON_SCHEMA_DRAFT_4,
|
||||||
'title': '{0} Schema'.format(model)})
|
'title': '{0} Schema'.format(model)})
|
||||||
@ -1273,8 +1276,9 @@ class _Swagger(object):
|
|||||||
ret['result'] = False
|
ret['result'] = False
|
||||||
ret['abort'] = True
|
ret['abort'] = True
|
||||||
if 'error' in update_model_schema_response:
|
if 'error' in update_model_schema_response:
|
||||||
ret['comment'] = 'Failed to update existing model {0} with schema {1}, error: {2}'.format(model,
|
ret['comment'] = ('Failed to update existing model {0} with schema {1}, '
|
||||||
_dict_to_json_pretty(schema), update_model_schema_response['error']['message'])
|
'error: {2}'.format(model, _dict_to_json_pretty(schema),
|
||||||
|
update_model_schema_response['error']['message']))
|
||||||
return ret
|
return ret
|
||||||
|
|
||||||
ret = _log_changes(ret, 'deploy_models', update_model_schema_response)
|
ret = _log_changes(ret, 'deploy_models', update_model_schema_response)
|
||||||
@ -1290,8 +1294,9 @@ class _Swagger(object):
|
|||||||
ret['result'] = False
|
ret['result'] = False
|
||||||
ret['abort'] = True
|
ret['abort'] = True
|
||||||
if 'error' in create_model_response:
|
if 'error' in create_model_response:
|
||||||
ret['comment'] = 'Failed to create model {0}, schema {1}, error: {2}'.format(model,
|
ret['comment'] = ('Failed to create model {0}, schema {1}, '
|
||||||
_dict_to_json_pretty(schema), create_model_response['error']['message'])
|
'error: {2}'.format(model, _dict_to_json_pretty(schema),
|
||||||
|
create_model_response['error']['message']))
|
||||||
return ret
|
return ret
|
||||||
|
|
||||||
ret = _log_changes(ret, 'deploy_models', create_model_response)
|
ret = _log_changes(ret, 'deploy_models', create_model_response)
|
||||||
@ -1393,9 +1398,13 @@ class _Swagger(object):
|
|||||||
response_header = 'method.response.header.{0}'.format(header)
|
response_header = 'method.response.header.{0}'.format(header)
|
||||||
method_response_params[response_header] = False
|
method_response_params[response_header] = False
|
||||||
header_data = method_response.headers.get(header)
|
header_data = method_response.headers.get(header)
|
||||||
method_integration_response_params[response_header] = "'{0}'".format(header_data.get('default')) if 'default' in header_data else "'*'"
|
method_integration_response_params[response_header] = (
|
||||||
|
"'{0}'".format(header_data.get('default')) if 'default' in header_data else "'*'")
|
||||||
|
|
||||||
response_templates = _Swagger.RESPONSE_OPTION_TEMPLATE if (method_name == 'options' or not self._is_http_error_rescode(httpStatus)) else _Swagger.RESPONSE_TEMPLATE
|
if method_name == 'options' or not self._is_http_error_rescode(httpStatus):
|
||||||
|
response_templates = _Swagger.RESPONSE_OPTION_TEMPLATE
|
||||||
|
else:
|
||||||
|
response_templates = _Swagger.RESPONSE_TEMPLATE
|
||||||
|
|
||||||
return {'params': method_response_params,
|
return {'params': method_response_params,
|
||||||
'models': method_response_models,
|
'models': method_response_models,
|
||||||
@ -1404,7 +1413,7 @@ class _Swagger(object):
|
|||||||
'response_templates': response_templates}
|
'response_templates': response_templates}
|
||||||
|
|
||||||
def _deploy_method(self, ret, resource_path, method_name, method_data, api_key_required,
|
def _deploy_method(self, ret, resource_path, method_name, method_data, api_key_required,
|
||||||
lambda_integration_role, lambda_region):
|
lambda_integration_role, lambda_region):
|
||||||
'''
|
'''
|
||||||
Method to create a method for the given resource path, along with its associated
|
Method to create a method for the given resource path, along with its associated
|
||||||
request and response integrations.
|
request and response integrations.
|
||||||
@ -1476,7 +1485,7 @@ class _Swagger(object):
|
|||||||
for response, response_data in method_data['responses'].iteritems():
|
for response, response_data in method_data['responses'].iteritems():
|
||||||
httpStatus = str(response)
|
httpStatus = str(response)
|
||||||
method_response = self._parse_method_response(method_name.lower(),
|
method_response = self._parse_method_response(method_name.lower(),
|
||||||
_Swagger.SwaggerMethodResponse(response_data), httpStatus)
|
_Swagger.SwaggerMethodResponse(response_data), httpStatus)
|
||||||
|
|
||||||
mr = __salt__['boto_apigateway.create_api_method_response'](
|
mr = __salt__['boto_apigateway.create_api_method_response'](
|
||||||
restApiId=self.restApiId,
|
restApiId=self.restApiId,
|
||||||
@ -1541,4 +1550,3 @@ class _Swagger(object):
|
|||||||
ret = self._deploy_method(ret, path, method, method_data,
|
ret = self._deploy_method(ret, path, method, method_data,
|
||||||
api_key_required, lambda_integration_role, lambda_region)
|
api_key_required, lambda_integration_role, lambda_region)
|
||||||
return ret
|
return ret
|
||||||
|
|
||||||
|
@ -1,8 +1,5 @@
|
|||||||
# -*- coding: utf-8 -*-
|
# -*- coding: utf-8 -*-
|
||||||
|
|
||||||
# TODO: Update skipped tests to expect dictionary results from the execution
|
|
||||||
# module functions.
|
|
||||||
|
|
||||||
# Import Python libs
|
# Import Python libs
|
||||||
from __future__ import absolute_import
|
from __future__ import absolute_import
|
||||||
from distutils.version import LooseVersion # pylint: disable=import-error,no-name-in-module
|
from distutils.version import LooseVersion # pylint: disable=import-error,no-name-in-module
|
||||||
@ -12,7 +9,7 @@ from md5 import md5
|
|||||||
|
|
||||||
# Import Salt Testing libs
|
# Import Salt Testing libs
|
||||||
from salttesting.unit import skipIf, TestCase
|
from salttesting.unit import skipIf, TestCase
|
||||||
from salttesting.mock import NO_MOCK, NO_MOCK_REASON, MagicMock, patch, call
|
from salttesting.mock import NO_MOCK, NO_MOCK_REASON, MagicMock, patch
|
||||||
from salttesting.helpers import ensure_in_syspath
|
from salttesting.helpers import ensure_in_syspath
|
||||||
|
|
||||||
ensure_in_syspath('../../')
|
ensure_in_syspath('../../')
|
||||||
@ -21,13 +18,9 @@ ensure_in_syspath('../../')
|
|||||||
import salt.config
|
import salt.config
|
||||||
import salt.loader
|
import salt.loader
|
||||||
from salt.modules import boto_apigateway
|
from salt.modules import boto_apigateway
|
||||||
from salt.exceptions import SaltInvocationError, CommandExecutionError
|
|
||||||
|
|
||||||
# Import 3rd-party libs
|
# Import 3rd-party libs
|
||||||
import salt.ext.six as six
|
|
||||||
from tempfile import NamedTemporaryFile
|
|
||||||
import logging
|
import logging
|
||||||
import os
|
|
||||||
|
|
||||||
# pylint: disable=import-error,no-name-in-module
|
# pylint: disable=import-error,no-name-in-module
|
||||||
try:
|
try:
|
||||||
@ -64,7 +57,7 @@ api_key_ret = {
|
|||||||
u'id': u'88883333amaa1ZMVGCoLeaTrQk8kzOC36vCgRcT2',
|
u'id': u'88883333amaa1ZMVGCoLeaTrQk8kzOC36vCgRcT2',
|
||||||
u'name': u'test-salt-key',
|
u'name': u'test-salt-key',
|
||||||
'ResponseMetadata': {'HTTPStatusCode': 200,
|
'ResponseMetadata': {'HTTPStatusCode': 200,
|
||||||
'RequestId': '7cc233dd-9dc8-11e5-ba47-1b7350cc2757'}}
|
'RequestId': '7cc233dd-9dc8-11e5-ba47-1b7350cc2757'}}
|
||||||
|
|
||||||
api_model_error_schema = u'{"properties":{"code":{"type":"integer","format":"int32"},"message":{"type":"string"},"fields":{"type":"string"}},"definitions":{}}'
|
api_model_error_schema = u'{"properties":{"code":{"type":"integer","format":"int32"},"message":{"type":"string"},"fields":{"type":"string"}},"definitions":{}}'
|
||||||
api_model_ret = {
|
api_model_ret = {
|
||||||
@ -97,14 +90,6 @@ api_create_resource_ret = {
|
|||||||
u'pathPart': u'api3',
|
u'pathPart': u'api3',
|
||||||
'ResponseMetadata': {'HTTPStatusCode': 200, 'RequestId': '2d31072c-9d15-11e5-9977-6d9fcfda9c0a'}}
|
'ResponseMetadata': {'HTTPStatusCode': 200, 'RequestId': '2d31072c-9d15-11e5-9977-6d9fcfda9c0a'}}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
#cidr_block = '10.0.0.0/24'
|
|
||||||
#dhcp_options_parameters = {'domain_name': 'example.com', 'domain_name_servers': ['1.2.3.4'], 'ntp_servers': ['5.6.7.8'],
|
|
||||||
# 'netbios_name_servers': ['10.0.0.1'], 'netbios_node_type': 2}
|
|
||||||
#network_acl_entry_parameters = ('fake', 100, -1, 'allow', cidr_block)
|
|
||||||
#dhcp_options_parameters.update(conn_parameters)
|
|
||||||
|
|
||||||
log = logging.getLogger(__name__)
|
log = logging.getLogger(__name__)
|
||||||
|
|
||||||
opts = salt.config.DEFAULT_MINION_OPTS
|
opts = salt.config.DEFAULT_MINION_OPTS
|
||||||
@ -128,6 +113,7 @@ def _has_required_boto():
|
|||||||
else:
|
else:
|
||||||
return True
|
return True
|
||||||
|
|
||||||
|
|
||||||
class BotoApiGatewayTestCaseBase(TestCase):
|
class BotoApiGatewayTestCaseBase(TestCase):
|
||||||
conn = None
|
conn = None
|
||||||
|
|
||||||
@ -144,6 +130,7 @@ class BotoApiGatewayTestCaseBase(TestCase):
|
|||||||
self.conn = MagicMock()
|
self.conn = MagicMock()
|
||||||
session_instance.client.return_value = self.conn
|
session_instance.client.return_value = self.conn
|
||||||
|
|
||||||
|
|
||||||
class BotoApiGatewayTestCaseMixin(object):
|
class BotoApiGatewayTestCaseMixin(object):
|
||||||
def _diff_list_dicts(self, listdict1, listdict2, sortkey):
|
def _diff_list_dicts(self, listdict1, listdict2, sortkey):
|
||||||
'''
|
'''
|
||||||
@ -232,14 +219,11 @@ class BotoApiGatewayTestCase(BotoApiGatewayTestCaseBase, BotoApiGatewayTestCaseM
|
|||||||
items_dt = map(boto_apigateway._convert_datetime_str, items)
|
items_dt = map(boto_apigateway._convert_datetime_str, items)
|
||||||
apis = get_apis_result.get('restapi')
|
apis = get_apis_result.get('restapi')
|
||||||
|
|
||||||
diff = False
|
diff = self._diff_list_dicts(apis, items_dt, 'id')
|
||||||
if len(apis) != len(items):
|
|
||||||
diff = True
|
|
||||||
else:
|
|
||||||
# compare individual items.
|
|
||||||
diff = self._diff_list_dicts(apis, items_dt, 'id')
|
|
||||||
|
|
||||||
self.assertTrue(apis and not diff)
|
self.assertTrue(apis)
|
||||||
|
self.assertEqual(len(apis), len(items))
|
||||||
|
self.assertFalse(diff)
|
||||||
|
|
||||||
def test_that_when_describing_rest_apis_and_name_is_testing123_the_describe_apis_method_returns_list_of_two_rest_apis(self):
|
def test_that_when_describing_rest_apis_and_name_is_testing123_the_describe_apis_method_returns_list_of_two_rest_apis(self):
|
||||||
'''
|
'''
|
||||||
@ -403,7 +387,7 @@ class BotoApiGatewayTestCase(BotoApiGatewayTestCaseBase, BotoApiGatewayTestCaseM
|
|||||||
u'id': u'999999989b8cNSp4505pL6OgDe3oW7oY29Z3eIZ4',
|
u'id': u'999999989b8cNSp4505pL6OgDe3oW7oY29Z3eIZ4',
|
||||||
u'name': u'testing_salt'}],
|
u'name': u'testing_salt'}],
|
||||||
'ResponseMetadata': {'HTTPStatusCode': 200,
|
'ResponseMetadata': {'HTTPStatusCode': 200,
|
||||||
'RequestId': '7cc233dd-9dc8-11e5-ba47-1b7350cc2757'}}
|
'RequestId': '7cc233dd-9dc8-11e5-ba47-1b7350cc2757'}}
|
||||||
|
|
||||||
items = self.conn.get_api_keys.return_value['items']
|
items = self.conn.get_api_keys.return_value['items']
|
||||||
get_api_keys_result = boto_apigateway.describe_api_keys(**conn_parameters)
|
get_api_keys_result = boto_apigateway.describe_api_keys(**conn_parameters)
|
||||||
@ -460,15 +444,15 @@ class BotoApiGatewayTestCase(BotoApiGatewayTestCaseBase, BotoApiGatewayTestCaseM
|
|||||||
u'id': u'88883333amaa1ZMVGCoLeaTrQk8kzOC36vCgRcT2',
|
u'id': u'88883333amaa1ZMVGCoLeaTrQk8kzOC36vCgRcT2',
|
||||||
u'name': u'test-salt-key',
|
u'name': u'test-salt-key',
|
||||||
'ResponseMetadata': {'HTTPStatusCode': 200,
|
'ResponseMetadata': {'HTTPStatusCode': 200,
|
||||||
'RequestId': '7cc233dd-9dc8-11e5-ba47-1b7350cc2757'}}
|
'RequestId': '7cc233dd-9dc8-11e5-ba47-1b7350cc2757'}}
|
||||||
|
|
||||||
create_api_key_result = boto_apigateway.create_api_key('test-salt-key', 'test-lambda-api-key', **conn_parameters)
|
create_api_key_result = boto_apigateway.create_api_key('test-salt-key', 'test-lambda-api-key', **conn_parameters)
|
||||||
api_key = create_api_key_result.get('apiKey')
|
api_key = create_api_key_result.get('apiKey')
|
||||||
now_str = '{0}'.format(now)
|
now_str = '{0}'.format(now)
|
||||||
|
|
||||||
self.assertTrue(create_api_key_result.get('created') == True and
|
self.assertTrue(create_api_key_result.get('created'))
|
||||||
api_key.get('lastUpdatedDate') == now_str and
|
self.assertEqual(api_key.get('lastUpdatedDate'), now_str)
|
||||||
api_key.get('createdDate') == now_str)
|
self.assertEqual(api_key.get('createdDate'), now_str)
|
||||||
|
|
||||||
def test_that_when_creating_an_api_key_fails_the_create_api_key_method_returns_error(self):
|
def test_that_when_creating_an_api_key_fails_the_create_api_key_method_returns_error(self):
|
||||||
'''
|
'''
|
||||||
@ -479,9 +463,9 @@ class BotoApiGatewayTestCase(BotoApiGatewayTestCaseBase, BotoApiGatewayTestCaseM
|
|||||||
create_api_key_result = boto_apigateway.create_api_key('test-salt-key', 'unit-testing1234')
|
create_api_key_result = boto_apigateway.create_api_key('test-salt-key', 'unit-testing1234')
|
||||||
api_key = create_api_key_result.get('apiKey')
|
api_key = create_api_key_result.get('apiKey')
|
||||||
|
|
||||||
self.assertTrue(not api_key and
|
self.assertFalse(api_key)
|
||||||
create_api_key_result.get('created') == False and
|
self.assertIs(create_api_key_result.get('created'), False)
|
||||||
create_api_key_result.get('error').get('message') == error_message.format('create_api_key'))
|
self.assertEqual(create_api_key_result.get('error').get('message'), error_message.format('create_api_key'))
|
||||||
|
|
||||||
def test_that_when_deleting_an_api_key_that_exists_the_delete_api_key_method_returns_true(self):
|
def test_that_when_deleting_an_api_key_that_exists_the_delete_api_key_method_returns_true(self):
|
||||||
'''
|
'''
|
||||||
@ -670,14 +654,14 @@ class BotoApiGatewayTestCase(BotoApiGatewayTestCaseBase, BotoApiGatewayTestCaseM
|
|||||||
u'id': 'n05smo',
|
u'id': 'n05smo',
|
||||||
u'createdDate': now,
|
u'createdDate': now,
|
||||||
'ResponseMetadata': {'HTTPStatusCode': 200,
|
'ResponseMetadata': {'HTTPStatusCode': 200,
|
||||||
'RequestId': '7cc233dd-9dc8-11e5-ba47-1b7350cc2757'}}
|
'RequestId': '7cc233dd-9dc8-11e5-ba47-1b7350cc2757'}}
|
||||||
|
|
||||||
result = boto_apigateway.create_api_deployment(restApiId='rm06h9oac4', stageName='test', **conn_parameters)
|
result = boto_apigateway.create_api_deployment(restApiId='rm06h9oac4', stageName='test', **conn_parameters)
|
||||||
deployment = result.get('deployment')
|
deployment = result.get('deployment')
|
||||||
now_str = '{0}'.format(now)
|
now_str = '{0}'.format(now)
|
||||||
|
|
||||||
self.assertTrue(result.get('created') == True and
|
self.assertTrue(result.get('created'))
|
||||||
deployment.get('createdDate') == now_str)
|
self.assertEqual(deployment.get('createdDate'), now_str)
|
||||||
|
|
||||||
def test_that_when_creating_an_deployment_fails_the_create_api_deployment_method_returns_error(self):
|
def test_that_when_creating_an_deployment_fails_the_create_api_deployment_method_returns_error(self):
|
||||||
'''
|
'''
|
||||||
@ -686,8 +670,8 @@ class BotoApiGatewayTestCase(BotoApiGatewayTestCaseBase, BotoApiGatewayTestCaseM
|
|||||||
|
|
||||||
self.conn.create_deployment.side_effect = ClientError(error_content, 'create_deployment')
|
self.conn.create_deployment.side_effect = ClientError(error_content, 'create_deployment')
|
||||||
result = boto_apigateway.create_api_deployment(restApiId='rm06h9oac4', stageName='test', **conn_parameters)
|
result = boto_apigateway.create_api_deployment(restApiId='rm06h9oac4', stageName='test', **conn_parameters)
|
||||||
self.assertTrue(result.get('created') == False and
|
self.assertIs(result.get('created'), False)
|
||||||
result.get('error').get('message') == error_message.format('create_deployment'))
|
self.assertEqual(result.get('error').get('message'), error_message.format('create_deployment'))
|
||||||
|
|
||||||
def test_that_when_deleting_an_api_deployment_that_exists_the_delete_api_deployment_method_returns_true(self):
|
def test_that_when_deleting_an_api_deployment_that_exists_the_delete_api_deployment_method_returns_true(self):
|
||||||
'''
|
'''
|
||||||
@ -830,9 +814,9 @@ class BotoApiGatewayTestCase(BotoApiGatewayTestCaseBase, BotoApiGatewayTestCaseM
|
|||||||
**conn_parameters)
|
**conn_parameters)
|
||||||
stage = result.get('stage')
|
stage = result.get('stage')
|
||||||
now_str = '{0}'.format(now)
|
now_str = '{0}'.format(now)
|
||||||
self.assertTrue(result.get('created') == True and
|
self.assertIs(result.get('created'), True)
|
||||||
stage.get('createdDate') == now_str and
|
self.assertEqual(stage.get('createdDate'), now_str)
|
||||||
stage.get('lastUpdatedDate') == now_str)
|
self.assertEqual(stage.get('lastUpdatedDate'), now_str)
|
||||||
|
|
||||||
def test_that_when_creating_an_api_stage_fails_the_create_api_stage_method_returns_error(self):
|
def test_that_when_creating_an_api_stage_fails_the_create_api_stage_method_returns_error(self):
|
||||||
'''
|
'''
|
||||||
@ -842,8 +826,8 @@ class BotoApiGatewayTestCase(BotoApiGatewayTestCaseBase, BotoApiGatewayTestCaseM
|
|||||||
self.conn.create_stage.side_effect = ClientError(error_content, 'create_stage')
|
self.conn.create_stage.side_effect = ClientError(error_content, 'create_stage')
|
||||||
result = boto_apigateway.create_api_stage(restApiId='rm06h9oac4', stageName='test', deploymentId='n05smo',
|
result = boto_apigateway.create_api_stage(restApiId='rm06h9oac4', stageName='test', deploymentId='n05smo',
|
||||||
**conn_parameters)
|
**conn_parameters)
|
||||||
self.assertTrue(result.get('created') == False and
|
self.assertIs(result.get('created'), False)
|
||||||
result.get('error').get('message') == error_message.format('create_stage'))
|
self.assertEqual(result.get('error').get('message'), error_message.format('create_stage'))
|
||||||
|
|
||||||
def test_that_when_deleting_an_api_stage_that_exists_the_delete_api_stage_method_returns_true(self):
|
def test_that_when_deleting_an_api_stage_that_exists_the_delete_api_stage_method_returns_true(self):
|
||||||
'''
|
'''
|
||||||
@ -941,7 +925,7 @@ class BotoApiGatewayTestCase(BotoApiGatewayTestCaseBase, BotoApiGatewayTestCaseM
|
|||||||
'''
|
'''
|
||||||
self.conn.update_model.return_value = api_model_ret
|
self.conn.update_model.return_value = api_model_ret
|
||||||
result = boto_apigateway.update_api_model_schema(restApiId='rm06h9oac4', modelName='Error',
|
result = boto_apigateway.update_api_model_schema(restApiId='rm06h9oac4', modelName='Error',
|
||||||
schema=api_model_error_schema, **conn_parameters)
|
schema=api_model_error_schema, **conn_parameters)
|
||||||
self.assertTrue(result.get('updated'))
|
self.assertTrue(result.get('updated'))
|
||||||
|
|
||||||
def test_that_updating_model_schema_when_model_does_not_exist_the_update_api_model_schema_emthod_returns_false(self):
|
def test_that_updating_model_schema_when_model_does_not_exist_the_update_api_model_schema_emthod_returns_false(self):
|
||||||
@ -950,7 +934,7 @@ class BotoApiGatewayTestCase(BotoApiGatewayTestCaseBase, BotoApiGatewayTestCaseM
|
|||||||
'''
|
'''
|
||||||
self.conn.update_model.side_effect = ClientError(error_content, 'update_model')
|
self.conn.update_model.side_effect = ClientError(error_content, 'update_model')
|
||||||
result = boto_apigateway.update_api_model_schema(restApiId='rm06h9oac4', modelName='no_such_model',
|
result = boto_apigateway.update_api_model_schema(restApiId='rm06h9oac4', modelName='no_such_model',
|
||||||
schema=api_model_error_schema, **conn_parameters)
|
schema=api_model_error_schema, **conn_parameters)
|
||||||
self.assertFalse(result.get('updated'))
|
self.assertFalse(result.get('updated'))
|
||||||
|
|
||||||
def test_that_when_creating_an_api_model_succeeds_the_create_api_model_method_returns_true(self):
|
def test_that_when_creating_an_api_model_succeeds_the_create_api_model_method_returns_true(self):
|
||||||
@ -1040,10 +1024,10 @@ class BotoApiGatewayTestCase(BotoApiGatewayTestCaseBase, BotoApiGatewayTestCaseM
|
|||||||
result = boto_apigateway.create_api_resources(restApiId='rm06h9oac4', path='/api3')
|
result = boto_apigateway.create_api_resources(restApiId='rm06h9oac4', path='/api3')
|
||||||
|
|
||||||
resources = result.get('resources')
|
resources = result.get('resources')
|
||||||
self.assertTrue(result.get('created') == True and
|
self.assertIs(result.get('created'), True)
|
||||||
len(resources) == 2 and
|
self.assertEqual(len(resources), 2)
|
||||||
resources[0].get('path') == '/' and
|
self.assertEqual(resources[0].get('path'), '/')
|
||||||
resources[1].get('path') == '/api3')
|
self.assertEqual(resources[1].get('path'), '/api3')
|
||||||
|
|
||||||
def test_that_when_creating_api_resources_for_a_path_whose_resources_exist_the_create_resources_api_method_returns_all_resources(self):
|
def test_that_when_creating_api_resources_for_a_path_whose_resources_exist_the_create_resources_api_method_returns_all_resources(self):
|
||||||
'''
|
'''
|
||||||
@ -1053,11 +1037,11 @@ class BotoApiGatewayTestCase(BotoApiGatewayTestCaseBase, BotoApiGatewayTestCaseM
|
|||||||
self.conn.get_resources.return_value = api_resources_ret
|
self.conn.get_resources.return_value = api_resources_ret
|
||||||
result = boto_apigateway.create_api_resources(restApiId='rm06h9oac4', path='/api/users', **conn_parameters)
|
result = boto_apigateway.create_api_resources(restApiId='rm06h9oac4', path='/api/users', **conn_parameters)
|
||||||
resources = result.get('resources')
|
resources = result.get('resources')
|
||||||
self.assertTrue(result.get('created') == True and
|
self.assertIs(result.get('created'), True)
|
||||||
len(resources) == len(api_resources_ret.get('items')) and
|
self.assertEqual(len(resources), len(api_resources_ret.get('items')))
|
||||||
resources[0].get('path') == '/' and
|
self.assertEqual(resources[0].get('path'), '/')
|
||||||
resources[1].get('path') == '/api' and
|
self.assertEqual(resources[1].get('path'), '/api')
|
||||||
resources[2].get('path') == '/api/users')
|
self.assertEqual(resources[2].get('path'), '/api/users')
|
||||||
|
|
||||||
def test_that_when_creating_api_resource_fails_the_create_resources_api_method_returns_false(self):
|
def test_that_when_creating_api_resource_fails_the_create_resources_api_method_returns_false(self):
|
||||||
'''
|
'''
|
||||||
@ -1318,9 +1302,9 @@ class BotoApiGatewayTestCase(BotoApiGatewayTestCaseBase, BotoApiGatewayTestCaseM
|
|||||||
'ResponseMetadata': {'HTTPStatusCode': 200,
|
'ResponseMetadata': {'HTTPStatusCode': 200,
|
||||||
'RequestId': '7cc233dd-9dc8-11e5-ba47-1b7350cc2757'}}
|
'RequestId': '7cc233dd-9dc8-11e5-ba47-1b7350cc2757'}}
|
||||||
result = boto_apigateway.describe_api_integration(restApiId='rm06h9oac4',
|
result = boto_apigateway.describe_api_integration(restApiId='rm06h9oac4',
|
||||||
resourcePath='/api/users',
|
resourcePath='/api/users',
|
||||||
httpMethod='POST',
|
httpMethod='POST',
|
||||||
**conn_parameters)
|
**conn_parameters)
|
||||||
self.assertTrue(result.get('integration'))
|
self.assertTrue(result.get('integration'))
|
||||||
|
|
||||||
def test_that_when_describing_an_api_integration_and_method_does_not_have_integration_defined_the_describe_api_integration_method_returns_error(self):
|
def test_that_when_describing_an_api_integration_and_method_does_not_have_integration_defined_the_describe_api_integration_method_returns_error(self):
|
||||||
@ -1356,10 +1340,10 @@ class BotoApiGatewayTestCase(BotoApiGatewayTestCaseBase, BotoApiGatewayTestCaseM
|
|||||||
'ResponseMetadata': {'HTTPStatusCode': 200,
|
'ResponseMetadata': {'HTTPStatusCode': 200,
|
||||||
'RequestId': '7cc233dd-9dc8-11e5-ba47-1b7350cc2757'}}
|
'RequestId': '7cc233dd-9dc8-11e5-ba47-1b7350cc2757'}}
|
||||||
result = boto_apigateway.describe_api_integration_response(restApiId='rm06h9oac4',
|
result = boto_apigateway.describe_api_integration_response(restApiId='rm06h9oac4',
|
||||||
resourcePath='/api/users',
|
resourcePath='/api/users',
|
||||||
httpMethod='POST',
|
httpMethod='POST',
|
||||||
statusCode='200',
|
statusCode='200',
|
||||||
**conn_parameters)
|
**conn_parameters)
|
||||||
self.assertTrue(result.get('response'))
|
self.assertTrue(result.get('response'))
|
||||||
|
|
||||||
def test_that_when_describing_an_api_integration_response_and_status_code_does_not_exist_the_describe_api_integration_response_method_returns_error(self):
|
def test_that_when_describing_an_api_integration_response_and_status_code_does_not_exist_the_describe_api_integration_response_method_returns_error(self):
|
||||||
@ -1369,10 +1353,10 @@ class BotoApiGatewayTestCase(BotoApiGatewayTestCaseBase, BotoApiGatewayTestCaseM
|
|||||||
self.conn.get_resources.return_value = api_resources_ret
|
self.conn.get_resources.return_value = api_resources_ret
|
||||||
self.conn.get_integration_response.side_effect = ClientError(error_content, 'get_integration_response')
|
self.conn.get_integration_response.side_effect = ClientError(error_content, 'get_integration_response')
|
||||||
result = boto_apigateway.describe_api_integration_response(restApiId='rm06h9oac4',
|
result = boto_apigateway.describe_api_integration_response(restApiId='rm06h9oac4',
|
||||||
resourcePath='/api/users',
|
resourcePath='/api/users',
|
||||||
httpMethod='POST',
|
httpMethod='POST',
|
||||||
statusCode='201',
|
statusCode='201',
|
||||||
**conn_parameters)
|
**conn_parameters)
|
||||||
self.assertEqual(result.get('error').get('message'), error_message.format('get_integration_response'))
|
self.assertEqual(result.get('error').get('message'), error_message.format('get_integration_response'))
|
||||||
|
|
||||||
def test_that_when_describing_an_api_integration_response_and_resource_does_not_exist_the_describe_api_integration_response_method_returns_error(self):
|
def test_that_when_describing_an_api_integration_response_and_resource_does_not_exist_the_describe_api_integration_response_method_returns_error(self):
|
||||||
|
@ -3,13 +3,14 @@
|
|||||||
# Import Python libs
|
# Import Python libs
|
||||||
from __future__ import absolute_import
|
from __future__ import absolute_import
|
||||||
from distutils.version import LooseVersion # pylint: disable=import-error,no-name-in-module
|
from distutils.version import LooseVersion # pylint: disable=import-error,no-name-in-module
|
||||||
|
import logging
|
||||||
import os
|
import os
|
||||||
import datetime
|
import datetime
|
||||||
from dateutil.tz import tzlocal
|
from dateutil.tz import tzlocal
|
||||||
|
|
||||||
# Import Salt Testing libs
|
# Import Salt Testing libs
|
||||||
from salttesting.unit import skipIf, TestCase
|
from salttesting.unit import skipIf, TestCase
|
||||||
from salttesting.mock import NO_MOCK, NO_MOCK_REASON, patch
|
from salttesting.mock import NO_MOCK, NO_MOCK_REASON, MagicMock, patch
|
||||||
from salttesting.helpers import ensure_in_syspath
|
from salttesting.helpers import ensure_in_syspath
|
||||||
|
|
||||||
ensure_in_syspath('../../')
|
ensure_in_syspath('../../')
|
||||||
@ -19,13 +20,8 @@ import salt.config
|
|||||||
import salt.loader
|
import salt.loader
|
||||||
|
|
||||||
# Import 3rd-party libs
|
# Import 3rd-party libs
|
||||||
import logging
|
|
||||||
from tempfile import NamedTemporaryFile
|
|
||||||
import yaml
|
import yaml
|
||||||
|
|
||||||
# Import Mock libraries
|
|
||||||
from salttesting.mock import NO_MOCK, NO_MOCK_REASON, MagicMock, patch
|
|
||||||
|
|
||||||
# pylint: disable=import-error,no-name-in-module
|
# pylint: disable=import-error,no-name-in-module
|
||||||
from unit.modules.boto_apigateway_test import BotoApiGatewayTestCaseMixin
|
from unit.modules.boto_apigateway_test import BotoApiGatewayTestCaseMixin
|
||||||
|
|
||||||
@ -174,7 +170,7 @@ stage1_deployment1_vars_ret = dict(cacheClusterEnabled=False,
|
|||||||
lastUpdatedDate=datetime.datetime(2015, 11, 17, 16, 33, 50, tzinfo=tzlocal()),
|
lastUpdatedDate=datetime.datetime(2015, 11, 17, 16, 33, 50, tzinfo=tzlocal()),
|
||||||
methodSettings=dict(),
|
methodSettings=dict(),
|
||||||
stageName='test',
|
stageName='test',
|
||||||
variables={'var1':'val1'})
|
variables={'var1': 'val1'})
|
||||||
|
|
||||||
stage1_deployment2_ret = dict(cacheClusterEnabled=False,
|
stage1_deployment2_ret = dict(cacheClusterEnabled=False,
|
||||||
cacheClusterSize=0.5,
|
cacheClusterSize=0.5,
|
||||||
@ -264,7 +260,7 @@ function_ret = dict(FunctionName='unit_test_api_users_post',
|
|||||||
FunctionArn='arn:lambda:us-east-1:1234:Something',
|
FunctionArn='arn:lambda:us-east-1:1234:Something',
|
||||||
LastModified='yes')
|
LastModified='yes')
|
||||||
|
|
||||||
method_integration_response_200_ret = dict(responseParameters={'method.response.header.Access-Control-Allow-Origin':'*'},
|
method_integration_response_200_ret = dict(responseParameters={'method.response.header.Access-Control-Allow-Origin': '*'},
|
||||||
responseTemplates={},
|
responseTemplates={},
|
||||||
selectionPattern='.*',
|
selectionPattern='.*',
|
||||||
statusCode='200')
|
statusCode='200')
|
||||||
@ -321,16 +317,17 @@ def _has_required_boto():
|
|||||||
else:
|
else:
|
||||||
return True
|
return True
|
||||||
|
|
||||||
|
|
||||||
class TempSwaggerFile(object):
|
class TempSwaggerFile(object):
|
||||||
_tmp_swagger_dict = {'info': {'version': '0.0.0',
|
_tmp_swagger_dict = {'info': {'version': '0.0.0',
|
||||||
'description': 'salt boto apigateway unit test service',
|
'description': 'salt boto apigateway unit test service',
|
||||||
'title': 'salt boto apigateway unit test service'},
|
'title': 'salt boto apigateway unit test service'},
|
||||||
'paths': {'/users': {'post': {'responses':
|
'paths': {'/users': {'post': {'responses': {
|
||||||
{'200':
|
'200': {'headers': {'Access-Control-Allow-Origin': {'type': 'string'}},
|
||||||
{'headers': {'Access-Control-Allow-Origin': {'type': 'string'}},
|
'description': 'The username of the new user',
|
||||||
'description': 'The username of the new user',
|
'schema': {'$ref': '#/definitions/User'}}
|
||||||
'schema': {'$ref': '#/definitions/User'}}},
|
},
|
||||||
'parameters': [{'in': 'body',
|
'parameters': [{'in': 'body',
|
||||||
'description': 'New user details.',
|
'description': 'New user details.',
|
||||||
'name': 'NewUser',
|
'name': 'NewUser',
|
||||||
'schema': {'$ref': '#/definitions/User'}}],
|
'schema': {'$ref': '#/definitions/User'}}],
|
||||||
@ -343,16 +340,18 @@ class TempSwaggerFile(object):
|
|||||||
'produces': ['application/json'],
|
'produces': ['application/json'],
|
||||||
'basePath': '/api',
|
'basePath': '/api',
|
||||||
'host': 'rm06h9oac4.execute-api.us-west-2.amazonaws.com',
|
'host': 'rm06h9oac4.execute-api.us-west-2.amazonaws.com',
|
||||||
'definitions': {'User': {'properties':
|
'definitions': {'User': {'properties': {
|
||||||
{'username': {'type': 'string',
|
'username': {'type': 'string',
|
||||||
'description': 'A unique username for the user'},
|
'description': 'A unique username for the user'},
|
||||||
'password': {'type': 'string',
|
'password': {'type': 'string',
|
||||||
'description': 'A password for the new user'}}},
|
'description': 'A password for the new user'}
|
||||||
'Error': {'properties':
|
}},
|
||||||
{'fields': {'type': 'string'},
|
'Error': {'properties': {
|
||||||
|
'fields': {'type': 'string'},
|
||||||
'message': {'type': 'string'},
|
'message': {'type': 'string'},
|
||||||
'code': {'type': 'integer',
|
'code': {'type': 'integer',
|
||||||
'format': 'int32'}}}},
|
'format': 'int32'}
|
||||||
|
}}},
|
||||||
'swagger': '2.0'}
|
'swagger': '2.0'}
|
||||||
|
|
||||||
def __enter__(self):
|
def __enter__(self):
|
||||||
@ -361,7 +360,7 @@ class TempSwaggerFile(object):
|
|||||||
f.write(yaml.dump(self.swaggerdict))
|
f.write(yaml.dump(self.swaggerdict))
|
||||||
return self.swaggerfile
|
return self.swaggerfile
|
||||||
|
|
||||||
def __exit__(self, type, value, traceback):
|
def __exit__(self, objtype, value, traceback):
|
||||||
os.remove(self.swaggerfile)
|
os.remove(self.swaggerfile)
|
||||||
|
|
||||||
def __init__(self, create_invalid_file=False):
|
def __init__(self, create_invalid_file=False):
|
||||||
@ -378,6 +377,7 @@ class TempSwaggerFile(object):
|
|||||||
else:
|
else:
|
||||||
self.swaggerdict = TempSwaggerFile._tmp_swagger_dict
|
self.swaggerdict = TempSwaggerFile._tmp_swagger_dict
|
||||||
|
|
||||||
|
|
||||||
class BotoApiGatewayStateTestCaseBase(TestCase):
|
class BotoApiGatewayStateTestCaseBase(TestCase):
|
||||||
conn = None
|
conn = None
|
||||||
|
|
||||||
@ -418,7 +418,7 @@ class BotoApiGatewayFunctionTestCase(BotoApiGatewayStateTestCaseBase, BotoApiGat
|
|||||||
False,
|
False,
|
||||||
'arn:aws:iam::1234:role/apigatewayrole',
|
'arn:aws:iam::1234:role/apigatewayrole',
|
||||||
**conn_parameters)
|
**conn_parameters)
|
||||||
|
|
||||||
self.assertFalse(result.get('result', True))
|
self.assertFalse(result.get('result', True))
|
||||||
|
|
||||||
def test_present_when_stage_is_already_at_desired_deployment(self):
|
def test_present_when_stage_is_already_at_desired_deployment(self):
|
||||||
@ -440,10 +440,10 @@ class BotoApiGatewayFunctionTestCase(BotoApiGatewayStateTestCaseBase, BotoApiGat
|
|||||||
False,
|
False,
|
||||||
'arn:aws:iam::1234:role/apigatewayrole',
|
'arn:aws:iam::1234:role/apigatewayrole',
|
||||||
**conn_parameters)
|
**conn_parameters)
|
||||||
self.assertTrue(not result.get('abort', False) and
|
self.assertFalse(result.get('abort'))
|
||||||
result.get('current', False) and
|
self.assertTrue(result.get('current'))
|
||||||
result.get('result', False) and
|
self.assertIs(result.get('result'), True)
|
||||||
result.get('comment', '').find('update_stage should not be called') == -1)
|
self.assertNotIn('update_stage should not be called', result.get('comment', ''))
|
||||||
|
|
||||||
def test_present_when_stage_is_already_at_desired_deployment_and_needs_stage_variables_update(self):
|
def test_present_when_stage_is_already_at_desired_deployment_and_needs_stage_variables_update(self):
|
||||||
'''
|
'''
|
||||||
@ -463,12 +463,12 @@ class BotoApiGatewayFunctionTestCase(BotoApiGatewayStateTestCaseBase, BotoApiGat
|
|||||||
'test',
|
'test',
|
||||||
False,
|
False,
|
||||||
'arn:aws:iam::1234:role/apigatewayrole',
|
'arn:aws:iam::1234:role/apigatewayrole',
|
||||||
stage_variables={'var1':'val1'},
|
stage_variables={'var1': 'val1'},
|
||||||
**conn_parameters)
|
**conn_parameters)
|
||||||
|
|
||||||
self.assertTrue(not result.get('abort', False) and
|
self.assertFalse(result.get('abort'))
|
||||||
result.get('current', False) and
|
self.assertTrue(result.get('current'))
|
||||||
result.get('result', False))
|
self.assertIs(result.get('result'), True)
|
||||||
|
|
||||||
def test_present_when_stage_exists_and_is_to_associate_to_existing_deployment(self):
|
def test_present_when_stage_exists_and_is_to_associate_to_existing_deployment(self):
|
||||||
'''
|
'''
|
||||||
@ -496,10 +496,10 @@ class BotoApiGatewayFunctionTestCase(BotoApiGatewayStateTestCaseBase, BotoApiGat
|
|||||||
'arn:aws:iam::1234:role/apigatewayrole',
|
'arn:aws:iam::1234:role/apigatewayrole',
|
||||||
**conn_parameters)
|
**conn_parameters)
|
||||||
|
|
||||||
self.assertTrue(result.get('publish', False) and
|
self.assertTrue(result.get('publish'))
|
||||||
result.get('result', False) and
|
self.assertIs(result.get('result'), True)
|
||||||
not result.get('abort') and
|
self.assertFalse(result.get('abort'))
|
||||||
bool(result.get('changes', {}).get('new', [{}])[0]))
|
self.assertTrue(result.get('changes', {}).get('new', [{}])[0])
|
||||||
|
|
||||||
def test_present_when_stage_is_to_associate_to_new_deployment(self):
|
def test_present_when_stage_is_to_associate_to_new_deployment(self):
|
||||||
'''
|
'''
|
||||||
@ -539,8 +539,8 @@ class BotoApiGatewayFunctionTestCase(BotoApiGatewayStateTestCaseBase, BotoApiGat
|
|||||||
'arn:aws:iam::1234:role/apigatewayrole',
|
'arn:aws:iam::1234:role/apigatewayrole',
|
||||||
**conn_parameters)
|
**conn_parameters)
|
||||||
|
|
||||||
self.assertTrue(result.get('result', False) and
|
self.assertIs(result.get('result'), True)
|
||||||
result.get('abort') is None)
|
self.assertIs(result.get('abort'), None)
|
||||||
|
|
||||||
def test_present_when_stage_associating_to_new_deployment_errored_on_api_creation(self):
|
def test_present_when_stage_associating_to_new_deployment_errored_on_api_creation(self):
|
||||||
'''
|
'''
|
||||||
@ -563,10 +563,10 @@ class BotoApiGatewayFunctionTestCase(BotoApiGatewayStateTestCaseBase, BotoApiGat
|
|||||||
'arn:aws:iam::1234:role/apigatewayrole',
|
'arn:aws:iam::1234:role/apigatewayrole',
|
||||||
**conn_parameters)
|
**conn_parameters)
|
||||||
|
|
||||||
self.assertTrue(result.get('abort', False) and
|
self.assertIs(result.get('abort'), True)
|
||||||
not result.get('result', True) and
|
self.assertIs(result.get('result'), False)
|
||||||
result.get('comment', '').find('create_rest_api') != -1)
|
self.assertIn('create_rest_api', result.get('comment', ''))
|
||||||
|
|
||||||
def test_present_when_stage_associating_to_new_deployment_errored_on_model_creation(self):
|
def test_present_when_stage_associating_to_new_deployment_errored_on_model_creation(self):
|
||||||
'''
|
'''
|
||||||
Tests creation of a new api/model/resource given nothing has been created previously,
|
Tests creation of a new api/model/resource given nothing has been created previously,
|
||||||
@ -592,9 +592,9 @@ class BotoApiGatewayFunctionTestCase(BotoApiGatewayStateTestCaseBase, BotoApiGat
|
|||||||
'arn:aws:iam::1234:role/apigatewayrole',
|
'arn:aws:iam::1234:role/apigatewayrole',
|
||||||
**conn_parameters)
|
**conn_parameters)
|
||||||
|
|
||||||
self.assertTrue(result.get('abort', False) and
|
self.assertIs(result.get('abort'), True)
|
||||||
not result.get('result', True) and
|
self.assertIs(result.get('result'), False)
|
||||||
result.get('comment', '').find('create_model') != -1)
|
self.assertIn('create_model', result.get('comment', ''))
|
||||||
|
|
||||||
def test_present_when_stage_associating_to_new_deployment_errored_on_resource_creation(self):
|
def test_present_when_stage_associating_to_new_deployment_errored_on_resource_creation(self):
|
||||||
'''
|
'''
|
||||||
@ -624,9 +624,9 @@ class BotoApiGatewayFunctionTestCase(BotoApiGatewayStateTestCaseBase, BotoApiGat
|
|||||||
False,
|
False,
|
||||||
'arn:aws:iam::1234:role/apigatewayrole',
|
'arn:aws:iam::1234:role/apigatewayrole',
|
||||||
**conn_parameters)
|
**conn_parameters)
|
||||||
self.assertTrue(result.get('abort', False) and
|
self.assertIs(result.get('abort'), True)
|
||||||
not result.get('result', True) and
|
self.assertIs(result.get('result'), False)
|
||||||
result.get('comment', '').find('create_resource') != -1)
|
self.assertIn('create_resource', result.get('comment', ''))
|
||||||
|
|
||||||
def test_present_when_stage_associating_to_new_deployment_errored_on_put_method(self):
|
def test_present_when_stage_associating_to_new_deployment_errored_on_put_method(self):
|
||||||
'''
|
'''
|
||||||
@ -662,9 +662,9 @@ class BotoApiGatewayFunctionTestCase(BotoApiGatewayStateTestCaseBase, BotoApiGat
|
|||||||
'arn:aws:iam::1234:role/apigatewayrole',
|
'arn:aws:iam::1234:role/apigatewayrole',
|
||||||
**conn_parameters)
|
**conn_parameters)
|
||||||
|
|
||||||
self.assertTrue(result.get('abort', False) and
|
self.assertIs(result.get('abort'), True)
|
||||||
not result.get('result', True) and
|
self.assertIs(result.get('result'), False)
|
||||||
result.get('comment', '').find('put_method') != -1)
|
self.assertIn('put_method', result.get('comment', ''))
|
||||||
|
|
||||||
def test_present_when_stage_associating_to_new_deployment_errored_on_lambda_function_lookup(self):
|
def test_present_when_stage_associating_to_new_deployment_errored_on_lambda_function_lookup(self):
|
||||||
'''
|
'''
|
||||||
@ -701,9 +701,9 @@ class BotoApiGatewayFunctionTestCase(BotoApiGatewayStateTestCaseBase, BotoApiGat
|
|||||||
'arn:aws:iam::1234:role/apigatewayrole',
|
'arn:aws:iam::1234:role/apigatewayrole',
|
||||||
**conn_parameters)
|
**conn_parameters)
|
||||||
|
|
||||||
self.assertTrue(not result.get('result', True) and
|
self.assertIs(result.get('result'), False)
|
||||||
result.get('comment', '').find('put_integration should not be invoked') == -1 and
|
self.assertNotIn('put_integration should not be invoked', result.get('comment', ''))
|
||||||
result.get('comment', '').find('not find lambda function') != -1)
|
self.assertIn('not find lambda function', result.get('comment', ''))
|
||||||
|
|
||||||
def test_present_when_stage_associating_to_new_deployment_errored_on_put_integration(self):
|
def test_present_when_stage_associating_to_new_deployment_errored_on_put_integration(self):
|
||||||
'''
|
'''
|
||||||
@ -740,10 +740,10 @@ class BotoApiGatewayFunctionTestCase(BotoApiGatewayStateTestCaseBase, BotoApiGat
|
|||||||
False,
|
False,
|
||||||
'arn:aws:iam::1234:role/apigatewayrole',
|
'arn:aws:iam::1234:role/apigatewayrole',
|
||||||
**conn_parameters)
|
**conn_parameters)
|
||||||
|
|
||||||
self.assertTrue(result.get('abort', False) and
|
self.assertIs(result.get('abort'), True)
|
||||||
not result.get('result', True) and
|
self.assertIs(result.get('result'), False)
|
||||||
result.get('comment', '').find('put_integration') != -1)
|
self.assertIn('put_integration', result.get('comment', ''))
|
||||||
|
|
||||||
def test_present_when_stage_associating_to_new_deployment_errored_on_put_method_response(self):
|
def test_present_when_stage_associating_to_new_deployment_errored_on_put_method_response(self):
|
||||||
'''
|
'''
|
||||||
@ -782,10 +782,10 @@ class BotoApiGatewayFunctionTestCase(BotoApiGatewayStateTestCaseBase, BotoApiGat
|
|||||||
False,
|
False,
|
||||||
'arn:aws:iam::1234:role/apigatewayrole',
|
'arn:aws:iam::1234:role/apigatewayrole',
|
||||||
**conn_parameters)
|
**conn_parameters)
|
||||||
|
|
||||||
self.assertTrue(result.get('abort', False) and
|
self.assertIs(result.get('abort'), True)
|
||||||
not result.get('result', True) and
|
self.assertIs(result.get('result'), False)
|
||||||
result.get('comment', '').find('put_method_response') != -1)
|
self.assertIn('put_method_response', result.get('comment', ''))
|
||||||
|
|
||||||
def test_present_when_stage_associating_to_new_deployment_errored_on_put_integration_response(self):
|
def test_present_when_stage_associating_to_new_deployment_errored_on_put_integration_response(self):
|
||||||
'''
|
'''
|
||||||
@ -826,10 +826,10 @@ class BotoApiGatewayFunctionTestCase(BotoApiGatewayStateTestCaseBase, BotoApiGat
|
|||||||
False,
|
False,
|
||||||
'arn:aws:iam::1234:role/apigatewayrole',
|
'arn:aws:iam::1234:role/apigatewayrole',
|
||||||
**conn_parameters)
|
**conn_parameters)
|
||||||
|
|
||||||
self.assertTrue(result.get('abort', False) and
|
self.assertIs(result.get('abort'), True)
|
||||||
not result.get('result', True) and
|
self.assertIs(result.get('result'), False)
|
||||||
result.get('comment', '').find('put_integration_response') != -1)
|
self.assertIn('put_integration_response', result.get('comment', ''))
|
||||||
|
|
||||||
def test_absent_when_rest_api_does_not_exist(self):
|
def test_absent_when_rest_api_does_not_exist(self):
|
||||||
'''
|
'''
|
||||||
@ -846,11 +846,10 @@ class BotoApiGatewayFunctionTestCase(BotoApiGatewayStateTestCaseBase, BotoApiGat
|
|||||||
nuke_api=False,
|
nuke_api=False,
|
||||||
**conn_parameters)
|
**conn_parameters)
|
||||||
|
|
||||||
self.assertTrue(result.get('result', False) and
|
self.assertIs(result.get('result'), True)
|
||||||
result.get('comment', '').find('get_stage should not be called') == -1 and
|
self.assertNotIn('get_stage should not be called', result.get('comment', ''))
|
||||||
result.get('changes') == {})
|
self.assertEqual(result.get('changes'), {})
|
||||||
|
|
||||||
|
|
||||||
def test_absent_when_stage_is_invalid(self):
|
def test_absent_when_stage_is_invalid(self):
|
||||||
'''
|
'''
|
||||||
Tests scenario where the stagename doesn't exist
|
Tests scenario where the stagename doesn't exist
|
||||||
@ -925,11 +924,10 @@ class BotoApiGatewayFunctionTestCase(BotoApiGatewayStateTestCaseBase, BotoApiGat
|
|||||||
|
|
||||||
self.assertTrue(result.get('abort', False))
|
self.assertTrue(result.get('abort', False))
|
||||||
|
|
||||||
|
|
||||||
def test_absent_when_nuke_api_and_no_more_stages_deployments_remain(self):
|
def test_absent_when_nuke_api_and_no_more_stages_deployments_remain(self):
|
||||||
'''
|
'''
|
||||||
Tests scenario where the stagename exists and there are two stages associated with same deployment,
|
Tests scenario where the stagename exists and there are no stages associated with same deployment,
|
||||||
though nuke_api is requested, due to remaining deployments, we will not call the delete_rest_api call.
|
the api would be deleted.
|
||||||
'''
|
'''
|
||||||
self.conn.get_rest_apis.return_value = apis_ret
|
self.conn.get_rest_apis.return_value = apis_ret
|
||||||
self.conn.get_stage.return_value = stage1_deployment1_ret
|
self.conn.get_stage.return_value = stage1_deployment1_ret
|
||||||
@ -945,9 +943,9 @@ class BotoApiGatewayFunctionTestCase(BotoApiGatewayStateTestCaseBase, BotoApiGat
|
|||||||
nuke_api=True,
|
nuke_api=True,
|
||||||
**conn_parameters)
|
**conn_parameters)
|
||||||
|
|
||||||
self.assertTrue(result.get('result', False) and
|
self.assertIs(result.get('result'), True)
|
||||||
result.get('abort') != True and
|
self.assertIsNot(result.get('abort'), True)
|
||||||
result.get('changes', {}).get('new', [{}])[0].get('delete_api', {}).get('deleted'))
|
self.assertIs(result.get('changes', {}).get('new', [{}])[0].get('delete_api', {}).get('deleted'), True)
|
||||||
|
|
||||||
def test_absent_when_nuke_api_and_other_stages_deployments_exist(self):
|
def test_absent_when_nuke_api_and_other_stages_deployments_exist(self):
|
||||||
'''
|
'''
|
||||||
@ -968,5 +966,5 @@ class BotoApiGatewayFunctionTestCase(BotoApiGatewayStateTestCaseBase, BotoApiGat
|
|||||||
nuke_api=True,
|
nuke_api=True,
|
||||||
**conn_parameters)
|
**conn_parameters)
|
||||||
|
|
||||||
self.assertTrue(result.get('result', False) and
|
self.assertIs(result.get('result'), True)
|
||||||
result.get('abort') != True)
|
self.assertIsNot(result.get('abort'), True)
|
||||||
|
Loading…
Reference in New Issue
Block a user