示例#1
0
文件: auth.py 项目: pjegouic/ban
def createclient(name=None, user=None, **kwargs):
    """Create a client.

    name    name of the client to create
    user    username or email of an existing user
    """
    if not name:
        name = helpers.prompt('Client name')
    if not user:
        user = helpers.prompt('User username or email')
    user_inst = User.first((User.username == user) | (User.email == user))
    if not user_inst:
        return reporter.error('User not found', user)
    validator = Client.validator(name=name, user=user_inst)
    if validator.errors:
        return reporter.error('Errored', validator.errors)
    client = validator.save()
    reporter.notice('Created', client)
    listclients()
示例#2
0
def createclient(name=None, user=None, **kwargs):
    """Create a client.

    name    name of the client to create
    user    username or email of an existing user
    """
    if not name:
        name = helpers.prompt('Client name')
    if not user:
        user = helpers.prompt('User username or email')
    user_inst = User.first((User.username == user) | (User.email == user))
    if not user_inst:
        return reporter.error('User not found', user)
    validator = Client.validator(name=name, user=user_inst)
    if validator.errors:
        return reporter.error('Errored', validator.errors)
    client = validator.save()
    reporter.notice('Created', client)
    listclients()
示例#3
0
def createclient(name=None,
                 user=None,
                 scopes=[],
                 contributor_types=[],
                 **kwargs):
    """Create a client.

    name    name of the client to create
    user    username or email of an existing user
    """
    if not name:
        name = helpers.prompt('Client name')
    if not user:
        user = helpers.prompt('User username or email')
    user_inst = User.first((User.username == user) | (User.email == user))
    if not user_inst:
        return reporter.error('User not found', user)
    if not scopes:
        scopes = helpers.prompt('Scopes (separated by spaces)',
                                default='').split()
    if not contributor_types:
        contributor_types = helpers.prompt(
            'Contributor types (separated by spaces)',
            default='viewer').split()
    for ct in contributor_types:
        if ct not in Client.CONTRIBUTOR_TYPE:
            return reporter.error(
                '{} not in {}'.format(ct, str(Client.CONTRIBUTOR_TYPE)),
                contributor_types)
    if contributor_types != ['viewer']:
        contributor_types.append('viewer')
    validator = Client.validator(name=name,
                                 user=user_inst,
                                 scopes=scopes,
                                 contributor_types=contributor_types)
    if validator.errors:
        return reporter.error('Errored', validator.errors)
    client = validator.save()
    reporter.notice('Created', client)
    listclients()