developer-toolkit-elasticache 1.0.0__tar.gz

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.
Files changed (19) hide show
  1. developer_toolkit_elasticache-1.0.0/LICENSE +202 -0
  2. developer_toolkit_elasticache-1.0.0/NOTICE +2 -0
  3. developer_toolkit_elasticache-1.0.0/PKG-INFO +145 -0
  4. developer_toolkit_elasticache-1.0.0/README.md +125 -0
  5. developer_toolkit_elasticache-1.0.0/pyproject.toml +94 -0
  6. developer_toolkit_elasticache-1.0.0/setup.cfg +4 -0
  7. developer_toolkit_elasticache-1.0.0/src/developer_toolkit_elasticache/__init__.py +22 -0
  8. developer_toolkit_elasticache-1.0.0/src/developer_toolkit_elasticache/cli.py +80 -0
  9. developer_toolkit_elasticache-1.0.0/src/developer_toolkit_elasticache/errors.py +35 -0
  10. developer_toolkit_elasticache-1.0.0/src/developer_toolkit_elasticache/py.typed +0 -0
  11. developer_toolkit_elasticache-1.0.0/src/developer_toolkit_elasticache/token_generator.py +240 -0
  12. developer_toolkit_elasticache-1.0.0/src/developer_toolkit_elasticache.egg-info/PKG-INFO +145 -0
  13. developer_toolkit_elasticache-1.0.0/src/developer_toolkit_elasticache.egg-info/SOURCES.txt +17 -0
  14. developer_toolkit_elasticache-1.0.0/src/developer_toolkit_elasticache.egg-info/dependency_links.txt +1 -0
  15. developer_toolkit_elasticache-1.0.0/src/developer_toolkit_elasticache.egg-info/entry_points.txt +2 -0
  16. developer_toolkit_elasticache-1.0.0/src/developer_toolkit_elasticache.egg-info/requires.txt +1 -0
  17. developer_toolkit_elasticache-1.0.0/src/developer_toolkit_elasticache.egg-info/top_level.txt +1 -0
  18. developer_toolkit_elasticache-1.0.0/tests/test_cli.py +191 -0
  19. developer_toolkit_elasticache-1.0.0/tests/test_token_generator.py +557 -0
