1313# pylint: disable=too-many-locals
1414
1515from .generated .custom import * # noqa: F403
16+
1617try :
1718 from .manual .custom import * # noqa: F403
1819except ImportError :
1920 pass
2021
21-
2222import uuid
2323import re
2424import os
@@ -79,7 +79,6 @@ def apim_create(client, resource_group_name, name, publisher_email, sku_name=Sku
7979 sku_capacity = 1 , virtual_network_type = VirtualNetworkType .none .value , enable_managed_identity = False ,
8080 public_network_access = None , disable_gateway = None , enable_client_certificate = None ,
8181 publisher_name = None , location = None , tags = None , no_wait = False ):
82-
8382 parameters = ApiManagementServiceResource (
8483 location = location ,
8584 notification_sender_email = publisher_email ,
@@ -110,7 +109,6 @@ def apim_update(instance, publisher_email=None, sku_name=None, sku_capacity=None
110109 virtual_network_type = None , publisher_name = None , enable_managed_identity = None ,
111110 public_network_access = None , disable_gateway = None , enable_client_certificate = None ,
112111 tags = None ):
113-
114112 if publisher_email is not None :
115113 instance .publisher_email = publisher_email
116114
@@ -517,25 +515,15 @@ def apim_api_import(
517515 parameters = parameters )
518516
519517
520- def apim_api_export (client , resource_group_name , service_name , api_id , export_format , file_path = None , file_name = None ,):
521- """Gets the details of the API specified by its identifier in the format specified """
522-
523- import json
524- import yaml
525- import xml .etree .ElementTree as ET
526- import os
527- import requests
528-
529518def _determine_file_extension (mapped_format ):
530519 """Determine file extension based on the mapped format."""
531520 if mapped_format in ['swagger' , 'openapi+json' ]:
532521 return '.json'
533- elif mapped_format in ['wsdl' , 'wadl' ]:
522+ if mapped_format in ['wsdl' , 'wadl' ]:
534523 return '.xml'
535- elif mapped_format in ['openapi' ]:
524+ if mapped_format in ['openapi' ]:
536525 return '.yaml'
537- else :
538- return '.txt'
526+ return '.txt'
539527
540528
541529def _extract_export_link_or_text (response ):
@@ -572,10 +560,10 @@ def _parse_exported_content(exported_text):
572560 import json
573561 import yaml
574562 import xml .etree .ElementTree as ET
575-
563+
576564 if exported_text is None :
577565 return None
578-
566+
579567 try :
580568 return json .loads (exported_text )
581569 except json .JSONDecodeError :
@@ -620,45 +608,38 @@ def _handle_playback_mode(export_format, file_path, file_name, api_id, format_ma
620608 if file_path is None :
621609 raise RequiredArgumentMissingError (
622610 "Please specify file path using '--file-path' argument." )
623-
624- file_extension = _determine_file_extension_from_export_format (export_format , format_mapping )
611+
612+ file_extension = _determine_file_extension_from_export_format (export_format )
625613 export_type = format_mapping .get (export_format , '' ).replace ('-link' , '' )
626-
614+
627615 if file_name is None :
628616 file_name = f"{ api_id } _{ export_type } { file_extension } "
629-
617+
630618 full_path = os .path .join (file_path , file_name )
631619 try :
632620 os .makedirs (os .path .dirname (full_path ), exist_ok = True )
633621 with open (full_path , 'w' , encoding = 'utf-8' ) as f :
634622 f .write ('' )
635623 except OSError as e :
636624 logger .warning ("Error writing exported API to file in playback mode: %s" , e )
637-
625+
638626 logger .warning ("APIM export results written to file (playback stub): %s" , full_path )
639- return None
640627
641628
642- def _determine_file_extension_from_export_format (export_format , format_mapping ):
629+ def _determine_file_extension_from_export_format (export_format ):
643630 """Determine file extension based on the export format."""
644631 if export_format in ['SwaggerFile' , 'OpenApiJsonFile' ]:
645632 return '.json'
646- elif export_format in ['WsdlFile' , 'WadlFile' ]:
633+ if export_format in ['WsdlFile' , 'WadlFile' ]:
647634 return '.xml'
648- elif export_format in ['OpenApiYamlFile' ]:
635+ if export_format in ['OpenApiYamlFile' ]:
649636 return '.yaml'
650- else :
651- return '.txt'
652637
638+ return '.txt'
653639
654- def apim_api_export (client , resource_group_name , service_name , api_id , export_format , file_path = None , file_name = None ,):
655- """Gets the details of the API specified by its identifier in the format specified """
656640
657- import json
658- import yaml
659- import xml .etree .ElementTree as ET
660- import os
661- import requests
641+ def apim_api_export (client , resource_group_name , service_name , api_id , export_format , file_path = None , file_name = None , ):
642+ """Gets the details of the API specified by its identifier in the format specified """
662643
663644 # Define the mapping from old format values to new ones
664645 format_mapping = {
@@ -696,7 +677,7 @@ def apim_api_export(client, resource_group_name, service_name, api_id, export_fo
696677
697678 file_extension = _determine_file_extension (mapped_format )
698679 export_type = mapped_format
699-
680+
700681 if file_name is None :
701682 file_name = f"{ api_id } _{ export_type } { file_extension } "
702683 full_path = os .path .join (file_path , file_name )
@@ -733,17 +714,14 @@ def api_export_result_to_dict(api_export_result):
733714
734715# Product API Operations
735716def apim_product_api_list (client , resource_group_name , service_name , product_id ):
736-
737717 return client .product_api .list_by_product (resource_group_name , service_name , product_id )
738718
739719
740720def apim_product_api_check_association (client , resource_group_name , service_name , product_id , api_id ):
741-
742721 return client .product_api .check_entity_exists (resource_group_name , service_name , product_id , api_id )
743722
744723
745724def apim_product_api_add (client , resource_group_name , service_name , product_id , api_id , no_wait = False ):
746-
747725 return sdk_no_wait (
748726 no_wait ,
749727 client .product_api .create_or_update ,
@@ -754,7 +732,6 @@ def apim_product_api_add(client, resource_group_name, service_name, product_id,
754732
755733
756734def apim_product_api_delete (client , resource_group_name , service_name , product_id , api_id , no_wait = False ):
757-
758735 return sdk_no_wait (
759736 no_wait ,
760737 client .product_api .delete ,
@@ -767,19 +744,16 @@ def apim_product_api_delete(client, resource_group_name, service_name, product_i
767744# Product Operations
768745
769746def apim_product_list (client , resource_group_name , service_name ):
770-
771747 return client .product .list_by_service (resource_group_name , service_name )
772748
773749
774750def apim_product_show (client , resource_group_name , service_name , product_id ):
775-
776751 return client .product .get (resource_group_name , service_name , product_id )
777752
778753
779754def apim_product_create (
780755 client , resource_group_name , service_name , product_name , product_id = None , description = None , legal_terms = None ,
781756 subscription_required = None , approval_required = None , subscriptions_limit = None , state = None , no_wait = False ):
782-
783757 parameters = ProductContract (
784758 description = description ,
785759 terms = legal_terms ,
@@ -814,7 +788,6 @@ def apim_product_create(
814788def apim_product_update (
815789 instance , product_name = None , description = None , legal_terms = None , subscription_required = None ,
816790 approval_required = None , subscriptions_limit = None , state = None ):
817-
818791 if product_name is not None :
819792 instance .display_name = product_name
820793
@@ -847,7 +820,6 @@ def apim_product_update(
847820
848821def apim_product_delete (
849822 client , resource_group_name , service_name , product_id , delete_subscriptions = None , if_match = None , no_wait = False ):
850-
851823 return sdk_no_wait (
852824 no_wait ,
853825 client .product .delete ,
@@ -1171,6 +1143,7 @@ def apim_ds_purge(client, service_name, location, no_wait=False):
11711143 service_name = service_name ,
11721144 location = location )
11731145
1146+
11741147# Graphql Resolver Operations
11751148
11761149
@@ -1194,7 +1167,6 @@ def apim_graphql_resolver_create(
11941167
11951168def apim_graphql_resolver_delete (
11961169 client , resource_group_name , service_name , api_id , resolver_id , no_wait = False , if_match = None ):
1197-
11981170 return sdk_no_wait (no_wait , client .graph_ql_api_resolver .delete ,
11991171 resource_group_name = resource_group_name ,
12001172 service_name = service_name ,
@@ -1240,7 +1212,6 @@ def apim_graphql_resolver_policy_create(
12401212
12411213
12421214def apim_graphql_resolver_policy_show (client , resource_group_name , service_name , api_id , resolver_id ):
1243-
12441215 return client .graph_ql_api_resolver_policy .get (
12451216 resource_group_name = resource_group_name ,
12461217 service_name = service_name ,
@@ -1250,7 +1221,6 @@ def apim_graphql_resolver_policy_show(client, resource_group_name, service_name,
12501221
12511222
12521223def apim_graphql_resolver_policy_list (client , resource_group_name , service_name , api_id , resolver_id ):
1253-
12541224 return client .graph_ql_api_resolver_policy .list_by_resolver (
12551225 resource_group_name = resource_group_name ,
12561226 service_name = service_name ,
@@ -1260,7 +1230,6 @@ def apim_graphql_resolver_policy_list(client, resource_group_name, service_name,
12601230
12611231def apim_graphql_resolver_policy_delete (
12621232 client , resource_group_name , service_name , api_id , resolver_id , no_wait = False , if_match = None ):
1263-
12641233 return sdk_no_wait (no_wait , client .graph_ql_api_resolver_policy .delete ,
12651234 resource_group_name = resource_group_name ,
12661235 service_name = service_name ,
0 commit comments