Example #1
0
def set(client, user_id, group_id, limit):
    try:
        qos = qos_lib.set(client,
                          user_id=user_id,
                          group_id=group_id,
                          limit=limit)
        utils.check(qos)
        click.secho("Storage limit changed", fg="green")
    except Exception as exc:
        click.secho(f"Storage limit change failed. \n{exc}",
                    fg="yellow",
                    bold=True,
                    err=True)
Example #2
0
    def post(self):
        options = {
            "userId": "",
            "groupId": "",
            "userType": "User",
            "fullName": "",
            "emailAddr": "",
            "address1": "",
            "city": "",
            "state": "",
            "zip": "",
            "country": "",
            "phone": "",
            "website": "",
            "active": True,
            "ldapEnabled": False,
        }

        parser = reqparse.RequestParser()
        for index, option in options.items():
            if index in ["userId", "groupId", "fullName"]:
                parser.add_argument(index, type=str, required=True)
            elif index in ["active", "ldapEnabled"]:
                parser.add_argument(index, type=inputs.boolean)
            else:
                parser.add_argument(index, type=str)
        parser.add_argument("quotaLimit", type=int)
        parser.add_argument("debug", type=inputs.boolean, default=False)
        args = parser.parse_args()

        try:
            for index, option in options.items():
                if args[index] not in (option, None):
                    options[index] = args[index]
            options = utils.user_sanitize(options)
            status = user.create(get_client(), options)
            if args["quotaLimit"]:
                status = qos.set(get_client(), args["userId"], args["groupId"],
                                 args["quotaLimit"])
            if "reason" in status:
                current_app.logger.error(status["reason"])
                return response(status["status_code"],
                                message=status["reason"])
            else:
                return response(
                    201, f"User {options['userId']} created successfully.")
        except Exception as e:
            current_app.logger.error(f"{e}", exc_info=args["debug"])
            return response(500, f"{e}")
Example #3
0
    def post(self):
        parser = init_parser().copy()
        parser.add_argument("limit", type=int, required=True)
        args = parser.parse_args()

        try:
            status = qos.set(get_client(), args["userId"], args["groupId"],
                             args["limit"])
            if "reason" in status:
                current_app.logger.error(status["reason"])
                return response(status["status_code"],
                                message=status["reason"])

            return response(
                201, f"User {args['userId']} quota changed successfully.",
                status)
        except Exception as e:
            current_app.logger.error(f"{e}", exc_info=args["debug"])
            return response(500, f"{e}")
Example #4
0
def test_set():
    assert qos.set(fake_client(), "user", "group", "limit") == limit()