Skip to content

Commit

Permalink
Cleanup IAM user create format. Closes #898.
Browse files Browse the repository at this point in the history
  • Loading branch information
spulec committed Apr 14, 2017
1 parent d35e143 commit 34c7111
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 6 deletions.
4 changes: 4 additions & 0 deletions moto/core/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -170,6 +170,10 @@ def iso_8601_datetime_with_milliseconds(datetime):
return datetime.strftime("%Y-%m-%dT%H:%M:%S.%f")[:-3] + 'Z'


def iso_8601_datetime_without_milliseconds(datetime):
return datetime.strftime("%Y-%m-%dT%H:%M:%S") + 'Z'


def rfc_1123_datetime(datetime):
RFC1123 = '%a, %d %b %Y %H:%M:%S GMT'
return datetime.strftime(RFC1123)
Expand Down
12 changes: 7 additions & 5 deletions moto/iam/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@

import pytz
from moto.core import BaseBackend, BaseModel
from moto.core.utils import iso_8601_datetime_without_milliseconds

from .exceptions import IAMNotFoundException, IAMConflictException, IAMReportNotPresentException
from .utils import random_access_key, random_alphanumeric, random_resource_id, random_policy_id
Expand Down Expand Up @@ -235,10 +236,7 @@ def __init__(self, name, path=None):
self.name = name
self.id = random_resource_id()
self.path = path if path else "/"
self.created = datetime.strftime(
datetime.utcnow(),
"%Y-%m-%d-%H-%M-%S"
)
self.created = datetime.utcnow()
self.mfa_devices = {}
self.policies = {}
self.access_keys = []
Expand All @@ -248,6 +246,10 @@ def __init__(self, name, path=None):
def arn(self):
return "arn:aws:iam::{0}:user{1}{2}".format(ACCOUNT_ID, self.path, self.name)

@property
def created_iso_8601(self):
return iso_8601_datetime_without_milliseconds(self.created)

def get_policy(self, policy_name):
policy_json = None
try:
Expand Down Expand Up @@ -310,7 +312,7 @@ def get_cfn_attribute(self, attribute_name):

def to_csv(self):
date_format = '%Y-%m-%dT%H:%M:%S+00:00'
date_created = datetime.strptime(self.created, '%Y-%m-%d-%H-%M-%S')
date_created = self.created
# aagrawal,arn:aws:iam::509284790694:user/aagrawal,2014-09-01T22:28:48+00:00,true,2014-11-12T23:36:49+00:00,2014-09-03T18:59:00+00:00,N/A,false,true,2014-09-01T22:28:48+00:00,false,N/A,false,N/A,false,N/A
if not self.password:
password_enabled = 'false'
Expand Down
2 changes: 1 addition & 1 deletion moto/iam/responses.py
Original file line number Diff line number Diff line change
Expand Up @@ -823,7 +823,7 @@ def get_credential_report(self):
<UserId>{{ user.id }}</UserId>
<Path>{{ user.path }}</Path>
<UserName>{{ user.name }}</UserName>
<CreateDate>{{ user.created }}</CreateDate>
<CreateDate>{{ user.created_iso_8601 }}</CreateDate>
<Arn>{{ user.arn }}</Arn>
</member>
{% endfor %}
Expand Down

0 comments on commit 34c7111

Please sign in to comment.