def release_package(self, package_name: str, version: str,
                        manifest_uri: str) -> bytes:
        """
        Returns the release id generated by releasing a package on the current registry.
        Requires ``web3.PM`` to have a registry set. Requires ``web3.eth.defaultAccount``
        to be the registry owner.

        * Parameters:
            * ``package_name``: Must be a valid package name, matching the given manifest.
            * ``version``: Must be a valid package version, matching the given manifest.
            * ``manifest_uri``: Must be a valid content-addressed URI. Currently, only IPFS
              and Github content-addressed URIs are supported.

        """
        validate_is_supported_manifest_uri(manifest_uri)
        raw_manifest = to_text(resolve_uri_contents(manifest_uri))
        validate_raw_manifest_format(raw_manifest)
        manifest = json.loads(raw_manifest)
        validate_manifest_against_schema(manifest)
        if package_name != manifest["package_name"]:
            raise ManifestValidationError(
                f"Provided package name: {package_name} does not match the package name "
                f"found in the manifest: {manifest['package_name']}.")

        if version != manifest["version"]:
            raise ManifestValidationError(
                f"Provided package version: {version} does not match the package version "
                f"found in the manifest: {manifest['version']}.")

        self._validate_set_registry()
        return self.registry._release(package_name, version, manifest_uri)
Esempio n. 2
0
def test_validate_raw_manifest_format_invalidates_invalid_manifests(
        tmpdir, manifest):
    p = tmpdir.mkdir("invalid").join("manifest.json")
    p.write(manifest)
    invalid_manifest = p.read()
    with pytest.raises(ValidationError):
        validate_raw_manifest_format(invalid_manifest)
Esempio n. 3
0
def process_and_validate_raw_manifest(raw_manifest: bytes) -> Manifest:
    raw_manifest_text = to_text(raw_manifest).rstrip("\n")
    validate_raw_manifest_format(raw_manifest_text)
    manifest = json.loads(raw_manifest_text)
    validate_manifest_against_schema(manifest)
    validate_manifest_deployments(manifest)
    return manifest
Esempio n. 4
0
 def from_file(cls, file_path: Path, w3: Web3) -> "Package":
     """
     Returns a ``Package`` instantiated by a manifest located at the provided Path.
     ``file_path`` arg must be a ``pathlib.Path`` instance.
     A valid ``Web3`` instance is required to instantiate a ``Package``.
     """
     if isinstance(file_path, Path):
         raw_manifest = file_path.read_text()
         validate_raw_manifest_format(raw_manifest)
         manifest = json.loads(raw_manifest)
     else:
         raise TypeError(
             "The Package.from_file method expects a pathlib.Path instance."
             f"Got {type(file_path)} instead.")
     return cls(manifest, w3, file_path.as_uri())
Esempio n. 5
0
    def from_uri(cls, uri: URI, w3: Web3) -> "Package":
        """
        Returns a Package object instantiated by a manifest located at a content-addressed URI.
        A valid ``Web3`` instance is also required.
        URI schemes supported:
        - IPFS          `ipfs://Qm...`
        - HTTP          `https://api.github.com/repos/:owner/:repo/git/blobs/:file_sha`
        - Registry      `erc1319://registry.eth:1/greeter?version=1.0.0`

        .. code:: python

           OwnedPackage = Package.from_uri('ipfs://QmbeVyFLSuEUxiXKwSsEjef7icpdTdA4kGG9BcrJXKNKUW', w3)  # noqa: E501
        """
        contents = to_text(resolve_uri_contents(uri))
        validate_raw_manifest_format(contents)
        manifest = json.loads(contents)
        return cls(manifest, w3, uri)
Esempio n. 6
0
def test_validate_raw_manifest_format_invalidates_pretty_manifests(
        all_pretty_manifests):
    with pytest.raises(ValidationError):
        validate_raw_manifest_format(all_pretty_manifests)
Esempio n. 7
0
def test_validate_raw_manifest_configuration_validates_strict_manifests(
        all_strict_manifests):
    assert validate_raw_manifest_format(all_strict_manifests) is None