Esempio n. 1
0
def addAdmin(userId):
    try:
        AuthenticationHelper.ValidateSignitureAndAdmin(getToken())
        if AgentUser.GetAdmin(userId):
            return "The admin with user id {userId} already exists.".format(
                userId=userId), 409

        if "ObjectId" not in request.json:
            raise LunaUserException(HTTPStatus.BAD_REQUEST,
                                    "The object id is required")
        user = AgentUser(**request.json)

        if user.Role != "Admin":
            return "The role of the admin user must be Admin.", 400
        if userId != user.AADUserId:
            return "The user id in request body doesn't match the user id in request url.", 400
        AgentUser.Create(user)
        return jsonify(request.json), 202

    except Exception as e:
        return handleExceptions(e)
Esempio n. 2
0
def addSubscriptionUser(subscriptionId, userId):
    try:
        AuthenticationHelper.ValidateSignitureAndAdmin(getToken())
        if AgentUser.GetUser(subscriptionId, userId):
            return "The user with user id {userId} already exists in subscription {subscriptionId}".format(
                userId=userId, subscriptionId=subscriptionId), 409

        if "ObjectId" not in request.json:
            raise LunaUserException(HTTPStatus.BAD_REQUEST,
                                    "The object id is required")

        user = AgentUser(**request.json)
        if subscriptionId != user.SubscriptionId:
            return "The subscription id in request body doesn't match the subscription id in request url.", 400
        if userId != user.AADUserId:
            return "The user id in request body doesn't match the user id in request url.", 400
        AgentUser.Create(user)
        return jsonify(request.json), 202

    except Exception as e:
        return handleExceptions(e)