1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 600 601 602 603 604 605 606 607 608 609 610 611 612 613 614 615 616 617 618 619 620 621 622 623 624 625 626 627 628 629 630 631 632 633 634 635 636 637 638 639 640 641 642 643 644 645 646 647 648 649 650 651 652 653 654 655 656 657 658 659 660 661 662 663 664 665 666 667 668 669 670 671 672 673 674 675 676 677 678 679 680 681 682 683 684 685 686 687 688 689 690 691 692 693 694 695 696 697
|
"""Handles incoming apigatewayv2 requests, invokes methods, returns responses."""
import json
from typing import Any
from urllib.parse import unquote
from moto.core.responses import TYPE_RESPONSE, BaseResponse
from .exceptions import UnknownProtocol
from .models import ApiGatewayV2Backend, apigatewayv2_backends
class ApiGatewayV2Response(BaseResponse):
"""Handler for ApiGatewayV2 requests and responses."""
def __init__(self) -> None:
super().__init__(service_name="apigatewayv2")
@property
def apigatewayv2_backend(self) -> ApiGatewayV2Backend:
"""Return backend instance specific for this region."""
return apigatewayv2_backends[self.current_account][self.region]
def create_api(self) -> TYPE_RESPONSE:
params = json.loads(self.body)
api_key_selection_expression = params.get("apiKeySelectionExpression")
cors_configuration = params.get("corsConfiguration")
description = params.get("description")
disable_schema_validation = params.get("disableSchemaValidation")
disable_execute_api_endpoint = params.get("disableExecuteApiEndpoint")
name = params.get("name")
protocol_type = params.get("protocolType")
route_selection_expression = params.get("routeSelectionExpression")
tags = params.get("tags")
version = params.get("version")
if protocol_type not in ["HTTP", "WEBSOCKET"]:
raise UnknownProtocol
api = self.apigatewayv2_backend.create_api(
api_key_selection_expression=api_key_selection_expression,
cors_configuration=cors_configuration,
description=description,
disable_schema_validation=disable_schema_validation,
disable_execute_api_endpoint=disable_execute_api_endpoint,
name=name,
protocol_type=protocol_type,
route_selection_expression=route_selection_expression,
tags=tags,
version=version,
)
return 200, {}, json.dumps(api.to_json())
def delete_api(self) -> TYPE_RESPONSE:
api_id = self.path.split("/")[-1]
self.apigatewayv2_backend.delete_api(api_id=api_id)
return 200, {}, "{}"
def get_api(self) -> TYPE_RESPONSE:
api_id = self.path.split("/")[-1]
api = self.apigatewayv2_backend.get_api(api_id=api_id)
return 200, {}, json.dumps(api.to_json())
@staticmethod
def get_api_without_id(*args: Any) -> TYPE_RESPONSE: # type: ignore[misc]
"""
AWS is returning an empty response when apiId is an empty string. This is slightly odd and it seems an
outlier, therefore it was decided we could have a custom handler for this particular use case instead of
trying to make it work with the existing url-matcher.
"""
return 200, {}, "{}"
def get_apis(self) -> TYPE_RESPONSE:
apis = self.apigatewayv2_backend.get_apis()
return 200, {}, json.dumps({"items": [a.to_json() for a in apis]})
def update_api(self) -> TYPE_RESPONSE:
api_id = self.path.split("/")[-1]
params = json.loads(self.body)
api_key_selection_expression = params.get("apiKeySelectionExpression")
cors_configuration = params.get("corsConfiguration")
description = params.get("description")
disable_schema_validation = params.get("disableSchemaValidation")
disable_execute_api_endpoint = params.get("disableExecuteApiEndpoint")
name = params.get("name")
route_selection_expression = params.get("routeSelectionExpression")
version = params.get("version")
api = self.apigatewayv2_backend.update_api(
api_id=api_id,
api_key_selection_expression=api_key_selection_expression,
cors_configuration=cors_configuration,
description=description,
disable_schema_validation=disable_schema_validation,
disable_execute_api_endpoint=disable_execute_api_endpoint,
name=name,
route_selection_expression=route_selection_expression,
version=version,
)
return 200, {}, json.dumps(api.to_json())
def reimport_api(self) -> TYPE_RESPONSE:
api_id = self.path.split("/")[-1]
params = json.loads(self.body)
body = params.get("body")
fail_on_warnings = (
str(self._get_param("failOnWarnings", "false")).lower() == "true"
)
api = self.apigatewayv2_backend.reimport_api(api_id, body, fail_on_warnings)
return 201, {}, json.dumps(api.to_json())
def create_authorizer(self) -> TYPE_RESPONSE:
api_id = self.path.split("/")[-2]
params = json.loads(self.body)
auth_creds_arn = params.get("authorizerCredentialsArn")
auth_payload_format_version = params.get("authorizerPayloadFormatVersion")
auth_result_ttl = params.get("authorizerResultTtlInSeconds")
authorizer_type = params.get("authorizerType")
authorizer_uri = params.get("authorizerUri")
enable_simple_response = params.get("enableSimpleResponses")
identity_source = params.get("identitySource")
identity_validation_expr = params.get("identityValidationExpression")
jwt_config = params.get("jwtConfiguration")
name = params.get("name")
authorizer = self.apigatewayv2_backend.create_authorizer(
api_id,
auth_creds_arn=auth_creds_arn,
auth_payload_format_version=auth_payload_format_version,
auth_result_ttl=auth_result_ttl,
authorizer_type=authorizer_type,
authorizer_uri=authorizer_uri,
enable_simple_response=enable_simple_response,
identity_source=identity_source,
identity_validation_expr=identity_validation_expr,
jwt_config=jwt_config,
name=name,
)
return 200, {}, json.dumps(authorizer.to_json())
def delete_authorizer(self) -> TYPE_RESPONSE:
api_id = self.path.split("/")[-3]
authorizer_id = self.path.split("/")[-1]
self.apigatewayv2_backend.delete_authorizer(api_id, authorizer_id)
return 200, {}, "{}"
def get_authorizer(self) -> TYPE_RESPONSE:
api_id = self.path.split("/")[-3]
authorizer_id = self.path.split("/")[-1]
authorizer = self.apigatewayv2_backend.get_authorizer(api_id, authorizer_id)
return 200, {}, json.dumps(authorizer.to_json())
def update_authorizer(self) -> TYPE_RESPONSE:
api_id = self.path.split("/")[-3]
authorizer_id = self.path.split("/")[-1]
params = json.loads(self.body)
auth_creds_arn = params.get("authorizerCredentialsArn")
auth_payload_format_version = params.get("authorizerPayloadFormatVersion")
auth_result_ttl = params.get("authorizerResultTtlInSeconds")
authorizer_type = params.get("authorizerType")
authorizer_uri = params.get("authorizerUri")
enable_simple_response = params.get("enableSimpleResponses")
identity_source = params.get("identitySource")
identity_validation_expr = params.get("identityValidationExpression")
jwt_config = params.get("jwtConfiguration")
name = params.get("name")
authorizer = self.apigatewayv2_backend.update_authorizer(
api_id,
authorizer_id=authorizer_id,
auth_creds_arn=auth_creds_arn,
auth_payload_format_version=auth_payload_format_version,
auth_result_ttl=auth_result_ttl,
authorizer_type=authorizer_type,
authorizer_uri=authorizer_uri,
enable_simple_response=enable_simple_response,
identity_source=identity_source,
identity_validation_expr=identity_validation_expr,
jwt_config=jwt_config,
name=name,
)
return 200, {}, json.dumps(authorizer.to_json())
def delete_cors_configuration(self) -> TYPE_RESPONSE:
api_id = self.path.split("/")[-2]
self.apigatewayv2_backend.delete_cors_configuration(api_id)
return 200, {}, "{}"
def create_model(self) -> TYPE_RESPONSE:
api_id = self.path.split("/")[-2]
params = json.loads(self.body)
content_type = params.get("contentType")
description = params.get("description")
name = params.get("name")
schema = params.get("schema")
model = self.apigatewayv2_backend.create_model(
api_id, content_type, description, name, schema
)
return 200, {}, json.dumps(model.to_json())
def delete_model(self) -> TYPE_RESPONSE:
api_id = self.path.split("/")[-3]
model_id = self.path.split("/")[-1]
self.apigatewayv2_backend.delete_model(api_id, model_id)
return 200, {}, "{}"
def get_model(self) -> TYPE_RESPONSE:
api_id = self.path.split("/")[-3]
model_id = self.path.split("/")[-1]
model = self.apigatewayv2_backend.get_model(api_id, model_id)
return 200, {}, json.dumps(model.to_json())
def update_model(self) -> TYPE_RESPONSE:
api_id = self.path.split("/")[-3]
model_id = self.path.split("/")[-1]
params = json.loads(self.body)
content_type = params.get("contentType")
description = params.get("description")
name = params.get("name")
schema = params.get("schema")
model = self.apigatewayv2_backend.update_model(
api_id,
model_id,
content_type=content_type,
description=description,
name=name,
schema=schema,
)
return 200, {}, json.dumps(model.to_json())
def get_tags(self) -> TYPE_RESPONSE:
resource_arn = unquote(self.path.split("/tags/")[1])
tags = self.apigatewayv2_backend.get_tags(resource_arn)
return 200, {}, json.dumps({"tags": tags})
def tag_resource(self) -> TYPE_RESPONSE:
resource_arn = unquote(self.path.split("/tags/")[1])
tags = json.loads(self.body).get("tags", {})
self.apigatewayv2_backend.tag_resource(resource_arn, tags)
return 201, {}, "{}"
def untag_resource(self) -> TYPE_RESPONSE:
resource_arn = unquote(self.path.split("/tags/")[1])
tag_keys = self.querystring.get("tagKeys") or []
self.apigatewayv2_backend.untag_resource(resource_arn, tag_keys)
return 200, {}, "{}"
def create_route(self) -> TYPE_RESPONSE:
api_id = self.path.split("/")[-2]
params = json.loads(self.body)
api_key_required: bool = params.get("apiKeyRequired", False)
authorization_scopes = params.get("authorizationScopes")
authorization_type = params.get("authorizationType", "NONE")
authorizer_id = params.get("authorizerId")
model_selection_expression = params.get("modelSelectionExpression")
operation_name = params.get("operationName")
request_models = params.get("requestModels")
request_parameters = params.get("requestParameters")
route_key = params.get("routeKey")
route_response_selection_expression = params.get(
"routeResponseSelectionExpression"
)
target = params.get("target")
route = self.apigatewayv2_backend.create_route(
api_id=api_id,
api_key_required=api_key_required,
authorization_scopes=authorization_scopes,
authorization_type=authorization_type,
authorizer_id=authorizer_id,
model_selection_expression=model_selection_expression,
operation_name=operation_name,
request_models=request_models,
request_parameters=request_parameters,
route_key=route_key,
route_response_selection_expression=route_response_selection_expression,
target=target,
)
return 201, {}, json.dumps(route.to_json())
def delete_route(self) -> TYPE_RESPONSE:
api_id = self.path.split("/")[-3]
route_id = self.path.split("/")[-1]
self.apigatewayv2_backend.delete_route(api_id=api_id, route_id=route_id)
return 200, {}, "{}"
def delete_route_request_parameter(self) -> TYPE_RESPONSE:
api_id = self.path.split("/")[-5]
route_id = self.path.split("/")[-3]
request_param = self.path.split("/")[-1]
self.apigatewayv2_backend.delete_route_request_parameter(
api_id, route_id, request_param
)
return 200, {}, "{}"
def get_route(self) -> TYPE_RESPONSE:
api_id = self.path.split("/")[-3]
route_id = self.path.split("/")[-1]
api = self.apigatewayv2_backend.get_route(api_id=api_id, route_id=route_id)
return 200, {}, json.dumps(api.to_json())
def get_routes(self) -> TYPE_RESPONSE:
api_id = self.path.split("/")[-2]
apis = self.apigatewayv2_backend.get_routes(api_id=api_id)
return 200, {}, json.dumps({"items": [api.to_json() for api in apis]})
def update_route(self) -> TYPE_RESPONSE:
api_id = self.path.split("/")[-3]
route_id = self.path.split("/")[-1]
params = json.loads(self.body)
api_key_required = params.get("apiKeyRequired")
authorization_scopes = params.get("authorizationScopes")
authorization_type = params.get("authorizationType")
authorizer_id = params.get("authorizerId")
model_selection_expression = params.get("modelSelectionExpression")
operation_name = params.get("operationName")
request_models = params.get("requestModels")
request_parameters = params.get("requestParameters")
route_key = params.get("routeKey")
route_response_selection_expression = params.get(
"routeResponseSelectionExpression"
)
target = params.get("target")
api = self.apigatewayv2_backend.update_route(
api_id=api_id,
api_key_required=api_key_required,
authorization_scopes=authorization_scopes,
authorization_type=authorization_type,
authorizer_id=authorizer_id,
model_selection_expression=model_selection_expression,
operation_name=operation_name,
request_models=request_models,
request_parameters=request_parameters,
route_id=route_id,
route_key=route_key,
route_response_selection_expression=route_response_selection_expression,
target=target,
)
return 200, {}, json.dumps(api.to_json())
def create_route_response(self) -> TYPE_RESPONSE:
api_id = self.path.split("/")[-4]
route_id = self.path.split("/")[-2]
params = json.loads(self.body)
response_models = params.get("responseModels")
route_response_key = params.get("routeResponseKey")
model_selection_expression = params.get("modelSelectionExpression")
route_response = self.apigatewayv2_backend.create_route_response(
api_id,
route_id,
route_response_key,
model_selection_expression=model_selection_expression,
response_models=response_models,
)
return 200, {}, json.dumps(route_response.to_json())
def delete_route_response(self) -> TYPE_RESPONSE:
api_id = self.path.split("/")[-5]
route_id = self.path.split("/")[-3]
route_response_id = self.path.split("/")[-1]
self.apigatewayv2_backend.delete_route_response(
api_id, route_id, route_response_id
)
return 200, {}, "{}"
def get_route_response(self) -> TYPE_RESPONSE:
api_id = self.path.split("/")[-5]
route_id = self.path.split("/")[-3]
route_response_id = self.path.split("/")[-1]
route_response = self.apigatewayv2_backend.get_route_response(
api_id, route_id, route_response_id
)
return 200, {}, json.dumps(route_response.to_json())
def create_integration(self) -> TYPE_RESPONSE:
api_id = self.path.split("/")[-2]
params = json.loads(self.body)
connection_id = params.get("connectionId")
connection_type = params.get("connectionType")
content_handling_strategy = params.get("contentHandlingStrategy")
credentials_arn = params.get("credentialsArn")
description = params.get("description")
integration_method = params.get("integrationMethod")
integration_subtype = params.get("integrationSubtype")
integration_type = params.get("integrationType")
integration_uri = params.get("integrationUri")
passthrough_behavior = params.get("passthroughBehavior")
payload_format_version = params.get("payloadFormatVersion")
request_parameters = params.get("requestParameters")
request_templates = params.get("requestTemplates")
response_parameters = params.get("responseParameters")
template_selection_expression = params.get("templateSelectionExpression")
timeout_in_millis = params.get("timeoutInMillis")
tls_config = params.get("tlsConfig")
integration = self.apigatewayv2_backend.create_integration(
api_id=api_id,
connection_id=connection_id,
connection_type=connection_type,
content_handling_strategy=content_handling_strategy,
credentials_arn=credentials_arn,
description=description,
integration_method=integration_method,
integration_subtype=integration_subtype,
integration_type=integration_type,
integration_uri=integration_uri,
passthrough_behavior=passthrough_behavior,
payload_format_version=payload_format_version,
request_parameters=request_parameters,
request_templates=request_templates,
response_parameters=response_parameters,
template_selection_expression=template_selection_expression,
timeout_in_millis=timeout_in_millis,
tls_config=tls_config,
)
return 200, {}, json.dumps(integration.to_json())
def get_integration(self) -> TYPE_RESPONSE:
api_id = self.path.split("/")[-3]
integration_id = self.path.split("/")[-1]
integration = self.apigatewayv2_backend.get_integration(
api_id=api_id, integration_id=integration_id
)
return 200, {}, json.dumps(integration.to_json())
def get_integrations(self) -> TYPE_RESPONSE:
api_id = self.path.split("/")[-2]
integrations = self.apigatewayv2_backend.get_integrations(api_id=api_id)
return 200, {}, json.dumps({"items": [i.to_json() for i in integrations]})
def delete_integration(self) -> TYPE_RESPONSE:
api_id = self.path.split("/")[-3]
integration_id = self.path.split("/")[-1]
self.apigatewayv2_backend.delete_integration(
api_id=api_id, integration_id=integration_id
)
return 200, {}, "{}"
def update_integration(self) -> TYPE_RESPONSE:
api_id = self.path.split("/")[-3]
integration_id = self.path.split("/")[-1]
params = json.loads(self.body)
connection_id = params.get("connectionId")
connection_type = params.get("connectionType")
content_handling_strategy = params.get("contentHandlingStrategy")
credentials_arn = params.get("credentialsArn")
description = params.get("description")
integration_method = params.get("integrationMethod")
integration_subtype = params.get("integrationSubtype")
integration_type = params.get("integrationType")
integration_uri = params.get("integrationUri")
passthrough_behavior = params.get("passthroughBehavior")
payload_format_version = params.get("payloadFormatVersion")
request_parameters = params.get("requestParameters")
request_templates = params.get("requestTemplates")
response_parameters = params.get("responseParameters")
template_selection_expression = params.get("templateSelectionExpression")
timeout_in_millis = params.get("timeoutInMillis")
tls_config = params.get("tlsConfig")
integration = self.apigatewayv2_backend.update_integration(
api_id=api_id,
connection_id=connection_id,
connection_type=connection_type,
content_handling_strategy=content_handling_strategy,
credentials_arn=credentials_arn,
description=description,
integration_id=integration_id,
integration_method=integration_method,
integration_subtype=integration_subtype,
integration_type=integration_type,
integration_uri=integration_uri,
passthrough_behavior=passthrough_behavior,
payload_format_version=payload_format_version,
request_parameters=request_parameters,
request_templates=request_templates,
response_parameters=response_parameters,
template_selection_expression=template_selection_expression,
timeout_in_millis=timeout_in_millis,
tls_config=tls_config,
)
return 200, {}, json.dumps(integration.to_json())
def create_integration_response(self) -> TYPE_RESPONSE:
api_id = self.path.split("/")[-4]
int_id = self.path.split("/")[-2]
params = json.loads(self.body)
content_handling_strategy = params.get("contentHandlingStrategy")
integration_response_key = params.get("integrationResponseKey")
response_parameters = params.get("responseParameters")
response_templates = params.get("responseTemplates")
template_selection_expression = params.get("templateSelectionExpression")
integration_response = self.apigatewayv2_backend.create_integration_response(
api_id=api_id,
integration_id=int_id,
content_handling_strategy=content_handling_strategy,
integration_response_key=integration_response_key,
response_parameters=response_parameters,
response_templates=response_templates,
template_selection_expression=template_selection_expression,
)
return 200, {}, json.dumps(integration_response.to_json())
def delete_integration_response(self) -> TYPE_RESPONSE:
api_id = self.path.split("/")[-5]
int_id = self.path.split("/")[-3]
int_res_id = self.path.split("/")[-1]
self.apigatewayv2_backend.delete_integration_response(
api_id=api_id, integration_id=int_id, integration_response_id=int_res_id
)
return 200, {}, "{}"
def get_integration_response(self) -> TYPE_RESPONSE:
api_id = self.path.split("/")[-5]
int_id = self.path.split("/")[-3]
int_res_id = self.path.split("/")[-1]
int_response = self.apigatewayv2_backend.get_integration_response(
api_id=api_id, integration_id=int_id, integration_response_id=int_res_id
)
return 200, {}, json.dumps(int_response.to_json())
def get_integration_responses(self) -> TYPE_RESPONSE:
api_id = self.path.split("/")[-4]
int_id = self.path.split("/")[-2]
int_response = self.apigatewayv2_backend.get_integration_responses(
api_id=api_id, integration_id=int_id
)
return 200, {}, json.dumps({"items": [res.to_json() for res in int_response]})
def update_integration_response(self) -> TYPE_RESPONSE:
api_id = self.path.split("/")[-5]
int_id = self.path.split("/")[-3]
int_res_id = self.path.split("/")[-1]
params = json.loads(self.body)
content_handling_strategy = params.get("contentHandlingStrategy")
integration_response_key = params.get("integrationResponseKey")
response_parameters = params.get("responseParameters")
response_templates = params.get("responseTemplates")
template_selection_expression = params.get("templateSelectionExpression")
integration_response = self.apigatewayv2_backend.update_integration_response(
api_id=api_id,
integration_id=int_id,
integration_response_id=int_res_id,
content_handling_strategy=content_handling_strategy,
integration_response_key=integration_response_key,
response_parameters=response_parameters,
response_templates=response_templates,
template_selection_expression=template_selection_expression,
)
return 200, {}, json.dumps(integration_response.to_json())
def create_vpc_link(self) -> TYPE_RESPONSE:
params = json.loads(self.body)
name = params.get("name")
sg_ids = params.get("securityGroupIds")
subnet_ids = params.get("subnetIds")
tags = params.get("tags")
vpc_link = self.apigatewayv2_backend.create_vpc_link(
name, sg_ids, subnet_ids, tags
)
return 200, {}, json.dumps(vpc_link.to_json())
def delete_vpc_link(self) -> TYPE_RESPONSE:
vpc_link_id = self.path.split("/")[-1]
self.apigatewayv2_backend.delete_vpc_link(vpc_link_id)
return 200, {}, "{}"
def get_vpc_link(self) -> TYPE_RESPONSE:
vpc_link_id = self.path.split("/")[-1]
vpc_link = self.apigatewayv2_backend.get_vpc_link(vpc_link_id)
return 200, {}, json.dumps(vpc_link.to_json())
def get_vpc_links(self) -> TYPE_RESPONSE:
vpc_links = self.apigatewayv2_backend.get_vpc_links()
return 200, {}, json.dumps({"items": [link.to_json() for link in vpc_links]})
def update_vpc_link(self) -> TYPE_RESPONSE:
vpc_link_id = self.path.split("/")[-1]
params = json.loads(self.body)
name = params.get("name")
vpc_link = self.apigatewayv2_backend.update_vpc_link(vpc_link_id, name=name)
return 200, {}, json.dumps(vpc_link.to_json())
def create_domain_name(self) -> TYPE_RESPONSE:
params = json.loads(self.body)
domain_name = params.get("domainName")
domain_name_configurations = params.get("domainNameConfigurations", [{}])
mutual_tls_authentication = params.get("mutualTlsAuthentication", {})
tags = params.get("tags", {})
domain_name = self.apigatewayv2_backend.create_domain_name(
domain_name=domain_name,
domain_name_configurations=domain_name_configurations,
mutual_tls_authentication=mutual_tls_authentication,
tags=tags,
)
return 201, {}, json.dumps(domain_name.to_json())
def get_domain_name(self) -> TYPE_RESPONSE:
domain_name_param = self.path.split("/")[-1]
domain_name = self.apigatewayv2_backend.get_domain_name(
domain_name=domain_name_param
)
return 200, {}, json.dumps(domain_name.to_json())
def get_domain_names(self) -> TYPE_RESPONSE:
domain_names = self.apigatewayv2_backend.get_domain_names()
list_of_dict = [domain_name.to_json() for domain_name in domain_names]
return 200, {}, json.dumps({"items": list_of_dict})
def create_api_mapping(self) -> TYPE_RESPONSE:
domain_name = self.path.split("/")[-2]
params = json.loads(self.body)
api_id = params.get("apiId")
api_mapping_key = params.get("apiMappingKey", "")
stage = params.get("stage")
mapping = self.apigatewayv2_backend.create_api_mapping(
api_id=api_id,
api_mapping_key=api_mapping_key,
domain_name=domain_name,
stage=stage,
)
return 201, {}, json.dumps(mapping.to_json())
def get_api_mapping(self) -> TYPE_RESPONSE:
api_mapping_id = self.path.split("/")[-1]
domain_name = self.path.split("/")[-3]
mapping = self.apigatewayv2_backend.get_api_mapping(
api_mapping_id=api_mapping_id,
domain_name=domain_name,
)
return 200, {}, json.dumps(mapping.to_json())
def get_api_mappings(self) -> TYPE_RESPONSE:
domain_name = self.path.split("/")[-2]
mappings = self.apigatewayv2_backend.get_api_mappings(domain_name=domain_name)
list_of_dict = [mapping.to_json() for mapping in mappings]
return 200, {}, json.dumps({"items": list_of_dict})
def delete_domain_name(self) -> TYPE_RESPONSE:
domain_name = self.path.split("/")[-1]
self.apigatewayv2_backend.delete_domain_name(
domain_name=domain_name,
)
return 204, {}, ""
def delete_api_mapping(self) -> TYPE_RESPONSE:
api_mapping_id = self.path.split("/")[-1]
domain_name = self.path.split("/")[-3]
self.apigatewayv2_backend.delete_api_mapping(
api_mapping_id=api_mapping_id,
domain_name=domain_name,
)
return 204, {}, ""
def create_stage(self) -> TYPE_RESPONSE:
api_id = self.path.split("/")[-2]
config = json.loads(self.body)
stage = self.apigatewayv2_backend.create_stage(api_id, config)
return 200, {}, json.dumps(stage.to_json())
def get_stage(self) -> TYPE_RESPONSE:
api_id = self.path.split("/")[-3]
stage_name = unquote(self.path.split("/")[-1])
stage = self.apigatewayv2_backend.get_stage(api_id, stage_name)
return 200, {}, json.dumps(stage.to_json())
def delete_stage(self) -> TYPE_RESPONSE:
api_id = self.path.split("/")[-3]
stage_name = unquote(self.path.split("/")[-1])
self.apigatewayv2_backend.delete_stage(api_id, stage_name)
return 200, {}, "{}"
def get_stages(self) -> TYPE_RESPONSE:
api_id = self.path.split("/")[-2]
stages = self.apigatewayv2_backend.get_stages(api_id)
return 200, {}, json.dumps({"items": [st.to_json() for st in stages]})
|