Exemplo n.º 1
0
def create_user_password(request):
    """ Creates a password for the user given. """
    username = request.matchdict['name']
    actor_id = server.get_user_id_from_name(username)
    newname = server.touch_to_add_password(actor_id, request.POST['password'])
    #FIXME - should we not just return OK?
    return newname
Exemplo n.º 2
0
def retrieve_servers(request):
    """
    Lists all artifacts related to the current user.
    """
    user_id = server.get_user_id_from_name(request.authenticated_userid)
    server_list = server.list_artifacts_for_user(user_id)
    return list(server_list)
Exemplo n.º 3
0
def _resolve_vm(request):
    """Function given a request works out the VM we are talking about and whether
       the current user actually has permission to do stuff to it.
       Also returns the internal ID for the user, as well as the VM.
    """

    actor_id = None
    vm_id = None
    try:
        actor_id = server.get_user_id_from_name(request.authenticated_userid)
    except:
        # OK, it must be an agent or an internal call.
        pass
    try:
        vm_id = (
            request.matchdict["id"]
            if "id" in request.matchdict
            else server.get_server_id_from_name(request.matchdict["name"])
        )
    except:
        # Presumably because there is no such VM
        raise HTTPNotFound()

    if request.has_permission("act") or server.check_ownership(vm_id, actor_id):
        return vm_id, actor_id
    else:
        raise HTTPUnauthorized()
Exemplo n.º 4
0
def _resolve_vm(request):
    """Function given a request works out the VM we are talking about and whether
       the current user actually has permission to do stuff to it.
       Also returns the internal ID for the user, as well as the VM.
    """

    actor_id = None
    vm_id = None
    try:
        actor_id = server.get_user_id_from_name(request.authenticated_userid)
    except:
        #OK, it must be an agent or an internal call.
        pass
    try:
        vm_id = (request.matchdict['id'] if 'id' in request.matchdict else
                 server.get_server_id_from_name(request.matchdict['name']))
    except:
        #Presumably because there is no such VM
        raise HTTPNotFound()

    if (request.has_permission('act')
            or server.check_ownership(vm_id, actor_id)):
        return vm_id, actor_id
    else:
        raise HTTPUnauthorized()
Exemplo n.º 5
0
def retrieve_servers(request):
    """
    Lists all artifacts related to the current user.
    """
    user_id = server.get_user_id_from_name(request.authenticated_userid)
    server_list = server.list_artifacts_for_user(user_id)
    return list(server_list)
Exemplo n.º 6
0
def create_user_password(request):
    """ Creates a password for the user given. """
    username = request.matchdict["name"]
    actor_id = server.get_user_id_from_name(username)
    newname = server.touch_to_add_password(actor_id, request.POST["password"])
    # FIXME - should we not just return OK?
    return newname
Exemplo n.º 7
0
    def create_server(self, name, owner):
        owner_id = server.get_user_id_from_name(owner)
        server_id = server.create_appliance(name, name)

        server.touch_to_add_ownership(server_id, owner_id)

        return server_id
Exemplo n.º 8
0
def create_my_password(request):
    """ Creates a password for the user given. """
    username = request.authenticated_userid
    actor_id = server.get_user_id_from_name(username)
    newname = server.touch_to_add_password(actor_id, request.POST['password'])
    #FIXME - should we not just return OK?
    #FIXME2 - also should this not be a POST?
    return newname
Exemplo n.º 9
0
def create_my_password(request):
    """ Creates a password for the user given. """
    username = request.authenticated_userid
    actor_id = server.get_user_id_from_name(username)
    newname = server.touch_to_add_password(actor_id, request.POST["password"])
    # FIXME - should we not just return OK?
    # FIXME2 - also should this not be a POST?
    return newname
Exemplo n.º 10
0
def retrieve_servers(request):
    """
    Lists all artifacts related to the current user.
    """
    user_id = None
    try:
        user_id = server.get_user_id_from_name(request.authenticated_userid)
    except:
        pass
        #This should only happen if the user is an agent, right?
    server_list = server.list_artifacts_for_user(user_id)
    return list(server_list)
Exemplo n.º 11
0
def retrieve_user_credit(request):
    """Return credits outstanding for any user.

    :param name: User for which we are checking credit.
    :returns: JSON containing actor_id and current balance.
    """
    username = request.matchdict["name"]
    try:
        user_id = server.get_user_id_from_name(username)
        credits = server.check_credit(user_id)
        return {"actor_id": user_id, "credit_balance": int(credits)}
    except KeyError as e:
        return HTTPNotFound(str(e))
