|
| 1 | +# Copyright (c) 2025 Beijing Volcano Engine Technology Co., Ltd. and/or its affiliates. |
| 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 | +# Copyright (c) 2025 Beijing Volcano Engine Technology Co., Ltd. and/or its affiliates. |
| 16 | +# |
| 17 | +# Licensed under the Apache License, Version 2.0 (the "License"); |
| 18 | +# you may not use this file except in compliance with the License. |
| 19 | +# You may obtain a copy of the License at |
| 20 | +# |
| 21 | +# http://www.apache.org/licenses/LICENSE-2.0 |
| 22 | +# |
| 23 | +# Unless required by applicable law or agreed to in writing, software |
| 24 | +# distributed under the License is distributed on an "AS IS" BASIS, |
| 25 | +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 26 | +# See the License for the specific language governing permissions and |
| 27 | +# limitations under the License. |
| 28 | + |
| 29 | +import os |
| 30 | + |
| 31 | +from typing_extensions import override |
| 32 | + |
| 33 | +from veadk.auth.veauth.base_veauth import BaseVeAuth |
| 34 | +from veadk.utils.logger import get_logger |
| 35 | + |
| 36 | +# from veadk.utils.volcengine_sign import ve_request |
| 37 | + |
| 38 | +logger = get_logger(__name__) |
| 39 | + |
| 40 | + |
| 41 | +class OpensearchVeAuth(BaseVeAuth): |
| 42 | + def __init__( |
| 43 | + self, |
| 44 | + access_key: str = os.getenv("VOLCENGINE_ACCESS_KEY", ""), |
| 45 | + secret_key: str = os.getenv("VOLCENGINE_SECRET_KEY", ""), |
| 46 | + ) -> None: |
| 47 | + super().__init__(access_key, secret_key) |
| 48 | + |
| 49 | + self._token: str = "" |
| 50 | + |
| 51 | + @override |
| 52 | + def _fetch_token(self) -> None: |
| 53 | + logger.info("Fetching Opensearch STS token...") |
| 54 | + |
| 55 | + # res = ve_request( |
| 56 | + # request_body={}, |
| 57 | + # action="GetOrCreatePromptPilotAPIKeys", |
| 58 | + # ak=self.access_key, |
| 59 | + # sk=self.secret_key, |
| 60 | + # service="ark", |
| 61 | + # version="2024-01-01", |
| 62 | + # region="cn-beijing", |
| 63 | + # host="open.volcengineapi.com", |
| 64 | + # ) |
| 65 | + # try: |
| 66 | + # self._token = res["Result"]["APIKeys"][0]["APIKey"] |
| 67 | + # except KeyError: |
| 68 | + # raise ValueError(f"Failed to get Prompt Pilot token: {res}") |
| 69 | + |
| 70 | + @property |
| 71 | + def token(self) -> str: |
| 72 | + if self._token: |
| 73 | + return self._token |
| 74 | + self._fetch_token() |
| 75 | + return self._token |
0 commit comments