elbx 0.1.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.
elbx/__init__.py ADDED
@@ -0,0 +1,103 @@
1
+ """
2
+ elbx: a read-only CLI and Python library for AWS ALB / NLB (ELBv2).
3
+
4
+ - Fetches a load balancer with everything behind it (listeners, rules, target groups,
5
+ targets) and the related resources (Route 53, EC2, ECS, Lambda, ENI, security groups,
6
+ subnets, ACM) in one call, resolving each target to the real resource
7
+ - Looks targets up the other way round (which load balancer / target group is this
8
+ EC2, IP, ECS service or Lambda in?)
9
+ - Simulates which listener rule a request matches and where it ends up
10
+ - Calls only Describe* / List* / Get* APIs; nothing in the account is changed
11
+
12
+ elbx: AWS の ALB / NLB(ELBv2)を調べる参照専用の CLI と Python ライブラリ。
13
+
14
+ - ELB の配下(リスナー・ルール・ターゲットグループ・ターゲット)と関連リソース
15
+ (Route 53・EC2・ECS・Lambda・ENI・SG・サブネット・ACM)を1回で取得し、
16
+ ターゲットの実体を特定する
17
+ - EC2・IP・ECS サービス・Lambda から、どの ELB / TG に登録されているかを逆引きする
18
+ - リクエストがどのリスナールールに一致し、どこへ届くかをシミュレーションする
19
+ - 呼び出すのは Describe* / List* / Get* の API だけで、アカウントの中は変更しない
20
+ """
21
+
22
+ from __future__ import annotations
23
+
24
+ import logging
25
+
26
+ from .client import ELBClient
27
+ from .errors import AWSAPIError, ELBError, ResourceNotFoundError
28
+ from .formatter import (
29
+ format_lb_map,
30
+ format_lb_summary_table,
31
+ format_lb_tree,
32
+ format_lookup_results_table,
33
+ format_route_simulation,
34
+ format_targets_table,
35
+ print_lb_tree,
36
+ )
37
+ from .messages import get_language, set_language
38
+ from .models import (
39
+ CertificateInfo,
40
+ EC2InstanceInfo,
41
+ ECSTaskInfo,
42
+ ENIInfo,
43
+ LambdaFunctionInfo,
44
+ ListenerView,
45
+ LoadBalancerView,
46
+ Route53RecordInfo,
47
+ RouteHop,
48
+ RouteNoteCode,
49
+ RouteSimulationResult,
50
+ RuleEvaluation,
51
+ RuleTargetGroupRef,
52
+ RuleView,
53
+ SecurityGroupInfo,
54
+ SecurityGroupRuleSummary,
55
+ SubnetInfo,
56
+ TargetGroupView,
57
+ TargetKind,
58
+ TargetLookupResult,
59
+ TargetView,
60
+ )
61
+
62
+ __version__ = "0.1.0"
63
+
64
+ # ログの出し方は利用する側が決める(何も設定しなければ何も出さない)
65
+ logging.getLogger("elbx").addHandler(logging.NullHandler())
66
+
67
+ __all__ = [
68
+ "AWSAPIError",
69
+ "CertificateInfo",
70
+ "EC2InstanceInfo",
71
+ "ECSTaskInfo",
72
+ "ELBClient",
73
+ "ELBError",
74
+ "ENIInfo",
75
+ "LambdaFunctionInfo",
76
+ "ListenerView",
77
+ "LoadBalancerView",
78
+ "ResourceNotFoundError",
79
+ "Route53RecordInfo",
80
+ "RouteHop",
81
+ "RouteNoteCode",
82
+ "RouteSimulationResult",
83
+ "RuleEvaluation",
84
+ "RuleTargetGroupRef",
85
+ "RuleView",
86
+ "SecurityGroupInfo",
87
+ "SecurityGroupRuleSummary",
88
+ "SubnetInfo",
89
+ "TargetGroupView",
90
+ "TargetKind",
91
+ "TargetLookupResult",
92
+ "TargetView",
93
+ "__version__",
94
+ "format_lb_map",
95
+ "format_lb_summary_table",
96
+ "format_lb_tree",
97
+ "format_lookup_results_table",
98
+ "format_route_simulation",
99
+ "format_targets_table",
100
+ "get_language",
101
+ "print_lb_tree",
102
+ "set_language",
103
+ ]
elbx/__main__.py ADDED
@@ -0,0 +1,12 @@
1
+ """
2
+ `python -m elbx` でCLIを実行するためのエントリポイント。
3
+ """
4
+
5
+ from __future__ import annotations
6
+
7
+ import sys
8
+
9
+ from .cli import main
10
+
11
+ if __name__ == "__main__":
12
+ sys.exit(main())
elbx/_ids.py ADDED
@@ -0,0 +1,36 @@
1
+ """
2
+ AWS のリソース ID・ARN・IP アドレスの判定と正規化(モジュール間で共有する小さなヘルパー)。
3
+ """
4
+
5
+ from __future__ import annotations
6
+
7
+ import ipaddress
8
+
9
+
10
+ def is_arn_of(value: str, service: str) -> bool:
11
+ """
12
+ 文字列が指定サービスの ARN かを判定する。
13
+ `arn:aws:`(標準)だけでなく `arn:aws-cn:`(中国)や `arn:aws-us-gov:`(GovCloud)も対象にする。
14
+
15
+ :param value: 判定する文字列
16
+ :param service: サービス名(例: `"elasticloadbalancing"`, `"lambda"`)
17
+ :return: `arn:<パーティション>:<service>:` で始まれば True
18
+ """
19
+ parts = value.split(":", 3)
20
+ return len(parts) == 4 and parts[0] == "arn" and parts[2] == service
21
+
22
+
23
+ def canonical_ip(value: str) -> str | None:
24
+ """
25
+ 文字列が有効な IPv4 または IPv6 アドレスであれば正規化表記(小文字・省略形)を返し、
26
+ IP アドレスでない場合(ARN やインスタンス ID 等)は None を返す。
27
+
28
+ :param value: 判定・正規化する文字列
29
+ :return: 正規化されたIPアドレス文字列、またはIPでない場合は None
30
+ """
31
+ if not value or value.startswith("arn:"):
32
+ return None
33
+ try:
34
+ return str(ipaddress.ip_address(value))
35
+ except ValueError:
36
+ return None