How to use moto_role_to_role_type method in localstack

Best Python code snippet using localstack_python

provider.py

Source:provider.py Github

copy

Full Screen

...144 policy.detach_from(role)145 except KeyError:146 raise IAMNotFoundException("Policy {0} was not found.".format(policy_arn))147 @staticmethod148 def moto_role_to_role_type(moto_role: MotoRole) -> Role:149 role = Role()150 role["Path"] = moto_role.path151 role["RoleName"] = moto_role.name152 role["RoleId"] = moto_role.id153 role["Arn"] = moto_role.arn154 role["CreateDate"] = moto_role.create_date155 if moto_role.assume_role_policy_document:156 role["AssumeRolePolicyDocument"] = moto_role.assume_role_policy_document157 if moto_role.description:158 role["Description"] = moto_role.description159 if moto_role.max_session_duration:160 role["MaxSessionDuration"] = moto_role.max_session_duration161 if moto_role.permissions_boundary:162 role["PermissionsBoundary"] = moto_role.permissions_boundary163 if moto_role.tags:164 role["Tags"] = [Tag(Key=k, Value=v) for k, v in moto_role.tags.items()]165 # role["RoleLastUsed"]: # TODO: add support166 return role167 def list_roles(168 self,169 context: RequestContext,170 path_prefix: pathPrefixType = None,171 marker: markerType = None,172 max_items: maxItemsType = None,173 ) -> ListRolesResponse:174 moto_roles = moto_iam_backend.roles.values()175 if path_prefix:176 moto_roles = filter_items_with_path_prefix(path_prefix, moto_roles)177 moto_roles = sorted(moto_roles, key=lambda role: role.id)178 response_roles = []179 for moto_role in moto_roles:180 response_role = self.moto_role_to_role_type(moto_role)181 response_roles.append(response_role)182 if (183 path_prefix184 ): # TODO: this is consistent with the patch it migrates, but should add tests for this.185 response_role["AssumeRolePolicyDocument"] = quote(186 json.dumps(moto_role.assume_role_policy_document or {})187 )188 return ListRolesResponse(Roles=response_roles, IsTruncated=False)189 def update_group(190 self,191 context: RequestContext,192 group_name: groupNameType,193 new_path: pathType = None,194 new_group_name: groupNameType = None,195 ) -> None:196 new_group_name = new_group_name or group_name197 group = moto_iam_backend.get_group(group_name)198 group.path = new_path199 group.name = new_group_name200 moto_iam_backend.groups[new_group_name] = moto_iam_backend.groups.pop(group_name)201 def list_instance_profile_tags(202 self,203 context: RequestContext,204 instance_profile_name: instanceProfileNameType,205 marker: markerType = None,206 max_items: maxItemsType = None,207 ) -> ListInstanceProfileTagsResponse:208 profile = moto_iam_backend.get_instance_profile(instance_profile_name)209 response = ListInstanceProfileTagsResponse()210 response["Tags"] = [Tag(Key=k, Value=v) for k, v in profile.tags.items()]211 return response212 def tag_instance_profile(213 self,214 context: RequestContext,215 instance_profile_name: instanceProfileNameType,216 tags: tagListType,217 ) -> None:218 profile = moto_iam_backend.get_instance_profile(instance_profile_name)219 value_by_key = {tag["Key"]: tag["Value"] for tag in tags}220 profile.tags.update(value_by_key)221 def untag_instance_profile(222 self,223 context: RequestContext,224 instance_profile_name: instanceProfileNameType,225 tag_keys: tagKeyListType,226 ) -> None:227 profile = moto_iam_backend.get_instance_profile(instance_profile_name)228 for tag in tag_keys:229 profile.tags.pop(tag, None)230 def create_service_linked_role(231 self,232 context: RequestContext,233 aws_service_name: groupNameType,234 description: roleDescriptionType = None,235 custom_suffix: customSuffixType = None,236 ) -> CreateServiceLinkedRoleResponse:237 # TODO: test238 # TODO: how to support "CustomSuffix" API request parameter?239 policy_doc = json.dumps(240 {241 "Version": "2012-10-17",242 "Statement": [243 {244 "Effect": "Allow",245 "Principal": {"Service": aws_service_name},246 "Action": "sts:AssumeRole",247 }248 ],249 }250 )251 path = f"{SERVICE_LINKED_ROLE_PATH_PREFIX}/{aws_service_name}"252 role_name = f"r-{short_uid()}"253 role = moto_iam_backend.create_role(254 role_name=role_name,255 assume_role_policy_document=policy_doc,256 path=path,257 permissions_boundary="",258 description=description,259 tags={},260 max_session_duration=3600,261 )262 role.service_linked_role_arn = "arn:aws:iam::{0}:role/aws-service-role/{1}/{2}".format(263 constants.TEST_AWS_ACCOUNT_ID, aws_service_name, role.name264 )265 res_role = self.moto_role_to_role_type(role)266 return CreateServiceLinkedRoleResponse(Role=res_role)267 def delete_service_linked_role(268 self, context: RequestContext, role_name: roleNameType269 ) -> DeleteServiceLinkedRoleResponse:270 # TODO: test271 moto_iam_backend.delete_role(role_name)272 return DeleteServiceLinkedRoleResponse(DeletionTaskId=short_uid())273 def get_service_linked_role_deletion_status(274 self, context: RequestContext, deletion_task_id: DeletionTaskIdType275 ) -> GetServiceLinkedRoleDeletionStatusResponse:276 # TODO: test277 return GetServiceLinkedRoleDeletionStatusResponse(Status=DeletionTaskStatusType.SUCCEEDED)278 # def get_user(279 # self, context: RequestContext, user_name: existingUserNameType = None...

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