Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
46 changes: 23 additions & 23 deletions google/ads/googleads/client.py
Original file line number Diff line number Diff line change
Expand Up @@ -104,7 +104,9 @@ def __dir__(self) -> Tuple[str]:

return self._enums

def __getattr__(self, name: str) -> Union[ProtoPlusMessageType, ProtobufMessageType]:
def __getattr__(
self, name: str
) -> Union[ProtoPlusMessageType, ProtobufMessageType]:
"""Dynamically loads the given enum class instance.

Args:
Expand Down Expand Up @@ -162,10 +164,10 @@ class GoogleAdsClient:

@classmethod
def copy_from(
cls,
destination: Union[ProtoPlusMessageType, ProtobufMessageType],
origin: Union[ProtoPlusMessageType, ProtobufMessageType]
) -> Union[ProtoPlusMessageType, ProtobufMessageType]:
cls,
destination: Union[ProtoPlusMessageType, ProtobufMessageType],
origin: Union[ProtoPlusMessageType, ProtobufMessageType],
) -> Union[ProtoPlusMessageType, ProtobufMessageType]:
"""Copies protobuf and proto-plus messages into one-another.

This method consolidates the CopyFrom logic of protobuf and proto-plus
Expand Down Expand Up @@ -204,7 +206,6 @@ def _get_client_kwargs(cls, config_data: Dict[str, Any]) -> Dict[str, Any]:
"use_cloud_org_for_api_access": config_data.get(
"use_cloud_org_for_api_access"
),
"gaada": config_data.get("gaada"),
}

