How to use get_access_key_last_used method in localstack

Best Python code snippet using localstack_python

aws-user-analyzer_v2.py

Source:aws-user-analyzer_v2.py Github

copy

Full Screen

...58 """59 get_access_key_last_used60 https://boto3.amazonaws.com/v1/documentation/api/latest/reference/services/iam.html#IAM.Client.get_access_key_last_used61 """62 r = IAMc.get_access_key_last_used(AccessKeyId=k)63 # R["get_access_key_last_used"][u["UserName"]] = r64 # USERS[u["UserName"]]["access_keys"][state][k].update(r["AccessKeyLastUsed"])65 return r66def ORGANIZE_ACCESS_KEYS(K):67 """68 Concise organization for user keys69 """70 if K:71 DATA = {"active":{}, "inactive":{}}72 for k in K:73 if k["Status"] == "Active":74 DATA["active"].update({k["AccessKeyId"]: {"CreateDate":k["CreateDate"]}})75 elif k["Status"] == "Inactive":76 DATA["inactive"].update({k["AccessKeyId"]: {"CreateDate":k["CreateDate"]}})...

Full Screen

Full Screen

test_aws_iam_client_for_audit_access_keys.py

Source:test_aws_iam_client_for_audit_access_keys.py Github

copy

Full Screen

...71 assert len(caplog.records) == 172 assert caplog.records[0].levelname == "WARNING"73 assert "unable to list access keys" in caplog.text74 assert "boom" in caplog.text75def test_get_access_key_last_used() -> None:76 last_used = datetime.now()77 mock_boto_iam = Mock(get_access_key_last_used=Mock(return_value={"AccessKeyLastUsed": {"LastUsedDate": last_used}}))78 key_id = "keyId"79 key = AccessKey(user_name="user", id=key_id, created=datetime.now())80 assert last_used == AwsIamAuditClient(mock_boto_iam).get_access_key_last_used(key)81 mock_boto_iam.get_access_key_last_used.assert_called_with(AccessKeyId=key_id)82def test_get_access_key_last_used_none() -> None:83 mock_boto_iam = Mock(get_access_key_last_used=Mock(return_value={"AccessKeyLastUsed": {}}))84 key = AccessKey(user_name="user", id="keyId", created=datetime.now())85 assert AwsIamAuditClient(mock_boto_iam).get_access_key_last_used(key) is None86def test_get_access_key_last_used_exception_returns_none(caplog: Any) -> None:87 mock_boto_iam = Mock(88 get_access_key_last_used=Mock(side_effect=client_error("GetAccessKeyLastUsed", "bad stuff", "error"))89 )90 key = AccessKey(user_name="user", id="keyId", created=datetime.now())91 with caplog.at_level(logging.INFO):92 assert AwsIamAuditClient(mock_boto_iam).get_access_key_last_used(key) is None93 assert len(caplog.records) == 194 assert caplog.records[0].levelname == "WARNING"95 assert "unable to get access key last used for key: keyId" in caplog.text...

Full Screen

Full Screen

EnsureSingleAccessKeyPerUser.py

Source:EnsureSingleAccessKeyPerUser.py Github

copy

Full Screen

...15 return True #Here as a default case, code should never reach this point16#Disables the access key not used most recently.17def disable_key(keys, username, client):18 #Covers null last used date19 if 'LastUsedDate' in client.get_access_key_last_used(AccessKeyId=keys[0]['AccessKeyId'])['AccessKeyLastUsed']:20 time0 = client.get_access_key_last_used(AccessKeyId=keys[0]['AccessKeyId'])['AccessKeyLastUsed']['LastUsedDate']21 else:22 time0 = 023 if 'LastUsedDate' in client.get_access_key_last_used(AccessKeyId=keys[1]['AccessKeyId'])['AccessKeyLastUsed']:24 time1 = client.get_access_key_last_used(AccessKeyId=keys[1]['AccessKeyId'])['AccessKeyLastUsed']['LastUsedDate']25 else:26 time1 = 027 #Compares last used dates and disables keys28 if compare_times(time0, time1):29 client.update_access_key(AccessKeyId=keys[1]['AccessKeyId'], UserName=username, Status='Inactive')30 else:31 client.update_access_key(AccessKeyId=keys[0]['AccessKeyId'], UserName=username, Status='Inactive')32#Determines if multiple access keys are active for a single user33def multiple_active_keys(user_keys, name, client):34 if len(user_keys) < 2:35 return False36 count = 037 for key in user_keys:38 if key['Status'] == 'Active':...

Full Screen

Full Screen

Automation Testing Tutorials

Learn to execute automation testing from scratch with LambdaTest Learning Hub. Right from setting up the prerequisites to run your first automation test, to following best practices and diving deeper into advanced test scenarios. LambdaTest Learning Hubs compile a list of step-by-step guides to help you be proficient with different test automation frameworks i.e. Selenium, Cypress, TestNG etc.

LambdaTest Learning Hubs:

YouTube

You could also refer to video tutorials over LambdaTest YouTube channel to get step by step demonstration from industry experts.

Run localstack automation tests on LambdaTest cloud grid

Perform automation testing on 3000+ real desktop and mobile devices online.

Try LambdaTest Now !!

Get 100 minutes of automation test minutes FREE!!

Next-Gen App & Browser Testing Cloud

Was this article helpful?

Helpful

NotHelpful