From 67529a8c4a4c29e59314f9f72fa813366506f69c Mon Sep 17 00:00:00 2001 From: Matthias Veit Date: Tue, 22 Nov 2022 18:42:16 +0100 Subject: [PATCH] [aws][fix] Support legacy interface (#1303) --- plugins/aws/resoto_plugin_aws/__init__.py | 8 +------- plugins/aws/resoto_plugin_aws/resource/base.py | 13 ++++++++++--- 2 files changed, 11 insertions(+), 10 deletions(-) diff --git a/plugins/aws/resoto_plugin_aws/__init__.py b/plugins/aws/resoto_plugin_aws/__init__.py index 72cabd680c..799f7d6ba1 100644 --- a/plugins/aws/resoto_plugin_aws/__init__.py +++ b/plugins/aws/resoto_plugin_aws/__init__.py @@ -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) @@ -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 diff --git a/plugins/aws/resoto_plugin_aws/resource/base.py b/plugins/aws/resoto_plugin_aws/resource/base.py index 55c80d4275..bd50afab23 100644 --- a/plugins/aws/resoto_plugin_aws/resource/base.py +++ b/plugins/aws/resoto_plugin_aws/resource/base.py @@ -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 @@ -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: """ @@ -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(