%PDF- %PDF-
Mini Shell

Mini Shell

Direktori : /lib/python2.7/site-packages/salt/states/
Upload File :
Create Path :
Current File : //lib/python2.7/site-packages/salt/states/boto_apigateway.pyo

�
���^c@@s�dZddlmZmZmZddlZddlZddlZddlZddl	Z
ddlZ
ddlZ
ddl
mZeje�Zd�Zeeeeeeddeed�
Zd	�Zeeeeed
�Zd�Zed�Zd
�Zdddddddddddfd�Zd�Zd�Zdefd��YZ eeeeeeed�Z!eeeed�Z"eeeed �Z#eeeed!�Z$dS("u�
Manage Apigateway Rest APIs
===========================

.. versionadded:: 2016.11.0

:depends:
  - boto >= 2.8.0
  - boto3 >= 1.2.1
  - botocore >= 1.4.49

Create and destroy rest apis depending on a swagger version 2 definition file.
Be aware that this interacts with Amazon's services, and so may incur charges.

This module uses ``boto3``, which can be installed via package, or pip.

This module accepts explicit vpc credentials but can also utilize
IAM roles assigned to the instance through Instance Profiles. Dynamic
credentials are then automatically obtained from AWS API and no further
configuration is necessary. More information available `here
<http://docs.aws.amazon.com/AWSEC2/latest/UserGuide/iam-roles-for-amazon-ec2.html>`_.

If IAM roles are not used you need to specify them either in a pillar file or
in the minion's config file:

.. code-block:: yaml

    vpc.keyid: GKTADJGHEIQSXMKKRBJ08H
    vpc.key: askdjghsdfjkghWupUjasdflkdfklgjsdfjajkghs

It's also possible to specify ``key``, ``keyid`` and ``region`` via a profile,
either passed in as a dict, or as a string to pull from pillars or minion
config:

.. code-block:: yaml

    myprofile:
      keyid: GKTADJGHEIQSXMKKRBJ08H
      key: askdjghsdfjkghWupUjasdflkdfklgjsdfjajkghs
      region: us-east-1

.. code-block:: yaml

    Ensure Apigateway API exists:
      boto_apigateway.present:
        - name: myfunction
        - region: us-east-1
        - keyid: GKTADJGHEIQSXMKKRBJ08H
        - key: askdjghsdfjkghWupUjasdflkdfklgjsdfjajkghs