@@ -0,0 +1,202 @@
1
+
2
+ Apache License
3
+ Version 2.0, January 2004
4
+ http://www.apache.org/licenses/
5
+
6
+ TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
7
+
8
+ 1. Definitions.
9
+
10
+ "License" shall mean the terms and conditions for use, reproduction,
11
+ and distribution as defined by Sections 1 through 9 of this document.
12
+
13
+ "Licensor" shall mean the copyright owner or entity authorized by
14
+ the copyright owner that is granting the License.
15
+
16
+ "Legal Entity" shall mean the union of the acting entity and all
17
+ other entities that control, are controlled by, or are under common
18
+ control with that entity. For the purposes of this definition,
19
+ "control" means (i) the power, direct or indirect, to cause the
20
+ direction or management of such entity, whether by contract or
21
+ otherwise, or (ii) ownership of fifty percent (50%) or more of the
22
+ outstanding shares, or (iii) beneficial ownership of such entity.
23
+
24
+ "You" (or "Your") shall mean an individual or Legal Entity
25
+ exercising permissions granted by this License.
26
+
27
+ "Source" form shall mean the preferred form for making modifications,
28
+ including but not limited to software source code, documentation
29
+ source, and configuration files.
30
+
31
+ "Object" form shall mean any form resulting from mechanical
32
+ transformation or translation of a Source form, including but
33
+ not limited to compiled object code, generated documentation,
34
+ and conversions to other media types.
35
+
36
+ "Work" shall mean the work of authorship, whether in Source or
37
+ Object form, made available under the License, as indicated by a
38
+ copyright notice that is included in or attached to the work
39
+ (an example is provided in the Appendix below).
40
+
41
+ "Derivative Works" shall mean any work, whether in Source or Object
42
+ form, that is based on (or derived from) the Work and for which the
43
+ editorial revisions, annotations, elaborations, or other modifications
44
+ represent, as a whole, an original work of authorship. For the purposes
45
+ of this License, Derivative Works shall not include works that remain
46
+ separable from, or merely link (or bind by name) to the interfaces of,
47
+ the Work and Derivative Works thereof.
48
+
49
+ "Contribution" shall mean any work of authorship, including
50
+ the original version of the Work and any modifications or additions
51
+ to that Work or Derivative Works thereof, that is intentionally
52
+ submitted to Licensor for inclusion in the Work by the copyright owner
53
+ or by an individual or Legal Entity authorized to submit on behalf of
54
+ the copyright owner. For the purposes of this definition, "submitted"
55
+ means any form of electronic, verbal, or written communication sent
56
+ to the Licensor or its representatives, including but not limited to
57
+ communication on electronic mailing lists, source code control systems,
58
+ and issue tracking systems that are managed by, or on behalf of, the
59
+ Licensor for the purpose of discussing and improving the Work, but
60
+ excluding communication that is conspicuously marked or otherwise
61
+ designated in writing by the copyright owner as "Not a Contribution."
62
+
63
+ "Contributor" shall mean Licensor and any individual or Legal Entity
64
+ on behalf of whom a Contribution has been received by Licensor and
65
+ subsequently incorporated within the Work.
66
+
67
+ 2. Grant of Copyright License. Subject to the terms and conditions of
68
+ this License, each Contributor hereby grants to You a perpetual,
69
+ worldwide, non-exclusive, no-charge, royalty-free, irrevocable
70
+ copyright license to reproduce, prepare Derivative Works of,
71
+ publicly display, publicly perform, sublicense, and distribute the
72
+ Work and such Derivative Works in Source or Object form.
73
+
74
+ 3. Grant of Patent License. Subject to the terms and conditions of
75
+ this License, each Contributor hereby grants to You a perpetual,
76
+ worldwide, non-exclusive, no-charge, royalty-free, irrevocable
77
+ (except as stated in this section) patent license to make, have made,
78
+ use, offer to sell, sell, import, and otherwise transfer the Work,
79
+ where such license applies only to those patent claims licensable
80
+ by such Contributor that are necessarily infringed by their
81
+ Contribution(s) alone or by combination of their Contribution(s)
82
+ with the Work to which such Contribution(s) was submitted. If You
83
+ institute patent litigation against any entity (including a
84
+ cross-claim or counterclaim in a lawsuit) alleging that the Work
85
+ or a Contribution incorporated within the Work constitutes direct
86
+ or contributory patent infringement, then any patent licenses
87
+ granted to You under this License for that Work shall terminate
88
+ as of the date such litigation is filed.
89
+
90
+ 4. Redistribution. You may reproduce and distribute copies of the
91
+ Work or Derivative Works thereof in any medium, with or without
92
+ modifications, and in Source or Object form, provided that You
93
+ meet the following conditions:
94
+
95
+ (a) You must give any other recipients of the Work or
96
+ Derivative Works a copy of this License; and
97
+
98
+ (b) You must cause any modified files to carry prominent notices
99
+ stating that You changed the files; and
100
+
101
+ (c) You must retain, in the Source form of any Derivative Works
102
+ that You distribute, all copyright, patent, trademark, and
103
+ attribution notices from the Source form of the Work,
104
+ excluding those notices that do not pertain to any part of
105
+ the Derivative Works; and
106
+
107
+ (d) If the Work includes a "NOTICE" text file as part of its
108
+ distribution, then any Derivative Works that You distribute must
109
+ include a readable copy of the attribution notices contained
110
+ within such NOTICE file, excluding those notices that do not
111
+ pertain to any part of the Derivative Works, in at least one
112
+ of the following places: within a NOTICE text file distributed
113
+ as part of the Derivative Works; within the Source form or
114
+ documentation, if provided along with the Derivative Works; or,
115
+ within a display generated by the Derivative Works, if and
116
+ wherever such third-party notices normally appear. The contents
117
+ of the NOTICE file are for informational purposes only and
118
+ do not modify the License. You may add Your own attribution
119
+ notices within Derivative Works that You distribute, alongside
120
+ or as an addendum to the NOTICE text from the Work, provided
121
+ that such additional attribution notices cannot be construed
122
+ as modifying the License.
123
+
124
+ You may add Your own copyright statement to Your modifications and
125
+ may provide additional or different license terms and conditions
126
+ for use, reproduction, or distribution of Your modifications, or
127
+ for any such Derivative Works as a whole, provided Your use,
128
+ reproduction, and distribution of the Work otherwise complies with
129
+ the conditions stated in this License.
130
+
131
+ 5. Submission of Contributions. Unless You explicitly state otherwise,
132
+ any Contribution intentionally submitted for inclusion in the Work
133
+ by You to the Licensor shall be under the terms and conditions of
134
+ this License, without any additional terms or conditions.
135
+ Notwithstanding the above, nothing herein shall supersede or modify
136
+ the terms of any separate license agreement you may have executed
137
+ with Licensor regarding such Contributions.
138
+
139
+ 6. Trademarks. This License does not grant permission to use the trade
140
+ names, trademarks, service marks, or product names of the Licensor,
141
+ except as required for reasonable and customary use in describing the
142
+ origin of the Work and reproducing the content of the NOTICE file.
143
+
144
+ 7. Disclaimer of Warranty. Unless required by applicable law or
145
+ agreed to in writing, Licensor provides the Work (and each
146
+ Contributor provides its Contributions) on an "AS IS" BASIS,
147
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
148
+ implied, including, without limitation, any warranties or conditions
149
+ of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
150
+ PARTICULAR PURPOSE. You are solely responsible for determining the
151
+ appropriateness of using or redistributing the Work and assume any
152
+ risks associated with Your exercise of permissions under this License.
153
+
154
+ 8. Limitation of Liability. In no event and under no legal theory,
155
+ whether in tort (including negligence), contract, or otherwise,
156
+ unless required by applicable law (such as deliberate and grossly
157
+ negligent acts) or agreed to in writing, shall any Contributor be
158
+ liable to You for damages, including any direct, indirect, special,
159
+ incidental, or consequential damages of any character arising as a
160
+ result of this License or out of the use or inability to use the
161
+ Work (including but not limited to damages for loss of goodwill,
162
+ work stoppage, computer failure or malfunction, or any and all
163
+ other commercial damages or losses), even if such Contributor
164
+ has been advised of the possibility of such damages.
165
+
166
+ 9. Accepting Warranty or Additional Liability. While redistributing
167
+ the Work or Derivative Works thereof, You may choose to offer,
168
+ and charge a fee for, acceptance of support, warranty, indemnity,
169
+ or other liability obligations and/or rights consistent with this
170
+ License. However, in accepting such obligations, You may act only
171
+ on Your own behalf and on Your sole responsibility, not on behalf
172
+ of any other Contributor, and only if You agree to indemnify,
173
+ defend, and hold each Contributor harmless for any liability
174
+ incurred by, or claims asserted against, such Contributor by reason
175
+ of your accepting any such warranty or additional liability.
176
+
177
+ END OF TERMS AND CONDITIONS
178
+
179
+ APPENDIX: How to apply the Apache License to your work.
180
+
181
+ To apply the Apache License to your work, attach the following
182
+ boilerplate notice, with the fields enclosed by brackets "[]"
183
+ replaced with your own identifying information. (Don't include
184
+ the brackets!) The text should be enclosed in the appropriate
185
+ comment syntax for the file format. We also recommend that a
186
+ file or class name and description of purpose be included on the
187
+ same "printed page" as the copyright notice for easier
188
+ identification within third-party archives.
189
+
190
+ Copyright [yyyy] [name of copyright owner]
191
+
192
+ Licensed under the Apache License, Version 2.0 (the "License");
193
+ you may not use this file except in compliance with the License.
194
+ You may obtain a copy of the License at
195
+
196
+ http://www.apache.org/licenses/LICENSE-2.0
197
+
198
+ Unless required by applicable law or agreed to in writing, software
199
+ distributed under the License is distributed on an "AS IS" BASIS,
200
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
201
+ See the License for the specific language governing permissions and
202
+ limitations under the License.
@@ -0,0 +1,2 @@
1
+ Developer Toolkit for Amazon ElastiCache
2
+ Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.
@@ -0,0 +1,145 @@
1
+ Metadata-Version: 2.4
2
+ Name: developer-toolkit-elasticache
3
+ Version: 1.0.0
4
+ Summary: Developer toolkit for Amazon ElastiCache
5
+ License-Expression: Apache-2.0
6
+ Classifier: Development Status :: 5 - Production/Stable
7
+ Classifier: Operating System :: OS Independent
8
+ Classifier: Programming Language :: Python :: 3
9
+ Classifier: Programming Language :: Python :: 3.10
10
+ Classifier: Programming Language :: Python :: 3.11
11
+ Classifier: Programming Language :: Python :: 3.12
12
+ Classifier: Programming Language :: Python :: 3.13
13
+ Classifier: Programming Language :: Python :: 3.14
14
+ Requires-Python: >=3.10
15
+ Description-Content-Type: text/markdown
16
+ License-File: LICENSE
17
+ License-File: NOTICE
18
+ Requires-Dist: botocore>=1.43.0
19
+ Dynamic: license-file
20
+
21
+ # Developer Toolkit for Amazon ElastiCache (Python)
22
+
23
+ This is a developer toolkit for working with Amazon ElastiCache, as a Python library and
24
+ CLI.
25
+ It provides a function to generate an [IAM authentication token](https://docs.aws.amazon.com/AmazonElastiCache/latest/dg/auth-iam.html) that Amazon ElastiCache requires as the
26
+ connection password for an IAM-enabled user.
27
+
28
+ ## Installation
29
+
30
+ Requires Python 3.10–3.14 and `pip`. Install from PyPI:
31
+
32
+ ```bash
33
+ python3 -m pip install developer-toolkit-elasticache
34
+ ```
35
+
36
+ If you don't have [`pip`](https://pip.pypa.io) installed, this
37
+ [Python installation guide](https://docs.python-guide.org/starting/installation/) can
38
+ guide you through the process.
39
+
40
+ This installs the library and the `developer-toolkit-elasticache` command. To install
41
+ from source instead, clone the repository and run `python3 -m pip install .` from the
42
+ `python/` directory.
43
+
44
+ ## Usage
45
+
46
+ To generate a usable token you need:
47
+
48
+ - An Amazon ElastiCache serverless cache or replication group with the following:
49
+ - Valkey 7.2 and above or Redis OSS 7.0 and above
50
+ - In-transit Encryption (TLS) enabled
51
+ - IAM-enabled user that has access to to the cache.
52
+ - AWS credentials on the default credential chain (environment variables, shared
53
+ config files, or an instance/container role), for an identity with the
54
+ `elasticache:Connect` permission to the cache.
55
+
56
+ ### Generate a token
57
+
58
+ ```python
59
+ from developer_toolkit_elasticache import generate_iam_auth_token
60
+
61
+ token = generate_iam_auth_token(
62
+ serverless_cache_name="my-cache", # or replication_group_id="my-group"
63
+ user_id="iam-user",
64
+ region="us-east-1",
65
+ )
66
+ ```
67
+ Use the returned token as the password when connecting to the cache.
68
+
69
+ **Arguments**
70
+
71
+ - `serverless_cache_name` or `replication_group_id` (string) [one required]
72
+ The serverless cache or node-based replication group to sign for.
73
+ - `user_id` (string) [required]
74
+ The IAM-enabled user to authenticate as.
75
+ - `region` (string) [optional]
76
+ The AWS region. Defaults to your AWS configuration (`AWS_REGION`,
77
+ `AWS_DEFAULT_REGION`, or the `region` in your profile, in that order).
78
+
79
+ **Credentials**
80
+
81
+ Credentials are resolved through the standard AWS credential provider chain
82
+ and are re-read on every call, so rotated credentials are picked up for every new token generation.
83
+ The chain is checked in this order:
84
+
85
+ 1. Environment variables (`AWS_ACCESS_KEY_ID`, `AWS_SECRET_ACCESS_KEY`, and
86
+ `AWS_SESSION_TOKEN`).
87
+ 2. The shared credentials and config files (`~/.aws/credentials`, `~/.aws/config`),
88
+ selected by `AWS_PROFILE`, including any assume-role or SSO configuration.
89
+ 3. Container credentials (Amazon ECS / EKS).
90
+ 4. EC2 instance profile credentials (IMDS).
91
+
92
+ ### Reconnecting clients
93
+
94
+ Clients such as redis-py and valkey-py request credentials on every reconnection.
95
+ Pass them an `ElastiCacheIAMAuthTokenProvider` and call `get_token()` when the
96
+ connection opens, so each connection uses a fresh token:
97
+
98
+ ```python
99
+ from developer_toolkit_elasticache import ElastiCacheIAMAuthTokenProvider
100
+
101
+ auth = ElastiCacheIAMAuthTokenProvider(
102
+ serverless_cache_name="my-cache",
103
+ user_id="iam-user",
104
+ region="us-east-1",
105
+ )
106
+ username, password = auth.user_id, auth.get_token()
107
+ ```
108
+
109
+ The [`examples/`](examples/) directory has redis-py and valkey-py integrations.
110
+
111
+ ### Command line
112
+
113
+ ```bash
114
+ developer-toolkit-elasticache generate_iam_auth_token \
115
+ --serverless-cache-name my-cache \
116
+ --user-id iam-user \
117
+ --region us-east-1
118
+ ```
119
+
120
+ Add `--region` to sign for a specific region instead of the one resolved from your
121
+ AWS configuration
122
+
123
+ For the command line, the token is written to stdout, so you can capture it
124
+ directly and pass it to a CLI client through an auth environment variable.
125
+ `REDISCLI_AUTH` works with both `redis-cli` and `valkey-cli`; `VALKEYCLI_AUTH`
126
+ works with `valkey-cli` 9.0.0 and later:
127
+
128
+ ```bash
129
+ export VALKEYCLI_AUTH=$(developer-toolkit-elasticache generate_iam_auth_token \
130
+ --serverless-cache-name my-cache --user-id iam-user --region us-east-1)
131
+
132
+ # Example: connecting via valkey-cli
133
+ valkey-cli --tls -h <my-cache-configured-endpoint> --user <iam-user>
134
+ ```
135
+
136
+ ## Security
137
+
138
+ The token is a bearer credential. Keep it out of logs and shell history, and
139
+ connect over TLS. When using a CLI client, you can use the `REDISCLI_AUTH` /
140
+ `VALKEYCLI_AUTH` environment variable to pass the token more safely than the
141
+ `-a` / `--pass` flags, which expose it in the process list.
142
+
143
+ ## License
144
+
145
+ Apache-2.0. See [LICENSE](LICENSE).
@@ -0,0 +1,125 @@
1
+ # Developer Toolkit for Amazon ElastiCache (Python)
2
+
3
+ This is a developer toolkit for working with Amazon ElastiCache, as a Python library and
4
+ CLI.
5
+ It provides a function to generate an [IAM authentication token](https://docs.aws.amazon.com/AmazonElastiCache/latest/dg/auth-iam.html) that Amazon ElastiCache requires as the
6
+ connection password for an IAM-enabled user.
7
+
8
+ ## Installation
9
+
10
+ Requires Python 3.10–3.14 and `pip`. Install from PyPI:
11
+
12
+ ```bash
13
+ python3 -m pip install developer-toolkit-elasticache
14
+ ```
15
+
16
+ If you don't have [`pip`](https://pip.pypa.io) installed, this
17
+ [Python installation guide](https://docs.python-guide.org/starting/installation/) can
18
+ guide you through the process.
19
+
20
+ This installs the library and the `developer-toolkit-elasticache` command. To install
21
+ from source instead, clone the repository and run `python3 -m pip install .` from the
22
+ `python/` directory.
23
+
24
+ ## Usage
25
+
26
+ To generate a usable token you need:
27
+
28
+ - An Amazon ElastiCache serverless cache or replication group with the following:
29
+ - Valkey 7.2 and above or Redis OSS 7.0 and above
30
+ - In-transit Encryption (TLS) enabled
31
+ - IAM-enabled user that has access to to the cache.
32
+ - AWS credentials on the default credential chain (environment variables, shared
33
+ config files, or an instance/container role), for an identity with the
34
+ `elasticache:Connect` permission to the cache.
35
+
36
+ ### Generate a token
37
+
38
+ ```python
39
+ from developer_toolkit_elasticache import generate_iam_auth_token
40
+
41
+ token = generate_iam_auth_token(
42
+ serverless_cache_name="my-cache", # or replication_group_id="my-group"
43
+ user_id="iam-user",
44
+ region="us-east-1",
45
+ )
46
+ ```
47
+ Use the returned token as the password when connecting to the cache.
48
+
49
+ **Arguments**
50
+
51
+ - `serverless_cache_name` or `replication_group_id` (string) [one required]
52
+ The serverless cache or node-based replication group to sign for.
53
+ - `user_id` (string) [required]
54
+ The IAM-enabled user to authenticate as.
55
+ - `region` (string) [optional]
56
+ The AWS region. Defaults to your AWS configuration (`AWS_REGION`,
57
+ `AWS_DEFAULT_REGION`, or the `region` in your profile, in that order).
58
+
59
+ **Credentials**
60
+
61
+ Credentials are resolved through the standard AWS credential provider chain
62
+ and are re-read on every call, so rotated credentials are picked up for every new token generation.
63
+ The chain is checked in this order:
64
+
65
+ 1. Environment variables (`AWS_ACCESS_KEY_ID`, `AWS_SECRET_ACCESS_KEY`, and
66
+ `AWS_SESSION_TOKEN`).
67
+ 2. The shared credentials and config files (`~/.aws/credentials`, `~/.aws/config`),
68
+ selected by `AWS_PROFILE`, including any assume-role or SSO configuration.
69
+ 3. Container credentials (Amazon ECS / EKS).
70
+ 4. EC2 instance profile credentials (IMDS).
71
+
72
+ ### Reconnecting clients
73
+
74
+ Clients such as redis-py and valkey-py request credentials on every reconnection.
75
+ Pass them an `ElastiCacheIAMAuthTokenProvider` and call `get_token()` when the
76
+ connection opens, so each connection uses a fresh token:
77
+
78
+ ```python
79
+ from developer_toolkit_elasticache import ElastiCacheIAMAuthTokenProvider
80
+
81
+ auth = ElastiCacheIAMAuthTokenProvider(
82
+ serverless_cache_name="my-cache",
83
+ user_id="iam-user",
84
+ region="us-east-1",
85
+ )
86
+ username, password = auth.user_id, auth.get_token()
87
+ ```
88
+
89
+ The [`examples/`](examples/) directory has redis-py and valkey-py integrations.
90
+
91
+ ### Command line
92
+
93
+ ```bash
94
+ developer-toolkit-elasticache generate_iam_auth_token \
95
+ --serverless-cache-name my-cache \
96
+ --user-id iam-user \
97
+ --region us-east-1
98
+ ```
99
+
100
+ Add `--region` to sign for a specific region instead of the one resolved from your
101
+ AWS configuration
102
+
103
+ For the command line, the token is written to stdout, so you can capture it
104
+ directly and pass it to a CLI client through an auth environment variable.
105
+ `REDISCLI_AUTH` works with both `redis-cli` and `valkey-cli`; `VALKEYCLI_AUTH`
106
+ works with `valkey-cli` 9.0.0 and later:
107
+
108
+ ```bash
109
+ export VALKEYCLI_AUTH=$(developer-toolkit-elasticache generate_iam_auth_token \
110
+ --serverless-cache-name my-cache --user-id iam-user --region us-east-1)
111
+
112
+ # Example: connecting via valkey-cli
113
+ valkey-cli --tls -h <my-cache-configured-endpoint> --user <iam-user>
114
+ ```
115
+
116
+ ## Security
117
+
118
+ The token is a bearer credential. Keep it out of logs and shell history, and
119
+ connect over TLS. When using a CLI client, you can use the `REDISCLI_AUTH` /
120
+ `VALKEYCLI_AUTH` environment variable to pass the token more safely than the
121
+ `-a` / `--pass` flags, which expose it in the process list.
122
+
123
+ ## License
124
+
125
+ Apache-2.0. See [LICENSE](LICENSE).
@@ -0,0 +1,94 @@
1
+ [build-system]
2
+ # 77 is the first release that understands PEP 639: the bare SPDX expression in
3
+ # `license` below, and the default license-files glob that ships LICENSE/NOTICE in
4
+ # the wheel. Older setuptools only accepts the pre-PEP-639 table form
5
+ # (`license = {text = ...}`) and fails metadata generation outright. Nothing in
6
+ # normal development catches this, because pip's isolated build pulls the newest
7
+ # setuptools regardless of this floor — it only bites a pinned or vendored build.
8
+ requires = ["setuptools>=77.0"]
9
+ build-backend = "setuptools.build_meta"
10
+
11
+ [project]
12
+ name = "developer-toolkit-elasticache"
13
+ version = "1.0.0"
14
+ description = "Developer toolkit for Amazon ElastiCache"
15
+ readme = "README.md"
16
+ license = "Apache-2.0"
17
+ requires-python = ">=3.10"
18
+ dependencies = [
19
+ "botocore>=1.43.0",
20
+ ]
21
+ classifiers = [
22
+ "Development Status :: 5 - Production/Stable",
23
+ "Operating System :: OS Independent",
24
+ "Programming Language :: Python :: 3",
25
+ "Programming Language :: Python :: 3.10",
26
+ "Programming Language :: Python :: 3.11",
27
+ "Programming Language :: Python :: 3.12",
28
+ "Programming Language :: Python :: 3.13",
29
+ "Programming Language :: Python :: 3.14",
30
+ ]
31
+
32
+ # Supported Python range — the source for the CI/release test matrices.
33
+ [tool.python-support]
34
+ min = "3.10"
35
+ max = "3.14"
36
+
37
+ [tool.ruff]
38
+ # The floor in requires-python. Keeps ruff from suggesting syntax that would not
39
+ # run on the oldest interpreter we claim to support.
40
+ target-version = "py310"
41
+ line-length = 90
42
+
43
+ [tool.ruff.lint]
44
+ extend-select = [
45
+ "B", # flake8-bugbear
46
+ "C4", # flake8-comprehensions
47
+ "I", # isort
48
+ "INP", # flake8-no-pep420 (implicit namespace packages)
49
+ "PL", # pylint
50
+ "RUF", # ruff-specific rules
51
+ "S", # flake8-bandit (security)
52
+ "T20", # flake8-print
53
+ "UP", # pyupgrade
54
+ "W", # pycodestyle warnings
55
+ ]
56
+
57
+ # Every rule exempted below must be selected above, or the exemption is inert and
58
+ # the config only looks like it is enforcing something.
59
+ [tool.ruff.lint.per-file-ignores]
60
+ # A CLI's whole job is to write to stdout/stderr, so printing is intended here
61
+ # rather than lint debt.
62
+ "src/developer_toolkit_elasticache/cli.py" = ["T201"]
63
+ # Asserts and magic values are the point of a test, and tests are collected by path
64
+ # rather than imported as a package. S105 fires on the known-answer token strings,
65
+ # which are expected signed URLs to assert against, not secrets.
66
+ "tests/**/*" = ["S101", "PLR2004", "INP001", "S105"]
67
+ # The examples are illustrative scripts whose job is to print, and they are not an
68
+ # importable package.
69
+ "examples/**/*" = ["T201", "INP001"]
70
+
71
+ [tool.pytest.ini_options]
72
+ # The examples/ scripts are runnable demos that need live AWS credentials and a
73
+ # reachable cache, and they do their work at import time, so collecting one would
74
+ # fail CI. Two independent guards, because testpaths alone is only a default and is
75
+ # silently overridden the moment anyone runs `pytest .` or `pytest <path>`:
76
+ # 1. testpaths — bare `pytest` looks only at tests/
77
+ # 2. norecursedirs — examples/ is skipped even when a path IS given
78
+ # Keep example filenames clear of test_*.py / *_test.py as well, since a matching
79
+ # name is what turned this into a CI failure in the first place.
80
+ testpaths = ["tests"]
81
+ norecursedirs = ["examples", "build", "dist", ".*"]
82
+
83
+ [project.scripts]
84
+ developer-toolkit-elasticache = "developer_toolkit_elasticache.cli:main"
85
+
86
+ [tool.setuptools.packages.find]
87
+ where = ["src"]
88
+
89
+ # PEP 561: py.typed tells a consumer's type checker that the annotations in this
90
+ # package are meant to be used. Without the marker they are ignored downstream no
91
+ # matter how completely the code is annotated, and it has to be declared here or it
92
+ # does not make it into the wheel.
93
+ [tool.setuptools.package-data]
94
+ developer_toolkit_elasticache = ["py.typed"]
@@ -0,0 +1,4 @@
1
+ [egg_info]
2
+ tag_build =
3
+ tag_date = 0
4
+
@@ -0,0 +1,22 @@
1
+ # Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.
2
+ # SPDX-License-Identifier: Apache-2.0
3
+
4
+ """Developer Toolkit for Amazon ElastiCache."""
5
+
6
+ from developer_toolkit_elasticache.errors import (
7
+ ConfigurationError,
8
+ InvalidParameterError,
9
+ ToolkitInputError,
10
+ )
11
+ from developer_toolkit_elasticache.token_generator import (
12
+ ElastiCacheIAMAuthTokenProvider,
13
+ generate_iam_auth_token,
14
+ )
15
+
16
+ __all__ = [
17
+ "ConfigurationError",
18
+ "ElastiCacheIAMAuthTokenProvider",
19
+ "InvalidParameterError",
20
+ "ToolkitInputError",
21
+ "generate_iam_auth_token",
22
+ ]
@@ -0,0 +1,80 @@
1
+ # Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.
2
+ # SPDX-License-Identifier: Apache-2.0
3
+
4
+ import argparse
5
+ import sys
6
+
7
+ from developer_toolkit_elasticache import generate_iam_auth_token
8
+ from developer_toolkit_elasticache.errors import ToolkitInputError
9
+
10
+
11
+ def _add_generate_iam_auth_token_args(parser: argparse.ArgumentParser) -> None:
12
+ target = parser.add_mutually_exclusive_group(required=True)
13
+ target.add_argument(
14
+ "--serverless-cache-name",
15
+ help="Serverless cache name (the SigV4 signing host)",
16
+ )
17
+ target.add_argument(
18
+ "--replication-group-id",
19
+ help="Replication group id for a node-based cluster (the SigV4 signing host)",
20
+ )
21
+ parser.add_argument(
22
+ "--user-id",
23
+ required=True,
24
+ help="ElastiCache user id (used to build the User ARN in the IAM policy)",
25
+ )
26
+ parser.add_argument(
27
+ "--region",
28
+ help="AWS region (default: the region resolved from your AWS configuration)",
29
+ )
30
+
31
+
32
+ def _cmd_generate_iam_auth_token(args: argparse.Namespace) -> str | None:
33
+ return generate_iam_auth_token(
34
+ user_id=args.user_id,
35
+ region=args.region,
36
+ serverless_cache_name=args.serverless_cache_name,
37
+ replication_group_id=args.replication_group_id,
38
+ )
39
+
40
+
41
+ def _build_parser() -> argparse.ArgumentParser:
42
+ """Build the top-level parser.
43
+
44
+ Each tool contributes one subparser and sets ``func`` to a callable taking the
45
+ parsed namespace. That callable returns the text to write to stdout, or ``None``
46
+ if the tool has nothing to print. It signals a user-fixable failure by raising
47
+ an ``ToolkitInputError`` subclass; ``main`` handles the rest, so adding a tool
48
+ means adding a subparser here and nothing else.
49
+ """
50
+ parser = argparse.ArgumentParser(
51
+ prog="developer-toolkit-elasticache",
52
+ description="Developer tools for Amazon ElastiCache",
53
+ )
54
+ subparsers = parser.add_subparsers(dest="command", required=True)
55
+
56
+ gen = subparsers.add_parser(
57
+ "generate_iam_auth_token",
58
+ help="Generate an IAM auth token for an ElastiCache cache",
59
+ )
60
+ _add_generate_iam_auth_token_args(gen)
61
+ gen.set_defaults(func=_cmd_generate_iam_auth_token)
62
+
63
+ return parser
64
+
65
+
66
+ def main(argv: list[str] | None = None) -> int:
67
+ args = _build_parser().parse_args(argv)
68
+
69
+ try:
70
+ output = args.func(args)
71
+ except ToolkitInputError as e:
72
+ print(f"Error: {e}", file=sys.stderr)
73
+ return 1
74
+ if output is not None:
75
+ print(output)
76
+ return 0
77
+
78
+
79
+ if __name__ == "__main__":
80
+ sys.exit(main())