qodalis-cli-server-plugin-aws 1.0.0b13__py3-none-any.whl
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- qodalis_cli_aws/__init__.py +5 -0
- qodalis_cli_aws/aws_module.py +34 -0
- qodalis_cli_aws/processors/__init__.py +0 -0
- qodalis_cli_aws/processors/aws_command_processor.py +297 -0
- qodalis_cli_aws/processors/cloudwatch_processor.py +237 -0
- qodalis_cli_aws/processors/dynamodb_processor.py +274 -0
- qodalis_cli_aws/processors/ec2_processor.py +405 -0
- qodalis_cli_aws/processors/ecs_processor.py +236 -0
- qodalis_cli_aws/processors/iam_processor.py +208 -0
- qodalis_cli_aws/processors/lambda_processor.py +247 -0
- qodalis_cli_aws/processors/s3_processor.py +446 -0
- qodalis_cli_aws/processors/sns_processor.py +205 -0
- qodalis_cli_aws/processors/sqs_processor.py +250 -0
- qodalis_cli_aws/services/__init__.py +4 -0
- qodalis_cli_aws/services/aws_config_service.py +81 -0
- qodalis_cli_aws/services/aws_credential_manager.py +59 -0
- qodalis_cli_aws/utils/__init__.py +0 -0
- qodalis_cli_aws/utils/output_helpers.py +170 -0
- qodalis_cli_server_plugin_aws-1.0.0b13.dist-info/METADATA +25 -0
- qodalis_cli_server_plugin_aws-1.0.0b13.dist-info/RECORD +21 -0
- qodalis_cli_server_plugin_aws-1.0.0b13.dist-info/WHEEL +4 -0
|
@@ -0,0 +1,250 @@
|
|
|
1
|
+
from __future__ import annotations
|
|
2
|
+
|
|
3
|
+
import asyncio
|
|
4
|
+
|
|
5
|
+
from typing import Any
|
|
6
|
+
|
|
7
|
+
from qodalis_cli_server_abstractions import (
|
|
8
|
+
get_positional_text,
|
|
9
|
+
CliCommandParameterDescriptor,
|
|
10
|
+
CliCommandProcessor,
|
|
11
|
+
CliProcessCommand,
|
|
12
|
+
ICliCommandParameterDescriptor,
|
|
13
|
+
ICliCommandProcessor,
|
|
14
|
+
)
|
|
15
|
+
|
|
16
|
+
from ..services.aws_credential_manager import AwsCredentialManager
|
|
17
|
+
from ..utils.output_helpers import (
|
|
18
|
+
build_response,
|
|
19
|
+
build_error_response,
|
|
20
|
+
build_success_response,
|
|
21
|
+
format_as_json,
|
|
22
|
+
format_as_list,
|
|
23
|
+
apply_output_format,
|
|
24
|
+
is_dry_run,
|
|
25
|
+
CliServerTextOutput,
|
|
26
|
+
)
|
|
27
|
+
|
|
28
|
+
|
|
29
|
+
class _SqsListProcessor(CliCommandProcessor):
|
|
30
|
+
"""Lists all SQS queue URLs."""
|
|
31
|
+
|
|
32
|
+
def __init__(self, credential_manager: AwsCredentialManager) -> None:
|
|
33
|
+
super().__init__()
|
|
34
|
+
self._credential_manager = credential_manager
|
|
35
|
+
|
|
36
|
+
@property
|
|
37
|
+
def command(self) -> str:
|
|
38
|
+
return "list"
|
|
39
|
+
|
|
40
|
+
@property
|
|
41
|
+
def description(self) -> str:
|
|
42
|
+
return "List SQS queues"
|
|
43
|
+
|
|
44
|
+
@property
|
|
45
|
+
def parameters(self) -> list[ICliCommandParameterDescriptor]:
|
|
46
|
+
return [
|
|
47
|
+
CliCommandParameterDescriptor(name="region", description="AWS region override", required=False, type="string", aliases=["-r"]),
|
|
48
|
+
CliCommandParameterDescriptor(name="output", description="Output format (list|json|text)", required=False, type="string", aliases=["-o"], default_value="list"),
|
|
49
|
+
]
|
|
50
|
+
|
|
51
|
+
async def handle_async(self, command: CliProcessCommand, cancellation_event: asyncio.Event | None = None) -> str:
|
|
52
|
+
return ""
|
|
53
|
+
|
|
54
|
+
async def handle_structured_async(self, command: CliProcessCommand, cancellation_event: asyncio.Event | None = None) -> Any:
|
|
55
|
+
"""Fetches and returns all SQS queue URLs."""
|
|
56
|
+
region = command.args.get("region")
|
|
57
|
+
client = self._credential_manager.get_client("sqs", region=str(region) if region else None)
|
|
58
|
+
|
|
59
|
+
try:
|
|
60
|
+
response = client.list_queues()
|
|
61
|
+
queue_urls = response.get("QueueUrls", [])
|
|
62
|
+
|
|
63
|
+
if not queue_urls:
|
|
64
|
+
return build_response([CliServerTextOutput(value="No SQS queues found.", style="warning")])
|
|
65
|
+
|
|
66
|
+
list_output = format_as_list(queue_urls)
|
|
67
|
+
return build_response([apply_output_format(command, list_output, queue_urls)])
|
|
68
|
+
except Exception as exc:
|
|
69
|
+
return build_error_response(f"Failed to list SQS queues: {exc}")
|
|
70
|
+
|
|
71
|
+
|
|
72
|
+
class _SqsSendProcessor(CliCommandProcessor):
|
|
73
|
+
"""Sends a message to an SQS queue."""
|
|
74
|
+
|
|
75
|
+
def __init__(self, credential_manager: AwsCredentialManager) -> None:
|
|
76
|
+
super().__init__()
|
|
77
|
+
self._credential_manager = credential_manager
|
|
78
|
+
|
|
79
|
+
@property
|
|
80
|
+
def command(self) -> str:
|
|
81
|
+
return "send"
|
|
82
|
+
|
|
83
|
+
@property
|
|
84
|
+
def description(self) -> str:
|
|
85
|
+
return "Send a message to an SQS queue"
|
|
86
|
+
|
|
87
|
+
@property
|
|
88
|
+
def value_required(self) -> bool | None:
|
|
89
|
+
return True
|
|
90
|
+
|
|
91
|
+
@property
|
|
92
|
+
def parameters(self) -> list[ICliCommandParameterDescriptor]:
|
|
93
|
+
return [
|
|
94
|
+
CliCommandParameterDescriptor(name="message", description="Message body to send", required=True, type="string", aliases=["-m"]),
|
|
95
|
+
CliCommandParameterDescriptor(name="region", description="AWS region override", required=False, type="string", aliases=["-r"]),
|
|
96
|
+
]
|
|
97
|
+
|
|
98
|
+
async def handle_async(self, command: CliProcessCommand, cancellation_event: asyncio.Event | None = None) -> str:
|
|
99
|
+
return ""
|
|
100
|
+
|
|
101
|
+
async def handle_structured_async(self, command: CliProcessCommand, cancellation_event: asyncio.Event | None = None) -> Any:
|
|
102
|
+
"""Sends the provided message body to the specified SQS queue."""
|
|
103
|
+
queue_url = get_positional_text(command)
|
|
104
|
+
if not queue_url:
|
|
105
|
+
return build_error_response("Queue URL is required. Usage: sqs send <queue-url> --message <body>")
|
|
106
|
+
|
|
107
|
+
message_body = command.args.get("message")
|
|
108
|
+
if not message_body:
|
|
109
|
+
return build_error_response("--message is required. Usage: sqs send <queue-url> --message <body>")
|
|
110
|
+
|
|
111
|
+
region = command.args.get("region")
|
|
112
|
+
client = self._credential_manager.get_client("sqs", region=str(region) if region else None)
|
|
113
|
+
|
|
114
|
+
try:
|
|
115
|
+
response = client.send_message(QueueUrl=queue_url, MessageBody=str(message_body))
|
|
116
|
+
return build_success_response(f"Message sent successfully. MessageId: {response.get('MessageId', '(unknown)')}")
|
|
117
|
+
except Exception as exc:
|
|
118
|
+
return build_error_response(f"Failed to send message: {exc}")
|
|
119
|
+
|
|
120
|
+
|
|
121
|
+
class _SqsReceiveProcessor(CliCommandProcessor):
|
|
122
|
+
"""Receives messages from an SQS queue."""
|
|
123
|
+
|
|
124
|
+
def __init__(self, credential_manager: AwsCredentialManager) -> None:
|
|
125
|
+
super().__init__()
|
|
126
|
+
self._credential_manager = credential_manager
|
|
127
|
+
|
|
128
|
+
@property
|
|
129
|
+
def command(self) -> str:
|
|
130
|
+
return "receive"
|
|
131
|
+
|
|
132
|
+
@property
|
|
133
|
+
def description(self) -> str:
|
|
134
|
+
return "Receive messages from an SQS queue"
|
|
135
|
+
|
|
136
|
+
@property
|
|
137
|
+
def value_required(self) -> bool | None:
|
|
138
|
+
return True
|
|
139
|
+
|
|
140
|
+
@property
|
|
141
|
+
def parameters(self) -> list[ICliCommandParameterDescriptor]:
|
|
142
|
+
return [
|
|
143
|
+
CliCommandParameterDescriptor(name="max", description="Maximum number of messages to receive (default: 1)", required=False, type="number", aliases=["-n"], default_value="1"),
|
|
144
|
+
CliCommandParameterDescriptor(name="region", description="AWS region override", required=False, type="string", aliases=["-r"]),
|
|
145
|
+
]
|
|
146
|
+
|
|
147
|
+
async def handle_async(self, command: CliProcessCommand, cancellation_event: asyncio.Event | None = None) -> str:
|
|
148
|
+
return ""
|
|
149
|
+
|
|
150
|
+
async def handle_structured_async(self, command: CliProcessCommand, cancellation_event: asyncio.Event | None = None) -> Any:
|
|
151
|
+
"""Polls the specified queue for up to ``--max`` messages."""
|
|
152
|
+
queue_url = get_positional_text(command)
|
|
153
|
+
if not queue_url:
|
|
154
|
+
return build_error_response("Queue URL is required. Usage: sqs receive <queue-url>")
|
|
155
|
+
|
|
156
|
+
try:
|
|
157
|
+
max_messages = int(command.args.get("max", 1))
|
|
158
|
+
except (ValueError, TypeError):
|
|
159
|
+
max_messages = 1
|
|
160
|
+
|
|
161
|
+
region = command.args.get("region")
|
|
162
|
+
client = self._credential_manager.get_client("sqs", region=str(region) if region else None)
|
|
163
|
+
|
|
164
|
+
try:
|
|
165
|
+
response = client.receive_message(QueueUrl=queue_url, MaxNumberOfMessages=max_messages)
|
|
166
|
+
messages = response.get("Messages", [])
|
|
167
|
+
|
|
168
|
+
if not messages:
|
|
169
|
+
return build_response([CliServerTextOutput(value="No messages available in the queue.", style="warning")])
|
|
170
|
+
|
|
171
|
+
return build_response([format_as_json(messages)])
|
|
172
|
+
except Exception as exc:
|
|
173
|
+
return build_error_response(f"Failed to receive messages: {exc}")
|
|
174
|
+
|
|
175
|
+
|
|
176
|
+
class _SqsPurgeProcessor(CliCommandProcessor):
|
|
177
|
+
"""Purges all messages from an SQS queue."""
|
|
178
|
+
|
|
179
|
+
def __init__(self, credential_manager: AwsCredentialManager) -> None:
|
|
180
|
+
super().__init__()
|
|
181
|
+
self._credential_manager = credential_manager
|
|
182
|
+
|
|
183
|
+
@property
|
|
184
|
+
def command(self) -> str:
|
|
185
|
+
return "purge"
|
|
186
|
+
|
|
187
|
+
@property
|
|
188
|
+
def description(self) -> str:
|
|
189
|
+
return "Purge all messages from an SQS queue"
|
|
190
|
+
|
|
191
|
+
@property
|
|
192
|
+
def value_required(self) -> bool | None:
|
|
193
|
+
return True
|
|
194
|
+
|
|
195
|
+
@property
|
|
196
|
+
def parameters(self) -> list[ICliCommandParameterDescriptor]:
|
|
197
|
+
return [
|
|
198
|
+
CliCommandParameterDescriptor(name="dry-run", description="Show what would be purged without actually purging", required=False, type="boolean", aliases=["--dry-run"]),
|
|
199
|
+
CliCommandParameterDescriptor(name="region", description="AWS region override", required=False, type="string", aliases=["-r"]),
|
|
200
|
+
]
|
|
201
|
+
|
|
202
|
+
async def handle_async(self, command: CliProcessCommand, cancellation_event: asyncio.Event | None = None) -> str:
|
|
203
|
+
return ""
|
|
204
|
+
|
|
205
|
+
async def handle_structured_async(self, command: CliProcessCommand, cancellation_event: asyncio.Event | None = None) -> Any:
|
|
206
|
+
"""Purges the queue, or previews the action in dry-run mode."""
|
|
207
|
+
queue_url = get_positional_text(command)
|
|
208
|
+
if not queue_url:
|
|
209
|
+
return build_error_response("Queue URL is required. Usage: sqs purge <queue-url>")
|
|
210
|
+
|
|
211
|
+
if is_dry_run(command):
|
|
212
|
+
return build_response([CliServerTextOutput(value=f"[dry-run] Would purge all messages from queue: {queue_url}", style="warning")])
|
|
213
|
+
|
|
214
|
+
region = command.args.get("region")
|
|
215
|
+
client = self._credential_manager.get_client("sqs", region=str(region) if region else None)
|
|
216
|
+
|
|
217
|
+
try:
|
|
218
|
+
client.purge_queue(QueueUrl=queue_url)
|
|
219
|
+
return build_success_response(f"Queue purged successfully: {queue_url}")
|
|
220
|
+
except Exception as exc:
|
|
221
|
+
return build_error_response(f"Failed to purge queue: {exc}")
|
|
222
|
+
|
|
223
|
+
|
|
224
|
+
class AwsSqsProcessor(CliCommandProcessor):
|
|
225
|
+
"""Parent processor for SQS sub-commands (list, send, receive, purge)."""
|
|
226
|
+
|
|
227
|
+
def __init__(self, credential_manager: AwsCredentialManager) -> None:
|
|
228
|
+
super().__init__()
|
|
229
|
+
self._sub_processors: list[ICliCommandProcessor] = [
|
|
230
|
+
_SqsListProcessor(credential_manager),
|
|
231
|
+
_SqsSendProcessor(credential_manager),
|
|
232
|
+
_SqsReceiveProcessor(credential_manager),
|
|
233
|
+
_SqsPurgeProcessor(credential_manager),
|
|
234
|
+
]
|
|
235
|
+
|
|
236
|
+
@property
|
|
237
|
+
def command(self) -> str:
|
|
238
|
+
return "sqs"
|
|
239
|
+
|
|
240
|
+
@property
|
|
241
|
+
def description(self) -> str:
|
|
242
|
+
return "AWS SQS operations -- list, send, receive, purge"
|
|
243
|
+
|
|
244
|
+
@property
|
|
245
|
+
def processors(self) -> list[ICliCommandProcessor]:
|
|
246
|
+
"""Returns sub-processors for SQS operations."""
|
|
247
|
+
return self._sub_processors
|
|
248
|
+
|
|
249
|
+
async def handle_async(self, command: CliProcessCommand, cancellation_event: asyncio.Event | None = None) -> str:
|
|
250
|
+
return ""
|
|
@@ -0,0 +1,81 @@
|
|
|
1
|
+
from __future__ import annotations
|
|
2
|
+
|
|
3
|
+
|
|
4
|
+
class AwsConfigService:
|
|
5
|
+
"""Manages AWS credentials, region, and profile configuration in memory."""
|
|
6
|
+
|
|
7
|
+
def __init__(self) -> None:
|
|
8
|
+
self._access_key_id: str | None = None
|
|
9
|
+
self._secret_access_key: str | None = None
|
|
10
|
+
self._region: str | None = None
|
|
11
|
+
self._profile: str | None = None
|
|
12
|
+
|
|
13
|
+
def get_access_key_id(self) -> str | None:
|
|
14
|
+
"""Returns the configured AWS access key ID, or ``None``."""
|
|
15
|
+
return self._access_key_id
|
|
16
|
+
|
|
17
|
+
def get_secret_access_key(self) -> str | None:
|
|
18
|
+
"""Returns the configured AWS secret access key, or ``None``."""
|
|
19
|
+
return self._secret_access_key
|
|
20
|
+
|
|
21
|
+
def get_region(self) -> str | None:
|
|
22
|
+
"""Returns the configured AWS region, or ``None``."""
|
|
23
|
+
return self._region
|
|
24
|
+
|
|
25
|
+
def get_profile(self) -> str | None:
|
|
26
|
+
"""Returns the configured AWS profile name, or ``None``."""
|
|
27
|
+
return self._profile
|
|
28
|
+
|
|
29
|
+
def set_credentials(self, access_key_id: str, secret_access_key: str) -> None:
|
|
30
|
+
"""Stores AWS access key credentials.
|
|
31
|
+
|
|
32
|
+
Args:
|
|
33
|
+
access_key_id: The AWS access key ID.
|
|
34
|
+
secret_access_key: The AWS secret access key.
|
|
35
|
+
"""
|
|
36
|
+
self._access_key_id = access_key_id
|
|
37
|
+
self._secret_access_key = secret_access_key
|
|
38
|
+
|
|
39
|
+
def set_region(self, region: str) -> None:
|
|
40
|
+
"""Sets the default AWS region.
|
|
41
|
+
|
|
42
|
+
Args:
|
|
43
|
+
region: AWS region identifier (e.g. ``us-east-1``).
|
|
44
|
+
"""
|
|
45
|
+
self._region = region
|
|
46
|
+
|
|
47
|
+
def set_profile(self, profile: str) -> None:
|
|
48
|
+
"""Sets the AWS profile name to use.
|
|
49
|
+
|
|
50
|
+
Args:
|
|
51
|
+
profile: Profile name from ``~/.aws/credentials``.
|
|
52
|
+
"""
|
|
53
|
+
self._profile = profile
|
|
54
|
+
|
|
55
|
+
def get_config_summary(self) -> dict[str, str | None]:
|
|
56
|
+
"""Returns a summary of the current configuration with secrets masked.
|
|
57
|
+
|
|
58
|
+
Returns:
|
|
59
|
+
Dictionary with ``access_key_id``, ``secret_access_key``, ``region``,
|
|
60
|
+
and ``profile`` keys.
|
|
61
|
+
"""
|
|
62
|
+
return {
|
|
63
|
+
"access_key_id": self._mask_key(self._access_key_id) if self._access_key_id else None,
|
|
64
|
+
"secret_access_key": "****" if self._secret_access_key else None,
|
|
65
|
+
"region": self._region,
|
|
66
|
+
"profile": self._profile,
|
|
67
|
+
}
|
|
68
|
+
|
|
69
|
+
@staticmethod
|
|
70
|
+
def _mask_key(key: str) -> str:
|
|
71
|
+
"""Masks the middle portion of a key string for safe display.
|
|
72
|
+
|
|
73
|
+
Args:
|
|
74
|
+
key: The key string to mask.
|
|
75
|
+
|
|
76
|
+
Returns:
|
|
77
|
+
The masked key with only the first 4 and last 5 characters visible.
|
|
78
|
+
"""
|
|
79
|
+
if len(key) <= 8:
|
|
80
|
+
return "****"
|
|
81
|
+
return key[:4] + "***" + key[-5:]
|
|
@@ -0,0 +1,59 @@
|
|
|
1
|
+
from __future__ import annotations
|
|
2
|
+
|
|
3
|
+
import os
|
|
4
|
+
from typing import Any
|
|
5
|
+
|
|
6
|
+
import boto3
|
|
7
|
+
|
|
8
|
+
from .aws_config_service import AwsConfigService
|
|
9
|
+
|
|
10
|
+
|
|
11
|
+
class AwsCredentialManager:
|
|
12
|
+
"""Creates and caches boto3 clients using the stored AWS configuration."""
|
|
13
|
+
|
|
14
|
+
def __init__(self, config: AwsConfigService) -> None:
|
|
15
|
+
self._config = config
|
|
16
|
+
self._client_cache: dict[str, Any] = {}
|
|
17
|
+
|
|
18
|
+
def get_client(self, service_name: str, region: str | None = None) -> Any:
|
|
19
|
+
"""Returns a boto3 client for the given service, reusing cached instances.
|
|
20
|
+
|
|
21
|
+
Credentials are resolved from the config service first, then from
|
|
22
|
+
environment variables.
|
|
23
|
+
|
|
24
|
+
Args:
|
|
25
|
+
service_name: AWS service name (e.g. ``"s3"``, ``"ec2"``).
|
|
26
|
+
region: Optional region override; falls back to config and env vars.
|
|
27
|
+
|
|
28
|
+
Returns:
|
|
29
|
+
A boto3 service client.
|
|
30
|
+
"""
|
|
31
|
+
effective_region = (
|
|
32
|
+
region
|
|
33
|
+
or self._config.get_region()
|
|
34
|
+
or os.environ.get("AWS_REGION")
|
|
35
|
+
or os.environ.get("AWS_DEFAULT_REGION")
|
|
36
|
+
)
|
|
37
|
+
profile = self._config.get_profile() or "default"
|
|
38
|
+
cache_key = f"{service_name}:{effective_region or 'default'}:{profile}"
|
|
39
|
+
|
|
40
|
+
if cache_key not in self._client_cache:
|
|
41
|
+
kwargs: dict[str, Any] = {}
|
|
42
|
+
|
|
43
|
+
access_key = self._config.get_access_key_id() or os.environ.get("AWS_ACCESS_KEY_ID")
|
|
44
|
+
secret_key = self._config.get_secret_access_key() or os.environ.get("AWS_SECRET_ACCESS_KEY")
|
|
45
|
+
|
|
46
|
+
if access_key and secret_key:
|
|
47
|
+
kwargs["aws_access_key_id"] = access_key
|
|
48
|
+
kwargs["aws_secret_access_key"] = secret_key
|
|
49
|
+
|
|
50
|
+
if effective_region:
|
|
51
|
+
kwargs["region_name"] = effective_region
|
|
52
|
+
|
|
53
|
+
self._client_cache[cache_key] = boto3.client(service_name, **kwargs)
|
|
54
|
+
|
|
55
|
+
return self._client_cache[cache_key]
|
|
56
|
+
|
|
57
|
+
def clear_cache(self) -> None:
|
|
58
|
+
"""Clears all cached boto3 clients, forcing re-creation on next access."""
|
|
59
|
+
self._client_cache.clear()
|
|
File without changes
|
|
@@ -0,0 +1,170 @@
|
|
|
1
|
+
from __future__ import annotations
|
|
2
|
+
|
|
3
|
+
import sys
|
|
4
|
+
import os
|
|
5
|
+
from typing import Any
|
|
6
|
+
|
|
7
|
+
_src_dir = os.path.join(os.path.dirname(__file__), '..', '..', '..', '..', 'src')
|
|
8
|
+
if _src_dir not in sys.path:
|
|
9
|
+
sys.path.insert(0, _src_dir)
|
|
10
|
+
|
|
11
|
+
from qodalis_cli.models.cli_server_response import CliServerResponse
|
|
12
|
+
from qodalis_cli.models.cli_server_output import (
|
|
13
|
+
CliServerTextOutput,
|
|
14
|
+
CliServerTableOutput,
|
|
15
|
+
CliServerListOutput,
|
|
16
|
+
CliServerJsonOutput,
|
|
17
|
+
CliServerKeyValueOutput,
|
|
18
|
+
CliServerKeyValueEntry,
|
|
19
|
+
CliServerOutput,
|
|
20
|
+
)
|
|
21
|
+
|
|
22
|
+
from qodalis_cli_server_abstractions import CliProcessCommand
|
|
23
|
+
|
|
24
|
+
|
|
25
|
+
def build_response(outputs: list[CliServerOutput], exit_code: int = 0) -> CliServerResponse:
|
|
26
|
+
"""Wraps a list of output objects into a CLI server response.
|
|
27
|
+
|
|
28
|
+
Args:
|
|
29
|
+
outputs: Output objects to include in the response.
|
|
30
|
+
exit_code: Process exit code (0 for success).
|
|
31
|
+
|
|
32
|
+
Returns:
|
|
33
|
+
A ``CliServerResponse`` containing the provided outputs.
|
|
34
|
+
"""
|
|
35
|
+
return CliServerResponse(exitCode=exit_code, outputs=outputs)
|
|
36
|
+
|
|
37
|
+
|
|
38
|
+
def build_error_response(message: str) -> CliServerResponse:
|
|
39
|
+
"""Creates an error response with exit code 1.
|
|
40
|
+
|
|
41
|
+
Args:
|
|
42
|
+
message: Error message to display.
|
|
43
|
+
|
|
44
|
+
Returns:
|
|
45
|
+
A ``CliServerResponse`` with error styling.
|
|
46
|
+
"""
|
|
47
|
+
return CliServerResponse(
|
|
48
|
+
exitCode=1,
|
|
49
|
+
outputs=[CliServerTextOutput(value=message, style="error")],
|
|
50
|
+
)
|
|
51
|
+
|
|
52
|
+
|
|
53
|
+
def build_success_response(message: str) -> CliServerResponse:
|
|
54
|
+
"""Creates a success response with exit code 0.
|
|
55
|
+
|
|
56
|
+
Args:
|
|
57
|
+
message: Success message to display.
|
|
58
|
+
|
|
59
|
+
Returns:
|
|
60
|
+
A ``CliServerResponse`` with success styling.
|
|
61
|
+
"""
|
|
62
|
+
return CliServerResponse(
|
|
63
|
+
exitCode=0,
|
|
64
|
+
outputs=[CliServerTextOutput(value=message, style="success")],
|
|
65
|
+
)
|
|
66
|
+
|
|
67
|
+
|
|
68
|
+
def format_as_json(data: Any) -> CliServerJsonOutput:
|
|
69
|
+
"""Wraps arbitrary data as a JSON output object.
|
|
70
|
+
|
|
71
|
+
Args:
|
|
72
|
+
data: Data to serialize as JSON.
|
|
73
|
+
|
|
74
|
+
Returns:
|
|
75
|
+
A ``CliServerJsonOutput`` wrapping the data.
|
|
76
|
+
"""
|
|
77
|
+
return CliServerJsonOutput(value=data)
|
|
78
|
+
|
|
79
|
+
|
|
80
|
+
def format_as_table(headers: list[str], rows: list[list[str]]) -> CliServerTableOutput:
|
|
81
|
+
"""Creates a table output with the given headers and rows.
|
|
82
|
+
|
|
83
|
+
Args:
|
|
84
|
+
headers: Column header labels.
|
|
85
|
+
rows: Row data as lists of strings.
|
|
86
|
+
|
|
87
|
+
Returns:
|
|
88
|
+
A ``CliServerTableOutput`` for tabular display.
|
|
89
|
+
"""
|
|
90
|
+
return CliServerTableOutput(headers=headers, rows=rows)
|
|
91
|
+
|
|
92
|
+
|
|
93
|
+
def format_as_key_value(entries: dict[str, str]) -> CliServerKeyValueOutput:
|
|
94
|
+
"""Creates a key-value output from a dictionary.
|
|
95
|
+
|
|
96
|
+
Args:
|
|
97
|
+
entries: Key-value pairs to display.
|
|
98
|
+
|
|
99
|
+
Returns:
|
|
100
|
+
A ``CliServerKeyValueOutput`` containing the entries.
|
|
101
|
+
"""
|
|
102
|
+
return CliServerKeyValueOutput(
|
|
103
|
+
entries=[CliServerKeyValueEntry(key=k, value=v) for k, v in entries.items()]
|
|
104
|
+
)
|
|
105
|
+
|
|
106
|
+
|
|
107
|
+
def format_as_list(items: list[str]) -> CliServerListOutput:
|
|
108
|
+
"""Creates a list output from string items.
|
|
109
|
+
|
|
110
|
+
Args:
|
|
111
|
+
items: Items to display as a list.
|
|
112
|
+
|
|
113
|
+
Returns:
|
|
114
|
+
A ``CliServerListOutput`` containing the items.
|
|
115
|
+
"""
|
|
116
|
+
return CliServerListOutput(items=items)
|
|
117
|
+
|
|
118
|
+
|
|
119
|
+
def get_output_format(command: CliProcessCommand) -> str:
|
|
120
|
+
"""Extracts the requested output format from command arguments.
|
|
121
|
+
|
|
122
|
+
Args:
|
|
123
|
+
command: The CLI command being processed.
|
|
124
|
+
|
|
125
|
+
Returns:
|
|
126
|
+
One of ``"json"``, ``"table"``, or ``"text"`` (defaults to ``"table"``).
|
|
127
|
+
"""
|
|
128
|
+
fmt = command.args.get("output")
|
|
129
|
+
if fmt in ("json", "table", "text"):
|
|
130
|
+
return fmt # type: ignore[return-value]
|
|
131
|
+
return "table"
|
|
132
|
+
|
|
133
|
+
|
|
134
|
+
def is_dry_run(command: CliProcessCommand) -> bool:
|
|
135
|
+
"""Checks whether the command was invoked with the dry-run flag.
|
|
136
|
+
|
|
137
|
+
Args:
|
|
138
|
+
command: The CLI command being processed.
|
|
139
|
+
|
|
140
|
+
Returns:
|
|
141
|
+
``True`` if dry-run mode is enabled.
|
|
142
|
+
"""
|
|
143
|
+
return command.args.get("dry-run") is True or command.args.get("dryRun") is True
|
|
144
|
+
|
|
145
|
+
|
|
146
|
+
def apply_output_format(
|
|
147
|
+
command: CliProcessCommand,
|
|
148
|
+
default_output: CliServerOutput,
|
|
149
|
+
raw_data: Any,
|
|
150
|
+
) -> CliServerOutput:
|
|
151
|
+
"""Converts the default output to the format requested by ``--output``.
|
|
152
|
+
|
|
153
|
+
If the user requested JSON, returns a JSON output. If text was requested
|
|
154
|
+
and the default is a table, converts rows to tab-separated text.
|
|
155
|
+
|
|
156
|
+
Args:
|
|
157
|
+
command: The CLI command containing output format arguments.
|
|
158
|
+
default_output: The pre-built output to use when no override applies.
|
|
159
|
+
raw_data: Raw data for JSON serialization when JSON format is requested.
|
|
160
|
+
|
|
161
|
+
Returns:
|
|
162
|
+
The output object in the requested format.
|
|
163
|
+
"""
|
|
164
|
+
fmt = get_output_format(command)
|
|
165
|
+
if fmt == "json":
|
|
166
|
+
return format_as_json(raw_data)
|
|
167
|
+
if fmt == "text" and isinstance(default_output, CliServerTableOutput):
|
|
168
|
+
text = "\n".join("\t".join(row) for row in default_output.rows)
|
|
169
|
+
return CliServerTextOutput(value=text)
|
|
170
|
+
return default_output
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
Metadata-Version: 2.5
|
|
2
|
+
Name: qodalis-cli-server-plugin-aws
|
|
3
|
+
Version: 1.0.0b13
|
|
4
|
+
Summary: AWS cloud resource management plugin for Qodalis CLI servers
|
|
5
|
+
Project-URL: Homepage, https://github.com/qodalis-solutions/cli-server-python
|
|
6
|
+
Project-URL: Repository, https://github.com/qodalis-solutions/cli-server-python
|
|
7
|
+
Project-URL: Issues, https://github.com/qodalis-solutions/cli-server-python/issues
|
|
8
|
+
Author-email: Nicolae Lupei <nicolae.lupei@qodalis.com>
|
|
9
|
+
License-Expression: MIT
|
|
10
|
+
Keywords: aws,cli,cloud,plugin,qodalis
|
|
11
|
+
Classifier: Development Status :: 4 - Beta
|
|
12
|
+
Classifier: Intended Audience :: Developers
|
|
13
|
+
Classifier: License :: OSI Approved :: MIT License
|
|
14
|
+
Classifier: Programming Language :: Python :: 3
|
|
15
|
+
Classifier: Programming Language :: Python :: 3.10
|
|
16
|
+
Classifier: Programming Language :: Python :: 3.11
|
|
17
|
+
Classifier: Programming Language :: Python :: 3.12
|
|
18
|
+
Classifier: Programming Language :: Python :: 3.13
|
|
19
|
+
Requires-Python: >=3.10
|
|
20
|
+
Requires-Dist: boto3>=1.34.0
|
|
21
|
+
Requires-Dist: qodalis-cli-server-abstractions>=1.0.0b7
|
|
22
|
+
Provides-Extra: test
|
|
23
|
+
Requires-Dist: moto[all]>=5.0.0; extra == 'test'
|
|
24
|
+
Requires-Dist: pytest; extra == 'test'
|
|
25
|
+
Requires-Dist: pytest-asyncio; extra == 'test'
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
qodalis_cli_aws/__init__.py,sha256=Jo7ErSXtg5ddohfFG7AGCgg8-IQDtkRuZL2uThQdBXw,133
|
|
2
|
+
qodalis_cli_aws/aws_module.py,sha256=H0xcZykuOoHeqwXxNorhuVNvUsjgBdGYZHPB59_3Z1M,875
|
|
3
|
+
qodalis_cli_aws/processors/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
|
|
4
|
+
qodalis_cli_aws/processors/aws_command_processor.py,sha256=58ywYg3Ay3rN3bDEFw62LB1HmbjNpcjepxkc9UF7Oso,11640
|
|
5
|
+
qodalis_cli_aws/processors/cloudwatch_processor.py,sha256=MA0cfnsW4rZwXbV20tZW-aRiSTkZYkFaIky5cBxOGLU,9185
|
|
6
|
+
qodalis_cli_aws/processors/dynamodb_processor.py,sha256=oi0LgA17NEsAP9yC3SvK29H80B3S9BHOl41nuCYqhcw,10650
|
|
7
|
+
qodalis_cli_aws/processors/ec2_processor.py,sha256=kl7a3hvr7rX6qDW2xPvheoRg7GjMwag8TSvqSHBK8No,15813
|
|
8
|
+
qodalis_cli_aws/processors/ecs_processor.py,sha256=92bhFbTjRWmCzA66oRFyAw6dpxDgYVu7IyX6D7-dwVk,9506
|
|
9
|
+
qodalis_cli_aws/processors/iam_processor.py,sha256=aSK6FyCHnRIPRPhdYJ43pk34SPHuLn4Xx5kKUOIgFxI,7958
|
|
10
|
+
qodalis_cli_aws/processors/lambda_processor.py,sha256=fUTgPrzCg-AoFhOmyS-5XfpfsCdVmQ7hG3PUPvDQpfk,9515
|
|
11
|
+
qodalis_cli_aws/processors/s3_processor.py,sha256=8jB6rKlDO9bufvwFo1Pq8t9hJKHhPVsp6Prw5-O6kQU,16918
|
|
12
|
+
qodalis_cli_aws/processors/sns_processor.py,sha256=pROufg3DcN2SpRk-a0KgD4tIoD1zJurhRWzfgMcEvQE,7962
|
|
13
|
+
qodalis_cli_aws/processors/sqs_processor.py,sha256=D1LRSIoF2Q7xAeMTXFYbvM6QU32wkWRT-ZSuscCrrn8,9683
|
|
14
|
+
qodalis_cli_aws/services/__init__.py,sha256=Cy7-1VrXussmcG7EccPVKUZLdGZQ2APsoUegcpgsUJ0,162
|
|
15
|
+
qodalis_cli_aws/services/aws_config_service.py,sha256=AMFx9O2Ls9d-bhxkumK15jjRGaxO09ZG7RGKl6R8WsE,2674
|
|
16
|
+
qodalis_cli_aws/services/aws_credential_manager.py,sha256=M2EtDzJ_4qC4x1H0YvnJeqTFNZP9oU5Yu9SxNyoW9x4,2040
|
|
17
|
+
qodalis_cli_aws/utils/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
|
|
18
|
+
qodalis_cli_aws/utils/output_helpers.py,sha256=3WPlWBESYPpfi2KkDuuS7aZpdgbdetkoNXIQr8qeBso,4887
|
|
19
|
+
qodalis_cli_server_plugin_aws-1.0.0b13.dist-info/METADATA,sha256=wfuhDtywbqBCs5_xY3g14am4YAdLl8-xXeXAJak5cv8,1161
|
|
20
|
+
qodalis_cli_server_plugin_aws-1.0.0b13.dist-info/WHEEL,sha256=2iZrJkDIkeDh0k9SikKMqFuRP-ua6mb4Ir1AsER4BEw,87
|
|
21
|
+
qodalis_cli_server_plugin_aws-1.0.0b13.dist-info/RECORD,,
|