-
Notifications
You must be signed in to change notification settings - Fork 65
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Need to b64 decode cockroach config secret
forgot to add this as well
- Loading branch information
1 parent
14c08fb
commit 5a111c6
Showing
20 changed files
with
157 additions
and
119 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -4,12 +4,12 @@ defmodule Core.Services.Cloud do | |
alias Core.Repo | ||
alias Core.PubSub | ||
alias Core.Services.{Accounts, Users, Repositories, Shell} | ||
alias Core.Schema.{CloudCluster, CockroachCluster, ConsoleInstance, User, OIDCProvider} | ||
alias Core.Schema.{CloudCluster, PostgresCluster, ConsoleInstance, User, OIDCProvider} | ||
|
||
@type error :: {:error, term} | ||
@type console_resp :: {:ok, ConsoleInstance.t} | error | ||
@type cluster_resp :: {:ok, CloudCluster.t} | error | ||
@type cockroach_resp :: {:ok, CockroachCluster.t} | error | ||
@type postgres_resp :: {:ok, PostgresCluster.t} | error | ||
|
||
def get_instance!(id), do: Repo.get!(ConsoleInstance, id) | ||
|
||
|
@@ -23,13 +23,13 @@ defmodule Core.Services.Cloud do | |
|> Repo.insert_or_update() | ||
end | ||
|
||
@spec upsert_cockroach(map, binary) :: cockroach_resp | ||
def upsert_cockroach(attrs, name) do | ||
case Repo.get_by(CockroachCluster, name: name) do | ||
%CockroachCluster{} = cluster -> cluster | ||
nil -> %CockroachCluster{name: name} | ||
@spec upsert_postgres(map, binary) :: postgres_resp | ||
def upsert_postgres(attrs, name) do | ||
case Repo.get_by(PostgresCluster, name: name) do | ||
%PostgresCluster{} = cluster -> cluster | ||
nil -> %PostgresCluster{name: name} | ||
end | ||
|> CockroachCluster.changeset(attrs) | ||
|> PostgresCluster.changeset(attrs) | ||
|> Repo.insert_or_update() | ||
end | ||
|
||
|
@@ -41,7 +41,7 @@ defmodule Core.Services.Cloud do | |
start_transaction() | ||
|> add_operation(:auth, fn _ -> allow(%ConsoleInstance{}, user, :create) end) | ||
|> add_operation(:cluster, fn _ -> select_cluster(attrs[:cloud], attrs[:region]) end) | ||
|> add_operation(:cockroach, fn _ -> select_roach(attrs[:cloud]) end) | ||
|> add_operation(:postgres, fn _ -> select_roach(attrs[:cloud]) end) | ||
|> add_operation(:sa, fn _ -> | ||
Accounts.create_service_account(%{name: "#{name}-cloud-sa", email: "#{name}[email protected]"}, user) | ||
end) | ||
|
@@ -61,8 +61,8 @@ defmodule Core.Services.Cloud do | |
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, cockroach: roach, sa: sa} -> | ||
%ConsoleInstance{status: :pending, cluster_id: cluster.id, cockroach_id: roach.id, owner_id: sa.id} | ||
|> add_operation(:instance, fn %{oidc: oidc, token: token, cluster: cluster, postgres: roach, sa: sa} -> | ||
%ConsoleInstance{status: :pending, cluster_id: cluster.id, postgres_id: roach.id, owner_id: sa.id} | ||
|> ConsoleInstance.changeset(add_configuration(attrs, name, token.token, oidc, user)) | ||
|> Repo.insert() | ||
end) | ||
|
@@ -147,6 +147,7 @@ defmodule Core.Services.Cloud do | |
owner_name: user.name, | ||
owner_email: user.email, | ||
admin_password: Core.random_alphanum(30), | ||
erlang_secret: Core.random_alphanum(30), | ||
client_id: oidc.client_id, | ||
client_secret: oidc.client_secret, | ||
plural_token: token, | ||
|
@@ -165,8 +166,8 @@ defmodule Core.Services.Cloud do | |
end | ||
|
||
defp select_roach(cloud) do | ||
CockroachCluster.for_cloud(cloud) | ||
|> CockroachCluster.unsaturated() | ||
PostgresCluster.for_cloud(cloud) | ||
|> PostgresCluster.unsaturated() | ||
|> Repo.all() | ||
|> random_choice("Could not place in #{cloud}") | ||
end | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.