Exemplo n.º 12
0
def retrieve_user_credit(request):
    """Return credits outstanding for any user.

    :param name: User for which we are checking credit.
    :returns: JSON containing actor_id and current balance.
    """
    username = request.matchdict['name']
    try:
        user_id = server.get_user_id_from_name(username)
        credits = server.check_credit(user_id)
        return {'actor_id': user_id, 'credit_balance': int(credits)}
    except KeyError as e:
        return HTTPNotFound(str(e))
Exemplo n.º 13
0
def retrieve_my_user(request):
    """Return account details for logged-in user.

    :param name: The user we are interested in.
    :returns JSON object containing user table data.
    """
    username = request.authenticated_userid
    try:
        actor_id = server.get_user_id_from_name(username)
        details = server.check_user_details(actor_id)
        details.update({'credits': server.check_credit(actor_id)})
        return details
    except KeyError:
        #Should be impossible unless a logged-in user is deleted.
        return HTTPInternalServerError()
Exemplo n.º 14
0
def retrieve_user(request):
    """Return account details for any user.  Anybody should be able to do this,
       though most users have no need to.

    :param name: The user we are interested in.
    :returns JSON object containing user table data.
    """
    username = request.matchdict['name']
    try:
        actor_id = server.get_user_id_from_name(username)
        details = server.check_user_details(actor_id)
        details.update({'credits': server.check_credit(actor_id)})
        return details
    except KeyError:
        return HTTPNotFound()
Exemplo n.º 15
0
def retrieve_my_user(request):
    """Return account details for logged-in user.

    :param name: The user we are interested in.
    :returns JSON object containing user table data.
    """
    username = request.authenticated_userid
    try:
        actor_id = server.get_user_id_from_name(username)
        details = server.check_user_details(actor_id)
        details.update({"credits": server.check_credit(actor_id)})
        return details
    except KeyError:
        # Should be impossible unless a logged-in user is deleted.
        return HTTPInternalServerError()
Exemplo n.º 16
0
def retrieve_user(request):
    """Return account details for any user.  Anybody should be able to do this,
       though most users have no need to.

    :param name: The user we are interested in.
    :returns JSON object containing user table data.
    """
    username = request.matchdict["name"]
    try:
        actor_id = server.get_user_id_from_name(username)
        details = server.check_user_details(actor_id)
        details.update({"credits": server.check_credit(actor_id)})
        return details
    except KeyError:
        return HTTPNotFound()
Exemplo n.º 17
0
def create_user_credit(request):
    """Adds credit to a user account, negative or positive.  Only an administrator can do this
       directly.  Boost and Deboost actions will do this implicitly.

    Checks if username is valid, otherwise throws HTTP 404.
    Checks if credit is an integer, otherwise throws HTTP 400.

    :param name: User for which we are amending credit.
    :returns: JSON containing actor id, credit change and new balance.
    """
    username, credit = request.matchdict["name"], request.POST["credit"]
    try:
        user_id = server.get_user_id_from_name(username)
        server.touch_to_add_credit(user_id, int(credit))
        credits = server.check_credit(user_id)
        return {"actor_id": int(user_id), "credit_change": int(credit), "credit_balance": int(credits)}
    except ValueError:
        return HTTPBadRequest()
    except KeyError:
        return HTTPNotFound()
Exemplo n.º 18
0
def create_user_credit(request):
    """Adds credit to a user account, negative or positive.  Only an administrator can do this
       directly.  Boost and Deboost actions will do this implicitly.

    Checks if username is valid, otherwise throws HTTP 404.
    Checks if credit is an integer, otherwise throws HTTP 400.

    :param name: User for which we are amending credit.
    :returns: JSON containing actor id, credit change and new balance.
    """
    username, credit = request.matchdict['name'], request.POST['credit']
    try:
        user_id = server.get_user_id_from_name(username)
        server.touch_to_add_credit(user_id, int(credit))
        credits = server.check_credit(user_id)
        return  {'actor_id': int(user_id),
                 'credit_change': int(credit),
                 'credit_balance': int(credits)}
    except ValueError:
        return HTTPBadRequest()
    except KeyError:
        return HTTPNotFound()
Exemplo n.º 19
0
def add_credit(amount, owner):
    owner_id = server.get_user_id_from_name(owner)
    server.touch_to_add_credit(owner_id, int(amount))
Exemplo n.º 20
0
def add_credit(amount, owner):
    owner_id = server.get_user_id_from_name(owner)
    server.touch_to_add_credit(owner_id, int(amount))