Skip to content

Commit a7caad5

Browse files
committed
#1262 - new safe type for maven namespaces
1 parent 86792a1 commit a7caad5

6 files changed

Lines changed: 21 additions & 9 deletions

File tree

atr/models/api.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -108,7 +108,7 @@ class DistributionRecordArgs(schema.Strict):
108108
project: safe.ProjectKey = schema.example("example")
109109
version: safe.VersionKey = schema.example("0.0.1")
110110
platform: sql.DistributionPlatform = schema.example(sql.DistributionPlatform.ARTIFACT_HUB)
111-
distribution_owner_namespace: safe.Alphanumeric | None = schema.default_example(None, "example")
111+
distribution_owner_namespace: safe.OwnerNamespace | None = schema.default_example(None, "example")
112112
distribution_package: safe.Alphanumeric = schema.example("example")
113113
distribution_version: safe.VersionKey = schema.example("0.0.1")
114114
staging: bool = schema.example(False)
@@ -136,7 +136,7 @@ class DistributionRecordFromWorkflowArgs(schema.Strict):
136136
project: safe.ProjectKey = schema.example("example")
137137
version: safe.VersionKey = schema.example("0.0.1")
138138
platform: sql.DistributionPlatform = schema.example(sql.DistributionPlatform.ARTIFACT_HUB)
139-
distribution_owner_namespace: safe.Alphanumeric | None = schema.default_example(None, "example")
139+
distribution_owner_namespace: safe.OwnerNamespace | None = schema.default_example(None, "example")
140140
distribution_package: safe.Alphanumeric = schema.example("example")
141141
distribution_version: safe.VersionKey = schema.example("0.0.1")
142142
phase: TrustedWorkflowPhase = schema.Field(default="compose", json_schema_extra={"examples": ["compose", "finish"]})
@@ -479,7 +479,7 @@ class PublisherDistributionRecordArgs(schema.Strict):
479479
jwt: str = schema.example("eyJhbGciOiJIUzI1[...]mMjLiuyu5CSpyHI=")
480480
version: safe.VersionKey = schema.example("0.0.1")
481481
platform: sql.DistributionPlatform = schema.example(sql.DistributionPlatform.ARTIFACT_HUB)
482-
distribution_owner_namespace: safe.Alphanumeric | None = schema.default_example(None, "example")
482+
distribution_owner_namespace: safe.OwnerNamespace | None = schema.default_example(None, "example")
483483
distribution_package: safe.Alphanumeric = schema.example("example")
484484
distribution_version: safe.VersionKey = schema.example("0.0.1")
485485
staging: bool = schema.example(False)

atr/models/distribution.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -93,7 +93,7 @@ class PyPIResponse(schema.Subset):
9393
# Including all of the enum properties
9494
class Data(schema.Subset):
9595
platform: sql.DistributionPlatform
96-
owner_namespace: safe.Alphanumeric | None = None
96+
owner_namespace: safe.OwnerNamespace | None = None
9797
package: safe.Alphanumeric
9898
version: safe.VersionKey
9999
details: bool

atr/models/safe.py

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@
2929
_ASF_UID_CHARS: Final = frozenset(string.ascii_lowercase + string.digits + "-_")
3030
_NUMERIC: Final = frozenset(string.digits)
3131
_PATH_CHARS: Final = frozenset(string.ascii_letters + string.digits + "-._+~/()")
32+
_OWNER_NAMESPACE_CHARS: Final = _ALPHANUM | frozenset(".")
3233
_VERSION_CHARS: Final = _ALPHANUM | frozenset(".+")
3334

3435

@@ -183,6 +184,12 @@ def _valid_chars(cls) -> frozenset[str]:
183184
return _ALPHANUM
184185

185186

187+
class OwnerNamespace(SafeType):
188+
@classmethod
189+
def _valid_chars(cls) -> frozenset[str]:
190+
return _OWNER_NAMESPACE_CHARS
191+
192+
186193
class AsfUid(SafeType):
187194
"""An ASF user ID validated to contain only lowercase letters, digits, hyphens, and underscores."""
188195

@@ -327,6 +334,11 @@ def _strip_slashes_or_none(v: object) -> object:
327334
pydantic.BeforeValidator(_strip_slashes_or_none),
328335
]
329336

337+
type OptionalOwnerNamespace = Annotated[
338+
OwnerNamespace | None,
339+
pydantic.BeforeValidator(_strip_slashes_or_none),
340+
]
341+
330342
type OptionalRelPath = Annotated[
331343
RelPath | None,
332344
pydantic.BeforeValidator(_strip_slashes_or_none),

atr/models/sql.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1566,7 +1566,7 @@ def distribution_data(self, details: bool = False) -> "distribution.Data":
15661566

15671567
return distribution.Data(
15681568
platform=self.platform,
1569-
owner_namespace=safe.Alphanumeric(self.owner_namespace),
1569+
owner_namespace=safe.OwnerNamespace(self.owner_namespace),
15701570
package=safe.Alphanumeric(self.package),
15711571
version=safe.VersionKey(self.version),
15721572
details=details,

atr/shared/distribution.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -131,7 +131,7 @@ class DistributionAutomateForm(form.Form):
131131
platform: form.Enum[DistributionPlatform] = form.label(
132132
"Platform", widget=form.Widget.SELECT, enum_filter_include=[DistributionPlatform.MAVEN.value]
133133
)
134-
owner_namespace: safe.OptionalAlphanumeric = form.label(
134+
owner_namespace: safe.OptionalOwnerNamespace = form.label(
135135
"Owner or Namespace",
136136
"Who owns or names the package (Maven groupId, npm @scope, Docker namespace, "
137137
"GitHub owner, ArtifactHub repo). Leave blank if not used.",
@@ -158,7 +158,7 @@ def validate_owner_namespace(self) -> DistributionAutomateForm:
158158

159159
class DistributionRecordForm(form.Form):
160160
platform: form.Enum[DistributionPlatform] = form.label("Platform", widget=form.Widget.SELECT)
161-
owner_namespace: safe.OptionalAlphanumeric = form.label(
161+
owner_namespace: safe.OptionalOwnerNamespace = form.label(
162162
"Owner or Namespace",
163163
"Who owns or names the package (Maven groupId, npm @scope, Docker namespace, "
164164
"GitHub owner, ArtifactHub repo). Leave blank if not used.",

atr/storage/writers/distributions.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -97,7 +97,7 @@ async def automate(
9797
release_key: models.safe.ReleaseKey,
9898
platform: models.sql.DistributionPlatform,
9999
committee_key: str,
100-
owner_namespace: models.safe.Alphanumeric | None,
100+
owner_namespace: models.safe.OwnerNamespace | None,
101101
project_key: models.safe.ProjectKey,
102102
version_key: models.safe.VersionKey,
103103
phase: str,
@@ -148,7 +148,7 @@ async def record(
148148
self,
149149
release_key: models.safe.ReleaseKey,
150150
platform: models.sql.DistributionPlatform,
151-
owner_namespace: models.safe.Alphanumeric | None,
151+
owner_namespace: models.safe.OwnerNamespace | None,
152152
package: models.safe.Alphanumeric,
153153
version: models.safe.VersionKey,
154154
staging: bool,

0 commit comments

Comments
 (0)