Skip to content

Commit

Permalink
[aws][fix] Support legacy interface (#1303)
Browse files Browse the repository at this point in the history
  • Loading branch information
aquamatthias authored Nov 22, 2022
1 parent 78045c6 commit 67529a8
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 10 deletions.
8 changes: 1 addition & 7 deletions plugins/aws/resoto_plugin_aws/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@
from resotolib.utils import log_runtime, NoExitArgumentParser
from .collector import AwsAccountCollector
from .configuration import AwsConfig
from .resource.base import AwsAccount, AwsResource
from .resource.base import AwsAccount, AwsResource, get_client
from .utils import aws_session

logging.getLogger("boto").setLevel(logging.CRITICAL)
Expand Down Expand Up @@ -376,12 +376,6 @@ def authenticated(account: AwsAccount, core_feedback: CoreFeedback) -> bool:
return True


def get_client(config: Config, resource: BaseResource) -> AwsClient:
account = resource.account()
assert isinstance(account, AwsAccount)
return AwsClient(config.aws, account.id, role=account.role, profile=account.profile, region=resource.region().id)


def current_account_id(profile: Optional[str] = None) -> str:
session = aws_session(profile=profile)
return session.client("sts").get_caller_identity().get("Account") # type: ignore
Expand Down
13 changes: 10 additions & 3 deletions plugins/aws/resoto_plugin_aws/resource/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@
BaseVolumeType,
ModelReference,
)
from resotolib.config import Config, current_config
from resotolib.core.actions import CoreFeedback
from resotolib.graph import Graph
from resotolib.json import to_json as to_js, from_json as from_js
Expand All @@ -35,6 +36,12 @@
log = logging.getLogger("resoto.plugins.aws")


def get_client(config: Config, resource: BaseResource) -> AwsClient:
account = resource.account()
assert isinstance(account, AwsAccount)
return AwsClient(config.aws, account.id, role=account.role, profile=account.profile, region=resource.region().id)


@define
class AwsApiSpec:
"""
Expand Down Expand Up @@ -80,15 +87,15 @@ def delete_resource(self, client: AwsClient) -> bool:

# legacy interface
def update_tag(self, key: str, value: str) -> bool:
return False
return self.update_resource_tag(get_client(current_config(), self), key, value)

# legacy interface
def delete_tag(self, key: str) -> bool:
return False
return self.delete_resource_tag(get_client(current_config(), self), key)

# legacy interface
def delete(self, graph: Graph) -> bool:
return False
return self.delete_resource(get_client(current_config(), self))

def to_json(self) -> Json:
return to_js(
Expand Down

0 comments on commit 67529a8

Please sign in to comment.