mirror of
https://github.com/datahub-project/datahub.git
synced 2025-11-15 19:03:43 +00:00
fix(ingest): remove alphabet field from allow/deny config (#5629)
This commit is contained in:
parent
dc08bedd6e
commit
dfd0d1581b
@ -1,7 +1,7 @@
|
|||||||
import re
|
import re
|
||||||
from abc import ABC, abstractmethod
|
from abc import ABC, abstractmethod
|
||||||
from enum import Enum
|
from enum import Enum
|
||||||
from typing import IO, Any, Dict, List, Optional, Pattern, cast
|
from typing import IO, Any, ClassVar, Dict, List, Optional, Pattern, cast
|
||||||
|
|
||||||
from pydantic import BaseModel, Extra, validator
|
from pydantic import BaseModel, Extra, validator
|
||||||
from pydantic.fields import Field
|
from pydantic.fields import Field
|
||||||
@ -121,6 +121,12 @@ class OauthConfiguration(ConfigModel):
|
|||||||
class AllowDenyPattern(ConfigModel):
|
class AllowDenyPattern(ConfigModel):
|
||||||
"""A class to store allow deny regexes"""
|
"""A class to store allow deny regexes"""
|
||||||
|
|
||||||
|
# This regex is used to check if a given rule is a regex expression or a literal.
|
||||||
|
# Note that this is not a perfect check. For example, the '.' character should
|
||||||
|
# be considered a regex special character, but it's used frequently in literal
|
||||||
|
# patterns and hence we allow it anyway.
|
||||||
|
IS_SIMPLE_REGEX: ClassVar = re.compile(r"^[A-Za-z0-9 _.-]+$")
|
||||||
|
|
||||||
allow: List[str] = Field(
|
allow: List[str] = Field(
|
||||||
default=[".*"],
|
default=[".*"],
|
||||||
description="List of regex patterns to include in ingestion",
|
description="List of regex patterns to include in ingestion",
|
||||||
@ -133,13 +139,6 @@ class AllowDenyPattern(ConfigModel):
|
|||||||
default=True,
|
default=True,
|
||||||
description="Whether to ignore case sensitivity during pattern matching.",
|
description="Whether to ignore case sensitivity during pattern matching.",
|
||||||
) # Name comparisons should default to ignoring case
|
) # Name comparisons should default to ignoring case
|
||||||
alphabet: str = Field(
|
|
||||||
default="[A-Za-z0-9 _.-]", description="Allowed alphabets pattern"
|
|
||||||
)
|
|
||||||
|
|
||||||
@property
|
|
||||||
def alphabet_pattern(self) -> Pattern:
|
|
||||||
return re.compile(f"^{self.alphabet}+$")
|
|
||||||
|
|
||||||
@property
|
@property
|
||||||
def regex_flags(self) -> int:
|
def regex_flags(self) -> int:
|
||||||
@ -167,7 +166,7 @@ class AllowDenyPattern(ConfigModel):
|
|||||||
much more efficient in some cases.
|
much more efficient in some cases.
|
||||||
"""
|
"""
|
||||||
return all(
|
return all(
|
||||||
self.alphabet_pattern.match(allow_pattern) for allow_pattern in self.allow
|
self.IS_SIMPLE_REGEX.match(allow_pattern) for allow_pattern in self.allow
|
||||||
)
|
)
|
||||||
|
|
||||||
def get_allowed_list(self) -> List[str]:
|
def get_allowed_list(self) -> List[str]:
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user