Ejemplo n.º 1
0
def list_accounts(filter={}, session=None):
    """ Returns a list of all account names.

    :param filter: Dictionary of attributes by which the input data should be filtered
    :param session: the database session in use.

    returns: a list of all account names.
    """
    query = session.query(models.Account.account, models.Account.account_type,
                          models.Account.email).filter_by(status=AccountStatus.ACTIVE)
    for filter_type in filter:
        if filter_type == 'account_type':
            if isinstance(filter['account_type'], string_types):
                query = query.filter_by(account_type=AccountType.from_sym(filter['account_type']))
            elif isinstance(filter['account_type'], EnumSymbol):
                query = query.filter_by(account_type=filter['account_type'])

        elif filter_type == 'identity':
            query = query.join(models.IdentityAccountAssociation, models.Account.account == models.IdentityAccountAssociation.account).\
                filter(models.IdentityAccountAssociation.identity == filter['identity'])

        else:
            query = query.join(models.AccountAttrAssociation, models.Account.account == models.AccountAttrAssociation.account).\
                filter(models.AccountAttrAssociation.key == filter_type).\
                filter(models.AccountAttrAssociation.value == filter[filter_type])

    for account, account_type, email in query.order_by(models.Account.account).yield_per(25):
        yield {'account': account, 'type': account_type, 'email': email}
Ejemplo n.º 2
0
def add_vo(vo, description, password, email, session=None):
    """
    Add a VO and setup a new root user.
    New root user will have account name 'root' and a userpass identity with username: '******' and password from the rootpass parameter

    :param vo: 3-letter unique tag for a VO.
    :param descrition: Descriptive string for the VO (e.g. Full name).
    :param email: Contact email for the VO.
    :param password: The password to set for the root user of the new VO
    :param session: The db session in use.
    """

    if len(vo) != 3:
        raise exception.RucioException('Invalid VO tag, must be 3 chars.')

    new_vo = models.VO(vo=vo, description=description, email=email)

    try:
        new_vo.save(session=session)
    except IntegrityError:
        raise exception.Duplicate('VO {} already exists!'.format(vo))
    except DatabaseError as error:
        raise exception.RucioException(error.args)

    from rucio.core.account import add_account, list_identities
    from rucio.core.identity import add_account_identity
    new_root = InternalAccount('root', vo=vo)
    add_account(account=new_root,
                type=AccountType.from_sym('SERVICE'),
                email=email,
                session=session)
    add_account_identity(identity='root@{}'.format(vo),
                         type=IdentityType.from_sym('userpass'),
                         account=new_root,
                         email=email,
                         default=False,
                         password=password,
                         session=session)

    for ident in list_identities(account=InternalAccount('super_root',
                                                         vo='def'),
                                 session=session):
        add_account_identity(identity=ident['identity'],
                             type=ident['type'],
                             account=new_root,
                             email='',
                             session=session)
Ejemplo n.º 3
0
def add_account(account, type, email, issuer):
    """
    Creates an account with the provided account name, contact information, etc.

    :param account: The account name.
    :param type: The account type
    :param email: The Email address associated with the account.

    :param issuer: The issuer account_core.

    """

    validate_schema(name='account', obj=account)

    kwargs = {'account': account, 'type': type}
    if not rucio.api.permission.has_permission(
            issuer=issuer, action='add_account', kwargs=kwargs):
        raise rucio.common.exception.AccessDenied(
            'Account %s can not add account' % (issuer))

    account_core.add_account(account, AccountType.from_sym(type), email)