fix url check
This commit is contained in:
@@ -41,6 +41,7 @@ class SupersetClient:
|
||||
self.logger.info("[INFO][SupersetClient.__init__][ENTER] Initializing SupersetClient.")
|
||||
self._validate_config(config)
|
||||
self.config = config
|
||||
self.env = config.env
|
||||
self.network = APIClient(
|
||||
config=config.dict(),
|
||||
verify_ssl=config.verify_ssl,
|
||||
@@ -146,6 +147,12 @@ class SupersetClient:
|
||||
return response_data.get("result", {})
|
||||
# END_FUNCTION_get_dataset
|
||||
|
||||
def get_databases(self) -> List[Dict]:
|
||||
self.logger.info("[INFO][SupersetClient.get_databases][ENTER] Getting databases.")
|
||||
response = self.network.request("GET", "/database/")
|
||||
self.logger.info("[INFO][SupersetClient.get_databases][SUCCESS] Got databases.")
|
||||
return response.get('result', [])
|
||||
|
||||
# [ENTITY: Function('export_dashboard')]
|
||||
# CONTRACT:
|
||||
# PURPOSE: Экспорт дашборда в ZIP-архив.
|
||||
|
||||
@@ -5,6 +5,7 @@
|
||||
"""
|
||||
|
||||
# [IMPORTS] Pydantic и Typing
|
||||
import re
|
||||
from typing import Optional, Dict, Any
|
||||
from pydantic import BaseModel, validator, Field, HttpUrl, VERSION
|
||||
|
||||
@@ -15,6 +16,7 @@ class SupersetConfig(BaseModel):
|
||||
"""
|
||||
[CONFIG] Конфигурация подключения к Superset API.
|
||||
"""
|
||||
env: str = Field(..., description="Название окружения (например, dev, prod).")
|
||||
base_url: str = Field(..., description="Базовый URL Superset API, включая версию /api/v1.", pattern=r'.*/api/v1.*')
|
||||
auth: Dict[str, str] = Field(..., description="Словарь с данными для аутентификации (provider, username, password, refresh).")
|
||||
verify_ssl: bool = Field(True, description="Флаг для проверки SSL-сертификатов.")
|
||||
@@ -45,15 +47,15 @@ class SupersetConfig(BaseModel):
|
||||
# POSTCONDITIONS: Возвращает `v` если это валидный URL.
|
||||
@validator('base_url')
|
||||
def check_base_url_format(cls, v: str, values: dict) -> str:
|
||||
logger = values.get('logger') or SupersetLogger(name="SupersetConfig")
|
||||
logger.debug("[DEBUG][SupersetConfig.check_base_url_format][ENTER] Validating base_url.")
|
||||
try:
|
||||
if VERSION.startswith('1'):
|
||||
HttpUrl(v)
|
||||
except (ValueError, TypeError) as exc:
|
||||
logger.error("[ERROR][SupersetConfig.check_base_url_format][FAILURE] Invalid base_url format.")
|
||||
raise ValueError(f"Invalid URL format: {v}") from exc
|
||||
logger.debug("[DEBUG][SupersetConfig.check_base_url_format][SUCCESS] base_url validated.")
|
||||
"""
|
||||
Простейшая проверка:
|
||||
- начинается с http/https,
|
||||
- содержит «/api/v1»,
|
||||
- не содержит пробельных символов в начале/конце.
|
||||
"""
|
||||
v = v.strip() # устраняем скрытые пробелы/переносы
|
||||
if not re.fullmatch(r'https?://.+/api/v1/?(?:.*)?', v):
|
||||
raise ValueError(f"Invalid URL format: {v}")
|
||||
return v
|
||||
# END_FUNCTION_check_base_url_format
|
||||
|
||||
|
||||
@@ -34,10 +34,10 @@ def setup_clients(logger: SupersetLogger) -> Dict[str, SupersetClient]:
|
||||
clients = {}
|
||||
|
||||
environments = {
|
||||
"dev": "https://devta.bi.dwh.rusal.com/api/v1",
|
||||
"prod": "https://prodta.bi.dwh.rusal.com/api/v1",
|
||||
"sbx": "https://sandboxta.bi.dwh.rusal.com/api/v1",
|
||||
"preprod": "https://preprodta.bi.dwh.rusal.com/api/v1"
|
||||
"dev": "https://devta.bi.dwh.rusal.com/api/v1/",
|
||||
"prod": "https://prodta.bi.dwh.rusal.com/api/v1/",
|
||||
"sbx": "https://sandboxta.bi.dwh.rusal.com/api/v1/",
|
||||
"preprod": "https://preprodta.bi.dwh.rusal.com/api/v1/"
|
||||
}
|
||||
|
||||
try:
|
||||
@@ -48,6 +48,7 @@ def setup_clients(logger: SupersetLogger) -> Dict[str, SupersetClient]:
|
||||
raise ValueError(f"Пароль для '{env_name} migrate' не найден в keyring.")
|
||||
|
||||
config = SupersetConfig(
|
||||
env=env_name,
|
||||
base_url=base_url,
|
||||
auth={
|
||||
"provider": "db",
|
||||
|
||||
Reference in New Issue
Block a user