Skip to content

Commit

Permalink
Merge pull request #210 from Cornerstone-OnDemand/ease-storage-driver…
Browse files Browse the repository at this point in the history
…-settings-extra

storage driver settings: ignore extra
  • Loading branch information
antoinejeannot authored Jan 19, 2024
2 parents 13144f5 + a44d68f commit 9090618
Show file tree
Hide file tree
Showing 5 changed files with 30 additions and 4 deletions.
2 changes: 1 addition & 1 deletion modelkit/assets/drivers/azure.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ class AzureStorageDriverSettings(StorageDriverSettings):
"connection_string", "AZURE_STORAGE_CONNECTION_STRING"
),
)
model_config = pydantic.ConfigDict(extra="forbid")
model_config = pydantic.ConfigDict(extra="ignore")


class AzureStorageDriver(StorageDriver):
Expand Down
2 changes: 1 addition & 1 deletion modelkit/assets/drivers/gcs.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ class GCSStorageDriverSettings(StorageDriverSettings):
"service_account_path", "GOOGLE_APPLICATION_CREDENTIALS"
),
)
model_config = pydantic.ConfigDict(extra="forbid")
model_config = pydantic.ConfigDict(extra="ignore")


class GCSStorageDriver(StorageDriver):
Expand Down
2 changes: 1 addition & 1 deletion modelkit/assets/drivers/local.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@


class LocalStorageDriverSettings(StorageDriverSettings):
model_config = pydantic.ConfigDict(extra="forbid")
model_config = pydantic.ConfigDict(extra="ignore")


class LocalStorageDriver(StorageDriver):
Expand Down
2 changes: 1 addition & 1 deletion modelkit/assets/drivers/s3.py
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ class S3StorageDriverSettings(StorageDriverSettings):
aws_kms_key_id: Optional[str] = pydantic.Field(
None, validation_alias=pydantic.AliasChoices("aws_kms_key_id", "AWS_KMS_KEY_ID")
)
model_config = pydantic.ConfigDict(extra="forbid")
model_config = pydantic.ConfigDict(extra="ignore")


class S3StorageDriver(StorageDriver):
Expand Down
26 changes: 26 additions & 0 deletions tests/test_settings.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,11 @@
import pydantic
import pytest

from modelkit.assets.drivers.abc import StorageDriverSettings
from modelkit.assets.drivers.azure import AzureStorageDriverSettings
from modelkit.assets.drivers.gcs import GCSStorageDriverSettings
from modelkit.assets.drivers.local import LocalStorageDriverSettings
from modelkit.assets.drivers.s3 import S3StorageDriverSettings
from modelkit.core.settings import ModelkitSettings


Expand All @@ -22,3 +28,23 @@ class ServingSettings(ModelkitSettings):
# because both `enable` and `SERVING_ENABLE` are set and passed to the
# constructor.
assert ServingSettings(enable=False).enable is False


@pytest.mark.parametrize(
"Settings",
[
StorageDriverSettings,
GCSStorageDriverSettings,
AzureStorageDriverSettings,
S3StorageDriverSettings,
LocalStorageDriverSettings,
],
)
def test_storage_driver_settings(Settings, monkeypatch):
monkeypatch.setenv("MODELKIT_STORAGE_BUCKET", "foo")
assert Settings().bucket == "foo"
assert Settings(bucket="bar").bucket == "bar"
monkeypatch.delenv("MODELKIT_STORAGE_BUCKET")
assert Settings(bucket="bar").bucket == "bar"
with pytest.raises(pydantic.ValidationError):
_ = Settings()

0 comments on commit 9090618

Please sign in to comment.