Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Switch to recursive subdomains instead of hyphens #1340

Merged
merged 1 commit into from
Aug 21, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 7 additions & 6 deletions apps/core/lib/core/clients/console.ex
Original file line number Diff line number Diff line change
Expand Up @@ -71,12 +71,7 @@ defmodule Core.Clients.Console do

def repo(client, url) do
Req.post(client, graphql: {@repo_q, %{url: url}})
|> case do
{:ok, %Req.Response{body: %{"data" => %{"gitRepository" => %{"id" => id}}}}} -> {:ok, id}
res ->
Logger.warn "Failed to fetch clusters: #{inspect(res)}"
{:error, "could not fetch repo"}
end
|> service_resp("gitRepository")
end

def create_service(client, cluster_id, attrs) do
Expand All @@ -92,6 +87,7 @@ defmodule Core.Clients.Console do
def delete_service(client, id) do
Req.post(client, graphql: {@delete_svc_q, %{id: id}})
|> service_resp("deleteServiceDeployment")
|> ignore_not_found()
end

def stack(client, id) do
Expand All @@ -105,11 +101,16 @@ defmodule Core.Clients.Console do
end
end

defp ignore_not_found({:error, ["could not find resource" <> _ | _]}), do: {:ok, nil}
defp ignore_not_found(pass), do: pass

defp service_resp({:ok, %Req.Response{body: %{"errors" => [_ | _] = errors}}}, _), do: {:error, errors}
defp service_resp({:ok, %Req.Response{status: 200, body: %{"data" => body}}}, field) do
case body[field] do
%{"id" => id} -> {:ok, id}
err ->
Logger.warn "invalid console gql response: #{inspect(err)}"
{:error, "#{field} query failed"}
end
end

Expand Down
4 changes: 2 additions & 2 deletions apps/core/lib/core/services/cloud.ex
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ defmodule Core.Services.Cloud do
Repositories.upsert_oidc_provider(%{
auth_method: :post,
bindings: Shell.oidc_bindings(inst.oidc_provider, user),
redirect_uris: Shell.merge_uris(["https://console-#{name}.cloud.plural.sh/oauth/callback"], inst.oidc_provider)
redirect_uris: Shell.merge_uris(["https://console.#{name}.cloud.plural.sh/oauth/callback"], inst.oidc_provider)
}, inst.id, sa)
end)
|> add_operation(:instance, fn %{oidc: oidc, token: token, cluster: cluster, postgres: roach, sa: sa} ->
Expand Down Expand Up @@ -135,7 +135,7 @@ defmodule Core.Services.Cloud do
end

defp add_configuration(attrs, name, token, %OIDCProvider{} = oidc, %User{} = user) do
Map.merge(attrs, %{subdomain: "#{name}.cloud.plural.sh", url: "console-#{name}.cloud.plural.sh"})
Map.merge(attrs, %{subdomain: "#{name}.cloud.plural.sh", url: "console.#{name}.cloud.plural.sh"})
|> Map.put(:configuration, %{
aes_key: aes_key(),
encryption_key: encryption_key(),
Expand Down
2 changes: 1 addition & 1 deletion apps/core/lib/core/services/cloud/workflow.ex
Original file line number Diff line number Diff line change
Expand Up @@ -106,7 +106,7 @@ defmodule Core.Services.Cloud.Workflow do
defp down(%ConsoleInstance{instance_status: %{svc: true}} = inst) do
with {:ok, _} <- Console.delete_service(console(), inst.external_id) do
ConsoleInstance.changeset(inst, %{
instance_status: %{svc: false},
instance_status: %{svc: false, db: true},
status: :deployment_deleted,
})
|> Repo.update()
Expand Down
Loading