Create a new IAM role. Returns the ARN of the newly created role

        Args:
            account (:obj:`Account`): Account where to create the IAM role

        Returns:
            `str`
975426
def create_iam_role(self, account):
        
        try:
            iam = self.session.client('iam')
            trust = get_template('vpc_flow_logs_iam_role_trust.json').render()
            policy = get_template('vpc_flow_logs_role_policy.json').render()

            newrole = iam.create_role(
                Path='/',
                RoleName=self.role_name,
                AssumeRolePolicyDocument=trust
            )['Role']['Arn']

            # Attach an inline policy to the role to avoid conflicts or hitting the Managed Policy Limit
            iam.put_role_policy(
                RoleName=self.role_name,
                PolicyName='VpcFlowPolicy',
                PolicyDocument=policy
            )

            self.log.debug('Created VPC Flow Logs role & policy for {}'.format(account.account_name))
            auditlog(
                event='vpc_flow_logs.create_iam_role',
                actor=self.ns,
                data={
                    'account': account.account_name,
                    'roleName': self.role_name,
                    'trustRelationship': trust,
                    'inlinePolicy': policy
                }
            )
            return newrole

        except Exception:
            self.log.exception('Failed creating the VPC Flow Logs role for {}.'.format(account))
86049
def create_account(self, **params):
        """"""
        response = self._post('v2', 'accounts', data=params)
        return self._make_api_object(response, Account)
42494
def _generate_iam_role_policy(self):
        
        endpoints = self.config.get('endpoints')
        queue_arns = []
        for ep in endpoints:
            for qname in endpoints[ep]['queues']:
                qarn = 'arn:aws:sqs:%s:%s:%s' % (self.aws_region,
                                                 self.aws_account_id, qname)
                if qarn not in queue_arns:
                    queue_arns.append(qarn)
        pol = {
            "Version": "2012-10-17",
            "Statement": [
                {
                    "Effect": "Allow",
                    "Action": "logs:CreateLogGroup",
                    "Resource": "arn:aws:logs:%s:%s:*" % (
                        self.aws_region, self.aws_account_id
                    )
                },
                {
                    "Effect": "Allow",
                    "Action": [
                        "logs:CreateLogStream",
                        "logs:PutLogEvents"
                    ],
                    "Resource": [
                        "arn:aws:logs:%s:%s:log-group:%s:*" % (
                            self.aws_region, self.aws_account_id,
                            '/aws/lambda/%s' % self.resource_name
                        )
                    ]
                },
                {
                    'Effect': 'Allow',
                    'Action': [
                        'sqs:ListQueues'
                    ],
                    'Resource': '*'
                },
                {
                    "Effect": "Allow",
                    "Action": [
                        "sqs:GetQueueUrl",
                        "sqs:SendMessage"
                    ],
                    "Resource": sorted(queue_arns)
                }
            ]
        }
        self.tf_conf['resource']['aws_iam_role_policy']['role_policy'] = {
            'name': self.resource_name,
            'role': '${aws_iam_role.lambda_role.id}',
            'policy': json.dumps(pol)
        }
505524
def role_present(name, profile=None, **connection_args):
    ''''
    
    '''
    ret = {'name': name,
           'changes': {},
           'result': True,
           'comment': 'Role "{0}" already exists'.format(name)}

    # Check if role is already present
    role = __salt__['keystone.role_get'](name=name, profile=profile,
                                         **connection_args)

    if 'Error' not in role:
        return ret
    else:
        if __opts__.get('test'):
            ret['result'] = None
            ret['comment'] = 'Role "{0}" will be added'.format(name)
            return ret
        # Create role
        __salt__['keystone.role_create'](name, profile=profile,
                                         **connection_args)
        ret['comment'] = 'Role "{0}" has been added'.format(name)
        ret['changes']['Role'] = 'Created'
    return ret
