keyrings.codeartifact 2.0.0__py3-none-any.whl → 2.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.
- keyrings/codeartifact.py +64 -16
- {keyrings.codeartifact-2.0.0.dist-info → keyrings_codeartifact-2.1.0.dist-info}/METADATA +3 -3
- keyrings_codeartifact-2.1.0.dist-info/RECORD +8 -0
- {keyrings.codeartifact-2.0.0.dist-info → keyrings_codeartifact-2.1.0.dist-info}/WHEEL +1 -1
- keyrings.codeartifact-2.0.0.dist-info/RECORD +0 -8
- {keyrings.codeartifact-2.0.0.dist-info → keyrings_codeartifact-2.1.0.dist-info}/entry_points.txt +0 -0
- {keyrings.codeartifact-2.0.0.dist-info → keyrings_codeartifact-2.1.0.dist-info/licenses}/LICENSE +0 -0
- {keyrings.codeartifact-2.0.0.dist-info → keyrings_codeartifact-2.1.0.dist-info}/top_level.txt +0 -0
keyrings/codeartifact.py
CHANGED
@@ -1,9 +1,11 @@
|
|
1
1
|
# codeartifact.py -- keyring backend
|
2
2
|
|
3
3
|
import re
|
4
|
-
import boto3
|
5
4
|
import logging
|
6
5
|
|
6
|
+
import boto3
|
7
|
+
import boto3.session
|
8
|
+
|
7
9
|
from datetime import datetime
|
8
10
|
from urllib.parse import urlparse
|
9
11
|
|
@@ -45,7 +47,8 @@ class CodeArtifactKeyringConfig:
|
|
45
47
|
config_parser.default_section = self.DEFAULT_SECTION
|
46
48
|
|
47
49
|
# Load the configuration file.
|
48
|
-
config_parser.read(config_file)
|
50
|
+
if not config_parser.read(config_file):
|
51
|
+
logging.warning(f"{config_file} does not exist!")
|
49
52
|
|
50
53
|
# Collect the defaults before we go further.
|
51
54
|
self.defaults = config_parser.defaults()
|
@@ -103,19 +106,37 @@ class CodeArtifactKeyringConfig:
|
|
103
106
|
return self.config.get(found_key)
|
104
107
|
|
105
108
|
|
109
|
+
def make_codeartifact_client(options):
|
110
|
+
# Build a session with the provided options.
|
111
|
+
session = boto3.session.Session(
|
112
|
+
# NOTE: Only the session accepts 'profile_name'.
|
113
|
+
profile_name=options.pop("profile_name", None),
|
114
|
+
region_name=options.get("region_name"),
|
115
|
+
)
|
116
|
+
|
117
|
+
# Create a client for this new session.
|
118
|
+
return session.client("codeartifact", **options)
|
119
|
+
|
120
|
+
|
106
121
|
class CodeArtifactBackend(backend.KeyringBackend):
|
107
122
|
HOST_REGEX = r"^(.+)-(\d{12})\.d\.codeartifact\.([^\.]+)\.amazonaws\.com$"
|
108
123
|
PATH_REGEX = r"^/pypi/([^/]+)/?"
|
109
124
|
|
110
125
|
priority = 9.9
|
111
126
|
|
112
|
-
def __init__(self,
|
127
|
+
def __init__(self, /, config=None, make_client=make_codeartifact_client):
|
113
128
|
super().__init__()
|
114
129
|
|
115
|
-
if
|
130
|
+
if config:
|
131
|
+
# Use the provided configuration.
|
132
|
+
self.config = config
|
133
|
+
else:
|
134
|
+
# Use the global configuration file.
|
116
135
|
config_file = config_root() / "keyringrc.cfg"
|
136
|
+
self.config = CodeArtifactKeyringConfig(config_file)
|
117
137
|
|
118
|
-
|
138
|
+
# Use our default built-in CodeArtifact client producer.
|
139
|
+
self.make_client = make_client
|
119
140
|
|
120
141
|
def get_credential(self, service, username):
|
121
142
|
authorization_token = self.get_password(service, username)
|
@@ -134,7 +155,7 @@ class CodeArtifactBackend(backend.KeyringBackend):
|
|
134
155
|
|
135
156
|
# If it didn't match the regex, it doesn't apply to us.
|
136
157
|
if not host_match:
|
137
|
-
logging.warning("Not an AWS CodeArtifact repository URL
|
158
|
+
logging.warning(f"Not an AWS CodeArtifact repository URL: {service}")
|
138
159
|
return
|
139
160
|
|
140
161
|
# Extract the domain, account and region for this repository.
|
@@ -148,7 +169,7 @@ class CodeArtifactBackend(backend.KeyringBackend):
|
|
148
169
|
|
149
170
|
repository_name = path_match.group(1)
|
150
171
|
|
151
|
-
#
|
172
|
+
# Lookup configuration options.
|
152
173
|
config = self.config.lookup(
|
153
174
|
domain=domain,
|
154
175
|
account=account,
|
@@ -156,16 +177,43 @@ class CodeArtifactBackend(backend.KeyringBackend):
|
|
156
177
|
name=repository_name,
|
157
178
|
)
|
158
179
|
|
159
|
-
#
|
160
|
-
|
161
|
-
|
162
|
-
|
163
|
-
|
164
|
-
|
165
|
-
|
180
|
+
# Options for the client callback.
|
181
|
+
options = {
|
182
|
+
# Pass in the region name.
|
183
|
+
"region_name": region,
|
184
|
+
}
|
185
|
+
|
186
|
+
# Extract any AWS profile name we should use.
|
187
|
+
profile_name = config.get("profile_name")
|
188
|
+
if profile_name:
|
189
|
+
options.update({"profile_name": profile_name})
|
190
|
+
|
191
|
+
# Provide option to disable SSL/TLS verification.
|
192
|
+
verify = config.get("verify")
|
193
|
+
if verify:
|
194
|
+
if verify.lower() in {"1", "yes", "on", "true"}:
|
195
|
+
# Enable SSL/TLS verification explicitly.
|
196
|
+
options.update({"verify": True})
|
197
|
+
elif verify.lower() in {"0", "no", "off", "false"}:
|
198
|
+
# Disable SSL/TLS verification entirely.
|
199
|
+
options.update({"verify": False})
|
200
|
+
else:
|
201
|
+
# The SSL/TLS certificate to verify against.
|
202
|
+
options.update({"verify": verify.strip('"')})
|
203
|
+
|
204
|
+
# If static access/secret keys were provided, use them.
|
205
|
+
aws_access_key_id = config.get("aws_access_key_id")
|
206
|
+
aws_secret_access_key = config.get("aws_secret_access_key")
|
207
|
+
if aws_access_key_id and aws_secret_access_key:
|
208
|
+
options.update(
|
209
|
+
{
|
210
|
+
"aws_access_key_id": aws_access_key_id,
|
211
|
+
"aws_secret_access_key": aws_secret_access_key,
|
212
|
+
}
|
213
|
+
)
|
166
214
|
|
167
|
-
#
|
168
|
-
client =
|
215
|
+
# Generate a CodeArtifact client using the callback.
|
216
|
+
client = self.make_client(options)
|
169
217
|
|
170
218
|
# Authorization tokens should be good for an hour by default.
|
171
219
|
token_duration = int(config.get("token_duration", 3600))
|
@@ -1,6 +1,6 @@
|
|
1
|
-
Metadata-Version: 2.
|
1
|
+
Metadata-Version: 2.4
|
2
2
|
Name: keyrings.codeartifact
|
3
|
-
Version: 2.
|
3
|
+
Version: 2.1.0
|
4
4
|
Summary: Automatically retrieve credentials for AWS CodeArtifact.
|
5
5
|
Author-email: "Joshua M. Keyes" <joshua.michael.keyes@gmail.com>
|
6
6
|
License: MIT License
|
@@ -45,6 +45,7 @@ Requires-Dist: black; extra == "devel"
|
|
45
45
|
Provides-Extra: testing
|
46
46
|
Requires-Dist: pytest>=6; extra == "testing"
|
47
47
|
Requires-Dist: pytest-cov; extra == "testing"
|
48
|
+
Dynamic: license-file
|
48
49
|
|
49
50
|
AWS CodeArtifact Keyring Backend
|
50
51
|
================================
|
@@ -103,7 +104,6 @@ profile_name=default
|
|
103
104
|
# Use the following access keys.
|
104
105
|
aws_access_key_id=xxxxxxxxx
|
105
106
|
aws_secret_access_key=xxxxxxxxx
|
106
|
-
|
107
107
|
```
|
108
108
|
|
109
109
|
### Multiple Section Configuration (EXPERIMENTAL)
|
@@ -0,0 +1,8 @@
|
|
1
|
+
keyrings/__init__.py,sha256=ED6jHcYiuYpr_0vjGz0zx2lrrmJT9sDJCzIljoDfmlM,65
|
2
|
+
keyrings/codeartifact.py,sha256=tfXlAFvgwiNHmCaJvhhWb_ZUEs_U18q58V_-cqFenqk,8516
|
3
|
+
keyrings_codeartifact-2.1.0.dist-info/licenses/LICENSE,sha256=rBKHwYBR3VuB8PVCXNYgSaJqhvpradtRbu9SEMxfRiI,1105
|
4
|
+
keyrings_codeartifact-2.1.0.dist-info/METADATA,sha256=B27xPhtKY5VovnL4ZXfgFROuYfEsAtXrIyXXkIWLs3A,5657
|
5
|
+
keyrings_codeartifact-2.1.0.dist-info/WHEEL,sha256=_zCd3N1l69ArxyTb8rzEoP9TpbYXkqRFSNOD5OuxnTs,91
|
6
|
+
keyrings_codeartifact-2.1.0.dist-info/entry_points.txt,sha256=Dtin9CsXc5q4hx0zKP2PiPNqVaQIlhnIX042QMqbM6U,60
|
7
|
+
keyrings_codeartifact-2.1.0.dist-info/top_level.txt,sha256=CFU-m0Q3B8OHGUonsk82bd-w5tsD16QsqpnMH4hufJY,9
|
8
|
+
keyrings_codeartifact-2.1.0.dist-info/RECORD,,
|
@@ -1,8 +0,0 @@
|
|
1
|
-
keyrings/__init__.py,sha256=ED6jHcYiuYpr_0vjGz0zx2lrrmJT9sDJCzIljoDfmlM,65
|
2
|
-
keyrings/codeartifact.py,sha256=H7Imyz0EI8jCRUR6hq0NbsHf7ALp8dDYhfVyY1ZmXlA,6709
|
3
|
-
keyrings.codeartifact-2.0.0.dist-info/LICENSE,sha256=rBKHwYBR3VuB8PVCXNYgSaJqhvpradtRbu9SEMxfRiI,1105
|
4
|
-
keyrings.codeartifact-2.0.0.dist-info/METADATA,sha256=z07WSTKR944BWBuD954rYcjnMIj_h_zzaViSDbVlx5E,5636
|
5
|
-
keyrings.codeartifact-2.0.0.dist-info/WHEEL,sha256=In9FTNxeP60KnTkGw7wk6mJPYd_dQSjEZmXdBdMCI-8,91
|
6
|
-
keyrings.codeartifact-2.0.0.dist-info/entry_points.txt,sha256=Dtin9CsXc5q4hx0zKP2PiPNqVaQIlhnIX042QMqbM6U,60
|
7
|
-
keyrings.codeartifact-2.0.0.dist-info/top_level.txt,sha256=CFU-m0Q3B8OHGUonsk82bd-w5tsD16QsqpnMH4hufJY,9
|
8
|
-
keyrings.codeartifact-2.0.0.dist-info/RECORD,,
|
{keyrings.codeartifact-2.0.0.dist-info → keyrings_codeartifact-2.1.0.dist-info}/entry_points.txt
RENAMED
File without changes
|
{keyrings.codeartifact-2.0.0.dist-info → keyrings_codeartifact-2.1.0.dist-info/licenses}/LICENSE
RENAMED
File without changes
|
{keyrings.codeartifact-2.0.0.dist-info → keyrings_codeartifact-2.1.0.dist-info}/top_level.txt
RENAMED
File without changes
|