Get and return all IAM role details, starting at the optional path.

    .. versionadded:: 2016.3.0

    CLI Example:

        salt-call boto_iam.get_all_roles
773925
def get_all_roles(path_prefix=None, region=None, key=None, keyid=None,
                 profile=None):
    '''
    
    '''
    conn = _get_conn(region=region, key=key, keyid=keyid, profile=profile)
    if not conn:
        return None
    _roles = conn.list_roles(path_prefix=path_prefix)
    roles = _roles.list_roles_response.list_roles_result.roles
    marker = getattr(
        _roles.list_roles_response.list_roles_result, 'marker', None
    )
    while marker:
        _roles = conn.list_roles(path_prefix=path_prefix, marker=marker)
        roles = roles + _roles.list_roles_response.list_roles_result.roles
        marker = getattr(
            _roles.list_roles_response.list_roles_result, 'marker', None
        )
    return roles
130101
function buildBastionIamRole({ name = 'BastionIamRole' } = {}) {
  return {
    [name]: {
      Type: 'AWS::IAM::Role',
      Properties: {
        AssumeRolePolicyDocument: {
          Statement: [
            {
              Effect: 'Allow',
              Principal: {
                Service: 'ec2.amazonaws.com',
              },
              Action: 'sts:AssumeRole',
            },
          ],
        },
        Policies: [
          {
            PolicyName: 'AllowEIPAssociation',
            PolicyDocument: {
              Version: '2012-10-17',
              Statement: [
                {
                  Action: 'ec2:AssociateAddress',
                  Resource: '*',
                  Effect: 'Allow',
                },
              ],
            },
          },
        ],
        ManagedPolicyArns: ['arn:aws:iam::aws:policy/service-role/AmazonEC2RoleforSSM'],
      },
    },
  };
}
695073
def _get_rules_from_aws(self):
        
        list_of_rules = list()

        if self.profile:
            boto3.setup_default_session(profile_name=self.profile)

        if self.region:
            ec2 = boto3.client('ec2', region_name=self.region)
        else:
            ec2 = boto3.client('ec2')

        security_groups = ec2.describe_security_groups(Filters=self.filters)

        for group in security_groups['SecurityGroups']:
            group_dict = dict()
            group_dict['id'] = group['GroupId']
            group_dict['name'] = group['GroupName']
            group_dict['description'] = group.get('Description', None)

            if (group.get('IpPermissions', None) or
                    group.get('IpPermissionsEgress', None)):
                group_dict['rules'] = list()

            for rule in group.get('IpPermissions', None):
                rule_dict = self._build_rule(rule)
                rule_dict['direction'] = "INGRESS"

                group_dict['rules'].append(rule_dict)

            for rule in group.get('IpPermissionsEgress', None):
                rule_dict = self._build_rule(rule)
                rule_dict['direction'] = "EGRESS"

                group_dict['rules'].append(rule_dict)

            list_of_rules.append(group_dict)

        return list_of_rules
45010
@GET
    @Path("role")
    @Produces(MediaType.APPLICATION_JSON)
    @HttpCache
    public List<RRoleDto> getRoles()
    {
        DbConn cnx = null;
        try
        {
            cnx = Helpers.getDbSession();
            return MetaService.getRoles(cnx);
        }
        finally
        {
            Helpers.closeQuietly(cnx);
        }
    }
1291114
def _get_role_arn():
    
    role_arn = bottle.request.headers.get('X-Role-ARN')
    if not role_arn:
        role_arn = _lookup_ip_role_arn(bottle.request.environ.get('REMOTE_ADDR'))
    if not role_arn:
        role_arn = _role_arn
    return role_arn
1349856
def role_show(self, role_id, **kwargs):
        ""
        api_path = "/api/v2/roles/{role_id}"
        api_path = api_path.format(role_id=role_id)
        return self.call(api_path, **kwargs)
224049
def get_single_role(self, id, role_id, account_id, role=None):
        
        path = {}
        data = {}
        params = {}

        # REQUIRED - PATH - id
        """ID"""
        path["id"] = id

        # REQUIRED - PATH - account_id
        """The id of the account containing the role"""
        path["account_id"] = account_id

        # REQUIRED - role_id
        """The unique identifier for the role"""
        params["role_id"] = role_id

        # OPTIONAL - role
        """The name for the role"""
        if role is not None:
            params["role"] = role

        self.logger.debug("GET /api/v1/accounts/{account_id}/roles/{id} with query params: {params} and form data: {data}".format(params=params, data=data, **path))
        return self.generic_request("GET", "/api/v1/accounts/{account_id}/roles/{id}".format(**path), data=data, params=params, single_item=True)
