Skip to content

Commit 4b21297

Browse files
add SHORT_UUID
1 parent 76f04b1 commit 4b21297

2 files changed

Lines changed: 10 additions & 5 deletions

File tree

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1,2 @@
1-
uvicorn[standard]
1+
uvicorn[standard]
2+
shortuuid~=1.0.11

ted_sws/notice_transformer/entrypoints/api/digest_service/routes/hashing.py

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
import uuid
33
from enum import Enum
44
from typing import Optional
5-
5+
import shortuuid
66
from fastapi import APIRouter
77

88
from ted_sws.notice_transformer.entrypoints.api.digest_service.common import ResponseType, single_result_response, \
@@ -30,6 +30,7 @@ class UUIDNamespaceType(Enum):
3030
class UUIDVersion(Enum):
3131
UUID3 = "UUID3"
3232
UUID5 = "UUID5"
33+
SHORT_UUID = "short"
3334

3435

3536
def string_md5(value: str):
@@ -73,7 +74,7 @@ async def fn_md5(value: str, response_type: Optional[ResponseType] = ResponseTyp
7374
async def fn_uuid(
7475
value: str,
7576
process_type: Optional[UUIDInputProcessType] = UUIDInputProcessType.XPATH,
76-
version: Optional[UUIDVersion] = UUIDVersion.UUID3,
77+
version: Optional[UUIDVersion] = UUIDVersion.SHORT_UUID,
7778
ns_type: Optional[UUIDNamespaceType] = UUIDNamespaceType.URL,
7879
response_type: Optional[ResponseType] = ResponseType.RAW
7980
):
@@ -95,10 +96,13 @@ async def fn_uuid(
9596
uuid_ns = uuid_ns_by_type(ns_type)
9697

9798
uuid_result: uuid.UUID
98-
if version == UUIDVersion.UUID5:
99+
if version == UUIDVersion.SHORT_UUID:
100+
uuid_result = shortuuid.uuid(name=value)
101+
elif version == UUIDVersion.UUID5:
99102
uuid_result = uuid.uuid5(uuid_ns, value)
100-
else:
103+
elif version == UUIDVersion.UUID3:
101104
uuid_result = uuid.uuid3(uuid_ns, value)
102105

106+
103107
result = str(uuid_result)
104108
return single_result_response(result, response_type)

0 commit comments

Comments
 (0)