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

timezone issue in iso_date #962

Open
yasinzaehringer-paradime opened this issue Aug 27, 2024 · 3 comments
Open

timezone issue in iso_date #962

yasinzaehringer-paradime opened this issue Aug 27, 2024 · 3 comments

Comments

@yasinzaehringer-paradime
Copy link

yasinzaehringer-paradime commented Aug 27, 2024

Note the Network Visualization functionality (command prepare) is no longer maintained.

Please mention the following:

  • What command was run? -> python cloudmapper.py audit

  • Are you working out of a virtualenv environment, Docker, or something else? -> virtualenv

  • Which branch? -> main

Exception was:

Exception:
unconverted data remains: Z

Traceback (most recent call last):
 File "/tmp/airflow/cloudmapper/shared/audit.py", line 1195, in audit
   audit_users(findings, region)
 File "/tmp/airflow/cloudmapper/shared/audit.py", line 409, in audit_users
   user_age = days_between(collection_date, user["user_creation_time"])
 File "/tmp/airflow/cloudmapper/shared/common.py", line 348, in days_between
   d2 = iso_date(s2)
 File "/tmp/airflow/cloudmapper/shared/common.py", line 342, in iso_date
   return datetime.datetime.strptime(d.split("+")[0], time_format)
 File "/usr/local/lib/python3.9/_strptime.py", line 568, in _strptime_datetime
   tt, fraction, gmtoff_fraction = _strptime(data_string, format)
 File "/usr/local/lib/python3.9/_strptime.py", line 352, in _strptime
   raise ValueError("unconverted data remains: %s" %
ValueError: unconverted data remains: Z

The reason seems to be that these commands

aws iam generate-credential-report 
aws iam get-credential-report

return data which have timestamps which end with Z instead of +00:00 - which are both valid values. And https://github.com/duo-labs/cloudmapper/blob/main/shared/common.py#L342 assumes that it ends with +00:00.

@yasinzaehringer-paradime yasinzaehringer-paradime changed the title timezone issue in timezone issue in iso_date Aug 27, 2024
@crash7
Copy link

crash7 commented Sep 18, 2024

I fixed this by changing this to something like:

def iso_date(d):
    """Convert ISO format date string such as 2018-04-08T23:33:20+00:00"""
    time_format = "%Y-%m-%dT%H:%M:%S"
-    return datetime.datetime.strptime(d.split("+")[0], time_format)
+    return datetime.datetime.strptime(d.replace('Z', '').split("+")[0], time_format)

Probably a better fix would be to just consider dates won't have the +00:00 now, but didn't know if this was used somewhere else.

@reifyhealth-caseybecking

This change also worked for me!

@Anonymous-RD
Copy link

@yasinzaehringer-paradime please assign me this issue

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

No branches or pull requests

4 participants