i(tabsolute_importtprint_functiontunicode_literalsN(tsixcC@sdtkrdStS(u)
    Only load if boto is available.
    uboto_apigateway.describe_apisuboto_apigateway(t__salt__tFalse(((s?/usr/lib/python2.7/site-packages/salt/states/boto_apigateway.pyt__virtual__Hsu!{stage}_{api}_{resource}_{method}uNONEc
C@s8i|d6td6dd6id6}y�td|fd|	fd|
fd	|fg�}t|||||||�}t|�}|j|�}|jd
�r�tdr�dj||||�|d<d|d<|S|j	||�S|jd
�r3tdr#dj||||�|d<d|d<n|j
||�Stdrgdj||||�|d<d|d<|S|j|�}|jd�r�|S|j|�}|jd�r�|S|j
|d|d|d|d|
�}|jd�r�|S|j	||�}Wn9ttfk
r3}t|d<dj|j�|d<nX|S(u,
    Ensure the spcified api_name with the corresponding swaggerfile is deployed to the
    given stage_name in AWS ApiGateway.

    this state currently only supports ApiGateway integration with AWS Lambda, and CORS support is
    handled through a Mock integration.

    There may be multiple deployments for the API object, each deployment is tagged with a description
    (i.e. unique label) in pretty printed json format consisting of the following key/values.

    .. code-block:: text

        {
            "api_name": api_name,
            "swagger_file": basename_of_swagger_file
            "swagger_file_md5sum": md5sum_of_swagger_file,
            "swagger_info_object": info_object_content_in_swagger_file
        }

    Please note that the name of the lambda function to be integrated will be derived
    via the provided lambda_funcname_format parameters:

    - the default lambda_funcname_format is a string with the following
      substitutable keys: "{stage}_{api}_{resource}_{method}".  The user can
      choose to reorder the known keys.
    - the stage key corresponds to the stage_name passed in.
    - the api key corresponds to the api_name passed in.
    - the resource corresponds to the resource path defined in the passed swagger file.
    - the method corresponds to the method for a resource path defined in the passed swagger file.

    For the default lambda_funcname_format, given the following input:

    .. code-block:: python

        api_name = '  Test    Service'
        stage_name = 'alpha'
        basePath = '/api'
        path = '/a/{b}/c'
        method = 'POST'

    We will end up with the following Lambda Function Name that will be looked
    up: 'test_service_alpha_a_b_c_post'

    The canconicalization of these input parameters is done in the following order:

    1. lambda_funcname_format is formatted with the input parameters as passed,
    2. resulting string is stripped for leading/trailing spaces,
    3. path parameter's curly braces are removed from the resource path,
    4. consecutive spaces and forward slashes in the paths are replaced with '_'
    5. consecutive '_' are replaced with '_'

    Please note that for error response handling, the swagger file must have an error response model
    with the following schema.  The lambda functions should throw exceptions for any non successful responses.
    An optional pattern field can be specified in errorMessage field to aid the response mapping from Lambda
    to the proper error return status codes.

    .. code-block:: yaml

        Error:
          type: object
          properties:
            stackTrace:
              type: array
              items:
                type: array
                items:
                  type: string
              description: call stack
          errorType:
            type: string
            description: error type
          errorMessage:
            type: string
            description: |
              Error message, will be matched based on pattern.
              If no pattern is specified, the default pattern used for response mapping will be +*.

    name
        The name of the state definition

    api_name
        The name of the rest api that we want to ensure exists in AWS API Gateway

    swagger_file
        Name of the location of the swagger rest api definition file in YAML format.

    stage_name
        Name of the stage we want to be associated with the given api_name and swagger_file
        definition

    api_key_required
        True or False - whether the API Key is required to call API methods

    lambda_integration_role
        The name or ARN of the IAM role that the AWS ApiGateway assumes when it
        executes your lambda function to handle incoming requests

    lambda_region
        The region where we expect to find the lambda functions.  This is used to
        determine the region where we should look for the Lambda Function for
        integration purposes.  The region determination is based on the following
        priority:

        1. lambda_region as passed in (is not None)
        2. if lambda_region is None, use the region as if a boto_lambda
           function were executed without explicitly specifying lambda region.
        3. if region determined in (2) is different than the region used by
           boto_apigateway functions, a final lookup will be attempted using
           the boto_apigateway region.

    stage_variables
        A dict with variables and their values, or a pillar key (string) that
        contains a dict with variables and their values.
        key and values in the dict must be strings.  {'string': 'string'}

    region
        Region to connect to.

    key
        Secret key to be used.

    keyid
        Access key to be used.

    profile
        A dict with region, key and keyid, or a pillar key (string) that
        contains a dict with region, key and keyid.

    lambda_funcname_format
        Please review the earlier example for the usage.  The only substituable keys in the funcname
        format are {stage}, {api}, {resource}, {method}.
        Any other keys or positional subsitution parameters will be flagged as an invalid input.

    authorization_type
        This field can be either 'NONE', or 'AWS_IAM'.  This will be applied to all methods in the given
        swagger spec file.  Default is set to 'NONE'

    error_response_template
        String value that defines the response template mapping that should be applied in cases error occurs.
        Refer to AWS documentation for details: http://docs.aws.amazon.com/apigateway/latest/developerguide/api-gateway-mapping-template-reference.html

        If set to None, the following default value is used:

        .. code-block:: text

            '#set($inputRoot = $input.path('$'))\n'
            '{\n'
            '  "errorMessage" : "$inputRoot.errorMessage",\n'
            '  "errorType" : "$inputRoot.errorType",\n'
            '  "stackTrace" : [\n'
            '#foreach($stackTrace in $inputRoot.stackTrace)\n'
            '    [\n'
            '#foreach($elem in $stackTrace)\n'
            '      "$elem"\n'
            '#if($foreach.hasNext),#end\n'
            '#end\n'
            '    ]\n'
            '#if($foreach.hasNext),#end\n'
            '#end\n'
            '  ]\n'

        .. versionadded:: 2017.7.0

    response_template
        String value that defines the response template mapping applied in case
        of success (including OPTIONS method) If set to None, empty ({})
        template is assumed, which will transfer response from the lambda
        function as is.

        .. versionadded:: 2017.7.0
    unameuresultuucommentuchangesuregionukeyukeyiduprofileupublishutestu�[stage: {0}] will be reassociated to an already available deployment that matched the given [api_name: {1}] and [swagger_file: {2}].
Stage variables will be set to {3}.ucurrentu�[stage: {0}] is already at desired state with an associated deployment matching the given [api_name: {1}] and [swagger_file: {2}].
Stage variables will be set to {3}.u�There is no deployment matching the given [api_name: {0}] and [swagger_file: {1}].  A new deployment will be created and the [stage_name: {2}] will then be associated to the newly created deployment.
Stage variables will be set to {3}.uaborttapi_key_requiredtlambda_integration_rolet
lambda_regiontauthorization_typeu{0}N(tTruetdictt_Swaggert_get_stage_variablest
verify_apitgett__opts__tformattNonetpublish_apitoverwrite_stage_variablest
deploy_apit
deploy_modelstdeploy_resourcest
ValueErrortIOErrorRtargs(tnametapi_nametswagger_filet
stage_nameRRR	tstage_variablestregiontkeytkeyidtprofiletlambda_funcname_formatR
terror_response_templatetresponse_templatetrettcommon_argstswaggert
stage_varste((s?/usr/lib/python2.7/site-packages/salt/states/boto_apigateway.pytpresentOsh�

				





	
cC@s�t�}|dkr|St|tj�r�|tkrDt|}ntjdi�}||kro||}n|tkr�t|}q�nt|t�r�|}nt|t�s�t�}n|S(uh
    Helper function to retrieve stage variables from pillars/options, if the
    input is a string
    umasterN(RRt
isinstanceRtstring_typesRt
__pillar__R(R R(tmaster_opts((s?/usr/lib/python2.7/site-packages/salt/states/boto_apigateway.pyRVs 	

	cC@sdi|d6td6dd6id6}ytd|fd|fd|fd	|fg�}	t||dddd|	�}
|
js�d
j|�|d<|Stdr�|r�dj||�|d<nd
j|�|d<d|d<|S|
j|�}|jd�r�|S|r#|
j	�r#|
j
|�}nWn9ttfk
r_}t
|d<dj|j�|d<nX|S(uE
    Ensure the stage_name associated with the given api_name deployed by boto_apigateway's
    present state is removed.  If the currently associated deployment to the given stage_name has
    no other stages associated with it, the deployment will also be removed.

    name
        Name of the swagger file in YAML format

    api_name
        Name of the rest api on AWS ApiGateway to ensure is absent.

    stage_name
        Name of the stage to be removed irrespective of the swagger file content.
        If the current deployment associated with the stage_name has no other stages associated
        with it, the deployment will also be removed.

    nuke_api
        If True, removes the API itself only if there are no other stages associated with any other
        deployments once the given stage_name is removed.

    region
        Region to connect to.

    key
        Secret key to be used.

    keyid
        Access key to be used.

    profile
        A dict with region, key and keyid, or a pillar key (string) that
        contains a dict with region, key and keyid.
    unameuresultuucommentuchangesuregionukeyukeyiduprofileu[Rest API: {0}] does not exist.utestuf[stage: {0}] will be deleted, if there are no other active stages, the [api: {1} will also be deleted.u[stage: {0}] will be deleted.uabortu{0}N(RRR
Rt	restApiIdRRtdelete_stageRtno_more_deployments_remaint
delete_apiRRRR(RRRtnuke_apiR!R"R#R$R(R)R*R,((s?/usr/lib/python2.7/site-packages/salt/states/boto_apigateway.pytabsentps:#

			


c@s�tj�}tjjj|d��7�x-t�fd�d�D]}|j|�q@WWdQXx*|D]"}|jtj	t
|���qdW|j�S(u�
    helper function to generate a md5 hash of the swagger definition file
    any extra argument passed to the function is converted to a string
    and participates in the hash calculation
    urbc@s
�jd�S(Ni(tread((tf(s?/usr/lib/python2.7/site-packages/salt/states/boto_apigateway.pyt<lambda>�stN(thashlibtmd5tsalttutilstfilestfopentitertupdateRtbtstrt	hexdigest(tfnameRt_hashtchunkt	extra_arg((R9s?/usr/lib/python2.7/site-packages/salt/states/boto_apigateway.pyt_gen_md5_filehash�s
 cC@s%tjjj|ddddd|�S(u@
    helper function to generate pretty printed json output
    tindentit
separatorsu,u: t	sort_keys(u,u: (R>R?tjsontdumps(tdRN((s?/usr/lib/python2.7/site-packages/salt/states/boto_apigateway.pyt_dict_to_json_pretty�scC@sgx`|D]X}|j|�r tS|j�jd|j��rCtS|j�|j�krtSqWtS(uW
    Helper function to see if given name has any of the patterns in given matches
    u_(tendswithRtlowerR(Rtmatchestm((s?/usr/lib/python2.7/site-packages/salt/states/boto_apigateway.pyt
_name_matches�s
uidunameupathu
httpMethodu
statusCodeuCreateduDeleteduUpdateduFlushedu
Associatedu
DisassociatedcC@si}t|t�rxtj|�D]�\}}t|t�r�|dkrR|nt||�}|svt||�r|||<qq%t|t�r�g}xB|D]:}t||�}|s�t||�r�|j|�q�q�W|r|||<qq%t||�r%|||<q%q%Wn|S(u�
    Helper function to reduce the amount of information that will be kept in the change log
    for API GW related return values
    u	variables(R.RRt	iteritemst_object_reducerRWtlisttappend(totnamestresulttktvtreducedtnewlisttval((s?/usr/lib/python2.7/site-packages/salt/states/boto_apigateway.pyRY�s$!
cC@sB|djdg�}|jit|�|6�||dd<|S(uG
    For logging create/update/delete operations to AWS ApiGateway
    uchangesunew(RR[RY(R(t	changekeytchangevaluetcl((s?/usr/lib/python2.7/site-packages/salt/states/boto_apigateway.pyt_log_changesscC@sCt|d<t|d<d|kr?dj|jd��|d<n|S(uB
    helper function to update errors in the return structure
    uresultuabortuerroru{0}ucomment(RRRR(R(tobj((s?/usr/lib/python2.7/site-packages/salt/states/boto_apigateway.pyt_log_error_and_aborts


R
cB@s�eZdZdUZdVZdWZdXZejd�Z	dZ
idd6Zidd6Zidd6Z
iZeidd6d d!6�Zd"efd#��YZd$efd%��YZd&�Zd'�Zd(�Zd)�Zd*�Zed+��Zed,��Zed-��Zed.��Zed/��Zd0�Zd1�Z ed2��Z!ed3��Z"ed4��Z#e#j$d5��Z#ed6��Z%ed7��Z&d8�Z'd9�Z(d:�Z)d;�Z*d<�Z+d=�Z,d>�Z-d?�Z.d@�Z/dA�Z0dB�Z1dC�Z2dD�Z3dE�Z4dF�Z5dG�Z6dH�Z7dI�Z8dJ�Z9dK�Z:dL�Z;dM�Z<dN�Z=dO�Z>dP�Z?dQ�Z@dR�ZAdS�ZBdT�ZCRS(Yu
    this is a helper class that holds the swagger definition file and the associated logic
    related to how to interpret the file and apply it to AWS Api Gateway.

    The main interface to the outside world is in deploy_api, deploy_models, and deploy_resources
    methods.
    uswaggeruinfouhostubasePathuschemesuconsumesuproducesupathsudefinitionsu
parametersu	responsesusecurityDefinitionsusecurityutagsuexternalDocsugetuputupostudeleteuoptionsuheadupatchu2.0u^x-u'http://json-schema.org/draft-04/schema#u/#set($inputRoot = $input.path('$'))
{
"header_params" : {
#set ($map = $input.params().header)
#foreach( $param in $map.entrySet() )
"$param.key" : "$param.value" #if( $foreach.hasNext ), #end
#end
},
"query_params" : {
#set ($map = $input.params().querystring)
#foreach( $param in $map.entrySet() )
"$param.key" : "$param.value" #if( $foreach.hasNext ), #end
#end
},
"path_params" : {
#set ($map = $input.params().path)
#foreach( $param in $map.entrySet() )
"$param.key" : "$param.value" #if( $foreach.hasNext ), #end
#end
},
"apigw_context" : {
"apiId": "$context.apiId",
"httpMethod": "$context.httpMethod",
"requestId": "$context.requestId",
"resourceId": "$context.resourceId",
"resourcePath": "$context.resourcePath",
"stage": "$context.stage",
"identity": {
  "user":"$context.identity.user",
  "userArn":"$context.identity.userArn",
  "userAgent":"$context.identity.userAgent",
  "sourceIp":"$context.identity.sourceIp",
  "cognitoIdentityId":"$context.identity.cognitoIdentityId",
  "cognitoIdentityPoolId":"$context.identity.cognitoIdentityPoolId",
  "cognitoAuthenticationType":"$context.identity.cognitoAuthenticationType",
  "cognitoAuthenticationProvider":["$util.escapeJavaScript($context.identity.cognitoAuthenticationProvider)"],
  "caller":"$context.identity.caller",
  "apiKey":"$context.identity.apiKey",
  "accountId":"$context.identity.accountId"
}
},
"body_params" : $input.json('$'),
"stage_variables": {
#foreach($variable in $stageVariables.keySet())
"$variable": "$util.escapeJavaScript($stageVariables.get($variable))"
#if($foreach.hasNext), #end
#end
}
}uapplication/jsonu{"statusCode": 200}u<#set($inputRoot = $input.path('$'))
{
  "errorMessage" : "$inputRoot.errorMessage",
  "errorType" : "$inputRoot.errorType",
  "stackTrace" : [
#foreach($stackTrace in $inputRoot.stackTrace)
    [
#foreach($elem in $stackTrace)
      "$elem"
#if($foreach.hasNext),#end
#end
    ]
#if($foreach.hasNext),#end
#end
  ]
}u"Salt boto_apigateway.present Stateuprovisioned_byu#See deployment or stage descriptionucontexttSwaggerParametercB@sJeZdZd	Zd�Zed��Zed��Zed��ZRS(
uI
        This is a helper class for the Swagger Parameter Object
        ubodyuqueryuheaderupathcC@s
||_dS(N(t
_paramdict(tselft	paramdict((s?/usr/lib/python2.7/site-packages/salt/states/boto_apigateway.pyt__init__�scC@sA|jjd�}|tjjkr(|Stdj|���dS(uJ
            returns location in the swagger parameter object
            uinu7Unsupported parameter location: {0} in Parameter ObjectN(RkRR
Rjt	LOCATIONSRR(Rlt	_location((s?/usr/lib/python2.7/site-packages/salt/states/boto_apigateway.pytlocation�scC@s�|jjd�}|rp|jdkr4dj|�S|jdkrPdj|�S|jdkrldj|�Sd	Stdjt|j����d	S(
uP
            returns parameter name in the swagger parameter object
            unameuheaderumethod.request.header.{0}uqueryumethod.request.querystring.{0}upathumethod.request.path.{0}uParameter must have a name: {0}N(RkRRqRRRRR(Rlt_name((s?/usr/lib/python2.7/site-packages/salt/states/boto_apigateway.pyR�s


cC@s�|jdkr�|jjd�}|rnd|krS|jd�jd�d}|Stdj|j���ntdj|j���ndS(	ul
            returns the name of the schema given the reference in the swagger parameter object
            ubodyuschemau$refu/i����ufBody parameter must have a JSON reference to the schema definition due to Amazon API restrictions: {0}u&Body parameter must have a schema: {0}N(RqRkRtsplitRRRR(Rlt_schematschema_name((s?/usr/lib/python2.7/site-packages/salt/states/boto_apigateway.pytschema�s	(ubodyuqueryuheaderupath(	t__name__t
__module__t__doc__RoRntpropertyRqRRv(((s?/usr/lib/python2.7/site-packages/salt/states/boto_apigateway.pyRj~s	
tSwaggerMethodResponsecB@s5eZdZd�Zed��Zed��ZRS(uA
        Helper class for Swagger Method Response Object
        cC@s
||_dS(N(t_r(Rltr((s?/usr/lib/python2.7/site-packages/salt/states/boto_apigateway.pyRn�scC@sZ|jjd�}|rVd|kr>|jd�jd�dStdj|���ndS(ur
            returns the name of the schema given the reference in the swagger method response object
            uschemau$refu/i����uHMethod response must have a JSON reference to the schema definition: {0}N(R|RRsRRR(RlRt((s?/usr/lib/python2.7/site-packages/salt/states/boto_apigateway.pyRv�s	cC@s|jjdi�}|S(uV
            returns the headers dictionary in the method response object
            uheaders(R|R(Rlt_headers((s?/usr/lib/python2.7/site-packages/salt/states/boto_apigateway.pytheaders�s(RwRxRyRnRzRvR(((s?/usr/lib/python2.7/site-packages/salt/states/boto_apigateway.pyR{�s	
c	C@s||_||_||_||_d|_d|_||_||_|dk	rt	j
j|�r�t	j
j|�r�||_
t|j
||�|_tjjj|j
d��}tjjj|�|_WdQXd|_ntdj|���|j�n|j�|j�dS(NuurbuInvalid swagger file path, {0}(t	_api_namet_stage_namet_lambda_funcname_formatt_common_aws_argst
_restApiIdt
_deploymentIdt_error_response_templatet_response_templateRtostpathtexiststisfilet
_swagger_fileRKt
_md5_filehashR>R?R@RAtyamlt	safe_loadt_cfgt_swagger_versionRRt_validate_swagger_filet _validate_lambda_funcname_formatt_resolve_api_id(	RlRRR%tswagger_file_pathR&R'tcommon_aws_argstsf((s?/usr/lib/python2.7/site-packages/salt/states/boto_apigateway.pyRn�s*								$		

cC@sttjd|��S(uu
        Helper function to determine if the passed code is in the 400~599 range of http error
        codes
        u^\s*[45]\d\d\s*$(tbooltretmatch(Rltcode((s?/usr/lib/python2.7/site-packages/salt/states/boto_apigateway.pyt_is_http_error_rescode�scC@s�x�|D]�\}}x�tj|�D]�\}}|tjkrDq#nd|kr_td��nx�tj|jd��D]f\}}|jt|��s�qxnd|kr�tdj|||���n|jd�}	d|	krtdj|||���n|	jdd�}
|
j	d�d}||krKtd	j|
���n|j|�}|jd
�dkr�tdj|���nd
|kr�tdj|���n|jd
�}
d|
krxtdj|���qxqxWq#WqWdS(u�
        Helper function to help validate the convention established in the swagger file on how
        to handle response code mapping/integration
        u	responsesu5missing mandatory responses field in path item objectuschemau6missing schema field in path {0}, op {1}, response {2}u$refuAmissing $ref field under schema in path {0}, op {1}, response {2}u/i����u7model schema {0} reference not found under /definitionsutypeuobjectu$model schema {0} must be type objectu
propertiesu,model schema {0} must have properties fieldsuerrorMessageuumodel schema {0} must have errorMessage as a property to match AWS convention. If pattern is not set, .+ will be usedN(
RRXR
tSWAGGER_OPERATION_NAMESRRR�RERRs(RltpathstmodsR�topstopnametopobjtrescodetresobjt	schemaobjtschemaobjreft	modelnametmodelt
modelprops((s?/usr/lib/python2.7/site-packages/salt/states/boto_apigateway.pyt_validate_error_response_model�s<%				c	C@suyE|jr@tdddddddd�}|jj|�ntSWn)tk
rptdj|j���nXdS(u�
        Checks if the lambda function name format contains only known elements
        :return: True on success, ValueError raised on error
        tstageutapitresourcetmethodu]Invalid lambda_funcname_format {0}.  Please review documentation for known substitutable keysN(R�RRRt	ExceptionR(Rltknown_kwargs((s?/usr/lib/python2.7/site-packages/salt/states/boto_apigateway.pyR�s		
	cC@sxK|jD]@}|tjkr
tjj|�r
tdj|���q
q
Wx8tjD]-}||jkrXtdj|���qXqXW|jjd�|_	|j	tj
kr�tdj|j	tj
���ntjt
|j��|j|j|j��dS(u�
        High level check/validation of the input swagger file based on
        https://github.com/swagger-api/swagger-spec/blob/master/versions/2.0.md

        This is not a full schema compliance check, but rather make sure that the input file (YAML or
        JSON) can be read into a dictionary, and we check for the content of the Swagger Object for version
        and info.
        u!Invalid Swagger Object Field: {0}u!Missing Swagger Object Field: {0}uswaggeru;Unsupported Swagger version: {0},Supported versions are {1}N(R�R
tSWAGGER_OBJ_V2_FIELDStVENDOR_EXT_PATTERNR�RRtSWAGGER_OBJ_V2_FIELDS_REQUIREDRR�tSWAGGER_VERSIONS_SUPPORTEDtlogtinfottypet_modelsR�R�(Rltfield((s?/usr/lib/python2.7/site-packages/salt/states/boto_apigateway.pyR�/s	cC@s|jS(u7
        returns md5 hash for the swagger file
        (R�(Rl((s?/usr/lib/python2.7/site-packages/salt/states/boto_apigateway.pytmd5_filehashNscC@s+|jjd�}|s'td��n|S(uA
        returns the swagger info object as a dictionary
        uinfouInfo Object has no values(R�RR(RlR�((s?/usr/lib/python2.7/site-packages/salt/states/boto_apigateway.pyR�UscC@s
t|j�S(uR
        returns the swagger info object as a pretty printed json string.
        (RRR�(Rl((s?/usr/lib/python2.7/site-packages/salt/states/boto_apigateway.pyt	info_json_scC@s|jS(u-
        returns the name of the api
        (R�(Rl((s?/usr/lib/python2.7/site-packages/salt/states/boto_apigateway.pyt
rest_api_namefscC@s+|jjd�}|s'td��n|S(uF
        returns the version field in the swagger info object
        uversionu$Missing version value in Info Object(R�RR(Rltversion((s?/usr/lib/python2.7/site-packages/salt/states/boto_apigateway.pytrest_api_versionmscC@s+|jjd�}|s'td��n|S(uR
        returns an iterator for the models specified in the swagger file
        udefinitionsuNDefinitions Object has no values, You need to define them in your swagger file(R�RR(Rltmodels((s?/usr/lib/python2.7/site-packages/salt/states/boto_apigateway.pyR�xscc@sP|j�}x=trK|j|�}|s.Pn||j�j|�fVqWdS(uY
        generator to return the tuple of model and its schema to create on aws.
        N(t_build_all_dependenciesRt_get_model_without_dependenciesR�R(Rlt
model_dictR�((s?/usr/lib/python2.7/site-packages/salt/states/boto_apigateway.pyR��s	cC@sl|jjd�}|s'td��nx5|D]-}|jd�s.tdj|���q.q.Wtj|�S(uc
        returns an iterator for the relative resource paths specified in the swagger file
        upathsuHPaths Object has no values, You need to define them in your swagger fileu/u2Path object {0} should start with /. Please fix it(R�RRt
startswithRRRX(RlR�R�((s?/usr/lib/python2.7/site-packages/salt/states/boto_apigateway.pyR��s
cC@s|jjdd�}|S(uL
        returns the base path field as defined in the swagger file
        ubasePathu(R�R(RltbasePath((s?/usr/lib/python2.7/site-packages/salt/states/boto_apigateway.pyR��scC@s|jS(uX
        returns the rest api id as returned by AWS on creation of the rest api
        (R�(Rl((s?/usr/lib/python2.7/site-packages/salt/states/boto_apigateway.pyR2�scC@s
||_dS(uV
        allows the assignment of the rest api id on creation of the rest api
        N(R�(RlR2((s?/usr/lib/python2.7/site-packages/salt/states/boto_apigateway.pyR2�scC@s
t|j�S(u}
        this property returns the unique description in pretty printed json for
        a particular api deployment
        (RRtdeployment_label(Rl((s?/usr/lib/python2.7/site-packages/salt/states/boto_apigateway.pytdeployment_label_json�scC@sMt�}|j|d<|j|d<tjj|j�|d<|j|d<|S(ur
        this property returns the deployment label dictionary (mainly used by
        stage description)
        uswagger_info_objectuapi_nameuswagger_fileuswagger_file_md5sum(RR�R�R�R�tbasenameR�R�(Rltlabel((s?/usr/lib/python2.7/site-packages/salt/states/boto_apigateway.pyR��s	


cC@s5tdd|jd||j�jd�}t|�S(uk
        Helper function to find whether there are other stages still associated with a deployment
        u#boto_apigateway.describe_api_stagesR2tdeploymentIdustages(RR2R�RR�(RlR�tstages((s?/usr/lib/python2.7/site-packages/salt/states/boto_apigateway.pyt_one_or_more_stages_remain�scC@s�t}tdd|j|j�jd�}|r�x[|D]P}|jd�}tdd|jd||j�jd�}|r8t}Pq8q8Wn|S(uc
        Helper function to find whether there are deployments left with stages associated
        u(boto_apigateway.describe_api_deploymentsR2udeploymentsuidu#boto_apigateway.describe_api_stagesR�ustages(RRR2R�RR(Rltno_more_deploymentstdeploymentst
deploymentR�R�((s?/usr/lib/python2.7/site-packages/salt/states/boto_apigateway.pyR4�s
cC@sPd}tdd|jd|j|j�jd�}|rL|jd�}n|S(uk
        Helper method to find the deployment id that the stage name is currently assocaited with.
        uu"boto_apigateway.describe_api_stageR2t	stageNameustageudeploymentId(RR2R�R�R(RlR�R�((s?/usr/lib/python2.7/site-packages/salt/states/boto_apigateway.pyt_get_current_deployment_id�scC@sN|j�}tdd|jd||j�jd�}|rJ|jd�SdS(un
        Helper method to find the deployment label that the stage_name is currently associated with.
        u'boto_apigateway.describe_api_deploymentR2R�u
deploymentudescriptionN(R�RR2R�RR(RlR�R�((s?/usr/lib/python2.7/site-packages/salt/states/boto_apigateway.pyt_get_current_deployment_label�s
cC@shtdd|j|j�jd�}|rdx6|D]+}|jd�|jkr2|jd�Sq2WndS(u�
        Helper method to return the deployment id matching the desired deployment label for
        this Swagger object based on the given api_name, swagger_file
        u(boto_apigateway.describe_api_deploymentsR2udeploymentsudescriptionuidu(RR2R�RR�(RlR�R�((s?/usr/lib/python2.7/site-packages/salt/states/boto_apigateway.pyt_get_desired_deployment_id�s
cC@s�tdd|jd|jd||j�}|jd�sdt|d<t|d<|jd�|d	<nt|d
|jd��}|S(ua
        overwrite the given stage_name's stage variables with the given stage_variables
        u-boto_apigateway.overwrite_api_stage_variablesR2R�t	variablesu	overwriteuresultuabortuerrorucommentuoverwrite_stage_variablesustage(RR2R�R�RRRRg(RlR(R tres((s?/usr/lib/python2.7/site-packages/salt/states/boto_apigateway.pyR	s	

cC@stdd|jd|j|j�jd�}|s�tdd|jd|jd|jd|d||j�}|jd�s�itd	6|jd
�d
6SnUtdd|jd|jd||j�}|jd�s�itd	6|jd
�d
6Stdd|jd|jd|j|j�S(
uk
        Helper method to associate the stage_name to the given deploymentId and make this current
        u"boto_apigateway.describe_api_stageR2R�ustageu boto_apigateway.create_api_stageR�tdescriptionR�usetuerroru-boto_apigateway.overwrite_api_stage_variablesu'boto_apigateway.activate_api_deployment(RR2R�R�RR�R(Rltstage_desc_jsonR R�t	overwrite((s?/usr/lib/python2.7/site-packages/salt/states/boto_apigateway.pyt_set_current_deployments,				cC@s�tdd|jdtj|j�jd�}|r�t|�dkr_|djd�|_q�tdj	|j|j
���nd	S(
u�
        returns an Api Id that matches the given api_name and the hardcoded _Swagger.AWS_API_DESCRIPTION
        as the api description
        uboto_apigateway.describe_apisRR�urestapiiiuidu9Multiple APIs matching given name {0} and description {1}N(RR�R
tAWS_API_DESCRIPTIONR�RtlenR2RRR�(Rltapis((s?/usr/lib/python2.7/site-packages/salt/states/boto_apigateway.pyR�:s	cC@s"|j�}|rtdd|jd|j|j�}|jd�syt|d<t|d<dj|jd��|d	<q|j	|�s�td
d|jd||j�}|jd�st|d<t|d<dj|jd��|d	<qqd
j|j�|d	<ndj|j�|d	<|S(u�
        Method to delete the given stage_name.  If the current deployment tied to the given
        stage_name has no other stages associated with it, the deployment will be removed
        as well
        u boto_apigateway.delete_api_stageR2R�udeleteduaborturesultu"delete_stage delete_api_stage, {0}uerrorucommentu%boto_apigateway.delete_api_deploymentR�u'delete_stage delete_api_deployment, {0}ustage {0} has been deleted.
ustage {0} does not exist(
R�RR2R�R�RRRRR�(RlR(R�R^((s?/usr/lib/python2.7/site-packages/salt/states/boto_apigateway.pyR3Is(



"cC@sw|jrs|j�}||jkrKdj|j|�|d<t|d<|S|j�|_|jrst|d<qsn|S(u�
        this method helps determine if the given stage_name is already on a deployment
        label matching the input api_name, swagger_file.

        If yes, returns abort with comment indicating already at desired state.
        If not and there is previous deployment labels in AWS matching the given input api_name and
        swagger file, indicate to the caller that we only need to reassociate stage_name to the
        previously existing deployment label.
        uWAlready at desired state, the stage {0} is already at the desired deployment label:
{1}ucommentucurrentupublish(R2R�R�RR�RR�R�(RlR(tdeployed_label_json((s?/usr/lib/python2.7/site-packages/salt/states/boto_apigateway.pyRjs	
	cC@s&t�}|j|d<t|�}|jr�|j||�}|jd�svt|d<t|d<|jd�|d<q"t|d|jd��}n�t	d	d
|j
d|jd|d
|jd||j
�}|jd�st|d<t|d<|jd�|d<nt|d|jd��}|S(uf
        this method tie the given stage_name to a deployment matching the given swagger_file
        ucurrent_deployment_labelusetuaborturesultuerrorucommentu9publish_api (reassociate deployment, set stage_variables)uresponseu%boto_apigateway.create_api_deploymentR2R�tstageDescriptionR�R�ucreatedupublish_api (new deployment)u
deployment(RR�RRR�R�RRRRgRR2R�R�R�(RlR(R t
stage_descR�R�((s?/usr/lib/python2.7/site-packages/salt/states/boto_apigateway.pyR�s0	
	

		

cC@s+tdd|j|j�}|jd�r�|jd�d}|j�xO|D]D}tdd|jd|jd�|j�}|jd�sO|SqOWntd	d|j|j�}|jd
�r xX|jd
�D]D}tdd|jd|jd
�|j�}|jd�s�|Sq�Wnitd6S(u�
        Helper method to clean up resources and models if we detected a change in the swagger file
        for a stage
        u&boto_apigateway.describe_api_resourcesR2u	resourcesiu$boto_apigateway.delete_api_resourcesR�upathudeletedu#boto_apigateway.describe_api_modelsumodelsu boto_apigateway.delete_api_modelt	modelNameuname(RR2R�RtreverseR(Rlt	resourcesR�R�tdelresR�R�((s?/usr/lib/python2.7/site-packages/salt/states/boto_apigateway.pyt_cleanup_api�s(

cC@s|jrV|j�}|jd�sRdj|j�|d<t|d<t|d<|S|Stdd|jdtj	|j
�}|jd	�s�t|d<t|d<d
|kr�dj|d
d�|d<n|S|jd
i�jd�|_t|d|jd
��S(uM
        this method create the top level rest api in AWS apigateway
        udeleteduFailed to cleanup restAreId {0}ucommentuaborturesultuboto_apigateway.create_apiRR�ucreateduerroruFailed to create rest api: {0}.umessageurestapiuidu
deploy_api(R2R�RRRRRR�R
R�R�Rg(RlR(R�tresponse((s?/usr/lib/python2.7/site-packages/salt/states/boto_apigateway.pyR�s&	



cC@stdd|jdtj|j�}|jd�r�tdrldj|j�|d<d|d<t	|d	<|Std
d|jdtj|j�}|jd�s�t
|d<t	|d	<d|kr�d
j|dd�|d<n|St|d|�}ndj|j|j�|d<|S(u�
        Method to delete a Rest Api named defined in the swagger file's Info Object's title value.

        ret
            a dictionary for returning status to Saltstack
        uboto_apigateway.api_existsRR�uexistsutestu(Rest API named {0} is set to be deleted.ucommenturesultuabortuboto_apigateway.delete_apiudeleteduerroruFailed to delete rest api: {0}.umessageu
delete_apiu3api already absent for swagger file: {0}, desc: {1}N(
RR�R
R�R�RRRRRRRgR�(RlR(texists_responsetdelete_api_response((s?/usr/lib/python2.7/site-packages/salt/states/boto_apigateway.pyR5�s,




cC@s&|jd�d}dj|j|�S(uJ
        Helper function to reference models created on aws apigw
        u/i����u8https://apigateway.amazonaws.com/restapis/{0}/models/{1}(RsRR2(RlR}t
model_name((s?/usr/lib/python2.7/site-packages/salt/states/boto_apigateway.pyt_aws_model_ref_from_swagger_refscC@spi}xc|j�D]U\}}|dkr=|j|�}nt|t�r^|j|�}n|||<qW|S(uE
        Helper function to map model schema to aws notation
        u$ref(titemsR�R.Rt_update_schema_to_aws_notation(RlRvR^R_R`((s?/usr/lib/python2.7/site-packages/salt/states/boto_apigateway.pyR�sc	C@sg}|r%|jdd�|d<n|ddkrZ|j|j|jdi���n�|jd�}|r�|jd�d}|j�j|�}|j|j|��|j|g�nN|jd�}|rx6tj|�D]"\}}|j|j|��q�Wntt|��S(	ue
        Helper function to build the list of models the given object schema is referencing.
        utypeuobjectuarrayuitemsu$refu/i����u
properties(	Rtextendt_build_dependent_model_listRsR�RRXRZtset(	Rlt
obj_schematdep_models_listtreft
ref_obj_modeltref_obj_schemat
propertiest_tprop_obj_schema((s?/usr/lib/python2.7/site-packages/salt/states/boto_apigateway.pyR�s %cC@sIi}x<tj|j��D]%\}}|j|�}|||<qW|S(ug
        Helper function to build a map of model to their list of model reference dependencies
        (RRXR�R�(RlR(R�Rvtdep_list((s?/usr/lib/python2.7/site-packages/salt/states/boto_apigateway.pyR�-s
"cC@s�d}|s|Sx3tj|�D]"\}}|gkr |}Pq q W|dkrjtdj|���n|j|�x9tj|�D](\}}||kr�|j|�q�q�W|S(uO
        Helper function to find the next model that should be created
        uHincomplete model definitions, models in dependency list not defined: {0}N(RRRXRRtpoptremove(Rltmodels_dictt
next_modelR�tdependenciesR�((s?/usr/lib/python2.7/site-packages/salt/states/boto_apigateway.pyR�7s	
c
C@s�x�|j�D]�\}}|j|�}|jitjd6dj|�d6�tdd|jd||j�}|j	d�r tdd|jd|d	t
|�|j�}|j	d
�st|d<t|d<d
|krdj|t
|�|d
d�|d<n|St
|d|�}q
tdd|jd|d|d	t
|�dd|j�}|j	d�s�t|d<t|d<d
|kr�dj|t
|�|d
d�|d<n|St
|d|�}q
W|S(u�
        Method to deploy swagger file's definition objects and associated schema to AWS Apigateway as Models

        ret
            a dictionary for returning status to Saltstack
        u$schemau
{0} Schemautitleu boto_apigateway.api_model_existsR2R�uexistsu'boto_apigateway.update_api_model_schemaRvuupdateduresultuabortuerroru?Failed to update existing model {0} with schema {1}, error: {2}umessageucommentu
deploy_modelsu boto_apigateway.create_api_modeltmodelDescriptiontcontentTypeuapplication/jsonucreatedu2Failed to create model {0}, schema {1}, error: {2}(R�R�RCR
tJSON_SCHEMA_DRAFT_4RRR2R�RRRRRRg(RlR(R�RvRttmodel_exists_responsetupdate_model_schema_responsetcreate_model_response((s?/usr/lib/python2.7/site-packages/salt/states/boto_apigateway.pyRPsH	



c	C@s||jjd|jd|jd|d|�}|j�}tjdd|�}tjdd|�j�}tjd	d|�S(
u�
        Helper method to construct lambda name based on the rule specified in doc string of
        boto_apigateway.api_present function
        R�R�R�R�u{|}uu\s+|/u_u_+(R�RR�R�tstripR�tsubRT(RltresourcePatht
httpMethodtlambda_name((s?/usr/lib/python2.7/site-packages/salt/states/boto_apigateway.pyt_lambda_name�s		c	C@s�|jjd�}|jjd�}tdd||�}tdd||�}td||j�}||kr�|jd�s�td||j�}q�n|jd�s�tdj|||���n|jd�jd	�}d
j||�}|S(uY
        Helper Method to construct the lambda uri for use in method integration
        uprofileuregionuboto3.get_regionulambdau
apigatewayuboto_lambda.describe_functionufunctionu9Could not find lambda function {0} in regions [{1}, {2}].uFunctionArnuGarn:aws:apigateway:{0}:lambda:path/2015-03-31/functions/{1}/invocations(R�Rt	__utils__RRR(	RlRR	R$R!tapigw_regiontlambda_desct
lambda_arnt
lambda_uri((s?/usr/lib/python2.7/site-packages/salt/states/boto_apigateway.pyt_lambda_uri�s	c	C@s�i}i}d|krqxV|dD]G}tj|�}|jrQt||j<n|jr#|j|d<q#q#Wn|dkr�tjntj}|dkr�dnd}i|d6|d6|d6|d	6S(
u�
        Helper function to construct the method request params, models, request_templates and
        integration_type values needed to configure method request integration/mappings.
        u
parametersuapplication/jsonuoptionsuMOCKuAWSuparamsumodelsurequest_templatesuintegration_type(R
RjRRRvtREQUEST_OPTION_TEMPLATEtREQUEST_TEMPLATE(	Rltmethod_nametmethod_datat
method_paramst
method_modelstparamtptrequest_templatestintegration_type((s?/usr/lib/python2.7/site-packages/salt/states/boto_apigateway.pyt_parse_method_data�s		
cC@s�g}t|t�r|xdtj|�D]P\}}t|t�rY|j|j|��q%|dkr%|j|�q%q%Wn|S(Nupattern(R.RRRXR�t_find_patternsR[(RlR\R^R_R`((s?/usr/lib/python2.7/site-packages/salt/states/boto_apigateway.pyR�scC@sQ|j|�rdnd}|j�j|�}|j|�}|rM|dS|S(uD
        returns the pattern specified in a response schema
        u.+u.*i(R�R�RR(RlRut
httpStatustdefaultPatternR�tpatterns((s?/usr/lib/python2.7/site-packages/salt/states/boto_apigateway.pyt_get_pattern_for_schema�scC@sg|dks|j|�rA|jr5i|jd6n|j}n"|jrZi|jd6n|j}|S(Nuoptionsuapplication/json(R�R�tRESPONSE_OPTION_TEMPLATER�tRESPONSE_TEMPLATE(RlRthttp_statustresponse_templates((s?/usr/lib/python2.7/site-packages/salt/states/boto_apigateway.pyt_get_response_template�s%"cC@s�i}d}|jr:|j|d<|j|j|�}ni}i}xj|jD]_}dj|�}	t||	<|jj|�}
d|
kr�dj|
jd��nd||	<qPW|j||�}i|d6|d6|d	6|d
6|d6S(u�
        Helper function to construct the method response params, models, and integration_params
        values needed to configure method response integration/mappings.
        u.*uapplication/jsonumethod.response.header.{0}udefaultu'{0}'u'*'uparamsumodelsuintegration_paramsupatternuresponse_templates(RvRRRRRR"(RlRtmethod_responseRtmethod_response_modelstmethod_response_patterntmethod_response_paramst"method_integration_response_paramstheadertresponse_headertheader_dataR!((s?/usr/lib/python2.7/site-packages/salt/states/boto_apigateway.pyt_parse_method_response�s$	

2
c	C@s-|j|j�|�}	|j�dkr9t}d}ntdd|jd|d|j�d|d|d	|	jd
�d|	jd�|j�}
|
jd
�s�t||
�}|St	|d|
�}d}|j�dkr|j
|j||�d|�}ntdd|jd|d|j�d|	jd�ddd|d|d|	jd�|j�}|jd
�s�t||�}|St	|d|�}d|krx�tj
|d�D]W\}
}t|
�}|j|j�tj|�|�}tdd|jd|d|j�d|d|jd
�d|jd�|j�}|jd
�sct||�}|St	|d |�}td!d|jd|d|j�d|d"|jd#�d|jd$�d%|jd&�|j�}|jd
�s�t||�}|St	|d'|�}q�Wntd(j||���|S()u�
        Method to create a method for the given resource path, along with its associated
        request and response integrations.

        ret
            a dictionary for returning status to Saltstack

        resource_path
            the full resource path where the named method_name will be associated with.

        method_name
            a string that is one of the following values: 'delete', 'get', 'head', 'options',
            'patch', 'post', 'put'

        method_data
            the value dictionary for this method in the swagger definition file.

        api_key_required
            True or False, whether api key is required to access this method.

        lambda_integration_role
            name of the IAM role or IAM role arn that Api Gateway will assume when executing
            the associated lambda function

        lambda_region
            the region for the lambda function that Api Gateway will integrate to.

        authorization_type
            'NONE' or 'AWS_IAM'

        uoptionsuNONEu!boto_apigateway.create_api_methodR2RRtauthorizationTypetapiKeyRequiredtrequestParametersuparamst
requestModelsumodelsucreatedu _deploy_method.create_api_methoduR	u&boto_apigateway.create_api_integrationtintegrationTypeuintegration_typetintegrationHttpMethoduPOSTturitcredentialstrequestTemplatesurequest_templatesu%_deploy_method.create_api_integrationu	responsesu*boto_apigateway.create_api_method_responset
statusCodetresponseParameterstresponseModelsu)_deploy_method.create_api_method_responseu/boto_apigateway.create_api_integration_responsetselectionPatternupatternuintegration_paramstresponseTemplatesuresponse_templatesu._deploy_method.create_api_integration_responseu"No responses specified for {0} {1}(RRTRRR2tupperRR�RiRgR
RRRXRER+R
R{RR(RlR(t
resource_pathRRRRR	R
R�RVRtintegrationR�t
response_dataRR#tmrtmir((s?/usr/lib/python2.7/site-packages/salt/states/boto_apigateway.pyt_deploy_methods�!	 
	
	cC@s�x�|jD]�\}}tdd|jd||j�}|jd�sZt||�}|St|d|�}xStj|�D]B\}	}
|	t	j
kr||j|||	|
||||�}q|q|Wq
W|S(uH
        Method to deploy resources defined in the swagger file.

        ret
            a dictionary for returning status to Saltstack

        api_key_required
            True or False, whether api key is required to access this method.

        lambda_integration_role
            name of the IAM role or IAM role arn that Api Gateway will assume when executing
            the associated lambda function

        lambda_region
            the region for the lambda function that Api Gateway will integrate to.

        authorization_type
            'NONE' or 'AWS_IAM'
        u$boto_apigateway.create_api_resourcesR2R�ucreatedudeploy_resources(R�RR2R�RRiRgRRXR
R�R@(RlR(RRR	R
R�tpathDataR�R�R((s?/usr/lib/python2.7/site-packages/salt/states/boto_apigateway.pyRts(uswaggeruinfouhostubasePathuschemesuconsumesuproducesupathsudefinitionsu
parametersu	responsesusecurityDefinitionsusecurityutagsuexternalDocs(uswaggeruinfoubasePathuschemesupathsudefinitions(ugetuputupostudeleteuoptionsuheadupatch(u2.0(DRwRxRyR�R�R�R�R�tcompileR�R�RRRRRRR�tobjectRjR{RnR�R�R�R�RzR�R�R�R�R�R�R�R�R�R2tsetterR�R�R�R4R�R�R�RR�R�R3RRR�RR5R�R�R�R�R�RRR
RRRR"R+R@R(((s?/usr/lib/python2.7/site-packages/salt/states/boto_apigateway.pyR
s�
1



3			,		
	
	
						
				!		#			#		
		
		:										rc	
C@sut�}	i|d6td6dd6id6}
y
td|fd|fd|fd	|fg�}td
d||�}d|kr�t|
d<d
|
d<|
S|dsTtdr�dj|�|
d<d*|
d<|
Stdd|d|d|d||�}
d|
kr)t|
d<dj||
d�|
d<|
Sid*d6|
dd<dj|�|
d<n�|dd}t}dd+fdd,ff}x�|D]�\}}xr|D]j}|	j|�d*kr�in|	j|�}|j|i�j|d*�|j|d*�kr�t}Pq�q�Wq�W|s3d!j|�|
d<t|
d<|
Stdr^d"j|�|
d<d*|
d<|
Std#|d$d|d||�}
d|
kr�t|
d<d%j||
d�|
d<|
Si|d6|
dd<d&j|�|
d<td
d||�}d|krt|
d<d'|
d<|
Si|ddd6|
dd(<Wn9t	t
fk
rp}t|
d<d)j|j�|
d<nX|
S(-u
    Ensure the spcifieda usage plan with the corresponding metrics is deployed

    .. versionadded:: 2017.7.0

    name
        name of the state

    plan_name
        [Required] name of the usage plan

    throttle
        [Optional] throttling parameters expressed as a dictionary.
        If provided, at least one of the throttling parameters must be present

        rateLimit
            rate per second at which capacity bucket is populated

        burstLimit
            maximum rate allowed

    quota
        [Optional] quota on the number of api calls permitted by the plan.
        If provided, limit and period must be present

        limit
            [Required] number of calls permitted per quota period

        offset
            [Optional] number of calls to be subtracted from the limit at the beginning of the period

        period
            [Required] period to which quota applies. Must be DAY, WEEK or MONTH

    .. code-block:: yaml

        UsagePlanPresent:
          boto_apigateway.usage_plan_present:
            - plan_name: my_usage_plan
            - throttle:
                rateLimit: 70
                burstLimit: 100
            - quota:
                limit: 1000
                offset: 0
                period: DAY
            - profile: my_profile

    unameuresultuucommentuchangesuregionukeyukeyiduprofileu$boto_apigateway.describe_usage_plansRuerroru'Failed to describe existing usage plansuplansutestu%a new usage plan {0} would be createdu!boto_apigateway.create_usage_planR�tthrottletquotau&Failed to create a usage plan {0}, {1}uplanuoldu%A new usage plan {0} has been creatediuthrottleu	rateLimitu
burstLimituquotaulimituoffsetuperiodu,usage plan {0} is already in a correct stateu%a new usage plan {0} would be updatedu!boto_apigateway.update_usage_planuidu&Failed to update a usage plan {0}, {1}uusage plan {0} has been updatedu5Failed to describe existing usage plans after updatesunewu{0}N(u	rateLimitu
burstLimit(ulimituoffsetuperiod(tlocalsRRRRRRRRRRR(Rt	plan_nameR�RERFR!R"R#R$tfunc_paramsR(R)texistingR^tplantneeds_updatingtmodifiable_paramsRtfieldsR9tactual_paramtnewstateR,((s?/usr/lib/python2.7/site-packages/salt/states/boto_apigateway.pytusage_plan_present�s�3	

		




	

*0


	


!
cC@s�i|d6td6dd6id6}yTtd|fd|fd|fd	|fg�}td
d||�}d|kr�t|d<d
|d<|S|ds�dj|�|d<|Stdr�dj|�|d<d|d<|S|ddd}	td|	|�}
d|
kr0t|d<dj||
�|d<|Sdj|�|d<i|ddd6|dd<idd6|dd<Wn9ttfk
r�}t|d<dj|j	�|d<nX|S(ug
    Ensures usage plan identified by name is no longer present

    .. versionadded:: 2017.7.0

    name
        name of the state

    plan_name
        name of the plan to remove

    .. code-block:: yaml

        usage plan absent:
          boto_apigateway.usage_plan_absent:
            - plan_name: my_usage_plan
            - profile: my_profile

    unameuresultuucommentuchangesuregionukeyukeyiduprofileu$boto_apigateway.describe_usage_plansRuerroru'Failed to describe existing usage plansuplansu%Usage plan {0} does not exist alreadyutestu*Usage plan {0} exists and would be deletediuidu!boto_apigateway.delete_usage_planu$Failed to delete usage plan {0}, {1}uUsage plan {0} has been deleteduplanuoldunewu{0}N(
RRRRRRRRRR(RRHR!R"R#R$R(R)RJtplan_idR^R,((s?/usr/lib/python2.7/site-packages/salt/states/boto_apigateway.pytusage_plan_absent%sD

		






cC@s%i|d6td6dd6id6}y�td|fd|fd|fd	|fg�}td
d||�}	d|	kr�t|d<d
|d<|S|	ds�dj|�|d<t|d<|St|	d�dkr�d|d<t|d<|S|	dd}
|
d}|
jdg�}g}
x*|D]"}||kr|
j|�qqW|
sYd|d<|Std||
|�}d|kr�dj||
|d�|d<t|d<|Sd|d<||dd<|jdi�jdg�|dd<Wn9tt	fk
r }t|d<dj|j
�|d<nX|S(u
    Ensures usage plan identified by name is added to provided api_stages

    .. versionadded:: 2017.7.0

    name
        name of the state

    plan_name
        name of the plan to use

    api_stages
        list of dictionaries, where each dictionary consists of the following keys:

        apiId
            apiId of the api to attach usage plan to

        stage
            stage name of the api to attach usage plan to

    .. code-block:: yaml

        UsagePlanAssociationPresent:
          boto_apigateway.usage_plan_association_present:
            - plan_name: my_plan
            - api_stages:
              - apiId: 9kb0404ec0
                stage: my_stage
              - apiId: l9v7o2aj90
                stage: my_stage
            - profile: my_profile

    unameuresultuucommentuchangesuregionukeyukeyiduprofileu$boto_apigateway.describe_usage_plansRuerroru'Failed to describe existing usage plansuplansuUsage plan {0} does not existiuGThere are multiple usage plans with the same name - it is not supportediuidu	apiStagesu3Usage plan is already asssociated to all api stagesu)boto_apigateway.attach_usage_plan_to_apisu9Failed to associate a usage plan {0} to the apis {1}, {2}u*successfully associated usage plan to apisuoldunewu{0}(RRRRRR�RR[RRR(RRHt
api_stagesR!R"R#R$R(R)RJRKRRtplan_stagest
stages_to_addR�R^R,((s?/usr/lib/python2.7/site-packages/salt/states/boto_apigateway.pytusage_plan_association_presentgs\"

		








	

*
cC@sBi|d6td6dd6id6}y�td|fd|fd|fd	|fg�}td
d||�}	d|	kr�t|d<d
|d<|S|	ds�dj|�|d<t|d<|St|	d�dkr�d|d<t|d<|S|	dd}
|
d}|
jdg�}|s/dj|�|d<|Sg}
x*|D]"}||kr<|
j|�q<q<W|
svd|d<|Std||
|�}d|kr�dj||
|d�|d<t|d<|Sd|d<||dd<|jdi�jdg�|dd<Wn9tt	fk
r=}t|d<dj|j
�|d<nX|S(u�
    Ensures usage plan identified by name is removed from provided api_stages
    If a plan is associated to stages not listed in api_stages parameter,
    those associations remain intact.

    .. versionadded:: 2017.7.0

    name
        name of the state

    plan_name
        name of the plan to use

    api_stages
        list of dictionaries, where each dictionary consists of the following keys:

        apiId
            apiId of the api to detach usage plan from

        stage
            stage name of the api to detach usage plan from

    .. code-block:: yaml

        UsagePlanAssociationAbsent:
          boto_apigateway.usage_plan_association_absent:
            - plan_name: my_plan
            - api_stages:
              - apiId: 9kb0404ec0
                stage: my_stage
              - apiId: l9v7o2aj90
                stage: my_stage
            - profile: my_profile

    unameuresultuucommentuchangesuregionukeyukeyiduprofileu$boto_apigateway.describe_usage_plansRuerroru'Failed to describe existing usage plansuplansuUsage plan {0} does not existiuGThere are multiple usage plans with the same name - it is not supportediuidu	apiStagesu/Usage plan {0} has no associated stages alreadyu7Usage plan is already not asssociated to any api stagesu+boto_apigateway.detach_usage_plan_from_apisu>Failed to disassociate a usage plan {0} from the apis {1}, {2}u/successfully disassociated usage plan from apisuoldunewu{0}(RRRRRR�RR[RRR(RRHRTR!R"R#R$R(R)RJRKRRRUtstages_to_removeR�R^R,((s?/usr/lib/python2.7/site-packages/salt/states/boto_apigateway.pytusage_plan_association_absent�sb$

		








	

*
(%Ryt
__future__RRRR<tloggingR�R�tsalt.utils.filesR>tsalt.utils.jsontsalt.utils.yamltsalt.extRt	getLoggerRwR�RRR-RRR7RKRRRRWRYRgRiRCR
RQRSRWRY(((s?/usr/lib/python2.7/site-packages/salt/states/boto_apigateway.pyt<module>4sH	�	O					
	������B]

Zerion Mini Shell 1.0