@@ -102,7 +102,7 @@ def _validated_token_subject(value: object) -> str:
102102 return subject
103103
104104
105- def _token_subject (saved : dict , * , uses_persisted_credential : bool = True ) -> str :
105+ def _token_subject (saved : dict ) -> str :
106106 """Return the immutable subject bound to the current credential family.
107107
108108 ``ENGRAPHIS_CLOUD_TOKEN_SUBJECT`` selects the subject for an environment-only
@@ -111,13 +111,11 @@ def _token_subject(saved: dict, *, uses_persisted_credential: bool = True) -> st
111111 environment override win causes the next refresh to present (for example) a
112112 member credential as ``device``; the service must reject that mismatch, and the
113113 client then has to retire a credential that was never actually spent. Persisted
114- state therefore wins only while the selected credential itself is persisted.
115- A retired saved credential leaves its subject behind for auditability; a replacement
116- environment bootstrap credential must instead use its explicitly configured subject.
114+ state therefore wins whenever it carries a subject.
117115 """
118116
119117 persisted = saved .get ("token_subject" )
120- if uses_persisted_credential and persisted is not None and str (persisted ).strip ():
118+ if persisted is not None and str (persisted ).strip ():
121119 return _validated_token_subject (persisted )
122120 configured = os .environ .get ("ENGRAPHIS_CLOUD_TOKEN_SUBJECT" , "" ).strip ()
123121 return _validated_token_subject (configured or "member" )
@@ -796,15 +794,15 @@ def configured(*, require_compute: bool = True) -> bool:
796794 # A configured environment value is bootstrap material. After its first successful
797795 # use, the server-returned rotation is persisted and must take precedence; otherwise
798796 # every subsequent call would replay the now-invalid bootstrap credential.
799- saved_refresh = str (saved .get ("refresh_credential" ) or "" ).strip ()
800- refresh = saved_refresh or os .environ .get ("ENGRAPHIS_CLOUD_REFRESH_CREDENTIAL" , "" ).strip ()
797+ refresh = str (saved .get ("refresh_credential" ) or "" ).strip ()
798+ refresh = refresh or os .environ .get ("ENGRAPHIS_CLOUD_REFRESH_CREDENTIAL" , "" ).strip ()
801799 if _refresh_is_unusable (saved , refresh ):
802800 refresh = ""
803801 control = os .environ .get ("ENGRAPHIS_CLOUD_CONTROL_URL" , "" ).strip ()
804802 control = control or str (saved .get ("control_url" ) or "" ).strip ()
805803 compute = direct_compute or str (saved .get ("compute_url" ) or "" ).strip ()
806804 if refresh and control :
807- _token_subject (saved , uses_persisted_credential = bool ( saved_refresh ) )
805+ _token_subject (saved )
808806 return bool (refresh and control and (compute or not require_compute ))
809807
810808
@@ -839,8 +837,8 @@ def access_for_workspace(
839837 # single-use credential; reading it before the lock lets two workers spend the
840838 # same value and causes one request to fail as a replay.
841839 saved = _load ()
842- saved_refresh = str (saved .get ("refresh_credential" ) or "" ).strip ()
843- refresh = saved_refresh or os .environ .get (
840+ refresh = str (saved .get ("refresh_credential" ) or "" ).strip ()
841+ refresh = refresh or os .environ .get (
844842 "ENGRAPHIS_CLOUD_REFRESH_CREDENTIAL" , ""
845843 ).strip ()
846844 if _refresh_is_unusable (saved , refresh ):
@@ -858,9 +856,7 @@ def access_for_workspace(
858856 )
859857 control = _reachable_cloud_base_url (control )
860858 compute = _reachable_cloud_base_url (compute ) if compute else ""
861- token_subject = _token_subject (
862- saved , uses_persisted_credential = bool (saved_refresh )
863- )
859+ token_subject = _token_subject (saved )
864860 try :
865861 body = _post_refresh (control , refresh , workspace_id , token_subject )
866862 except CloudSessionError as exc :
0 commit comments