@@ -629,8 +629,8 @@ def create_signer(self) -> Dict:
629629 user = configuration ["user" ],
630630 fingerprint = configuration ["fingerprint" ],
631631 private_key_file_location = configuration .get ("key_file" ),
632- pass_phrase = configuration .get ("pass_phrase" ),
633- private_key_content = configuration .get ("key_content" )
632+ pass_phrase = configuration .get ("pass_phrase" ),
633+ private_key_content = configuration .get ("key_content" ),
634634 ),
635635 "client_kwargs" : self .client_kwargs ,
636636 }
@@ -750,21 +750,10 @@ class SecurityToken(AuthSignerGenerator):
750750 a given user - it requires that user's private key and security token.
751751 It prepares extra arguments necessary for creating clients for variety of OCI services.
752752 """
753- SECURITY_TOKEN_GENERIC_HEADERS = [
754- "date" ,
755- "(request-target)" ,
756- "host"
757- ]
758- SECURITY_TOKEN_BODY_HEADERS = [
759- "content-length" ,
760- "content-type" ,
761- "x-content-sha256"
762- ]
763- SECURITY_TOKEN_REQUIRED = [
764- "security_token_file" ,
765- "key_file" ,
766- "region"
767- ]
753+
754+ SECURITY_TOKEN_GENERIC_HEADERS = ["date" , "(request-target)" , "host" ]
755+ SECURITY_TOKEN_BODY_HEADERS = ["content-length" , "content-type" , "x-content-sha256" ]
756+ SECURITY_TOKEN_REQUIRED = ["security_token_file" , "key_file" , "region" ]
768757
769758 def __init__ (self , args : Optional [Dict ] = None ):
770759 """
@@ -831,12 +820,18 @@ def create_signer(self) -> Dict:
831820 return {
832821 "config" : configuration ,
833822 "signer" : oci .auth .signers .SecurityTokenSigner (
834- token = self ._read_security_token_file (configuration .get ("security_token_file" )),
823+ token = self ._read_security_token_file (
824+ configuration .get ("security_token_file" )
825+ ),
835826 private_key = oci .signer .load_private_key_from_file (
836827 configuration .get ("key_file" ), configuration .get ("pass_phrase" )
837828 ),
838- generic_headers = configuration .get ("generic_headers" , self .SECURITY_TOKEN_GENERIC_HEADERS ),
839- body_headers = configuration .get ("body_headers" , self .SECURITY_TOKEN_BODY_HEADERS )
829+ generic_headers = configuration .get (
830+ "generic_headers" , self .SECURITY_TOKEN_GENERIC_HEADERS
831+ ),
832+ body_headers = configuration .get (
833+ "body_headers" , self .SECURITY_TOKEN_BODY_HEADERS
834+ ),
840835 ),
841836 "client_kwargs" : self .client_kwargs ,
842837 }
@@ -849,30 +844,37 @@ def _validate_and_refresh_token(self, configuration: Dict[str, Any]):
849844 configuration: Dict
850845 Security token configuration.
851846 """
852- security_token = self ._read_security_token_file (configuration .get ("security_token_file" ))
853- security_token_container = oci .auth .security_token_container .SecurityTokenContainer (
854- session_key_supplier = None ,
855- security_token = security_token
847+ security_token = self ._read_security_token_file (
848+ configuration .get ("security_token_file" )
849+ )
850+ security_token_container = (
851+ oci .auth .security_token_container .SecurityTokenContainer (
852+ session_key_supplier = None , security_token = security_token
853+ )
856854 )
857855
858856 if not security_token_container .valid ():
859857 raise SecurityTokenError (
860858 "Security token has expired. Call `oci session authenticate` to generate new session."
861859 )
862-
860+
863861 time_now = int (time .time ())
864862 time_expired = security_token_container .get_jwt ()["exp" ]
865863 if time_expired - time_now < SECURITY_TOKEN_LEFT_TIME :
866864 if not self .oci_config_location :
867- logger .warning ("Can not auto-refresh token. Specify parameter `oci_config_location` through ads.set_auth() or ads.auth.create_signer()." )
865+ logger .warning (
866+ "Can not auto-refresh token. Specify parameter `oci_config_location` through ads.set_auth() or ads.auth.create_signer()."
867+ )
868868 else :
869- result = os .system (f"oci session refresh --config-file { self .oci_config_location } --profile { self .oci_key_profile } " )
869+ result = os .system (
870+ f"oci session refresh --config-file { self .oci_config_location } --profile { self .oci_key_profile } "
871+ )
870872 if result == 1 :
871873 logger .warning (
872874 "Some error happened during auto-refreshing the token. Continue using the current one that's expiring in less than {SECURITY_TOKEN_LEFT_TIME} seconds."
873875 "Please follow steps in https://docs.oracle.com/en-us/iaas/Content/API/SDKDocs/clitoken.htm to renew token."
874876 )
875-
877+
876878 date_time = datetime .fromtimestamp (time_expired ).strftime ("%Y-%m-%d %H:%M:%S" )
877879 logger .info (f"Session is valid until { date_time } ." )
878880
@@ -894,7 +896,7 @@ def _read_security_token_file(self, security_token_file: str) -> str:
894896 raise ValueError ("Invalid `security_token_file`. Specify a valid path." )
895897 try :
896898 token = None
897- with open (expanded_path , 'r' ) as f :
899+ with open (expanded_path , "r" ) as f :
898900 token = f .read ()
899901 return token
900902 except :
@@ -903,7 +905,7 @@ def _read_security_token_file(self, security_token_file: str) -> str:
903905
904906class AuthFactory :
905907 """
906- AuthFactory class which contains list of registered signers and alllows to register new signers.
908+ AuthFactory class which contains list of registered signers and allows to register new signers.
907909 Check documentation for more signers: https://docs.oracle.com/en-us/iaas/tools/python/latest/api/signing.html.
908910
909911 Current signers:
0 commit comments