pytorch-lightning
41 строка · 1.5 Кб
1# Copyright The Lightning AI team.
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
15from typing import Dict, Iterable
16
17from lightning.app.utilities.cloud import _get_project
18from lightning.app.utilities.network import LightningClient
19
20
21def _names_to_ids(secret_names: Iterable[str]) -> Dict[str, str]:
22"""Returns the name/ID pair for each given Secret name.
23
24Raises a `ValueError` if any of the given Secret names do not exist.
25
26"""
27lightning_client = LightningClient()
28
29project = _get_project(lightning_client)
30secrets = lightning_client.secret_service_list_secrets(project_id=project.project_id)
31
32secret_names_to_ids: Dict[str, str] = {}
33for secret in secrets.secrets:
34if secret.name in secret_names:
35secret_names_to_ids[secret.name] = secret.id
36
37for secret_name in secret_names:
38if secret_name not in secret_names_to_ids:
39raise ValueError(f"Secret with name '{secret_name}' not found")
40
41return secret_names_to_ids
42