Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Convert timedelta.total_seconds() to integer in credential providers. #1081

Merged
merged 2 commits into from
Feb 12, 2021

Conversation

hardbyte
Copy link
Contributor

@hardbyte hardbyte commented Feb 9, 2021

Ensure duration in seconds is an integer.

Closes #1080

Ensure duration in seconds is an integer. Closes minio#1080
@@ -98,11 +98,11 @@ def __init__(
query_params = {
"Action": "AssumeRole",
"Version": "2011-06-15",
"DurationSeconds": str(
"DurationSeconds": str(int(
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The actual fix is

diff --git a/minio/credentials/providers.py b/minio/credentials/providers.py
index 00d73b8..1447a59 100644
--- a/minio/credentials/providers.py
+++ b/minio/credentials/providers.py
@@ -37,9 +37,9 @@ from minio.xml import find, findtext
 
 from .credentials import Credentials
 
-_MIN_DURATION_SECONDS = timedelta(minutes=15).total_seconds()
-_MAX_DURATION_SECONDS = timedelta(days=7).total_seconds()
-_DEFAULT_DURATION_SECONDS = timedelta(hours=1).total_seconds()
+_MIN_DURATION_SECONDS = int(timedelta(minutes=15).total_seconds())
+_MAX_DURATION_SECONDS = int(timedelta(days=7).total_seconds())
+_DEFAULT_DURATION_SECONDS = int(timedelta(hours=1).total_seconds())
 
 
 def _parse_credentials(data, name):

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fine by me, of course that assumes the user passes an int. If they pass a string the comparison won't work, if they pass a float the same issue comes up.

Personally I'd be in favor of actually using what ever the user provides - even if it is less than the default, only falling back to the default if a value hasn't been provided.

duration_seconds
if duration_seconds > _DEFAULT_DURATION_SECONDS
else _DEFAULT_DURATION_SECONDS

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If you worry about duration_seconds argument type, you can add a check to raise ValueError if it is not int. That is the right way to fix.

@balamurugana balamurugana changed the title Bugfix in AssumeRoleProvider Convert timedelta.total_seconds() to integer in credential providers. Feb 9, 2021
@balamurugana balamurugana merged commit e925b67 into minio:master Feb 12, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Issue using AssumeRoleProvider
3 participants