mirror of
https://github.com/zulip/zulip.git
synced 2025-10-23 04:52:12 +00:00
billing: Add function to sign strings.
This commit is contained in:
@@ -2,17 +2,19 @@ import datetime
|
||||
from functools import wraps
|
||||
import logging
|
||||
import os
|
||||
from typing import Any, Callable, Optional, TypeVar
|
||||
from typing import Any, Callable, Optional, TypeVar, Tuple
|
||||
import ujson
|
||||
|
||||
from django.conf import settings
|
||||
from django.db import transaction
|
||||
from django.utils.translation import ugettext as _
|
||||
from django.core.signing import Signer
|
||||
import stripe
|
||||
|
||||
from zerver.lib.exceptions import JsonableError
|
||||
from zerver.lib.logging_util import log_to_file
|
||||
from zerver.lib.timestamp import datetime_to_timestamp, timestamp_to_datetime
|
||||
from zerver.lib.utils import generate_random_token
|
||||
from zerver.models import Realm, UserProfile, RealmAuditLog
|
||||
from zilencer.models import Customer, Plan
|
||||
from zproject.settings import get_secret
|
||||
@@ -52,6 +54,15 @@ CallableT = TypeVar('CallableT', bound=Callable[..., Any])
|
||||
def get_seat_count(realm: Realm) -> int:
|
||||
return UserProfile.objects.filter(realm=realm, is_active=True, is_bot=False).count()
|
||||
|
||||
def sign_string(string: str) -> Tuple[str, str]:
|
||||
salt = generate_random_token(64)
|
||||
signer = Signer(salt=salt)
|
||||
return signer.sign(string), salt
|
||||
|
||||
def unsign_string(signed_string: str, salt: str) -> str:
|
||||
signer = Signer(salt=salt)
|
||||
return signer.unsign(signed_string)
|
||||
|
||||
class StripeError(JsonableError):
|
||||
pass
|
||||
|
||||
|
Reference in New Issue
Block a user