Skip to content

Commit

Permalink
make s3 credentials optional
Browse files Browse the repository at this point in the history
  • Loading branch information
zubenkoivan committed Sep 18, 2024
1 parent fd1b1a3 commit b2eea99
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 4 deletions.
4 changes: 2 additions & 2 deletions platform_monitoring/config.py
Original file line number Diff line number Diff line change
Expand Up @@ -37,9 +37,9 @@ class ElasticsearchConfig:
@dataclass(frozen=True)
class S3Config:
region: str
access_key_id: str = field(repr=False)
secret_access_key: str = field(repr=False)
job_logs_bucket_name: str
access_key_id: str | None = field(default=None, repr=False)
secret_access_key: str | None = field(default=None, repr=False)
endpoint_url: URL | None = None


Expand Down
4 changes: 2 additions & 2 deletions platform_monitoring/config_factory.py
Original file line number Diff line number Diff line change
Expand Up @@ -82,8 +82,8 @@ def _create_s3(self) -> S3Config | None:
endpoint_url = self._environ.get("NP_MONITORING_S3_ENDPOINT_URL", "")
return S3Config(
region=self._environ.get("NP_MONITORING_S3_REGION", ""),
access_key_id=self._environ["NP_MONITORING_S3_ACCESS_KEY_ID"],
secret_access_key=self._environ["NP_MONITORING_S3_SECRET_ACCESS_KEY"],
access_key_id=self._environ.get("NP_MONITORING_S3_ACCESS_KEY_ID"),
secret_access_key=self._environ.get("NP_MONITORING_S3_SECRET_ACCESS_KEY"),
endpoint_url=URL(endpoint_url) if endpoint_url else None,
job_logs_bucket_name=self._environ["NP_MONITORING_S3_JOB_LOGS_BUCKET_NAME"],
)
Expand Down
19 changes: 19 additions & 0 deletions tests/unit/test_config.py
Original file line number Diff line number Diff line change
Expand Up @@ -123,6 +123,25 @@ def test_create_with_kubernetes_labels(environ: dict[str, Any]) -> None:
assert config.kube.node_pool_label == "node-pool"


def test_create_with_s3__default(environ: dict[str, Any]) -> None:
environ["NP_MONITORING_S3_REGION"] = "us-east-1"
environ["NP_MONITORING_S3_JOB_LOGS_BUCKET_NAME"] = "logs"

config = EnvironConfigFactory(environ).create()

assert config.s3 == S3Config(
region="us-east-1",
job_logs_bucket_name="logs",
)

environ["NP_MONITORING_S3_ENDPOINT_URL"] = "http://minio:9000"

config = EnvironConfigFactory(environ).create()

assert config.s3
assert config.s3.endpoint_url == URL("http://minio:9000")


def test_create_with_s3(environ: dict[str, Any]) -> None:
environ["NP_MONITORING_S3_REGION"] = "us-east-1"
environ["NP_MONITORING_S3_ACCESS_KEY_ID"] = "access_key"
Expand Down

0 comments on commit b2eea99

Please sign in to comment.