mirror of
https://github.com/zulip/zulip.git
synced 2025-10-27 10:03:56 +00:00
utils: Move random API key generator as generate_api_key.
random_api_key, the function we use to generate random tokens for API keys, has been moved to zerver/lib/utils.py because it's used in more parts of the codebase (apart from user creation), and having it in zerver/lib/create_user.py was prone to cyclic dependencies. The function has also been renamed to generate_api_key to have an imperative name, that makes clearer what it does.
This commit is contained in:
committed by
Tim Abbott
parent
f6219745de
commit
6a192ac84c
@@ -7,6 +7,7 @@ import hashlib
|
||||
import heapq
|
||||
import itertools
|
||||
import os
|
||||
import string
|
||||
import sys
|
||||
from time import sleep
|
||||
from itertools import zip_longest
|
||||
@@ -112,6 +113,12 @@ def log_statsd_event(name: str) -> None:
|
||||
def generate_random_token(length: int) -> str:
|
||||
return str(base64.b16encode(os.urandom(length // 2)).decode('utf-8').lower())
|
||||
|
||||
def generate_api_key() -> str:
|
||||
choices = string.ascii_letters + string.digits
|
||||
altchars = ''.join([choices[ord(os.urandom(1)) % 62] for _ in range(2)]).encode("utf-8")
|
||||
api_key = base64.b64encode(os.urandom(24), altchars=altchars).decode("utf-8")
|
||||
return api_key
|
||||
|
||||
def query_chunker(queries: List[Any],
|
||||
id_collector: Optional[Set[int]]=None,
|
||||
chunk_size: int=1000,
|
||||
|
||||
Reference in New Issue
Block a user