1# -*- coding: utf-8 -*-
2# Copyright 2025 Google LLC
3#
4# Licensed under the Apache License, Version 2.0 (the "License");
5# you may not use this file except in compliance with the License.
6# You may obtain a copy of the License at
7#
8# http://www.apache.org/licenses/LICENSE-2.0
9#
10# Unless required by applicable law or agreed to in writing, software
11# distributed under the License is distributed on an "AS IS" BASIS,
12# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13# See the License for the specific language governing permissions and
14# limitations under the License.
15#
16import abc
17from typing import Awaitable, Callable, Dict, Optional, Sequence, Union
18
19from google.cloud.errorreporting_v1beta1 import gapic_version as package_version
20
21import google.auth # type: ignore
22import google.api_core
23from google.api_core import exceptions as core_exceptions
24from google.api_core import gapic_v1
25from google.api_core import retry as retries
26from google.auth import credentials as ga_credentials # type: ignore
27from google.oauth2 import service_account # type: ignore
28import google.protobuf
29
30from google.cloud.errorreporting_v1beta1.types import error_stats_service
31
32DEFAULT_CLIENT_INFO = gapic_v1.client_info.ClientInfo(
33 gapic_version=package_version.__version__
34)
35
36if hasattr(DEFAULT_CLIENT_INFO, "protobuf_runtime_version"): # pragma: NO COVER
37 DEFAULT_CLIENT_INFO.protobuf_runtime_version = google.protobuf.__version__
38
39
40class ErrorStatsServiceTransport(abc.ABC):
41 """Abstract transport class for ErrorStatsService."""
42
43 AUTH_SCOPES = ("https://www.googleapis.com/auth/cloud-platform",)
44
45 DEFAULT_HOST: str = "clouderrorreporting.googleapis.com"
46
47 def __init__(
48 self,
49 *,
50 host: str = DEFAULT_HOST,
51 credentials: Optional[ga_credentials.Credentials] = None,
52 credentials_file: Optional[str] = None,
53 scopes: Optional[Sequence[str]] = None,
54 quota_project_id: Optional[str] = None,
55 client_info: gapic_v1.client_info.ClientInfo = DEFAULT_CLIENT_INFO,
56 always_use_jwt_access: Optional[bool] = False,
57 api_audience: Optional[str] = None,
58 **kwargs,
59 ) -> None:
60 """Instantiate the transport.
61
62 Args:
63 host (Optional[str]):
64 The hostname to connect to (default: 'clouderrorreporting.googleapis.com').
65 credentials (Optional[google.auth.credentials.Credentials]): The
66 authorization credentials to attach to requests. These
67 credentials identify the application to the service; if none
68 are specified, the client will attempt to ascertain the
69 credentials from the environment.
70 credentials_file (Optional[str]): A file with credentials that can
71 be loaded with :func:`google.auth.load_credentials_from_file`.
72 This argument is mutually exclusive with credentials.
73 scopes (Optional[Sequence[str]]): A list of scopes.
74 quota_project_id (Optional[str]): An optional project to use for billing
75 and quota.
76 client_info (google.api_core.gapic_v1.client_info.ClientInfo):
77 The client info used to send a user-agent string along with
78 API requests. If ``None``, then default info will be used.
79 Generally, you only need to set this if you're developing
80 your own client library.
81 always_use_jwt_access (Optional[bool]): Whether self signed JWT should
82 be used for service account credentials.
83 """
84
85 scopes_kwargs = {"scopes": scopes, "default_scopes": self.AUTH_SCOPES}
86
87 # Save the scopes.
88 self._scopes = scopes
89 if not hasattr(self, "_ignore_credentials"):
90 self._ignore_credentials: bool = False
91
92 # If no credentials are provided, then determine the appropriate
93 # defaults.
94 if credentials and credentials_file:
95 raise core_exceptions.DuplicateCredentialArgs(
96 "'credentials_file' and 'credentials' are mutually exclusive"
97 )
98
99 if credentials_file is not None:
100 credentials, _ = google.auth.load_credentials_from_file(
101 credentials_file, **scopes_kwargs, quota_project_id=quota_project_id
102 )
103 elif credentials is None and not self._ignore_credentials:
104 credentials, _ = google.auth.default(
105 **scopes_kwargs, quota_project_id=quota_project_id
106 )
107 # Don't apply audience if the credentials file passed from user.
108 if hasattr(credentials, "with_gdch_audience"):
109 credentials = credentials.with_gdch_audience(
110 api_audience if api_audience else host
111 )
112
113 # If the credentials are service account credentials, then always try to use self signed JWT.
114 if (
115 always_use_jwt_access
116 and isinstance(credentials, service_account.Credentials)
117 and hasattr(service_account.Credentials, "with_always_use_jwt_access")
118 ):
119 credentials = credentials.with_always_use_jwt_access(True)
120
121 # Save the credentials.
122 self._credentials = credentials
123
124 # Save the hostname. Default to port 443 (HTTPS) if none is specified.
125 if ":" not in host:
126 host += ":443"
127 self._host = host
128
129 @property
130 def host(self):
131 return self._host
132
133 def _prep_wrapped_messages(self, client_info):
134 # Precompute the wrapped methods.
135 self._wrapped_methods = {
136 self.list_group_stats: gapic_v1.method.wrap_method(
137 self.list_group_stats,
138 default_timeout=None,
139 client_info=client_info,
140 ),
141 self.list_events: gapic_v1.method.wrap_method(
142 self.list_events,
143 default_timeout=None,
144 client_info=client_info,
145 ),
146 self.delete_events: gapic_v1.method.wrap_method(
147 self.delete_events,
148 default_timeout=None,
149 client_info=client_info,
150 ),
151 }
152
153 def close(self):
154 """Closes resources associated with the transport.
155
156 .. warning::
157 Only call this method if the transport is NOT shared
158 with other clients - this may cause errors in other clients!
159 """
160 raise NotImplementedError()
161
162 @property
163 def list_group_stats(
164 self,
165 ) -> Callable[
166 [error_stats_service.ListGroupStatsRequest],
167 Union[
168 error_stats_service.ListGroupStatsResponse,
169 Awaitable[error_stats_service.ListGroupStatsResponse],
170 ],
171 ]:
172 raise NotImplementedError()
173
174 @property
175 def list_events(
176 self,
177 ) -> Callable[
178 [error_stats_service.ListEventsRequest],
179 Union[
180 error_stats_service.ListEventsResponse,
181 Awaitable[error_stats_service.ListEventsResponse],
182 ],
183 ]:
184 raise NotImplementedError()
185
186 @property
187 def delete_events(
188 self,
189 ) -> Callable[
190 [error_stats_service.DeleteEventsRequest],
191 Union[
192 error_stats_service.DeleteEventsResponse,
193 Awaitable[error_stats_service.DeleteEventsResponse],
194 ],
195 ]:
196 raise NotImplementedError()
197
198 @property
199 def kind(self) -> str:
200 raise NotImplementedError()
201
202
203__all__ = ("ErrorStatsServiceTransport",)