Skip to content

Commit 187a921

Browse files
authored
Fix organization auth to create user key instead of organization key (#1135) (#1136)
The `mix hex.organization auth` command should create a user-level key with repository permissions scoped to the organization, not an organization-owned key. This was changed incorrectly in 5c039c3.
1 parent ff0eca4 commit 187a921

2 files changed

Lines changed: 10 additions & 5 deletions

File tree

lib/mix/tasks/hex.organization.ex

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -170,9 +170,14 @@ defmodule Mix.Tasks.Hex.Organization do
170170
permissions = [%{"domain" => "repository", "resource" => organization}]
171171
auth = Mix.Tasks.Hex.auth_info(:write)
172172

173-
case Mix.Tasks.Hex.generate_organization_key(organization, key_name, permissions, auth) do
174-
{:ok, key} -> key
175-
:error -> nil
173+
case Hex.API.Key.new(key_name, permissions, auth) do
174+
{:ok, {201, _, body}} ->
175+
body["secret"]
176+
177+
other ->
178+
Mix.shell().error("Generation of key failed")
179+
Hex.Utils.print_error_result(other)
180+
nil
176181
end
177182
end
178183

test/mix/tasks/hex.organization_test.exs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ defmodule Mix.Tasks.Hex.OrganizationTest do
2121

2222
{:ok, hostname} = :inet.gethostname()
2323
name = "#{hostname}-repository-myorgauth"
24-
assert {:ok, {200, _, body}} = Hex.API.Key.Organization.get("myorgauth", auth)
24+
assert {:ok, {200, _, body}} = Hex.API.Key.get(auth)
2525
assert name in Enum.map(body, & &1["name"])
2626
end)
2727
end
@@ -54,7 +54,7 @@ defmodule Mix.Tasks.Hex.OrganizationTest do
5454
assert myorg.url == "http://localhost:4043/repo/repos/myorgauthwithkeyname"
5555
assert is_binary(myorg.auth_key)
5656

57-
assert {:ok, {200, _, body}} = Hex.API.Key.Organization.get("myorgauthwithkeyname", auth)
57+
assert {:ok, {200, _, body}} = Hex.API.Key.get(auth)
5858
assert "orgauthkeyname-repository-myorgauthwithkeyname" in Enum.map(body, & &1["name"])
5959
end)
6060
end

0 commit comments

Comments
 (0)