@@ -513,64 +513,56 @@ def called_mutator_apis(cls) -> List[AwsApiSpec]:
513513 ]
514514
515515 @classmethod
516- def collect (cls : Type [AwsResource ], json : List [Json ], builder : GraphBuilder ) -> List [AwsResource ]:
517- instances : List [AwsResource ] = []
516+ def collect (cls : Type [AwsResource ], json : List [Json ], builder : GraphBuilder ) -> None :
517+ def add_instance (api_instance : AwsResource ) -> None :
518+ for deployment in builder .client .list (service_name , "get-deployments" , "items" , restApiId = api_instance .id ):
519+ if deploy_instance := AwsApiGatewayDeployment .from_api (deployment , builder ):
520+ deploy_instance .set_arn (
521+ builder = builder ,
522+ account = "" ,
523+ resource = f"/restapis/{ api_instance .id } /deployments/{ deploy_instance .id } " ,
524+ )
525+ deploy_instance .api_link = api_instance .id
526+ builder .add_node (deploy_instance , deployment )
527+ builder .add_edge (api_instance , EdgeType .default , node = deploy_instance )
528+ for stage in builder .client .list (
529+ service_name ,
530+ "get-stages" ,
531+ "item" ,
532+ restApiId = api_instance .id ,
533+ deploymentId = deploy_instance .id ,
534+ ):
535+ stage ["syntheticId" ] = f'{ api_instance .id } _{ stage ["stageName" ]} ' # create unique id
536+ if stage_instance := AwsApiGatewayStage .from_api (stage , builder ):
537+ stage_instance .api_link = api_instance .id
538+ builder .add_node (stage_instance , stage )
539+ # reference kinds for this edge are maintained in AwsApiGatewayDeployment.reference_kinds # noqa: E501
540+ builder .add_edge (deploy_instance , EdgeType .default , node = stage_instance )
541+ for authorizer in builder .client .list (service_name , "get-authorizers" , "items" , restApiId = api_instance .id ):
542+ if auth_instance := AwsApiGatewayAuthorizer .from_api (authorizer , builder ):
543+ auth_instance .api_link = api_instance .id
544+ builder .add_node (auth_instance , authorizer )
545+ builder .add_edge (api_instance , EdgeType .default , node = auth_instance )
546+ for resource in builder .client .list (service_name , "get-resources" , "items" , restApiId = api_instance .id ):
547+ if resource_instance := AwsApiGatewayResource .from_api (resource , builder ):
548+ resource_instance .api_link = api_instance .id
549+ if resource_instance .resource_methods :
550+ for method in resource_instance .resource_methods :
551+ mapped = bend (AwsApiGatewayMethod .mapping , resource ["resourceMethods" ][method ])
552+ if gm := parse_json (mapped , AwsApiGatewayMethod , builder ):
553+ resource_instance .resource_methods [method ] = gm
554+ builder .add_node (resource_instance , resource )
555+ builder .add_edge (api_instance , EdgeType .default , node = resource_instance )
556+
518557 for js in json :
519558 if api_instance := cls .from_api (js , builder ):
520559 api_instance .set_arn (
521560 builder = builder ,
522561 account = "" ,
523562 resource = f"/restapis/{ api_instance .id } " ,
524563 )
525- instances .append (api_instance )
526564 builder .add_node (api_instance , js )
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
565+ builder .submit_work (service_name , add_instance , api_instance )
574566
575567 def connect_in_graph (self , builder : GraphBuilder , source : Json ) -> None :
576568 if self .api_endpoint_configuration :
0 commit comments