Skip to content

Commit 3ebfc4f

Browse files
committed
Updated pr.
1 parent 4d82169 commit 3ebfc4f

File tree

1 file changed

+19
-19
lines changed

1 file changed

+19
-19
lines changed

ads/common/auth.py

Lines changed: 19 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -22,21 +22,6 @@
2222
from oci.config import DEFAULT_LOCATION # "~/.oci/config"
2323
from oci.config import DEFAULT_PROFILE # "DEFAULT"
2424

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-
]
4025
SECURITY_TOKEN_LEFT_TIME = 600
4126

4227

@@ -768,6 +753,21 @@ class SecurityToken(AuthSignerGenerator):
768753
a given user - it requires that user's private key and security token.
769754
It prepares extra arguments necessary for creating clients for variety of OCI services.
770755
"""
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+
]
771771

772772
def __init__(self, args: Optional[Dict] = None):
773773
"""
@@ -823,7 +823,7 @@ def create_signer(self) -> Dict:
823823

824824
logger.info(f"Using 'security_token' authentication.")
825825

826-
for parameter in SECURITY_TOKEN_REQUIRED:
826+
for parameter in self.SECURITY_TOKEN_REQUIRED:
827827
if parameter not in configuration:
828828
raise ValueError(
829829
f"Parameter `{parameter}` must be provided for using `security_token` authentication."
@@ -838,8 +838,8 @@ def create_signer(self) -> Dict:
838838
private_key=oci.signer.load_private_key_from_file(
839839
configuration.get("key_file"), configuration.get("pass_phrase")
840840
),
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)
843843
),
844844
"client_kwargs": self.client_kwargs,
845845
}
@@ -860,7 +860,7 @@ def _validate_and_refresh_token(self, configuration: Dict[str, Any]):
860860

861861
if not security_token_container.valid():
862862
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."
864864
)
865865

866866
time_now = int(time.time())

0 commit comments

Comments
 (0)