Skip to content

Commit

Permalink
Update boto3 variables to optional
Browse files Browse the repository at this point in the history
  • Loading branch information
Sophie Glinton authored and Sophie Glinton committed Feb 14, 2025
1 parent 770bdfb commit bca35a7
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 15 deletions.
33 changes: 21 additions & 12 deletions src/matchbox/server/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
TYPE_CHECKING,
Any,
Callable,
Optional,
ParamSpec,
Protocol,
TypeVar,
Expand Down Expand Up @@ -54,25 +55,33 @@ class MatchboxDatastoreSettings(BaseSettings):
extra="ignore",
)

host: str
port: int
access_key_id: SecretStr
secret_access_key: SecretStr
default_region: str
host: Optional[str] = None
port: Optional[int] = None
access_key_id: Optional[SecretStr] = None
secret_access_key: Optional[SecretStr] = None
default_region: Optional[str] = None
cache_bucket_name: str

def get_client(self) -> S3Client:
"""Returns an S3 client for the datastore.
Creates S3 buckets if they don't exist.
"""
client = boto3.client(
"s3",
endpoint_url=f"http://{self.host}:{self.port}",
aws_access_key_id=self.access_key_id.get_secret_value(),
aws_secret_access_key=self.secret_access_key.get_secret_value(),
region_name=self.default_region,
)

kwargs = {
"endpoint_url": f"http://{self.host}:{self.port}"
if self.host and self.port
else None,
"aws_access_key_id": self.access_key_id.get_secret_value()
if self.access_key_id
else None,
"aws_secret_access_key": self.secret_access_key.get_secret_value()
if self.secret_access_key
else None,
"region_name": self.default_region,
}

client = boto3.client("s3", **kwargs)

try:
client.head_bucket(Bucket=self.cache_bucket_name)
Expand Down
6 changes: 3 additions & 3 deletions uv.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

0 comments on commit bca35a7

Please sign in to comment.