(client_klass, kaggle_kernel_credentials)
| 204 | logging.info("aiplatform.init patched") |
| 205 | |
| 206 | def monkeypatch_client(client_klass, kaggle_kernel_credentials): |
| 207 | client_init = client_klass.__init__ |
| 208 | def patched_init(self, *args, **kwargs): |
| 209 | specified_credentials = kwargs.get('credentials') |
| 210 | if specified_credentials is None: |
| 211 | logging.info("No credentials specified, using KaggleKernelCredentials.") |
| 212 | # Some GCP services demand the billing and target project must be the same. |
| 213 | # To avoid using default service account based credential as caller credential |
| 214 | # user need to provide ClientOptions with quota_project_id: |
| 215 | # srv.Client(client_options=client_options.ClientOptions(quota_project_id="YOUR PROJECT")) |
| 216 | client_options=kwargs.get('client_options') |
| 217 | if client_options != None and client_options.quota_project_id != None: |
| 218 | kwargs['credentials'] = KaggleKernelWithProjetCredentials( |
| 219 | parentCredential = kaggle_kernel_credentials, |
| 220 | quota_project_id = client_options.quota_project_id) |
| 221 | else: |
| 222 | kwargs['credentials'] = kaggle_kernel_credentials |
| 223 | |
| 224 | kwargs['client_info'] = set_kaggle_user_agent(kwargs.get('client_info')) |
| 225 | return client_init(self, *args, **kwargs) |
| 226 | |
| 227 | if (not has_been_monkeypatched(client_klass.__init__)): |
| 228 | client_klass.__init__ = patched_init |
| 229 | logging.info(f"Client patched: {client_klass}") |
| 230 | |
| 231 | def set_kaggle_user_agent(client_info: ClientInfo): |
| 232 | # Add kaggle client user agent in order to attribute usage. |
no test coverage detected