1309811
def get_account(self, account_id, **params):
        """"""
        response = self._get('v2', 'accounts', account_id, params=params)
        return self._make_api_object(response, Account)
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
189184
def create_committee_member(self, url="", account=None, **kwargs):
        
        if not account:
            if "default_account" in self.config:
                account = self.config["default_account"]
        if not account:
            raise ValueError("You need to provide an account")
        account = Account(account, blockchain_instance=self)

        op = operations.Committee_member_create(
            **{
                "fee": {"amount": 0, "asset_id": "1.3.0"},
                "committee_member_account": account["id"],
                "url": url,
            }
        )
        return self.finalizeOp(op, account, "active", **kwargs)
447037
def add_role(role, reason = nil)
      role_ids = role_id_array(role)

      if role_ids.count == 1
        API::Server.add_member_role(@bot.token, @server.id, @user.id, role_ids[0], reason)
      else
        old_role_ids = @roles.map(&:id)
        new_role_ids = (old_role_ids + role_ids).uniq
        API::Server.update_member(@bot.token, @server.id, @user.id, roles: new_role_ids, reason: reason)
      end
    end
796875
def create_role(name, policy_document=None, path=None, region=None, key=None,
                keyid=None, profile=None):
    '''
    
    '''
    conn = _get_conn(region=region, key=key, keyid=keyid, profile=profile)

    if role_exists(name, region, key, keyid, profile):
        return True
    if not policy_document:
        policy_document = None
    try:
        conn.create_role(name, assume_role_policy_document=policy_document,
                         path=path)
        log.info('Created IAM role %s.', name)
        return True
    except boto.exception.BotoServerError as e:
        log.error(e)
        log.error('Failed to create IAM role %s.', name)
        return False
1119290
def add_role(self, role_obj):
        
        role_node = role_obj.get_node()
        self.node.append(role_node)
1200119
def access(config, region, accounts=()):
    """"""
    config = validate.callback(config)
    accounts_report = []

    def check_access(account):
        accounts_report.append(account)
        session = get_session(account['role'], region)
        identity = session.client('sts').get_caller_identity()
        account['account_id'] = identity['Account']
        account.pop('groups')
        account.pop('role')
        client = session.client('iam')
        policy_arn = identity['Arn']
        if policy_arn.count('/') > 1:
            policy_arn = policy_arn.rsplit('/', 1)[0]
        if ':sts:' in policy_arn:
            policy_arn = policy_arn.replace(':sts', ':iam')
        if ':assumed-role' in policy_arn:
            policy_arn = policy_arn.replace(':assumed-role', ':role')
        evaluation = client.simulate_principal_policy(
            PolicySourceArn=policy_arn,
            ActionNames=['logs:CreateExportTask'])['EvaluationResults']
        account['access'] = evaluation[0]['EvalDecision']

    with ThreadPoolExecutor(max_workers=16) as w:
        futures = {}
        for account in config.get('accounts', ()):
            if accounts and account['name'] not in accounts:
                continue
            futures[w.submit(check_access, account)] = None
        for f in as_completed(futures):
            pass
    accounts_report.sort(key=operator.itemgetter('access'), reverse=True)
    print(tabulate(accounts_report, headers='keys'))
616471
def accounts():
    
    import yaml

    for path in account_files:
        try:

            c_dir = os.path.dirname(path)

            if not os.path.exists(c_dir):
                os.makedirs(c_dir)

            with open(path, 'rb') as f:
                return yaml.load(f)['accounts']

        except (OSError, IOError) as e:
            pass

    return {}
906488
def cli(ctx, email, first_name, last_name, password, role="user", metadata={}):
    
    return ctx.gi.users.create_user(email, first_name, last_name, password, role=role, metadata=metadata)
592538
def CreateReply(self, **attributes):
        
        return AcctPacket(AccountingResponse, self.id,
            self.secret, self.authenticator, dict=self.dict,
            **attributes)
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)
1351146
def find_or_create_role(self, name, **kwargs):
        
        kwargs["name"] = name
        return self.find_role(name) or self.create_role(**kwargs)
945796
def get_credentials_arn(self):
        
        role = self.iam.Role(self.role_name)
        self.credentials_arn = role.arn
        return role, self.credentials_arn