|
1 | 1 | from datetime import datetime |
2 | 2 | from typing import ClassVar, Dict, Optional, List, Type, Union, Any |
3 | | -from concurrent.futures import wait as futures_wait |
| 3 | + |
4 | 4 | from attrs import define, field |
5 | 5 | from fix_plugin_aws.aws_client import AwsClient |
6 | 6 |
|
@@ -514,69 +514,63 @@ def called_mutator_apis(cls) -> List[AwsApiSpec]: |
514 | 514 |
|
515 | 515 | @classmethod |
516 | 516 | def collect(cls: Type[AwsResource], json: List[Json], builder: GraphBuilder) -> List[AwsResource]: |
517 | | - api_instances: List[AwsResource] = [] |
518 | | - |
519 | | - def add_instance(api_instance: AwsResource) -> List[AwsResource]: |
520 | | - instances: List[AwsResource] = [] |
521 | | - for deployment in builder.client.list(service_name, "get-deployments", "items", restApiId=api_instance.id): |
522 | | - if deploy_instance := AwsApiGatewayDeployment.from_api(deployment, builder): |
523 | | - deploy_instance.set_arn( |
524 | | - builder=builder, |
525 | | - account="", |
526 | | - resource=f"/restapis/{api_instance.id}/deployments/{deploy_instance.id}", |
527 | | - ) |
528 | | - deploy_instance.api_link = api_instance.id |
529 | | - instances.append(deploy_instance) |
530 | | - builder.add_node(deploy_instance, deployment) |
531 | | - builder.add_edge(api_instance, EdgeType.default, node=deploy_instance) |
532 | | - for stage in builder.client.list( |
533 | | - service_name, |
534 | | - "get-stages", |
535 | | - "item", |
536 | | - restApiId=api_instance.id, |
537 | | - deploymentId=deploy_instance.id, |
538 | | - ): |
539 | | - stage["syntheticId"] = f'{api_instance.id}_{stage["stageName"]}' # create unique id |
540 | | - if stage_instance := AwsApiGatewayStage.from_api(stage, builder): |
541 | | - stage_instance.api_link = api_instance.id |
542 | | - instances.append(stage_instance) |
543 | | - builder.add_node(stage_instance, stage) |
544 | | - # reference kinds for this edge are maintained in AwsApiGatewayDeployment.reference_kinds # noqa: E501 |
545 | | - builder.add_edge(deploy_instance, EdgeType.default, node=stage_instance) |
546 | | - for authorizer in builder.client.list(service_name, "get-authorizers", "items", restApiId=api_instance.id): |
547 | | - if auth_instance := AwsApiGatewayAuthorizer.from_api(authorizer, builder): |
548 | | - auth_instance.api_link = api_instance.id |
549 | | - instances.append(auth_instance) |
550 | | - builder.add_node(auth_instance, authorizer) |
551 | | - builder.add_edge(api_instance, EdgeType.default, node=auth_instance) |
552 | | - for resource in builder.client.list(service_name, "get-resources", "items", restApiId=api_instance.id): |
553 | | - if resource_instance := AwsApiGatewayResource.from_api(resource, builder): |
554 | | - resource_instance.api_link = api_instance.id |
555 | | - instances.append(resource_instance) |
556 | | - if resource_instance.resource_methods: |
557 | | - for method in resource_instance.resource_methods: |
558 | | - mapped = bend(AwsApiGatewayMethod.mapping, resource["resourceMethods"][method]) |
559 | | - if gm := parse_json(mapped, AwsApiGatewayMethod, builder): |
560 | | - resource_instance.resource_methods[method] = gm |
561 | | - builder.add_node(resource_instance, resource) |
562 | | - builder.add_edge(api_instance, EdgeType.default, node=resource_instance) |
563 | | - return instances |
564 | | - |
565 | | - futures = [] |
| 517 | + instances: List[AwsResource] = [] |
566 | 518 | for js in json: |
567 | 519 | if api_instance := cls.from_api(js, builder): |
568 | 520 | api_instance.set_arn( |
569 | 521 | builder=builder, |
570 | 522 | account="", |
571 | 523 | resource=f"/restapis/{api_instance.id}", |
572 | 524 | ) |
573 | | - api_instances.append(api_instance) |
| 525 | + instances.append(api_instance) |
574 | 526 | builder.add_node(api_instance, js) |
575 | | - future = builder.submit_work(service_name, add_instance, api_instance) |
576 | | - futures.append(future) |
577 | | - futures_wait(futures) |
578 | | - instances: List[AwsResource] = [result for future in futures for result in future.result()] |
579 | | - return api_instances + instances |
| 527 | + for deployment in builder.client.list( |
| 528 | + service_name, "get-deployments", "items", restApiId=api_instance.id |
| 529 | + ): |
| 530 | + if deploy_instance := AwsApiGatewayDeployment.from_api(deployment, builder): |
| 531 | + deploy_instance.set_arn( |
| 532 | + builder=builder, |
| 533 | + account="", |
| 534 | + resource=f"/restapis/{api_instance.id}/deployments/{deploy_instance.id}", |
| 535 | + ) |
| 536 | + deploy_instance.api_link = api_instance.id |
| 537 | + instances.append(deploy_instance) |
| 538 | + builder.add_node(deploy_instance, deployment) |
| 539 | + builder.add_edge(api_instance, EdgeType.default, node=deploy_instance) |
| 540 | + for stage in builder.client.list( |
| 541 | + service_name, |
| 542 | + "get-stages", |
| 543 | + "item", |
| 544 | + restApiId=api_instance.id, |
| 545 | + deploymentId=deploy_instance.id, |
| 546 | + ): |
| 547 | + stage["syntheticId"] = f'{api_instance.id}_{stage["stageName"]}' # create unique id |
| 548 | + if stage_instance := AwsApiGatewayStage.from_api(stage, builder): |
| 549 | + stage_instance.api_link = api_instance.id |
| 550 | + instances.append(stage_instance) |
| 551 | + builder.add_node(stage_instance, stage) |
| 552 | + # reference kinds for this edge are maintained in AwsApiGatewayDeployment.reference_kinds # noqa: E501 |
| 553 | + builder.add_edge(deploy_instance, EdgeType.default, node=stage_instance) |
| 554 | + for authorizer in builder.client.list( |
| 555 | + service_name, "get-authorizers", "items", restApiId=api_instance.id |
| 556 | + ): |
| 557 | + if auth_instance := AwsApiGatewayAuthorizer.from_api(authorizer, builder): |
| 558 | + auth_instance.api_link = api_instance.id |
| 559 | + instances.append(auth_instance) |
| 560 | + builder.add_node(auth_instance, authorizer) |
| 561 | + builder.add_edge(api_instance, EdgeType.default, node=auth_instance) |
| 562 | + for resource in builder.client.list(service_name, "get-resources", "items", restApiId=api_instance.id): |
| 563 | + if resource_instance := AwsApiGatewayResource.from_api(resource, builder): |
| 564 | + resource_instance.api_link = api_instance.id |
| 565 | + instances.append(resource_instance) |
| 566 | + if resource_instance.resource_methods: |
| 567 | + for method in resource_instance.resource_methods: |
| 568 | + mapped = bend(AwsApiGatewayMethod.mapping, resource["resourceMethods"][method]) |
| 569 | + if gm := parse_json(mapped, AwsApiGatewayMethod, builder): |
| 570 | + resource_instance.resource_methods[method] = gm |
| 571 | + builder.add_node(resource_instance, resource) |
| 572 | + builder.add_edge(api_instance, EdgeType.default, node=resource_instance) |
| 573 | + return instances |
580 | 574 |
|
581 | 575 | def connect_in_graph(self, builder: GraphBuilder, source: Json) -> None: |
582 | 576 | if self.api_endpoint_configuration: |
|
0 commit comments