Fix issue when deserializing GithubIssueTemplate with hidden secret (#1008)

This commit is contained in:
Cheick Keita
2021-06-24 10:50:54 -07:00
committed by GitHub
parent 4c9a9f2948
commit 5f72cc20b8
3 changed files with 101 additions and 32 deletions

View File

@ -511,15 +511,26 @@ class GithubIssueTemplate(BaseModel):
# validator needed for backward compatibility
@validator("auth", pre=True, always=True)
def validate_auth(cls, v: Any) -> SecretData:
def try_parse_GithubAuth(x: dict) -> Optional[GithubAuth]:
try:
return GithubAuth.parse_obj(x)
except Exception:
return None
if isinstance(v, GithubAuth):
return SecretData(secret=v)
elif isinstance(v, SecretData):
return v
elif isinstance(v, dict):
try:
return SecretData(GithubAuth.parse_obj(v))
except Exception:
return SecretData(GithubAuth.parse_obj(v["secret"]))
githubAuth = try_parse_GithubAuth(v)
if githubAuth:
return SecretData(secret=githubAuth)
githubAuth = try_parse_GithubAuth(v["secret"])
if githubAuth:
return SecretData(secret=githubAuth)
return SecretData(secret=v["secret"])
else:
raise TypeError(f"invalid datatype {type(v)}")

View File

@ -6,8 +6,8 @@
import unittest
from onefuzztypes.models import Scaleset, SecretData, TeamsTemplate
from onefuzztypes.requests import NotificationCreate
from onefuzztypes.primitives import PoolName, Region
from onefuzztypes.requests import NotificationCreate
from pydantic import ValidationError