From 6d5871a34cf1103cc907b933ba3a7db4251a2465 Mon Sep 17 00:00:00 2001 From: AJ Foster <2789166+aj-foster@users.noreply.github.com> Date: Thu, 10 Feb 2022 21:28:32 -0500 Subject: [PATCH] Require --name for hex.registry add --- lib/mix/tasks/hex.registry.ex | 30 ++++++------------------------ src/mix_hex_registry.erl | 16 +--------------- 2 files changed, 7 insertions(+), 39 deletions(-) diff --git a/lib/mix/tasks/hex.registry.ex b/lib/mix/tasks/hex.registry.ex index 26e926ff..e8cd6846 100644 --- a/lib/mix/tasks/hex.registry.ex +++ b/lib/mix/tasks/hex.registry.ex @@ -112,22 +112,22 @@ defmodule Mix.Tasks.Hex.Registry do ## Add defp add(public_dir, packages, opts) do - repo_name_or_nil = opts[:name] - private_key_path = opts[:private_key] || raise "missing --private-key" + repo_name = opts[:name] || Mix.raise("missing --name") + private_key_path = opts[:private_key] || Mix.raise("missing --private-key") private_key = private_key_path |> File.read!() |> decode_private_key() - add(repo_name_or_nil, public_dir, private_key, packages) + add(repo_name, public_dir, private_key, packages) end - defp add(repo_name_or_nil, public_dir, private_key, packages) do + defp add(repo_name, public_dir, private_key, packages) do public_key = ensure_public_key(private_key, public_dir) existing_names = - read_names!(repo_name_or_nil, public_dir, public_key) + read_names!(repo_name, public_dir, public_key) |> Enum.map(fn %{name: name, updated_at: updated_at} -> {name, updated_at} end) |> Enum.into(%{}) existing_versions = - read_versions!(repo_name_or_nil, public_dir, public_key) + read_versions!(repo_name, public_dir, public_key) |> Enum.map(fn %{name: name, versions: versions} -> {name, %{updated_at: existing_names[name], versions: versions}} end) @@ -135,7 +135,6 @@ defmodule Mix.Tasks.Hex.Registry do tarball_dir = Path.join(public_dir, "tarballs") create_directory(tarball_dir) - repo_name = repo_name_or_nil || read_repository_name!(public_dir, private_key) paths_per_name = packages @@ -371,23 +370,6 @@ defmodule Mix.Tasks.Hex.Registry do end end - defp read_repository_name!(public_dir, public_key) do - path = Path.join(public_dir, "names") - payload = read_file!(path) - - case :mix_hex_registry.get_repository_name(payload, public_key) do - {:ok, repo_name} -> - repo_name - - _ -> - Mix.raise(""" - Invalid package name manifest at #{path} - - Is the public key correct? - """) - end - end - defp read_package(repo_name, public_dir, public_key, package_name) do path = Path.join([public_dir, "packages", package_name]) diff --git a/src/mix_hex_registry.erl b/src/mix_hex_registry.erl index c7ae8be2..4375f28c 100644 --- a/src/mix_hex_registry.erl +++ b/src/mix_hex_registry.erl @@ -1,4 +1,4 @@ -%% Vendored from hex_core v0.8.2, do not edit manually +%% Vendored from hex_core v0.8.0, do not edit manually %% @doc %% Functions for encoding and decoding Hex registries. @@ -8,7 +8,6 @@ decode_names/2, build_names/2, unpack_names/3, - get_repository_name/2, encode_versions/1, decode_versions/2, build_versions/2, @@ -63,19 +62,6 @@ decode_names(Payload, Repository) -> {error, unverified} end. -%% @doc -%% Get the encoded repository name. -get_repository_name(Payload, PublicKey) -> - case decode_and_verify_signed(zlib:gunzip(Payload), PublicKey) of - {ok, Names} -> decode_repository_name(Names); - Other -> Other - end. - -%% @private -decode_repository_name(Payload) -> - #{repository := Repository} = mix_hex_pb_names:decode_msg(Payload, 'Names'), - {ok, Repository}. - %% @doc %% Builds versions resource. build_versions(Versions, PrivateKey) ->