1
1
import os
2
2
from typing import Optional
3
3
4
- from pydantic import BaseModel # pylint: disable=E0611
5
- from pydantic import Field
6
- from pydantic import validator
4
+ from pydantic import (
5
+ BaseModel , # pylint: disable=E0611
6
+ Field ,
7
+ ValidationInfo ,
8
+ field_validator ,
9
+ )
7
10
8
11
OptBool = Optional [bool ]
9
12
OptStr = Optional [str ]
@@ -13,28 +16,25 @@ class SecretEnvError(Exception): ...
13
16
14
17
15
18
class Secret (BaseModel ):
16
- type : OptStr = Field (None , description = "Type of secret, can be `dependabot` or `actions`" )
17
- key : OptStr = Field (None , description = "Secret's name." )
19
+ type : str = Field (
20
+ "actions" ,
21
+ description = "Type of secret, can be `dependabot` or `actions` or an `environment` path" ,
22
+ )
23
+ key : str = Field (None , description = "Secret's name." )
18
24
env : OptStr = Field (None , description = "Environment variable to pull the secret from" )
19
- value : OptStr = Field (None , description = "Value to set this secret to" )
25
+ value : OptStr = Field (None , description = "Value to set this secret to" , validate_default = True )
20
26
required : OptBool = Field (
21
27
True ,
22
28
description = "Setting a value as not required allows you to not pass in an env var without causing an error" ,
23
29
)
24
30
exists : OptBool = Field (True , description = "Set to false to delete a secret" )
25
31
26
- @validator ("type" )
27
- def validate_type (cls , v ):
28
- if v not in ["dependabot" , "actions" ]:
29
- raise ValueError ("Secret type must be either `dependabot` or `actions`" )
30
- return v
31
-
32
- @validator ("value" , always = True )
33
- def validate_value (cls , v , values ) -> OptStr :
32
+ @field_validator ("value" )
33
+ def validate_value (cls , v , info : ValidationInfo ) -> OptStr :
34
34
if v is None :
35
35
return None
36
36
37
- if values ["env" ] is not None :
37
+ if info . data ["env" ] is not None :
38
38
raise ValueError ("Cannot set an env and a value in the same secret, remove one." )
39
39
40
40
return v
0 commit comments