|
33 | 33 | Address,
|
34 | 34 | Manifest,
|
35 | 35 | )
|
| 36 | +from ethpm.utils.backend import ( |
| 37 | + resolve_uri_contents, |
| 38 | +) |
| 39 | +from ethpm.utils.ipfs import ( |
| 40 | + is_ipfs_uri, |
| 41 | +) |
| 42 | +from ethpm.utils.manifest_validation import ( |
| 43 | + validate_manifest_against_schema, |
| 44 | + validate_raw_manifest_format, |
| 45 | +) |
| 46 | +from ethpm.utils.uri import ( |
| 47 | + is_valid_content_addressed_github_uri, |
| 48 | +) |
36 | 49 | from ethpm.validation import (
|
37 | 50 | validate_package_name,
|
38 | 51 | validate_package_version,
|
|
44 | 57 | )
|
45 | 58 | from web3.exceptions import (
|
46 | 59 | InvalidAddress,
|
| 60 | + ManifestValidationError, |
47 | 61 | NameNotFound,
|
48 | 62 | PMError,
|
49 | 63 | )
|
@@ -463,12 +477,28 @@ def release_package(
|
463 | 477 | to be the registry owner.
|
464 | 478 |
|
465 | 479 | * Parameters:
|
466 |
| - * ``package_name``: Must be a valid package name. |
467 |
| - * ``version``: Must be a valid package version. |
468 |
| - * ``manifest_uri``: Must be a valid manifest URI. |
469 |
| - """ |
470 |
| - validate_package_name(package_name) |
471 |
| - validate_package_version(version) |
| 480 | + * ``package_name``: Must be a valid package name, matching the given manifest. |
| 481 | + * ``version``: Must be a valid package version, matching the given manifest. |
| 482 | + * ``manifest_uri``: Must be a valid content-addressed URI. Currently, only IPFS |
| 483 | + and Github content-addressed URIs are supported. |
| 484 | + """ |
| 485 | + validate_is_supported_manifest_uri(manifest_uri) |
| 486 | + raw_manifest = to_text(resolve_uri_contents(manifest_uri)) |
| 487 | + validate_raw_manifest_format(raw_manifest) |
| 488 | + manifest = json.loads(raw_manifest) |
| 489 | + validate_manifest_against_schema(manifest) |
| 490 | + if package_name != manifest['package_name']: |
| 491 | + raise ManifestValidationError( |
| 492 | + f"Provided package name: {package_name} does not match the package name " |
| 493 | + f"found in the manifest: {manifest['package_name']}." |
| 494 | + ) |
| 495 | + |
| 496 | + if version != manifest['version']: |
| 497 | + raise ManifestValidationError( |
| 498 | + f"Provided package version: {version} does not match the package version " |
| 499 | + f"found in the manifest: {manifest['version']}." |
| 500 | + ) |
| 501 | + |
472 | 502 | self._validate_set_registry()
|
473 | 503 | return self.registry._release(package_name, version, manifest_uri)
|
474 | 504 |
|
@@ -597,6 +627,14 @@ def get_solidity_registry_manifest() -> Dict[str, Any]:
|
597 | 627 | return json.loads((ASSETS_DIR / "registry" / "1.0.0.json").read_text())
|
598 | 628 |
|
599 | 629 |
|
| 630 | +def validate_is_supported_manifest_uri(uri): |
| 631 | + if not is_ipfs_uri(uri) and not is_valid_content_addressed_github_uri(uri): |
| 632 | + raise ManifestValidationError( |
| 633 | + f"URI: {uri} is not a valid content-addressed URI. " |
| 634 | + "Currently only IPFS and Github content-addressed URIs are supported." |
| 635 | + ) |
| 636 | + |
| 637 | + |
600 | 638 | @to_tuple
|
601 | 639 | def process_vyper_args(*args: List[str]) -> Iterable[bytes]:
|
602 | 640 | for arg in args:
|
|
0 commit comments