5353from gapic import utils
5454from gapic .schema import metadata
5555from gapic .utils import uri_sample
56+ from gapic .utils import make_private
5657
5758
5859@dataclasses .dataclass (frozen = True )
@@ -900,6 +901,14 @@ def add_to_address_allowlist(self, *,
900901
901902 This method is used to create an allowlist of addresses to be used to filter out unneeded
902903 services, methods, messages, and enums at a later step.
904+
905+ Args:
906+ address_allowlist (Set[metadata.Address]): A set of allowlisted metadata.Address
907+ objects to add to. Only the addresses of the allowlisted methods, the services
908+ containing these methods, and messages/enums those methods use will be part of the
909+ final address_allowlist. The set may be modified during this call.
910+ Returns:
911+ None
903912 """
904913 address_allowlist .add (self .ident )
905914
@@ -1014,6 +1023,18 @@ def add_to_address_allowlist(self, *,
10141023
10151024 This method is used to create an allowlist of addresses to be used to filter out unneeded
10161025 services, methods, messages, and enums at a later step.
1026+
1027+ Args:
1028+ address_allowlist (Set[metadata.Address]): A set of allowlisted metadata.Address
1029+ objects to add to. Only the addresses of the allowlisted methods, the services
1030+ containing these methods, and messages/enums those methods use will be part of the
1031+ final address_allowlist. The set may be modified during this call.
1032+ resource_messages (Dict[str, wrappers.MessageType]): A dictionary mapping the unified
1033+ resource type name of a resource message to the corresponding MessageType object
1034+ representing that resource message. Only resources with a message representation
1035+ should be included in the dictionary.
1036+ Returns:
1037+ None
10171038 """
10181039
10191040 self .request_type .add_to_address_allowlist (
@@ -1061,6 +1082,18 @@ def add_to_address_allowlist(self, *,
10611082
10621083 This method is used to create an allowlist of addresses to be used to filter out unneeded
10631084 services, methods, messages, and enums at a later step.
1085+
1086+ Args:
1087+ address_allowlist (Set[metadata.Address]): A set of allowlisted metadata.Address
1088+ objects to add to. Only the addresses of the allowlisted methods, the services
1089+ containing these methods, and messages/enums those methods use will be part of the
1090+ final address_allowlist. The set may be modified during this call.
1091+ resource_messages (Dict[str, wrappers.MessageType]): A dictionary mapping the unified
1092+ resource type name of a resource message to the corresponding MessageType object
1093+ representing that resource message. Only resources with a message representation
1094+ should be included in the dictionary.
1095+ Returns:
1096+ None
10641097 """
10651098 self .response_type .add_to_address_allowlist (
10661099 address_allowlist = address_allowlist ,
@@ -1362,6 +1395,7 @@ class Method:
13621395 method_pb : descriptor_pb2 .MethodDescriptorProto
13631396 input : MessageType
13641397 output : MessageType
1398+ is_internal : bool = False
13651399 lro : Optional [OperationInfo ] = dataclasses .field (default = None )
13661400 extended_lro : Optional [ExtendedOperationInfo ] = dataclasses .field (
13671401 default = None )
@@ -1403,6 +1437,10 @@ def transport_safe_name(self) -> str:
14031437 def is_operation_polling_method (self ):
14041438 return self .output .is_extended_operation and self .options .Extensions [ex_ops_pb2 .operation_polling_method ]
14051439
1440+ @utils .cached_property
1441+ def name (self ):
1442+ return make_private (self .method_pb .name ) if self .is_internal else self .method_pb .name
1443+
14061444 @utils .cached_property
14071445 def client_output (self ):
14081446 return self ._client_output (enable_asyncio = False )
@@ -1814,6 +1852,22 @@ def add_to_address_allowlist(self, *,
18141852
18151853 This method is used to create an allowlist of addresses to be used to filter out unneeded
18161854 services, methods, messages, and enums at a later step.
1855+
1856+ Args:
1857+ address_allowlist (Set[metadata.Address]): A set of allowlisted metadata.Address
1858+ objects to add to. Only the addresses of the allowlisted methods, the services
1859+ containing these methods, and messages/enums those methods use will be part of the
1860+ final address_allowlist. The set may be modified during this call.
1861+ method_allowlist (Set[str]): An allowlist of fully-qualified method names.
1862+ resource_messages (Dict[str, wrappers.MessageType]): A dictionary mapping the unified
1863+ resource type name of a resource message to the corresponding MessageType object
1864+ representing that resource message. Only resources with a message representation
1865+ should be included in the dictionary.
1866+ services_in_proto (Dict[str, wrappers.Service]): A dictionary mapping the names of Service
1867+ objects in the proto containing this method to the Service objects. This is necessary
1868+ for traversing the operation service in the case of extended LROs.
1869+ Returns:
1870+ None
18171871 """
18181872
18191873 address_allowlist .add (self .ident )
@@ -1851,6 +1905,27 @@ def add_to_address_allowlist(self, *,
18511905 resource_messages = resource_messages ,
18521906 )
18531907
1908+ def with_internal_methods (self , * , public_methods : Set [str ]) -> 'Method' :
1909+ """Returns a version of this ``Method`` marked as internal
1910+
1911+ The methods not in the public_methods set will be marked as internal and
1912+ this ``Service`` will as well by extension (see :meth:`Service.is_internal`).
1913+
1914+ Args:
1915+ public_methods (Set[str]): An allowlist of fully-qualified method names.
1916+ Methods not in this allowlist will be marked as internal.
1917+ Returns:
1918+ Service: A version of this `Service` with `Method` objects corresponding to methods
1919+ not in `public_methods` marked as internal.
1920+ """
1921+ if self .ident .proto in public_methods :
1922+ return self
1923+
1924+ return dataclasses .replace (
1925+ self ,
1926+ is_internal = True ,
1927+ )
1928+
18541929
18551930@dataclasses .dataclass (frozen = True )
18561931class CommonResource :
@@ -1928,7 +2003,7 @@ def __getattr__(self, name):
19282003 @property
19292004 def client_name (self ) -> str :
19302005 """Returns the name of the generated client class"""
1931- return self .name + "Client"
2006+ return ( "Base" if self . is_internal else "" ) + self .name + "Client"
19322007
19332008 @property
19342009 def client_package_version (self ) -> str :
@@ -1937,7 +2012,7 @@ def client_package_version(self) -> str:
19372012 @property
19382013 def async_client_name (self ) -> str :
19392014 """Returns the name of the generated AsyncIO client class"""
1940- return self .name + "AsyncClient"
2015+ return ( "Base" if self . is_internal else "" ) + self .name + "AsyncClient"
19412016
19422017 @property
19432018 def transport_name (self ):
@@ -2143,6 +2218,10 @@ def operation_polling_method(self) -> Optional[Method]:
21432218 None
21442219 )
21452220
2221+ @utils .cached_property
2222+ def is_internal (self ) -> bool :
2223+ return any (m .is_internal for m in self .methods .values ())
2224+
21462225 def with_context (self , * ,
21472226 collisions : Set [str ],
21482227 visited_messages : Optional [Set ["MessageType" ]] = None ,
@@ -2224,3 +2303,32 @@ def prune_messages_for_selective_generation(self, *,
22242303 for k , v in self .methods .items () if v .ident in address_allowlist
22252304 }
22262305 )
2306+
2307+ def with_internal_methods (self , * ,
2308+ public_methods : Set [str ]) -> 'Service' :
2309+ """Returns a version of this ``Service`` with some Methods marked as internal.
2310+
2311+ The methods not in the public_methods set will be marked as internal and
2312+ this ``Service`` will as well by extension (see :meth:`Service.is_internal`).
2313+
2314+ Args:
2315+ public_methods (Set[str]): An allowlist of fully-qualified method names.
2316+ Methods not in this allowlist will be marked as internal.
2317+ Returns:
2318+ Service: A version of this `Service` with `Method` objects corresponding to methods
2319+ not in `public_methods` marked as internal.
2320+ """
2321+
2322+ # Internal methods need to be keyed with underscore prefixed method names
2323+ # (e.g. google.Service.Method -> google.Service._Method) in order for
2324+ # samplegen to work properly.
2325+ return dataclasses .replace (
2326+ self ,
2327+ methods = {
2328+ meth .name : meth
2329+ for meth in (
2330+ meth .with_internal_methods (public_methods = public_methods )
2331+ for meth in self .methods .values ()
2332+ )
2333+ }
2334+ )
0 commit comments