|
| 1 | +# Copyright 2025 Google LLC |
| 2 | +# |
| 3 | +# Licensed under the Apache License, Version 2.0 (the "License"); |
| 4 | +# you may not use this file except in compliance with the License. |
| 5 | +# You may obtain a copy of the License at |
| 6 | +# |
| 7 | +# http://www.apache.org/licenses/LICENSE-2.0 |
| 8 | +# |
| 9 | +# Unless required by applicable law or agreed to in writing, software |
| 10 | +# distributed under the License is distributed on an "AS IS" BASIS, |
| 11 | +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 12 | +# See the License for the specific language governing permissions and |
| 13 | +# limitations under the License. |
| 14 | + |
| 15 | +"""Base credential exchanger interface.""" |
| 16 | + |
| 17 | +from __future__ import annotations |
| 18 | + |
| 19 | +import abc |
| 20 | +from typing import Optional |
| 21 | + |
| 22 | +from ...utils.feature_decorator import experimental |
| 23 | +from ..auth_credential import AuthCredential |
| 24 | +from ..auth_schemes import AuthScheme |
| 25 | + |
| 26 | + |
| 27 | +@experimental |
| 28 | +class BaseCredentialExchanger(abc.ABC): |
| 29 | + """Base interface for credential exchangers.""" |
| 30 | + |
| 31 | + @abc.abstractmethod |
| 32 | + async def exchange( |
| 33 | + self, |
| 34 | + auth_credential: AuthCredential, |
| 35 | + auth_scheme: Optional[AuthScheme] = None, |
| 36 | + ) -> AuthCredential: |
| 37 | + """Exchange credential if needed. |
| 38 | +
|
| 39 | + Args: |
| 40 | + auth_credential: The credential to exchange. |
| 41 | + auth_scheme: The authentication scheme (optional, some exchangers don't need it). |
| 42 | +
|
| 43 | + Returns: |
| 44 | + The exchanged credential. |
| 45 | +
|
| 46 | + Raises: |
| 47 | + ValueError: If credential exchange fails. |
| 48 | + """ |
| 49 | + pass |
0 commit comments