Skip to content

Commit

Permalink
fix(object_storage): ARC new interface were not supporting
Browse files Browse the repository at this point in the history
  • Loading branch information
kkiani committed Aug 8, 2024
1 parent 694cc60 commit e3854d0
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 34 deletions.
24 changes: 6 additions & 18 deletions src/damavand/cloud/aws/object_storage.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
from functools import cache
import boto3
import io
import logging
Expand All @@ -9,7 +10,6 @@
from damavand import utils
from damavand.controllers import ObjectStorageController, buildtime, runtime
from damavand.errors import (
CallResourceBeforeProvision,
RuntimeException,
ObjectNotFound,
ResourceAccessDenied,
Expand All @@ -32,16 +32,11 @@ def __init__(
self.__s3_client = boto3.client("s3", region_name=region)

@buildtime
def provision(self):
if not self.id_:
self.id_ = self.name
logger.info(
f"Resource ID not provided for bucket with name `{self.name}`, using the name as ID."
)

self._pulumi_object = s3.Bucket(
self.id_,
bucket=self.name,
@cache
def resource(self) -> PulumiResource:
return s3.BucketV2(
resource_name=f"{self.name}-bucket",
bucket_prefix=self.name,
tags=self.tags,
**self.extra_args,
)
Expand Down Expand Up @@ -123,10 +118,3 @@ def exist(self, path: str) -> bool:
raise ResourceAccessDenied(name=self.name) from e
case _:
raise RuntimeException() from e

@buildtime
def to_pulumi(self) -> PulumiResource:
if self._pulumi_object is None:
raise CallResourceBeforeProvision()

return self._pulumi_object
3 changes: 0 additions & 3 deletions src/damavand/controllers/object_storage.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,9 +13,6 @@ def __init__(
) -> None:
super().__init__(name, id_, tags, **kwargs)

def provision(self):
raise NotImplementedError

def read(self, path: str) -> bytes:
"""Read an object from the storage."""
raise NotImplementedError
Expand Down
16 changes: 3 additions & 13 deletions tests/clouds/aws/test_aws_object_storage.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@

from pulumi_aws import s3
from damavand.cloud.aws import AwsObjectStorageController
from damavand.errors import CallResourceBeforeProvision, ObjectNotFound
from damavand.errors import ObjectNotFound


@pytest.fixture
Expand All @@ -20,22 +20,12 @@ def conn():
return boto3.resource("s3", region_name="us-east-1")


def test_to_pulumi_raise_before_provision(
def test_resource_return_pulumi_s3_bucket_v2(
monkeypatch: MonkeyPatch, bucket: AwsObjectStorageController
):
monkeypatch.setattr("damavand.utils.is_building", lambda: True)

with pytest.raises(CallResourceBeforeProvision):
bucket.to_pulumi()


def test_to_pulumi_return_pulumi_s3_bucket(
monkeypatch: MonkeyPatch, bucket: AwsObjectStorageController
):
monkeypatch.setattr("damavand.utils.is_building", lambda: True)

bucket.provision()
assert isinstance(bucket.to_pulumi(), s3.Bucket)
assert isinstance(bucket.resource(), s3.BucketV2)


@mock_aws
Expand Down

0 comments on commit e3854d0

Please sign in to comment.