|
13 | 13 | InitResourceContext, |
14 | 14 | ) |
15 | 15 | from dagster._check import CheckError |
16 | | -from dagster._config.pythonic_config import ConfigurableResourceFactory |
| 16 | +from dagster._config.pythonic_config import ( |
| 17 | + ConfigurableResourceFactory, |
| 18 | + infer_schema_from_config_class, |
| 19 | +) |
17 | 20 | from dagster._utils.cached_method import cached_method |
18 | 21 | from pydantic import ( |
19 | 22 | Field as PyField, |
@@ -1119,3 +1122,33 @@ class MergeResource(dg.ConfigurableResource): |
1119 | 1122 | int_res=StrResource.configure_at_launch(), |
1120 | 1123 | str_res=IntResource.configure_at_launch(), |
1121 | 1124 | ) |
| 1125 | + |
| 1126 | + |
| 1127 | +def test_secret_field(): |
| 1128 | + """Test that is_secret is extracted from json_schema_extra in ConfigurableResource.""" |
| 1129 | + |
| 1130 | + class MyResource(dg.ConfigurableResource): |
| 1131 | + api_key: str = PyField( |
| 1132 | + description="API key for authentication", |
| 1133 | + json_schema_extra={"is_secret": True}, |
| 1134 | + ) |
| 1135 | + host: str = PyField(description="Host URL") |
| 1136 | + password: str = PyField(json_schema_extra={"is_secret": True}) |
| 1137 | + |
| 1138 | + # Get the inferred schema |
| 1139 | + schema_field = infer_schema_from_config_class(MyResource) |
| 1140 | + |
| 1141 | + # The schema should have the fields |
| 1142 | + fields_dict = schema_field.config_type.fields # type: ignore |
| 1143 | + |
| 1144 | + # Check that api_key is marked as secret |
| 1145 | + assert "api_key" in fields_dict |
| 1146 | + assert fields_dict["api_key"].is_secret is True |
| 1147 | + |
| 1148 | + # Check that host is not marked as secret |
| 1149 | + assert "host" in fields_dict |
| 1150 | + assert fields_dict["host"].is_secret is False |
| 1151 | + |
| 1152 | + # Check that password is marked as secret |
| 1153 | + assert "password" in fields_dict |
| 1154 | + assert fields_dict["password"].is_secret is True |
0 commit comments