@classmethod
Expand Down Expand Up @@ -267,7 +268,9 @@ def load_from_string(
Raises:
ValueError: If the configuration lacks a required field.
"""
config_data: Dict[str, Any] = config.parse_yaml_document_to_dict(yaml_str)
config_data: Dict[str, Any] = config.parse_yaml_document_to_dict(
yaml_str
)
kwargs: Dict[str, Any] = cls._get_client_kwargs(config_data)
return cls(**dict(version=version, **kwargs))

Expand Down Expand Up @@ -329,7 +332,6 @@ def __init__(
http_proxy: Union[str, None] = None,
use_proto_plus: bool = False,
use_cloud_org_for_api_access: Union[str, None] = None,
gaada: Union[str, None] = None,
):
"""Initializer for the GoogleAdsClient.

Expand All @@ -349,7 +351,6 @@ def __init__(
of developer token to determine your Google Ads API access
levels. Use this flag only if you are enrolled into a limited
pilot that supports this configuration.
gaada: a str specifying the Google Ads API Assistant version.
"""
if logging_config:
logging.config.dictConfig(logging_config)
Expand All @@ -366,7 +367,6 @@ def __init__(
use_cloud_org_for_api_access
)
self.enums: _EnumGetter = _EnumGetter(self)
self.gaada: Union[str, None] = gaada

# If given, write the http_proxy channel option for GRPC to use
if http_proxy:
Expand Down Expand Up @@ -403,9 +403,7 @@ def get_service(
# override any version specified as an argument.
version = self.version if self.version else version
# api_module = self._get_api_services_by_version(version)
services_path: str = (
f"google.ads.googleads.{version}.services.services"
)
services_path: str = f"google.ads.googleads.{version}.services.services"
snaked: str = util.convert_upper_case_to_snake_case(name)
interceptors = interceptors or []

Expand Down Expand Up @@ -446,14 +444,12 @@ def get_service(
self.login_customer_id,
self.linked_customer_id,
self.use_cloud_org_for_api_access,
gaada=self.gaada,
),
AsyncUnaryStreamMetadataInterceptor(
self.developer_token,
self.login_customer_id,
self.linked_customer_id,
self.use_cloud_org_for_api_access,
gaada=self.gaada,
),
AsyncUnaryUnaryLoggingInterceptor(_logger, version, endpoint),
AsyncUnaryStreamLoggingInterceptor(_logger, version, endpoint),
Expand Down Expand Up @@ -485,7 +481,7 @@ def get_service(
developer_token=self.developer_token,
login_customer_id=self.login_customer_id,
linked_customer_id=self.linked_customer_id,
use_cloud_org_for_api_access=self.use_cloud_org_for_api_access
use_cloud_org_for_api_access=self.use_cloud_org_for_api_access,
)

return service_client_class(transport=service_transport)
Expand All @@ -496,18 +492,20 @@ def get_service(
options=_GRPC_CHANNEL_OPTIONS,
)

interceptors: List[Union[grpc.UnaryUnaryClientInterceptor, grpc.UnaryStreamClientInterceptor]] = interceptors + [
interceptors: List[
Union[
grpc.UnaryUnaryClientInterceptor,
grpc.UnaryStreamClientInterceptor,
]
] = interceptors + [
MetadataInterceptor(
self.developer_token,
self.login_customer_id,
self.linked_customer_id,
self.use_cloud_org_for_api_access,
gaada=self.gaada,
),
LoggingInterceptor(_logger, version, endpoint),
ExceptionInterceptor(
version, use_proto_plus=self.use_proto_plus
),
ExceptionInterceptor(version, use_proto_plus=self.use_proto_plus),
]

channel: grpc.Channel = grpc.intercept_channel(channel, *interceptors)
Expand All @@ -525,12 +523,14 @@ def get_service(
developer_token=self.developer_token,
login_customer_id=self.login_customer_id,
linked_customer_id=self.linked_customer_id,
use_cloud_org_for_api_access=self.use_cloud_org_for_api_access
use_cloud_org_for_api_access=self.use_cloud_org_for_api_access,
)

return service_client_class(transport=service_transport)

def get_type(self, name: str, version: str = _DEFAULT_VERSION) -> Union[ProtoPlusMessageType, ProtobufMessageType]:
def get_type(
self, name: str, version: str = _DEFAULT_VERSION
) -> Union[ProtoPlusMessageType, ProtobufMessageType]:
"""Returns the specified common, enum, error, or resource type.

Args:
Expand Down
26 changes: 17 additions & 9 deletions google/ads/googleads/config.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,6 @@
from typing import Any, Callable, List, Tuple, TypeVar, Union
import yaml


_logger = logging.getLogger(__name__)


Expand All @@ -35,7 +34,6 @@
"http_proxy",
"use_cloud_org_for_api_access",
"use_application_default_credentials",
"gaada",
)
_CONFIG_FILE_PATH_KEY = ("configuration_file_path",)
_OAUTH2_INSTALLED_APP_KEYS = ("client_id", "client_secret", "refresh_token")
Expand Down Expand Up @@ -96,7 +94,9 @@ def parser_wrapper(*args: Any, **kwargs: Any) -> Any:
parsed_config: dict[str, Any] = convert_login_customer_id_to_str(
config_dict
)
parsed_config: dict[str, Any] = convert_linked_customer_id_to_str(parsed_config)
parsed_config: dict[str, Any] = convert_linked_customer_id_to_str(
parsed_config
)

config_keys: List[str] = parsed_config.keys()

Expand All @@ -106,7 +106,9 @@ def parser_wrapper(*args: Any, **kwargs: Any) -> Any:
# that needs to be returned by this method.
if type(logging_config) is not dict:
try:
parsed_config["logging"]: dict[str, Any] = json.loads(logging_config)
parsed_config["logging"]: dict[str, Any] = json.loads(
logging_config
)
# The logger is configured here in case deprecation warnings
# need to be logged further down in this method. The logger
# is otherwise configured by the GoogleAdsClient class.
Expand Down Expand Up @@ -159,7 +161,9 @@ def parser_wrapper(*args: Any, **kwargs: Any) -> Any:
# the string "False" is truthy and can easily be incorrectly
# converted to the boolean True.
value: Union[str, bool] = parsed_config.get("use_proto_plus", False)
parsed_config["use_proto_plus"]: bool = disambiguate_string_bool(value)
parsed_config["use_proto_plus"]: bool = disambiguate_string_bool(
value
)

if "use_application_default_credentials" in config_keys:
# When loaded from YAML, YAML string or a dict, this value is
Expand All @@ -168,8 +172,12 @@ def parser_wrapper(*args: Any, **kwargs: Any) -> Any:
# variable we need to manually change it to the bool False because
# the string "False" is truthy and can easily be incorrectly
# converted to the boolean True.
value: Union[str, bool] = parsed_config.get("use_application_default_credentials", False)
parsed_config["use_application_default_credentials"]: bool = disambiguate_string_bool(value)
value: Union[str, bool] = parsed_config.get(
"use_application_default_credentials", False
)
parsed_config["use_application_default_credentials"]: bool = (
disambiguate_string_bool(value)
)

return parsed_config

Expand Down Expand Up @@ -380,7 +388,7 @@ def get_oauth2_required_service_account_keys() -> tuple[str, ...]:


def convert_login_customer_id_to_str(
config_data: dict[str, Any]
config_data: dict[str, Any],
) -> dict[str, Any]:
"""Parses a config dict's login_customer_id attr value to a str.

Expand All @@ -403,7 +411,7 @@ def convert_login_customer_id_to_str(


def convert_linked_customer_id_to_str(
config_data: dict[str, Any]
config_data: dict[str, Any],
) -> dict[str, Any]:
"""Parses a config dict's linked_customer_id attr value to a str.

Expand Down
Loading