Skip to content

Commit 40975b7

Browse files
committed
Configure hex_core repo_url and repo_public_key from application config
The hex_core config was hardcoded to default_config() which always points to production repo.hex.pm. Read repo_url and repo_public_key from application config so staging uses the correct repo and key.
1 parent 92e7903 commit 40975b7

3 files changed

Lines changed: 22 additions & 10 deletions

File tree

config/config.exs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,8 @@ import Config
99

1010
config :diff,
1111
cache_version: 2,
12-
package_store_impl: Diff.Package.DefaultStore
12+
package_store_impl: Diff.Package.DefaultStore,
13+
repo_url: "https://repo.hex.pm"
1314

1415
# Configures the endpoint
1516
config :diff, DiffWeb.Endpoint,

config/runtime.exs

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,9 @@ if config_env() == :prod do
55
host: System.fetch_env!("DIFF_HOST"),
66
hexpm_host: System.fetch_env!("DIFF_HEXPM_HOST"),
77
cache_version: String.to_integer(System.fetch_env!("DIFF_CACHE_VERSION")),
8-
bucket: System.fetch_env!("DIFF_BUCKET")
8+
bucket: System.fetch_env!("DIFF_BUCKET"),
9+
repo_url: System.fetch_env!("DIFF_REPO_URL"),
10+
repo_public_key: System.fetch_env!("DIFF_REPO_PUBLIC_KEY")
911

1012
config :diff, DiffWeb.Endpoint,
1113
http: [port: String.to_integer(System.fetch_env!("DIFF_PORT"))],

lib/diff/hex/hex.ex

Lines changed: 17 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,27 @@
11
defmodule Diff.Hex do
22
@behaviour Diff.Hex.Behaviour
33

4-
@config %{
5-
:hex_core.default_config()
6-
| http_adapter: {Diff.Hex.Adapter, %{}},
7-
http_user_agent_fragment: "hexpm_diff"
8-
}
4+
defp config() do
5+
config = %{
6+
:hex_core.default_config()
7+
| http_adapter: {Diff.Hex.Adapter, %{}},
8+
http_user_agent_fragment: "hexpm_diff",
9+
repo_url: Application.fetch_env!(:diff, :repo_url)
10+
}
11+
12+
if repo_public_key = Application.get_env(:diff, :repo_public_key) do
13+
%{config | repo_public_key: repo_public_key}
14+
else
15+
%{config | repo_verify: false}
16+
end
17+
end
918

1019
@max_file_size 1024 * 1024
1120

1221
require Logger
1322

1423
def get_versions() do
15-
with {:ok, {200, _, results}} <- :hex_repo.get_versions(@config) do
24+
with {:ok, {200, _, results}} <- :hex_repo.get_versions(config()) do
1625
{:ok, results}
1726
else
1827
{:ok, {status, _, _}} ->
@@ -28,7 +37,7 @@ defmodule Diff.Hex do
2837
def get_tarball(package, version) do
2938
path = Diff.TmpDir.tmp_file("tarball")
3039

31-
case :hex_repo.get_tarball_to_file(@config, package, version, to_charlist(path)) do
40+
case :hex_repo.get_tarball_to_file(config(), package, version, to_charlist(path)) do
3241
{:ok, {200, _headers}} ->
3342
{:ok, path}
3443

@@ -53,7 +62,7 @@ defmodule Diff.Hex do
5362
end
5463

5564
def get_checksums(package, versions) do
56-
with {:ok, {200, _, releases}} <- :hex_repo.get_package(@config, package) do
65+
with {:ok, {200, _, releases}} <- :hex_repo.get_package(config(), package) do
5766
checksums =
5867
for release <- releases.releases, release.version in versions do
5968
release.outer_checksum

0 commit comments

Comments
 (0)