Ensures that the keystone role exists

    name
        The name of the role that should be present
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
54429
def roles_required(*required_rolenames):
    
    def decorator(method):
        @functools.wraps(method)
        def wrapper(*args, **kwargs):
            role_set = set([str(n) for n in required_rolenames])
            _verify_and_add_jwt()
            try:
                MissingRoleError.require_condition(
                    current_rolenames().issuperset(role_set),
                    "This endpoint requires all the following roles: {}",
                    [', '.join(role_set)],
                )
                return method(*args, **kwargs)
            finally:
                remove_jwt_data_from_app_context()
        return wrapper
    return decorator
1050879
def register_system_role(self, system_role):
        
        assert system_role.value not in self.system_roles
        self.system_roles[system_role.value] = system_role
917492
function ensureDirExists (name) {
  try {
    fs.mkdirSync(path.join(__dirname, name));
  } catch (e) {
    if (e.code !== 'EEXIST') {
      console.log("Error ensuring that node_modules exists");
      process.exit(1);
    }
  }
}
364998
def role?(role_sym)
      role_sym = [role_sym] unless role_sym.is_a?(Array)

      roles.map { |r| r.name.underscore.to_sym }.any? { |user_role| role_sym.include?(user_role) }
    end
1299478
def roles_for_user(request, user, project=None, domain=None):
    """"""
    manager = keystoneclient(request, admin=True).roles
    if VERSIONS.active < 3:
        return manager.roles_for_user(user, project)
    else:
        return manager.list(user=user, domain=domain, project=project)
1061652
def role_required(role_name=None):
    

    def _role_required(http_method_handler):

        @wraps(http_method_handler)
        def secure_http_method_handler(self, *args, **kwargs):

            # role name must be provided
            if role_name is None:
                _message = "Role name must be provided"
                authorization_error = prestans.exception.AuthorizationError(_message)
                authorization_error.request = self.request
                raise authorization_error

            # authentication context must be set
            if not self.__provider_config__.authentication:
                _message = "Service available to authenticated users only, no auth context provider set in handler"
                authentication_error = prestans.exception.AuthenticationError(_message)
                authentication_error.request = self.request
                raise authentication_error

            # check for the role by calling current_user_has_role
            if not self.__provider_config__.authentication.current_user_has_role(role_name):
                authorization_error = prestans.exception.AuthorizationError(role_name)
                authorization_error.request = self.request
                raise authorization_error

            http_method_handler(self, *args, **kwargs)

        return wraps(http_method_handler)(secure_http_method_handler)

    return _role_required
785166
def update_role(u_name, newprivilege):
        '''
        
        '''
        entry = TabMember.update(
            role=newprivilege
        ).where(TabMember.user_name == u_name)
        try:
            entry.execute()
            return True
        except:
            return False
1236014
def role_exists(role, **kwargs):

    '''
    
    '''
    # We should get one, and only one row
    return len(tsql_query(query='sp_helprole "{0}"'.format(role), as_dict=True, **kwargs)) == 1
470652
def get_default_role(request):
    
    global DEFAULT_ROLE
    default = getattr(settings, "OPENSTACK_KEYSTONE_DEFAULT_ROLE", None)
    if default and DEFAULT_ROLE is None:
        try:
            roles = keystoneclient(request, admin=True).roles.list()
        except Exception:
            roles = []
            exceptions.handle(request)
        for role in roles:
            if default in (role.id, role.name):
                DEFAULT_ROLE = role
                break
    return DEFAULT_ROLE
641690
def has_role(self, role):
        '''
        
        '''
        return self.roles and any([re.search(role, our_role, re.I)
                                   for our_role in self.roles])
36969
def role_exists(name, region=None, key=None, keyid=None, profile=None):
    '''
    
    '''
    conn = _get_conn(region=region, key=key, keyid=keyid, profile=profile)
    try:
        conn.get_role(name)
        return True
    except boto.exception.BotoServerError:
        return False
1237524
def _ensure_exists(wrapped):
    '''
    
    '''
    @functools.wraps(wrapped)
    def check_exists(name, *args, **kwargs):
        if not exists(name):
            raise CommandExecutionError(
                'Container \'{0}\' does not exist'.format(name)
            )
        return wrapped(name, *args, **salt.utils.args.clean_kwargs(**kwargs))
    return check_exists
414531
def assume_role(credentials, account, role):
    """"""
    sts = boto3.client(
        'sts',
        aws_access_key_id=credentials['accessKeyId'],
        aws_secret_access_key=credentials['secretAccessKey'],
        aws_session_token=credentials['sessionToken'],
    )
    resp = sts.assume_role(
        RoleArn='arn:aws:sts::{}:role/{}'.format(account, role),
        RoleSessionName='fleece_assumed_role'
    )
    return {
        'accessKeyId': resp['Credentials']['AccessKeyId'],
        'secretAccessKey': resp['Credentials']['SecretAccessKey'],
        'sessionToken': resp['Credentials']['SessionToken'],
    }
729385
def has_roles?(*args)
      throw Exception.new("Must supply at least one role.") if args.empty?
      roles.where(name: args).count == args.count
    end
143279
def present(name, owner=None, grants=None, **kwargs):
    '''
    
    '''
    ret = {'name': name,
           'changes': {},
           'result': True,
           'comment': ''}

    if __salt__['mssql.role_exists'](name, **kwargs):
        ret['comment'] = 'Role {0} is already present (Not going to try to set its grants)'.format(name)
        return ret
    if __opts__['test']:
        ret['result'] = None
        ret['comment'] = 'Role {0} is set to be added'.format(name)
        return ret

    role_created = __salt__['mssql.role_create'](name, owner=owner, grants=grants, **kwargs)
    if role_created is not True:  # Non-empty strings are also evaluated to True, so we cannot use if not role_created:
        ret['result'] = False
        ret['comment'] += 'Role {0} failed to be created: {1}'.format(name, role_created)
        return ret
    ret['comment'] += 'Role {0} has been added'.format(name)
    ret['changes'][name] = 'Present'
    return ret
1322953
def get_role_arn(role_name, env, region):
    
    session = boto3.Session(profile_name=env, region_name=region)
    iam_client = session.client('iam')

    LOG.debug('Searching for %s.', role_name)

    role = iam_client.get_role(RoleName=role_name)
    role_arn = role['Role']['Arn']

    LOG.debug("Found role's %s ARN %s", role_name, role_arn)

    return role_arn