L i-NXUddlmZddlZddlZddlmZmZmZmZm Z m Z ddl m Z ddl mZmZmZddlmZddlZddlmZmZddlmZmZdd lmZeeZd ed <Gd d ZeZ d ed<ddZ!ddZ"ddZ#Gdde e$efZ%Gdde e$efZ&e&Z'd ed<y)) annotationsN)Callable ItemsViewIteratorKeysViewMapping ValuesView)deepcopy)AnyFinalNoReturn)Signal)configruntime)StreamlitMaxRetriesErrorStreamlitSecretNotFoundError) get_loggerr _LOGGERceZdZdZddZddZddZddZ ddZ ddZ ddZ dd Z dd Z dd Z dd Zdd ZddZy)SecretErrorMessagesa"SecretErrorMessages stores all error messages we use for secrets to allow customization for different environments. For example Streamlit Cloud can customize the message to be different than the open source. For internal use, may change in future releases without notice. cdd|_d|_d|_d|_d|_d|_y)Ncd|dS)Nzst.secrets has no attribute "". Did you forget to add it to secrets.toml, mount it to secret directory, or the app settings on Streamlit Cloud? More info: https://docs.streamlit.io/deploy/streamlit-community-cloud/deploy-your-app/secrets-management attr_names _/mnt/ssd/data/python-lab/Trading/venv/lib/python3.12/site-packages/streamlit/runtime/secrets.pyz.SecretErrorMessages.__init__../s+I;7l lcd|dS)Nzst.secrets has no key "rrkeys rrz.SecretErrorMessages.__init__..5s%cU+l lrc*ddj|S)NzQNo secrets found. Valid paths for a secrets.toml file or secret directories are: z, )join) file_pathss rrz.SecretErrorMessages.__init__..;s_`d`i`ijt`u_v wrcd|d|S)NzError parsing secrets file at z: r)pathexs rrz.SecretErrorMessages.__init__..?s=dV2bTJrc |dS)Nzn is not a folder. To use directory based secrets, mount every secret in a subfolder under the secret directoryr)sub_folder_paths rrz.SecretErrorMessages.__init__..Bs"#$oorcd|dS)NzInvalid secrets path: z): path is not a .toml file or a directoryr)r's rrz.SecretErrorMessages.__init__..Gs$TF*S Tr)missing_attr_messagemissing_key_messageno_secrets_founderror_parsing_file_at_pathsubfolder_path_is_not_a_folderinvalid_secret_pathselfs r__init__zSecretErrorMessages.__init__.sE; ! :  =  K '  + :  rc||_y)z(Set the missing attribute error message.Nr,r3messages rset_missing_attr_messagez,SecretErrorMessages.set_missing_attr_messageKs $+!rc||_y)z"Set the missing key error message.Nr-r7s rset_missing_key_messagez+SecretErrorMessages.set_missing_key_messageO #* rc||_y)z'Set the no secrets found error message.Nr.r7s rset_no_secrets_found_messagez0SecretErrorMessages.set_no_secrets_found_messageSs 'rc||_y)z1Set the error parsing file at path error message.Nr/r7s r&set_error_parsing_file_at_path_messagez:SecretErrorMessages.set_error_parsing_file_at_path_messageWs +2'rc||_y)z5Set the subfolder path is not a folder error message.Nr0r7s r*set_subfolder_path_is_not_a_folder_messagez>SecretErrorMessages.set_subfolder_path_is_not_a_folder_message]s /6+rc||_y)z*Set the invalid secret path error message.Nr1r7s rset_invalid_secret_path_messagez3SecretErrorMessages.set_invalid_secret_path_messagecr=rc$|j|S)z(Get the missing attribute error message.r6)r3rs rget_missing_attr_messagez,SecretErrorMessages.get_missing_attr_messagegs((33rc$|j|S)z"Get the missing key error message.r;r3r"s rget_missing_key_messagez+SecretErrorMessages.get_missing_key_messageks'',,rc$|j|S)z'Get the no secrets found error message.r?)r3r%s rget_no_secrets_found_messagez0SecretErrorMessages.get_no_secrets_found_messageos$$Z00rc&|j||S)z1Get the error parsing file at path error message.rB)r3r'r(s r&get_error_parsing_file_at_path_messagez:SecretErrorMessages.get_error_parsing_file_at_path_messagess..tR88rc$|j|S)z5Get the subfolder path is not a folder error message.rE)r3r*s r*get_subfolder_path_is_not_a_folder_messagez>SecretErrorMessages.get_subfolder_path_is_not_a_folder_messagews22?CCrc$|j|S)z*Get the invalid secret path error message.rH)r3r's rget_invalid_secret_path_messagez3SecretErrorMessages.get_invalid_secret_path_message{s''--rNreturnNone)r8zCallable[[str], str]rXrY)r8zCallable[[list[str]], str]rXrY)r8zCallable[[str, Exception], str]rXrYrstrrXr[r"r[rXr[)r%z list[str]rXr[)r'r[r( ExceptionrXr[)r*r[rXr[)r'r[rXr[)__name__ __module__ __qualname____doc__r4r9r<r@rCrFrIrKrNrPrRrTrVrrrrr%si :,+(262 2 6+6 6 +4-19D.rrsecret_error_messages_singletonc t|tr|jS|jDcic](\}}|t|tr|jn|*c}}Scc}}w)z4Convert Mapping or AttrDict objects to dictionaries.) isinstanceAttrDictto_dictitems)objkvs r_convert_to_dictrksL#x {{}IL UAAjH5qyy{1 < UU Us-A%c,tj|SN)rbrKrs r_missing_attr_error_messagerns * C CI NNrc,tj|Srm)rbrNr!s r_missing_key_error_messagerps * B B3 GGrcjeZdZdZd dZeddZddZddZddZ ddZ ddZ dd Z dd Z dd Zy )rezkWe use AttrDict to wrap up dictionary values from secrets to provide dot access to nested secrets. c4t||jd<y)N__nested_secrets__)dict__dict__)r3values rr4zAttrDict.__init__s.25k *+rc<t|ts|St|Srm)rdrre)rvs r_maybe_wrap_in_attr_dictz!AttrDict._maybe_wrap_in_attr_dicts%)Lrc,t|jSrm)lenrsr2s r__len__zAttrDict.__len__s4**++rc,t|jSrm)iterrsr2s r__iter__zAttrDict.__iter__D++,,rc |j|}|j|S#t$rtt|wxYwrm)rsrxKeyErrorrpr3r"rvs r __getitem__zAttrDict.__getitem__sH <++C0E007 7 <5c:; ; < "Ac |j|}|j|S#t$rtt |wxYwrm)rsrxrAttributeErrorrn)r3rrvs r __getattr__zAttrDict.__getattr__sK I++I6E007 7 I !1771= > DM  ! ! !sA(;A((A1cji}d} t|d5}|j}dddd} ddl}|j |j ||fS#1swY4xYw#t$ridfcYSwxYw#t jf$r'}tj||}t||d}~wwxYw)z9Parse a TOML file and return the secrets as a dictionary.Fzutf-8)encodingNTr) openreadFileNotFoundErrortomlupdateloadsrTomlDecodeErrorrbrRr) r3r'secretsfound_secrets_filefsecrets_file_strrr(msgs r_parse_toml_filezSecrets._parse_toml_files" dW- ,#$668  ,"&  <  NN4::&67 8***) , ,! u9  4//0 </VV"  /s3 ;  A#A A#$A6A A## A32A36B2 "B--B2ci}d}tj|D]2}tjj||}tjj |s t j |}t|i}tj|D]y}tjj||} tjj | rCt| 5} | jj||<d}ddd{t|dk(r*|tt|j||<.|||<5||fS#1swYxYw)aParse a directory for secrets. Directory style can be used to support Kubernetes secrets that are mounted to folders. Example structure: - top_level_secret_folder - user_pass_secret (folder) - username (file), content: myuser - password (file), content: mypassword - my_plain_secret (folder) - regular_secret (file), content: mysecret See: https://kubernetes.io/docs/tasks/inject-data-application/distribute-credentials-secure/#create-a-pod-that-has-access-to-the-secret-data-through-a-volume And: https://docs.snowflake.com/en/developer-guide/snowpark-container-services/additional-considerations-services-jobs#passing-secrets-in-local-container-files FTN)oslistdirr'r$isdirrbrTrrrstriprznextr}keys) r3r'rrdirnamer* error_msg sub_secretsfilename file_pathrs r_parse_directoryzSecrets._parse_directorys:#%"zz$' /G ggll49O77==1;ff# 39==KJJ7 .GGLL(C 77==+)_.,-FFHNN,C= C$C!C$ C!!C$$C-c|j5tjd||j|j ddd|j j y#1swY$xYw)Nz!Secret path %s changed, reloading)rrdebugrrrsend)r3changed_file_paths rrzSecrets._on_secrets_changedsT ZZ  MM=?P Q KKM KKM  !!&&(  s 7A''A0c |j|}t|ts|St|S#tt f$rt t|wxYw)z{Return the value with the given key. If no such key exists, raise an AttributeError. Thread-safe. )rrdrrerrrrnrs rrzSecrets.__getattr__s[  CKKM#&EeW- E? "+, C !rrrrr"_suppress_print_error_on_exceptionr)superrr)r3r"rv __class__s rrzSecrets.__setattr__s-    G U +LM Mrctjs|jjSt |j S)zAA string representation of the contents of the dict. Thread-safe.)rexistsrr^rrr2s rrzSecrets.__repr__s2 ~~nn--. /DKKM""rc4t|jS)z/The number of entries in the dict. Thread-safe.)rzrr2s rr{zSecrets.__len__s4;;=!!rc&||jvSz2True if the given key is in the dict. Thread-safe.r)r3ris rhas_keyzSecrets.has_keysDKKM!!rc>|jjS)z,A view of the keys in the dict. Thread-safe.)rrr2s rrz Secrets.keyss{{}!!##rc>|jjS)z.A view of the values in the dict. Thread-safe.)rvaluesr2s rrzSecrets.valuess{{}##%%rc>|jjS)z7A view of the key-value items in the dict. Thread-safe.)rrgr2s rrgz Secrets.items s{{}""$$rc&||jvSrrrMs r __contains__zSecrets.__contains__ sdkkm##rc4t|jS)z3An iterator over the keys in the dict. Thread-safe.)r}rr2s rr~zSecrets.__iter__sDKKM""rrW)rXbool)rrrXrY)r'r[rXztuple[Mapping[str, Any], bool])rXrr)rir rjr rXrY)rr[rXrYr)r"r[rvr rXrYrr)rir[rXr)rXz KeysView[str])rXzValuesView[Any])rXzItemsView[str, Any])r"r rXrr)r^r_r`rar4rrrrrrrrfrrrrrrrrrr{rrrrgrr~ __classcell__)rs@rrrs  " 15   !+8,+\ 61!f)##1<)C < N#""$&%$#rrsecrets_singleton)rhzMapping[str, Any] | AttrDictrXrrZr\)( __future__rrrcollections.abcrrrrrr copyr typingr r r blinkerrstreamlit.watcher.path_watcherrrrstreamlit.errorsrrstreamlit.loggerrr^r__annotations__rrbrkrnrpr[rerrrrrr s# XX %%S'H%%X.X.v*=)>>VOH,1wsCx ,1^R#gc3hR#j #95$r