1
1
import os
2
2
from collections .abc import Mapping
3
3
from pathlib import Path
4
- from typing import Dict
4
+ from typing import Dict , Optional
5
+
6
+ SECRETS_DOC_LINK = "https://truss.baseten.co/docs/using-secrets"
5
7
6
8
7
9
class SecretNotFound (Exception ):
@@ -17,7 +19,7 @@ def get_secrets(config: Dict):
17
19
return Secrets (config .get ("secrets" , {}))
18
20
19
21
@staticmethod
20
- def _resolve_secret (secret_name : str , default_value : str ):
22
+ def _resolve_secret (secret_name : str , default_value : Optional [ str ] ):
21
23
secret_value = default_value
22
24
secret_env_var_name = SecretsResolver .SECRET_ENV_VAR_PREFIX + secret_name
23
25
if secret_env_var_name in os .environ :
@@ -39,15 +41,11 @@ def __init__(self, base_secrets: Dict[str, str]):
39
41
40
42
def __getitem__ (self , key : str ) -> str :
41
43
if key not in self ._base_secrets :
42
- # Note this is the case where the secrets are not specified in
43
- # config.yaml
44
- raise SecretNotFound (f"Secret '{ key } ' not specified in the config." )
44
+ raise SecretNotFound (_secret_missing_error_message (key ))
45
45
46
46
found_secret = SecretsResolver ._resolve_secret (key , self ._base_secrets [key ])
47
47
if not found_secret :
48
- raise SecretNotFound (
49
- f"Secret '{ key } ' not found. Please check available secrets."
50
- )
48
+ raise SecretNotFound (_secret_missing_error_message (key ))
51
49
52
50
return found_secret
53
51
@@ -58,3 +56,13 @@ def __iter__(self):
58
56
59
57
def __len__ (self ):
60
58
return len (self ._base_secrets )
59
+
60
+
61
+ def _secret_missing_error_message (key : str ) -> str :
62
+ return f"""
63
+ Secret '{ key } ' not found. Please ensure that:
64
+ * Secret '{ key } ' is defined in the 'secrets' section of the Truss config file
65
+ * The model was pushed with the --trusted flag
66
+ * Secret '{ key } ' is defined in the secret manager
67
+ Read more about secrets here: { SECRETS_DOC_LINK } .
68
+ """
0 commit comments