def _uri(self, lambda_arn=None): # type: (Optional[str]) -> Any return StringFormat( 'arn:{partition}:apigateway:{region_name}:lambda:path/2015-03-31' '/functions/{api_handler_lambda_arn}/invocations', ['partition', 'region_name', 'api_handler_lambda_arn'], )
def test_can_handle_deeply_nested_format_string(self): nested = { 'a': { 'b': { 'c': { 'd': [{ 'e': { 'f': StringFormat('foo: {myvar}', ['myvar']) } }], } } } } variables = {'myvar': 'value'} assert self.resolve_vars(nested, variables) == { 'a': { 'b': { 'c': { 'd': [{ 'e': { 'f': 'foo: value' } }], } } } }
def _auth_uri(self, authorizer): # type: (ChaliceAuthorizer) -> Any varname = '%s_lambda_arn' % authorizer.name return StringFormat( 'arn:{partition}:apigateway:{region_name}:lambda:path/2015-03-31' '/functions/{%s}/invocations' % varname, ['partition', 'region_name', varname], )
def test_can_plan_rest_api(self): function = create_function_resource('function_name') rest_api = models.RestAPI( resource_name='rest_api', swagger_doc={'swagger': '2.0'}, api_gateway_stage='api', lambda_function=function, ) plan = self.determine_plan(rest_api) self.assert_loads_needed_variables(plan) assert plan[4:] == [ models.APICall( method_name='import_rest_api', params={'swagger_document': { 'swagger': '2.0' }}, output_var='rest_api_id', ), models.RecordResourceVariable( resource_type='rest_api', resource_name='rest_api', name='rest_api_id', variable_name='rest_api_id', ), models.APICall(method_name='deploy_rest_api', params={ 'rest_api_id': Variable('rest_api_id'), 'api_gateway_stage': 'api' }), models.APICall( method_name='add_permission_for_apigateway_if_needed', params={ 'function_name': 'appname-dev-function_name', 'region_name': Variable('region_name'), 'account_id': Variable('account_id'), 'rest_api_id': Variable('rest_api_id'), }), models.StoreValue( name='rest_api_url', value=StringFormat( 'https://{rest_api_id}.execute-api.{region_name}' '.amazonaws.com/api/', ['rest_api_id', 'region_name'], ), ), models.RecordResourceVariable(resource_type='rest_api', resource_name='rest_api', name='rest_api_url', variable_name='rest_api_url'), ] assert list( self.last_plan.messages.values()) == ['Creating Rest API\n']
def test_can_handle_format_string(self): params = {'bar': StringFormat('value: {my_var}', ['my_var'])} variables = {'my_var': 'foo'} assert self.resolve_vars(params, variables) == { 'bar': 'value: foo', }
def test_can_update_rest_api(self): function = create_function_resource('function_name') rest_api = models.RestAPI( resource_name='rest_api', swagger_doc={'swagger': '2.0'}, api_gateway_stage='api', lambda_function=function, ) self.remote_state.declare_resource_exists(rest_api) self.remote_state.deployed_values['rest_api'] = { 'rest_api_id': 'my_rest_api_id', } plan = self.determine_plan(rest_api) self.assert_loads_needed_variables(plan) assert plan[4:] == [ models.StoreValue(name='rest_api_id', value='my_rest_api_id'), models.RecordResourceVariable( resource_type='rest_api', resource_name='rest_api', name='rest_api_id', variable_name='rest_api_id', ), models.APICall( method_name='update_api_from_swagger', params={ 'rest_api_id': Variable('rest_api_id'), 'swagger_document': { 'swagger': '2.0' }, }, ), models.APICall( method_name='deploy_rest_api', params={ 'rest_api_id': Variable('rest_api_id'), 'api_gateway_stage': 'api' }, ), models.APICall( method_name='add_permission_for_apigateway_if_needed', params={ 'function_name': 'appname-dev-function_name', 'region_name': Variable('region_name'), 'account_id': Variable('account_id'), 'rest_api_id': Variable('rest_api_id') }, ), models.APICall( method_name='add_permission_for_apigateway_if_needed', params={ 'rest_api_id': Variable("rest_api_id"), 'region_name': Variable("region_name"), 'account_id': Variable("account_id"), 'function_name': 'appname-dev-function_name' }, output_var=None), models.StoreValue( name='rest_api_url', value=StringFormat( 'https://{rest_api_id}.execute-api.{region_name}' '.amazonaws.com/api/', ['rest_api_id', 'region_name'], ), ), models.RecordResourceVariable(resource_type='rest_api', resource_name='rest_api', name='rest_api_url', variable_name='rest_api_url'), ]