aws-annoying 0.7.0__py3-none-any.whl → 0.8.0__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.
- aws_annoying/cli/app.py +30 -1
- aws_annoying/cli/ecs/task_definition_lifecycle.py +0 -3
- aws_annoying/cli/logging_handler.py +3 -3
- aws_annoying/cli/mfa/configure.py +13 -8
- aws_annoying/cli/session_manager/install.py +6 -2
- aws_annoying/cli/session_manager/port_forward.py +21 -11
- aws_annoying/cli/session_manager/start.py +5 -1
- aws_annoying/cli/session_manager/stop.py +9 -3
- {aws_annoying-0.7.0.dist-info → aws_annoying-0.8.0.dist-info}/METADATA +1 -1
- {aws_annoying-0.7.0.dist-info → aws_annoying-0.8.0.dist-info}/RECORD +13 -13
- {aws_annoying-0.7.0.dist-info → aws_annoying-0.8.0.dist-info}/WHEEL +0 -0
- {aws_annoying-0.7.0.dist-info → aws_annoying-0.8.0.dist-info}/entry_points.txt +0 -0
- {aws_annoying-0.7.0.dist-info → aws_annoying-0.8.0.dist-info}/licenses/LICENSE +0 -0
aws_annoying/cli/app.py
CHANGED
|
@@ -8,6 +8,10 @@ from typing import Optional
|
|
|
8
8
|
import typer
|
|
9
9
|
from rich import print # noqa: A004
|
|
10
10
|
from rich.console import Console
|
|
11
|
+
from rich.highlighter import ReprHighlighter
|
|
12
|
+
from rich.theme import Theme
|
|
13
|
+
|
|
14
|
+
logger = logging.getLogger(__name__)
|
|
11
15
|
|
|
12
16
|
app = typer.Typer(
|
|
13
17
|
pretty_exceptions_short=True,
|
|
@@ -51,7 +55,7 @@ def main( # noqa: D103
|
|
|
51
55
|
),
|
|
52
56
|
) -> None:
|
|
53
57
|
log_level = logging.DEBUG if verbose else logging.INFO
|
|
54
|
-
console =
|
|
58
|
+
console = _get_console()
|
|
55
59
|
logging_config: logging.config._DictConfigArgs = {
|
|
56
60
|
"version": 1,
|
|
57
61
|
"disable_existing_loggers": False,
|
|
@@ -89,3 +93,28 @@ def main( # noqa: D103
|
|
|
89
93
|
|
|
90
94
|
# Global flags
|
|
91
95
|
ctx.meta["dry_run"] = dry_run
|
|
96
|
+
if dry_run:
|
|
97
|
+
logger.warning("Dry run mode enabled. Some operation may behave differently to avoid making changes.")
|
|
98
|
+
|
|
99
|
+
|
|
100
|
+
def _get_console() -> Console:
|
|
101
|
+
theme = Theme(
|
|
102
|
+
{
|
|
103
|
+
"repr.arn": "bold orange3",
|
|
104
|
+
"repr.constant": "bold blue",
|
|
105
|
+
},
|
|
106
|
+
)
|
|
107
|
+
return Console(soft_wrap=True, emoji=False, highlighter=CustomHighlighter(), theme=theme)
|
|
108
|
+
|
|
109
|
+
|
|
110
|
+
class CustomHighlighter(ReprHighlighter):
|
|
111
|
+
"""Custom highlighter to handle additional patterns."""
|
|
112
|
+
|
|
113
|
+
highlights = [ # noqa: RUF012
|
|
114
|
+
*ReprHighlighter.highlights,
|
|
115
|
+
# AWS Resource Name; https://docs.aws.amazon.com/IAM/latest/UserGuide/reference-arns.html
|
|
116
|
+
# NOTE: Quite simplified regex, may not cover all cases.
|
|
117
|
+
r"(?P<arn>\barn:[0-9a-zA-Z/+=,\.@_\-:]+\b)",
|
|
118
|
+
# Constants
|
|
119
|
+
r"(?P<constant>\b[A-Z_]+\b)",
|
|
120
|
+
]
|
|
@@ -40,9 +40,6 @@ def task_definition_lifecycle(
|
|
|
40
40
|
) -> None:
|
|
41
41
|
"""Execute ECS task definition lifecycle."""
|
|
42
42
|
dry_run = ctx.meta["dry_run"]
|
|
43
|
-
if dry_run:
|
|
44
|
-
logger.info("Dry run mode enabled. Will not perform any actual changes.")
|
|
45
|
-
|
|
46
43
|
ecs = boto3.client("ecs")
|
|
47
44
|
|
|
48
45
|
# Get all task definitions for the family
|
|
@@ -15,10 +15,10 @@ class RichLogHandler(logging.Handler):
|
|
|
15
15
|
|
|
16
16
|
_level_emojis: Final[dict[str, str]] = {
|
|
17
17
|
"DEBUG": "🔍",
|
|
18
|
-
"INFO": "
|
|
18
|
+
"INFO": "🔔",
|
|
19
19
|
"WARNING": "⚠️",
|
|
20
|
-
"ERROR": "
|
|
21
|
-
"CRITICAL": "
|
|
20
|
+
"ERROR": "🚨",
|
|
21
|
+
"CRITICAL": "🔥",
|
|
22
22
|
}
|
|
23
23
|
|
|
24
24
|
def __init__(self, console: Console, *args: Any, **kwargs: Any) -> None:
|
|
@@ -17,6 +17,7 @@ logger = logging.getLogger(__name__)
|
|
|
17
17
|
|
|
18
18
|
@mfa_app.command()
|
|
19
19
|
def configure( # noqa: PLR0913
|
|
20
|
+
ctx: typer.Context,
|
|
20
21
|
*,
|
|
21
22
|
mfa_profile: Optional[str] = typer.Option(
|
|
22
23
|
None,
|
|
@@ -54,6 +55,8 @@ def configure( # noqa: PLR0913
|
|
|
54
55
|
),
|
|
55
56
|
) -> None:
|
|
56
57
|
"""Configure AWS profile for MFA."""
|
|
58
|
+
dry_run = ctx.meta["dry_run"]
|
|
59
|
+
|
|
57
60
|
# Expand user home directory
|
|
58
61
|
aws_credentials = aws_credentials.expanduser()
|
|
59
62
|
aws_config = aws_config.expanduser()
|
|
@@ -102,13 +105,14 @@ def configure( # noqa: PLR0913
|
|
|
102
105
|
mfa_profile,
|
|
103
106
|
aws_credentials,
|
|
104
107
|
)
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
108
|
+
if not dry_run:
|
|
109
|
+
update_credentials(
|
|
110
|
+
aws_credentials,
|
|
111
|
+
mfa_profile, # type: ignore[arg-type]
|
|
112
|
+
access_key=credentials["AccessKeyId"],
|
|
113
|
+
secret_key=credentials["SecretAccessKey"],
|
|
114
|
+
session_token=credentials["SessionToken"],
|
|
115
|
+
)
|
|
112
116
|
|
|
113
117
|
# Persist MFA configuration
|
|
114
118
|
if persist:
|
|
@@ -120,6 +124,7 @@ def configure( # noqa: PLR0913
|
|
|
120
124
|
mfa_config.mfa_profile = mfa_profile
|
|
121
125
|
mfa_config.mfa_source_profile = mfa_source_profile
|
|
122
126
|
mfa_config.mfa_serial_number = mfa_serial_number
|
|
123
|
-
|
|
127
|
+
if not dry_run:
|
|
128
|
+
mfa_config.save_ini_file(aws_config, aws_config_section)
|
|
124
129
|
else:
|
|
125
130
|
logger.warning("MFA configuration not persisted.")
|
|
@@ -15,12 +15,15 @@ logger = logging.getLogger(__name__)
|
|
|
15
15
|
# https://docs.aws.amazon.com/systems-manager/latest/userguide/session-manager-working-with-install-plugin.html
|
|
16
16
|
@session_manager_app.command()
|
|
17
17
|
def install(
|
|
18
|
-
|
|
18
|
+
ctx: typer.Context,
|
|
19
|
+
*,
|
|
20
|
+
yes: bool = typer.Option(
|
|
19
21
|
False, # noqa: FBT003
|
|
20
22
|
help="Do not ask confirmation for installation.",
|
|
21
23
|
),
|
|
22
24
|
) -> None:
|
|
23
25
|
"""Install AWS Session Manager plugin."""
|
|
26
|
+
dry_run = ctx.meta["dry_run"]
|
|
24
27
|
session_manager = SessionManager()
|
|
25
28
|
|
|
26
29
|
# Check session-manager-plugin already installed
|
|
@@ -31,7 +34,8 @@ def install(
|
|
|
31
34
|
|
|
32
35
|
# Install session-manager-plugin
|
|
33
36
|
logger.warning("Installing AWS Session Manager plugin. You could be prompted for admin privileges request.")
|
|
34
|
-
|
|
37
|
+
if not dry_run:
|
|
38
|
+
session_manager.install(confirm=yes, downloader=TQDMDownloader())
|
|
35
39
|
|
|
36
40
|
# Verify installation
|
|
37
41
|
is_installed, binary_path, version = session_manager.verify_installation()
|
|
@@ -19,6 +19,8 @@ logger = logging.getLogger(__name__)
|
|
|
19
19
|
# https://docs.aws.amazon.com/systems-manager/latest/userguide/session-manager-working-with-install-plugin.html
|
|
20
20
|
@session_manager_app.command()
|
|
21
21
|
def port_forward( # noqa: PLR0913
|
|
22
|
+
ctx: typer.Context,
|
|
23
|
+
*,
|
|
22
24
|
# TODO(lasuillard): Add `--local-host` option, redirect the traffic to non-localhost bind (unsupported by AWS)
|
|
23
25
|
local_port: int = typer.Option(
|
|
24
26
|
...,
|
|
@@ -48,7 +50,7 @@ def port_forward( # noqa: PLR0913
|
|
|
48
50
|
"./session-manager-plugin.pid",
|
|
49
51
|
help="The path to the PID file to store the process ID of the session manager plugin.",
|
|
50
52
|
),
|
|
51
|
-
terminate_running_process: bool = typer.Option(
|
|
53
|
+
terminate_running_process: bool = typer.Option(
|
|
52
54
|
False, # noqa: FBT003
|
|
53
55
|
help="Terminate the process in the PID file if it already exists.",
|
|
54
56
|
),
|
|
@@ -58,6 +60,7 @@ def port_forward( # noqa: PLR0913
|
|
|
58
60
|
),
|
|
59
61
|
) -> None:
|
|
60
62
|
"""Start a port forwarding session using AWS Session Manager."""
|
|
63
|
+
dry_run = ctx.meta["dry_run"]
|
|
61
64
|
session_manager = SessionManager()
|
|
62
65
|
|
|
63
66
|
# Check if the PID file already exists
|
|
@@ -86,7 +89,7 @@ def port_forward( # noqa: PLR0913
|
|
|
86
89
|
logger.info("Instance ID resolved: [bold]%s[/bold]", instance_id)
|
|
87
90
|
target = instance_id
|
|
88
91
|
else:
|
|
89
|
-
logger.
|
|
92
|
+
logger.error("Instance with name '%s' not found.", through)
|
|
90
93
|
raise typer.Exit(1)
|
|
91
94
|
|
|
92
95
|
# Initiate the session
|
|
@@ -111,19 +114,26 @@ def port_forward( # noqa: PLR0913
|
|
|
111
114
|
through,
|
|
112
115
|
reason,
|
|
113
116
|
)
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
117
|
+
if not dry_run:
|
|
118
|
+
proc = subprocess.Popen( # noqa: S603
|
|
119
|
+
command,
|
|
120
|
+
stdout=stdout,
|
|
121
|
+
stderr=subprocess.STDOUT,
|
|
122
|
+
text=True,
|
|
123
|
+
close_fds=False, # FD inherited from parent process
|
|
124
|
+
)
|
|
125
|
+
pid = proc.pid
|
|
126
|
+
else:
|
|
127
|
+
pid = -1
|
|
128
|
+
|
|
121
129
|
logger.info(
|
|
122
130
|
"Session Manager Plugin started with PID %d. Outputs will be logged to %s.",
|
|
123
|
-
|
|
131
|
+
pid,
|
|
124
132
|
log_file.absolute(),
|
|
125
133
|
)
|
|
126
134
|
|
|
127
135
|
# Write the PID to the file
|
|
128
|
-
|
|
136
|
+
if not dry_run:
|
|
137
|
+
pid_file.write_text(str(pid))
|
|
138
|
+
|
|
129
139
|
logger.info("PID file written to %s.", pid_file.absolute())
|
|
@@ -18,6 +18,8 @@ logger = logging.getLogger(__name__)
|
|
|
18
18
|
|
|
19
19
|
@session_manager_app.command()
|
|
20
20
|
def start(
|
|
21
|
+
ctx: typer.Context,
|
|
22
|
+
*,
|
|
21
23
|
target: str = typer.Option(
|
|
22
24
|
...,
|
|
23
25
|
show_default=False,
|
|
@@ -29,6 +31,7 @@ def start(
|
|
|
29
31
|
),
|
|
30
32
|
) -> None:
|
|
31
33
|
"""Start new session."""
|
|
34
|
+
dry_run = ctx.meta["dry_run"]
|
|
32
35
|
session_manager = SessionManager()
|
|
33
36
|
|
|
34
37
|
# Resolve the instance name or ID
|
|
@@ -52,4 +55,5 @@ def start(
|
|
|
52
55
|
parameters={},
|
|
53
56
|
reason=reason,
|
|
54
57
|
)
|
|
55
|
-
|
|
58
|
+
if not dry_run:
|
|
59
|
+
os.execvp(command[0], command) # noqa: S606
|
|
@@ -14,16 +14,20 @@ logger = logging.getLogger(__name__)
|
|
|
14
14
|
|
|
15
15
|
@session_manager_app.command()
|
|
16
16
|
def stop(
|
|
17
|
+
ctx: typer.Context,
|
|
18
|
+
*,
|
|
17
19
|
pid_file: Path = typer.Option( # noqa: B008
|
|
18
20
|
"./session-manager-plugin.pid",
|
|
19
21
|
help="The path to the PID file to store the process ID of the session manager plugin.",
|
|
20
22
|
),
|
|
21
|
-
remove: bool = typer.Option(
|
|
23
|
+
remove: bool = typer.Option(
|
|
22
24
|
True, # noqa: FBT003
|
|
23
25
|
help="Remove the PID file after stopping the session.",
|
|
24
26
|
),
|
|
25
27
|
) -> None:
|
|
26
28
|
"""Stop running session for PID file."""
|
|
29
|
+
dry_run = ctx.meta["dry_run"]
|
|
30
|
+
|
|
27
31
|
# Check if PID file exists
|
|
28
32
|
if not pid_file.is_file():
|
|
29
33
|
logger.error("PID file not found: %s", pid_file)
|
|
@@ -40,13 +44,15 @@ def stop(
|
|
|
40
44
|
# Send SIGTERM to the process
|
|
41
45
|
try:
|
|
42
46
|
logger.warning("Terminating running process with PID %d.", pid)
|
|
43
|
-
|
|
47
|
+
if not dry_run:
|
|
48
|
+
os.kill(pid, signal.SIGTERM)
|
|
44
49
|
except ProcessLookupError:
|
|
45
50
|
logger.warning("Tried to terminate process with PID %d but does not exist.", pid)
|
|
46
51
|
|
|
47
52
|
# Remove the PID file
|
|
48
53
|
if remove:
|
|
49
54
|
logger.info("Removed the PID file %s.", pid_file)
|
|
50
|
-
|
|
55
|
+
if not dry_run:
|
|
56
|
+
pid_file.unlink()
|
|
51
57
|
|
|
52
58
|
logger.info("Terminated the session successfully.")
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
Metadata-Version: 2.4
|
|
2
2
|
Name: aws-annoying
|
|
3
|
-
Version: 0.
|
|
3
|
+
Version: 0.8.0
|
|
4
4
|
Summary: Utils to handle some annoying AWS tasks.
|
|
5
5
|
Project-URL: Homepage, https://github.com/lasuillard/aws-annoying
|
|
6
6
|
Project-URL: Repository, https://github.com/lasuillard/aws-annoying.git
|
|
@@ -2,24 +2,24 @@ aws_annoying/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
|
|
|
2
2
|
aws_annoying/mfa_config.py,sha256=z0GpRhLHEWaaXbECV4Ei4oNM1WCFoEZAxCIPbpY4Ymc,2200
|
|
3
3
|
aws_annoying/variable_loader.py,sha256=N9qPPHG6mzSIIHrWJnJ_FV5kKZxssOaTHoAQEwiDE3s,4569
|
|
4
4
|
aws_annoying/cli/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
|
|
5
|
-
aws_annoying/cli/app.py,sha256=
|
|
5
|
+
aws_annoying/cli/app.py,sha256=W0FPz0N7okjENwaGpdoWRhcei5Xs-uxSMRaYldaza3M,3295
|
|
6
6
|
aws_annoying/cli/load_variables.py,sha256=n5CIci_uAoGaOZ4EKIKEEfcyMq81Hjy9AFOXq1-Hbh0,4896
|
|
7
|
-
aws_annoying/cli/logging_handler.py,sha256=
|
|
7
|
+
aws_annoying/cli/logging_handler.py,sha256=z2fBHChHiyzQeKtKjykX-JvuWm57gARB3VDmpQSdu6U,1409
|
|
8
8
|
aws_annoying/cli/main.py,sha256=bU4Gxic5_3qrrd8l9eN709-D4o_OHgrdH91FS9Xs8zI,477
|
|
9
9
|
aws_annoying/cli/ecs/__init__.py,sha256=IxfaMXcGU6WTHE_RXj-aitXtSg25j5m3HGTG9O02GjI,125
|
|
10
10
|
aws_annoying/cli/ecs/_app.py,sha256=izD0VL55i7oG-2CtWCV21bSoAeE-DZbxyJ5pi6VXhjU,200
|
|
11
|
-
aws_annoying/cli/ecs/task_definition_lifecycle.py,sha256=
|
|
11
|
+
aws_annoying/cli/ecs/task_definition_lifecycle.py,sha256=COGYy5o9N6J7tv6aA7qhT-4WsAoxbyPC1UMPtKKrPpg,2704
|
|
12
12
|
aws_annoying/cli/ecs/wait_for_deployment.py,sha256=yBl-KMOya8ZSgpZLcEB0UqtsZfK5ezKPJWNaOdMRRcY,5234
|
|
13
13
|
aws_annoying/cli/mfa/__init__.py,sha256=rbEGhw5lOQZV_XAc3nSbo56JVhsSPpeOgEtiAy9qzEA,50
|
|
14
14
|
aws_annoying/cli/mfa/_app.py,sha256=Ub7gxb6kGF3Ve1ucQSOjHmc4jAu8mxgegcXsIbOzLLQ,189
|
|
15
|
-
aws_annoying/cli/mfa/configure.py,sha256=
|
|
15
|
+
aws_annoying/cli/mfa/configure.py,sha256=Lfmc4VKkUGngbrbxLRrgcEv-vyPM_-1ne_G4U-Vh7Mg,4092
|
|
16
16
|
aws_annoying/cli/session_manager/__init__.py,sha256=FkT6jT6OXduOURN61d-U6hgd-XluQbvuVtKXXiXgSEk,105
|
|
17
17
|
aws_annoying/cli/session_manager/_app.py,sha256=OVOHW0iyKzunvaqLhjoseHw1-WxJ1gGb7QmiyAEezyY,221
|
|
18
18
|
aws_annoying/cli/session_manager/_common.py,sha256=Uj-MF7z8Qntd24Z03xxE-jSKcgrsd8xl41E6db4qCtY,711
|
|
19
|
-
aws_annoying/cli/session_manager/install.py,sha256=
|
|
20
|
-
aws_annoying/cli/session_manager/port_forward.py,sha256=
|
|
21
|
-
aws_annoying/cli/session_manager/start.py,sha256=
|
|
22
|
-
aws_annoying/cli/session_manager/stop.py,sha256=
|
|
19
|
+
aws_annoying/cli/session_manager/install.py,sha256=QA88qIu7aYTlBN0tqU-lEN5nMGpshXF3jddBBCZixV8,1550
|
|
20
|
+
aws_annoying/cli/session_manager/port_forward.py,sha256=7tSaGlcoSpJ9G2NYHvcC-PpmVqz-I4B4T8e4Xe45BE8,4495
|
|
21
|
+
aws_annoying/cli/session_manager/start.py,sha256=p4vGUIT4IivJp_Sr7yYljRuYTDHBWULt2Av6AzAjL1I,1536
|
|
22
|
+
aws_annoying/cli/session_manager/stop.py,sha256=SrjGJdodTmcGK1OPyFX61vWzJTqgfsuBRFvScIdYJCU,1641
|
|
23
23
|
aws_annoying/ecs/__init__.py,sha256=G9vVNkbDg-fY3G0Qc7yOGZOnsVp4VtiwzzEgjr6S5Kw,666
|
|
24
24
|
aws_annoying/ecs/check.py,sha256=mxkW8MWCJYng60VKwq3Ws9PEvI1u0aVPdbs4p6SY2j4,1233
|
|
25
25
|
aws_annoying/ecs/common.py,sha256=TvP27SEvdIBnA92Oude-oDCy1SuaYNdtpokkbpZmdzo,139
|
|
@@ -35,8 +35,8 @@ aws_annoying/utils/downloader.py,sha256=bAh8Hu55L3F8Fyd1s4NBsyB_L0U-lk7SfKsS00Rp
|
|
|
35
35
|
aws_annoying/utils/ec2.py,sha256=VsOrnFQDSNplWQ_s-uT11IfiD2mi-74uLbSVoaeXynI,1055
|
|
36
36
|
aws_annoying/utils/platform.py,sha256=TBIzCzYiFj36HmndZedegvFlxPSNtBQyAxzuwelvxNg,985
|
|
37
37
|
aws_annoying/utils/timeout.py,sha256=9eCSqhkEp7f7wBoLzkyqfyUKAgY9irwL6LIWBvIvmFI,2394
|
|
38
|
-
aws_annoying-0.
|
|
39
|
-
aws_annoying-0.
|
|
40
|
-
aws_annoying-0.
|
|
41
|
-
aws_annoying-0.
|
|
42
|
-
aws_annoying-0.
|
|
38
|
+
aws_annoying-0.8.0.dist-info/METADATA,sha256=PDr5RneXMjRUQglP8tSmNSpBatkPyK3uJilJpm1RISo,3507
|
|
39
|
+
aws_annoying-0.8.0.dist-info/WHEEL,sha256=qtCwoSJWgHk21S1Kb4ihdzI2rlJ1ZKaIurTj_ngOhyQ,87
|
|
40
|
+
aws_annoying-0.8.0.dist-info/entry_points.txt,sha256=DcKE5V0WvVJ8wUOHxyUz1yLAJOuuJUgRPlMcQ4O7jEs,66
|
|
41
|
+
aws_annoying-0.8.0.dist-info/licenses/LICENSE,sha256=Q5GkvYijQ2KTQ-QWhv43ilzCno4ZrzrEuATEQZd9rYo,1067
|
|
42
|
+
aws_annoying-0.8.0.dist-info/RECORD,,
|
|
File without changes
|
|
File without changes
|
|
File without changes
|