22
22
from oci .config import DEFAULT_LOCATION # "~/.oci/config"
23
23
from oci .config import DEFAULT_PROFILE # "DEFAULT"
24
24
25
- SECURITY_TOKEN_GENERIC_HEADERS = [
26
- "date" ,
27
- "(request-target)" ,
28
- "host"
29
- ]
30
- SECURITY_TOKEN_BODY_HEADERS = [
31
- "content-length" ,
32
- "content-type" ,
33
- "x-content-sha256"
34
- ]
35
- SECURITY_TOKEN_REQUIRED = [
36
- "security_token_file" ,
37
- "key_file" ,
38
- "region"
39
- ]
40
25
SECURITY_TOKEN_LEFT_TIME = 600
41
26
42
27
@@ -768,6 +753,21 @@ class SecurityToken(AuthSignerGenerator):
768
753
a given user - it requires that user's private key and security token.
769
754
It prepares extra arguments necessary for creating clients for variety of OCI services.
770
755
"""
756
+ SECURITY_TOKEN_GENERIC_HEADERS = [
757
+ "date" ,
758
+ "(request-target)" ,
759
+ "host"
760
+ ]
761
+ SECURITY_TOKEN_BODY_HEADERS = [
762
+ "content-length" ,
763
+ "content-type" ,
764
+ "x-content-sha256"
765
+ ]
766
+ SECURITY_TOKEN_REQUIRED = [
767
+ "security_token_file" ,
768
+ "key_file" ,
769
+ "region"
770
+ ]
771
771
772
772
def __init__ (self , args : Optional [Dict ] = None ):
773
773
"""
@@ -823,7 +823,7 @@ def create_signer(self) -> Dict:
823
823
824
824
logger .info (f"Using 'security_token' authentication." )
825
825
826
- for parameter in SECURITY_TOKEN_REQUIRED :
826
+ for parameter in self . SECURITY_TOKEN_REQUIRED :
827
827
if parameter not in configuration :
828
828
raise ValueError (
829
829
f"Parameter `{ parameter } ` must be provided for using `security_token` authentication."
@@ -838,8 +838,8 @@ def create_signer(self) -> Dict:
838
838
private_key = oci .signer .load_private_key_from_file (
839
839
configuration .get ("key_file" ), configuration .get ("pass_phrase" )
840
840
),
841
- generic_headers = configuration .get ("generic_headers" , SECURITY_TOKEN_GENERIC_HEADERS ),
842
- body_headers = configuration .get ("body_headers" , SECURITY_TOKEN_BODY_HEADERS )
841
+ generic_headers = configuration .get ("generic_headers" , self . SECURITY_TOKEN_GENERIC_HEADERS ),
842
+ body_headers = configuration .get ("body_headers" , self . SECURITY_TOKEN_BODY_HEADERS )
843
843
),
844
844
"client_kwargs" : self .client_kwargs ,
845
845
}
@@ -860,7 +860,7 @@ def _validate_and_refresh_token(self, configuration: Dict[str, Any]):
860
860
861
861
if not security_token_container .valid ():
862
862
raise SecurityTokenError (
863
- "Security token has expired. Call `oci session authenticate` to generate new session."
863
+ "Security token is invalid or has expired. Call `oci session authenticate` to generate new session."
864
864
)
865
865
866
866
time_now = int (time .time ())
0 commit comments