Skip to content

Commit

Permalink
Remove zero ssl issuer for identifier and use ip for identifiers
Browse files Browse the repository at this point in the history
Signed-off-by: Zack Siri <[email protected]>
  • Loading branch information
zacksiri committed Nov 9, 2023
1 parent 5af4c8c commit c1c4681
Show file tree
Hide file tree
Showing 7 changed files with 51 additions and 64 deletions.
23 changes: 0 additions & 23 deletions lib/uplink/clients/caddy/admin.ex
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,6 @@ defmodule Uplink.Clients.Caddy.Admin do

@derive Jason.Encoder

@mappings %{
"zerossl" => __MODULE__.Issuer.ZeroSSL
}

@primary_key false
embedded_schema do
embeds_one :identity, Identity, primary_key: false do
Expand All @@ -34,24 +30,5 @@ defmodule Uplink.Clients.Caddy.Admin do
defp identity_changeset(identity, params) do
identity
|> cast(params, [:identifiers, :issuers])
|> maybe_cast_issuers()
end

defp maybe_cast_issuers(changeset) do
if issuers = get_change(changeset, :issuers) do
issuers =
issuers
|> Enum.map(fn issuer ->
module =
Map.get(@mappings, issuer["module"]) ||
Map.get(@mappings, issuer[:module])

module.parse(issuer)
end)

put_change(changeset, :issuers, issuers)
else
changeset
end
end
end
27 changes: 0 additions & 27 deletions lib/uplink/clients/caddy/admin/issuer/zero_ssl.ex

This file was deleted.

23 changes: 14 additions & 9 deletions lib/uplink/clients/caddy/config/builder.ex
Original file line number Diff line number Diff line change
Expand Up @@ -20,25 +20,30 @@ defmodule Uplink.Clients.Caddy.Config.Builder do
metadata.hosts == [] || is_nil(metadata.main_port)
end)

%{"organization" => %{"storage" => storage_params} = organization} =
Uplink.Clients.Instellar.get_self()
%{"organization" => %{"storage" => storage_params}} =
uplink = Uplink.Clients.Instellar.get_self()

%{
admin: admin(organization),
admin: admin(uplink),
apps: apps(install_states),
storage: Storage.parse(storage_params)
}
end

def admin(%{"slug" => slug}) do
zero_ssl_api_key = Caddy.config(:zero_ssl_api_key)
def admin(uplink) do
identifiers =
if instances = Map.get(uplink, "instances") do
instances
|> Enum.map(fn i ->
i["node"]["public_ip"]
end)
else
[]
end

%{
identity: %{
identifiers: ["uplink", slug],
issuers: [
%{module: "zerossl", api_key: zero_ssl_api_key}
]
identifiers: identifiers
}
}
|> Admin.parse()
Expand Down
13 changes: 12 additions & 1 deletion test/scenarios/deployment.ex
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,18 @@ defmodule Uplink.Scenarios.Deployment do
"secret_access_key" => "secret"
}
}
}
},
"instances" => [
%{
"id" => 1,
"slug" => "uplink-01",
"node" => %{
"id" => 1,
"slug" => "some-node-01",
"public_ip" => "127.0.0.1"
}
}
]
})

Application.put_env(
Expand Down
13 changes: 12 additions & 1 deletion test/uplink/boot_test.exs
Original file line number Diff line number Diff line change
Expand Up @@ -114,7 +114,18 @@ defmodule Uplink.BootTest do
"secret_access_key" => "secret"
}
}
}
},
"instances" => [
%{
"id" => 1,
"slug" => "uplink-01",
"node" => %{
"id" => 1,
"slug" => "some-node-01",
"public_ip" => "127.0.0.1"
}
}
]
})

Application.put_env(
Expand Down
3 changes: 1 addition & 2 deletions test/uplink/clients/caddy/config/builder_test.exs
Original file line number Diff line number Diff line change
Expand Up @@ -39,8 +39,7 @@ defmodule Uplink.Clients.Caddy.Config.BuilderTest do
assert %{host: _hosts} = match

assert %{identity: identity} = admin
assert %{issuers: [zerossl]} = identity
assert %{module: "zerossl"} = zerossl
assert %{issuers: [], identifiers: ["127.0.0.1"]} = identity

assert %{module: "s3"} = storage
end
Expand Down
13 changes: 12 additions & 1 deletion test/uplink/clients/caddy/config/reload_test.exs
Original file line number Diff line number Diff line change
Expand Up @@ -114,7 +114,18 @@ defmodule Uplink.Clients.Caddy.Config.ReloadTest do
"secret_access_key" => "secret"
}
}
}
},
"instances" => [
%{
"id" => 1,
"slug" => "uplink-01",
"node" => %{
"id" => 1,
"slug" => "some-node-01",
"public_ip" => "127.0.0.1"
}
}
]
})

Application.put_env(
Expand Down

0 comments on commit c1c4681

Please sign in to comment.