Skip to content

Commit c5b44cc

Browse files
committed
Fix goth config
1 parent b3d68a8 commit c5b44cc

File tree

5 files changed

+18
-8
lines changed

5 files changed

+18
-8
lines changed

Diff for: config/dev.exs

-2
Original file line numberDiff line numberDiff line change
@@ -70,5 +70,3 @@ config :phoenix, :plug_init_mode, :runtime
7070
config :diff,
7171
tmp_dir: Path.expand("tmp/dev"),
7272
storage_impl: Diff.Storage.Local
73-
74-
config :goth, config: %{"project_id" => "diff"}

Diff for: config/runtime.exs

-2
Original file line numberDiff line numberDiff line change
@@ -12,8 +12,6 @@ if config_env() == :prod do
1212
url: [host: System.fetch_env!("DIFF_HOST")],
1313
secret_key_base: System.fetch_env!("DIFF_SECRET_KEY_BASE")
1414

15-
config :goth, json: System.fetch_env!("DIFF_GCP_CREDENTIALS")
16-
1715
config :sentry,
1816
dsn: System.fetch_env!("DIFF_SENTRY_DSN"),
1917
environment_name: System.fetch_env!("DIFF_ENV")

Diff for: config/test.exs

-2
Original file line numberDiff line numberDiff line change
@@ -6,8 +6,6 @@ config :diff, DiffWeb.Endpoint,
66
http: [port: 5004],
77
server: false
88

9-
config :goth, config: %{"project_id" => "diff"}
10-
119
# Print only warnings and errors during test
1210
config :logger, level: :warning
1311

Diff for: lib/diff/application.ex

+17
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ defmodule Diff.Application do
1010

1111
# List all child processes to be supervised
1212
children = [
13+
goth_spec(),
1314
{Task.Supervisor, name: Diff.Tasks},
1415
# Start the PubSub system
1516
{Phoenix.PubSub, name: Diff.PubSub},
@@ -32,4 +33,20 @@ defmodule Diff.Application do
3233
DiffWeb.Endpoint.config_change(changed, removed)
3334
:ok
3435
end
36+
37+
if Mix.env() == :prod do
38+
defp goth_spec() do
39+
credentials =
40+
"DIFF_GCP_CREDENTIALS"
41+
|> System.fetch_env!()
42+
|> Jason.decode!()
43+
44+
options = [scope: "https://www.googleapis.com/auth/devstorage.read_write"]
45+
{Goth, name: Diff.Goth, source: {:service_account, credentials, options}}
46+
end
47+
else
48+
defp goth_spec() do
49+
{Task, fn -> :ok end}
50+
end
51+
end
3552
end

Diff for: lib/diff/storage/gcs.ex

+1-2
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,6 @@ defmodule Diff.Storage.GCS do
44
@behaviour Diff.Storage
55

66
@gs_xml_url "https://storage.googleapis.com"
7-
@oauth_scope "https://www.googleapis.com/auth/devstorage.read_write"
87

98
def get(package, from_version, to_version) do
109
with {:ok, hash} <- combined_checksum(package, from_version, to_version),
@@ -44,7 +43,7 @@ defmodule Diff.Storage.GCS do
4443
end
4544

4645
defp headers() do
47-
token = Goth.fetch!(@oauth_scope)
46+
token = Goth.fetch!(Diff.Goth)
4847
[{"authorization", "#{token.type} #{token.token}"}]
4948
end
5049

0 commit comments

Comments
 (0)