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

IAM: Performance improvements #7123

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
8 changes: 2 additions & 6 deletions moto/iam/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -474,12 +474,8 @@ def from_data(cls, name: str, account_id: str, data: Dict[str, Any]) -> "AWSMana
default_version_id=data.get("DefaultVersionId"),
path=data.get("Path"),
document=json.dumps(data.get("Document")),
create_date=datetime.strptime(
data.get("CreateDate"), "%Y-%m-%dT%H:%M:%S+00:00" # type: ignore[arg-type]
),
update_date=datetime.strptime(
data.get("UpdateDate"), "%Y-%m-%dT%H:%M:%S+00:00" # type: ignore[arg-type]
),
create_date=datetime.fromisoformat(data["CreateDate"]),
update_date=datetime.fromisoformat(data["UpdateDate"]),
)

@property
Expand Down
18 changes: 5 additions & 13 deletions moto/iam/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -38,16 +38,12 @@ def generate_access_key_id_from_account_id(


def random_alphanumeric(length: int) -> str:
return "".join(
str(random.choice(string.ascii_letters + string.digits + "+" + "/"))
for _ in range(length)
)
options = string.ascii_letters + string.digits + "+" + "/"
return "".join(random.choices(options, k=length))


def random_resource_id(size: int = 20) -> str:
chars = list(range(10)) + list(string.ascii_lowercase)

return "".join(str(random.choice(chars)) for x in range(size))
return "".join(random.choices(string.ascii_lowercase + string.digits, k=size))


def random_role_id(account_id: str) -> str:
Expand All @@ -57,12 +53,8 @@ def random_role_id(account_id: str) -> str:


def random_access_key() -> str:
return "".join(
str(random.choice(string.ascii_uppercase + string.digits)) for _ in range(16)
)
return "".join(random.choices(string.ascii_uppercase + string.digits, k=16))


def random_policy_id() -> str:
return "A" + "".join(
random.choice(string.ascii_uppercase + string.digits) for _ in range(20)
)
return "A" + "".join(random.choices(string.ascii_uppercase + string.digits, k=20))