245906
def get_user_switchable_roles(self):
        
        roles = []
        for rs in self.current.user.role_set:
            # rs.role != self.current.role is not True after python version 2.7.12
            if rs.role.key != self.current.role.key:
                roles.append((rs.role.key, '%s %s' % (rs.role.unit.name,
                                                      rs.role.abstract_role.name)))
        return roles
48959
def _generate_iam_invoke_role(self):
        

        invoke_assume = {
            "Version": "2012-10-17",
            "Statement": [
                {
                    "Action": "sts:AssumeRole",
                    "Principal": {
                        "Service": "apigateway.amazonaws.com"
                    },
                    "Effect": "Allow",
                    "Sid": ""
                }
            ]
        }
        self.tf_conf['resource']['aws_iam_role']['invoke_role'] = {
            'name': self.resource_name + '-invoke',
            'assume_role_policy': json.dumps(invoke_assume),
        }
        self.tf_conf['output']['iam_invoke_role_arn'] = {
            'value': '${aws_iam_role.invoke_role.arn}'
        }
        self.tf_conf['output']['iam_invoke_role_unique_id'] = {
            'value': '${aws_iam_role.invoke_role.unique_id}'
        }
219786
def get_ec2_role(self, role, mount_point='aws-ec2'):
        
        return self._adapter.get('/v1/auth/{0}/role/{1}'.format(mount_point, role)).json()
136864
def get_role(self, role):
        
        uri = "OS-KSADM/roles/%s" % utils.get_id(role)
        resp, resp_body = self.method_get(uri)
        role = Role(self, resp_body.get("role"))
        return role
497309
def _bse_cli_lookup_by_role(args):
    ''''''
    return api.lookup_basis_by_role(args.basis, args.role, args.data_dir)
620565
def _get_roles_query(self, session, identifier):
        
        return (session.query(Role).
                join(role_membership_table, Role.pk_id == role_membership_table.c.role_id).
                join(User, role_membership_table.c.user_id == User.pk_id).
                filter(User.identifier == identifier))
737260
def get_user_policy(user_name, policy_name, region=None, key=None, keyid=None, profile=None):
    '''
    
    '''
    conn = _get_conn(region=region, key=key, keyid=keyid, profile=profile)
    try:
        info = conn.get_user_policy(user_name, policy_name)
        log.debug('Info for IAM user %s policy %s: %s.', user_name, policy_name, info)
        if not info:
            return False
        info = info.get_user_policy_response.get_user_policy_result.policy_document
        info = _unquote(info)
        info = salt.utils.json.loads(info, object_pairs_hook=odict.OrderedDict)
        return info
    except boto.exception.BotoServerError as e:
        log.debug(e)
        log.error('Failed to get policy %s for IAM user %s.', policy_name, user_name)
        return False
893023
def get_permissions(self):
        
        path = Client.urls['all_permissions']
        conns = self._call(path, 'GET')
        return conns
1239005
def get_all_group_policies(group_name, region=None, key=None, keyid=None,
                           profile=None):
    '''
    
    '''
    conn = _get_conn(region=region, key=key, keyid=keyid, profile=profile)
    if not conn:
        return False
    try:
        response = conn.get_all_group_policies(group_name)
        _list = response.list_group_policies_response.list_group_policies_result
        return _list.policy_names
    except boto.exception.BotoServerError as e:
        log.debug(e)
        return []
211531
def profile_associated(role_name, profile_name, region, key, keyid, profile):
    '''
    
    '''
    conn = _get_conn(region=region, key=key, keyid=keyid, profile=profile)

    # The IAM module of boto doesn't return objects. Instead you need to grab
    # values through its properties. Sigh.
    try:
        profiles = conn.list_instance_profiles_for_role(role_name)
    except boto.exception.BotoServerError as e:
        log.debug(e)
        return False
    profiles = profiles.list_instance_profiles_for_role_response
    profiles = profiles.list_instance_profiles_for_role_result
    profiles = profiles.instance_profiles
    for profile in profiles:
        if profile.instance_profile_name == profile_name:
            return True
    return False