Пример #1
0
def verify_user_volume(lic_dict):
    """
    check if the token users count is covered by the license

    :param lic_dict: dictionary with license attributes
    :return: tuple with boolean and error detail if False
    """
    _ = context['translate']

    # get the current number of all active token users
    num = getNumTokenUsers()

    try:
        user_volume = int(lic_dict.get('user-num', 0))
    except TypeError as err:
        log.exception("Failed to convert license. Number of token users: %r. "
                      "Exception was:%r " % (lic_dict.get('user-num'), err))
        return False, "max %d" % user_volume

    if num > user_volume:
        log.error("Licensed token user volume exceeded. Currently %r users "
                  "present, but only %r allowed." % (num, user_volume))
        used = _("token user used")
        licnu = _("token users supported")
        detail = " %s: %d > %s: %d" % (used, num, licnu, user_volume)
        return False, detail

    return True, ""
Пример #2
0
def verify_user_volume(lic_dict):
    """
    check if the token users count is covered by the license

    :param lic_dict: dictionary with license attributes
    :return: tuple with boolean and verification detail
    """

    # get the current number of all active token users
    num = getNumTokenUsers()

    try:
        user_volume = int(lic_dict.get("user-num", 0))
    except TypeError as err:
        log.error(
            "Failed to convert license. Number of token users: %r. "
            "Exception was:%r ",
            lic_dict.get("user-num"),
            err,
        )
        return False, "max %d" % user_volume

    detail = ""

    if num > user_volume + GRACE_VOLUME:
        log.error(
            "Volume of licensed token users exceeded. Currently %r users "
            "are present, but only %r are licensed.",
            num,
            user_volume,
        )
        detail = _("%d token users found > %d token users licensed.") % (
            num,
            user_volume,
        )
        return False, detail

    if num >= user_volume and num <= user_volume + GRACE_VOLUME:
        log.warning(
            "Volume of licensed token users exceeded. Currently %d users "
            "are present, but only %d are licensed. Grace of %d additional "
            "users allowed.",
            num,
            user_volume,
            GRACE_VOLUME,
        )

        detail = _(
            "Grace limit reached: %d token users found >= %d token users "
            "licensed. %d additional users allowed."
        ) % (num, user_volume, GRACE_VOLUME)

    return True, detail
Пример #3
0
    def license(self):
        """
        license
        return the support status, which is community support by default
        or the support subscription info, which could be the old license
        :return: json result with license info
        """
        res = {}
        try:
            try:
                license_info, license_sig = getSupportLicenseInfo()
            except InvalidLicenseException as err:
                if err.type != "UNLICENSED":
                    raise err
                opt = {"valid": False, "message": "%r" % err}
                return sendResult(response, {}, 1, opt=opt)

            # Add Extra info
            # if needed; use details = None ... for no details!)...

            license_ok, license_msg = verifyLicenseInfo(
                license_info, license_sig
            )
            if not license_ok:
                res = {"valid": license_ok, "message": license_msg}
                return sendResult(response, res, 1)

            details = {"valid": license_ok}

            if "user-num" in license_info:
                res["user-num"] = int(license_info.get("user-num", 0))
                active_usercount = getNumTokenUsers()
                res["user-active"] = active_usercount
                res["user-left"] = res["user-num"] - active_usercount

            else:
                res["token-num"] = int(license_info.get("token-num", 0))
                active_tokencount = getTokenNumResolver()
                res["token-active"] = active_tokencount
                res["token-left"] = res["token-num"] - active_tokencount

            return sendResult(response, res, 1)

        except Exception as exception:
            log.error(exception)
            return sendError(response, exception)