@@ -4,12 +4,12 @@ defmodule Core.Services.Cloud do
4
4
alias Core.Repo
5
5
alias Core.PubSub
6
6
alias Core.Services . { Accounts , Users , Repositories , Shell }
7
- alias Core.Schema . { CloudCluster , CockroachCluster , ConsoleInstance , User , OIDCProvider }
7
+ alias Core.Schema . { CloudCluster , PostgresCluster , ConsoleInstance , User , OIDCProvider }
8
8
9
9
@ type error :: { :error , term }
10
10
@ type console_resp :: { :ok , ConsoleInstance . t } | error
11
11
@ type cluster_resp :: { :ok , CloudCluster . t } | error
12
- @ type cockroach_resp :: { :ok , CockroachCluster . t } | error
12
+ @ type postgres_resp :: { :ok , PostgresCluster . t } | error
13
13
14
14
def get_instance! ( id ) , do: Repo . get! ( ConsoleInstance , id )
15
15
@@ -23,13 +23,13 @@ defmodule Core.Services.Cloud do
23
23
|> Repo . insert_or_update ( )
24
24
end
25
25
26
- @ spec upsert_cockroach ( map , binary ) :: cockroach_resp
27
- def upsert_cockroach ( attrs , name ) do
28
- case Repo . get_by ( CockroachCluster , name: name ) do
29
- % CockroachCluster { } = cluster -> cluster
30
- nil -> % CockroachCluster { name: name }
26
+ @ spec upsert_postgres ( map , binary ) :: postgres_resp
27
+ def upsert_postgres ( attrs , name ) do
28
+ case Repo . get_by ( PostgresCluster , name: name ) do
29
+ % PostgresCluster { } = cluster -> cluster
30
+ nil -> % PostgresCluster { name: name }
31
31
end
32
- |> CockroachCluster . changeset ( attrs )
32
+ |> PostgresCluster . changeset ( attrs )
33
33
|> Repo . insert_or_update ( )
34
34
end
35
35
@@ -41,7 +41,7 @@ defmodule Core.Services.Cloud do
41
41
start_transaction ( )
42
42
|> add_operation ( :auth , fn _ -> allow ( % ConsoleInstance { } , user , :create ) end )
43
43
|> add_operation ( :cluster , fn _ -> select_cluster ( attrs [ :cloud ] , attrs [ :region ] ) end )
44
- |> add_operation ( :cockroach , fn _ -> select_roach ( attrs [ :cloud ] ) end )
44
+ |> add_operation ( :postgres , fn _ -> select_roach ( attrs [ :cloud ] ) end )
45
45
|> add_operation ( :sa , fn _ ->
46
46
Accounts . create_service_account ( % { name: "#{ name } -cloud-sa" , email: "#{ name } -cloud-sa@srv.plural.sh" } , user )
47
47
end )
@@ -58,11 +58,11 @@ defmodule Core.Services.Cloud do
58
58
Repositories . upsert_oidc_provider ( % {
59
59
auth_method: :post ,
60
60
bindings: Shell . oidc_bindings ( inst . oidc_provider , user ) ,
61
- redirect_uris: Shell . merge_uris ( [ "https://console. #{ name } .cloud.plural.sh/oauth/callback" ] , inst . oidc_provider )
61
+ redirect_uris: Shell . merge_uris ( [ "https://console- #{ name } .cloud.plural.sh/oauth/callback" ] , inst . oidc_provider )
62
62
} , inst . id , sa )
63
63
end )
64
- |> add_operation ( :instance , fn % { oidc: oidc , token: token , cluster: cluster , cockroach : roach , sa: sa } ->
65
- % ConsoleInstance { status: :pending , cluster_id: cluster . id , cockroach_id : roach . id , owner_id: sa . id }
64
+ |> add_operation ( :instance , fn % { oidc: oidc , token: token , cluster: cluster , postgres : roach , sa: sa } ->
65
+ % ConsoleInstance { status: :pending , cluster_id: cluster . id , postgres_id : roach . id , owner_id: sa . id }
66
66
|> ConsoleInstance . changeset ( add_configuration ( attrs , name , token . token , oidc , user ) )
67
67
|> Repo . insert ( )
68
68
end )
@@ -135,24 +135,25 @@ defmodule Core.Services.Cloud do
135
135
end
136
136
137
137
defp add_configuration ( attrs , name , token , % OIDCProvider { } = oidc , % User { } = user ) do
138
- Map . merge ( attrs , % { subdomain: "#{ name } .cloud.plural.sh" , url: "console. #{ name } .cloud.plural.sh" } )
138
+ Map . merge ( attrs , % { subdomain: "#{ name } .cloud.plural.sh" , url: "console- #{ name } .cloud.plural.sh" } )
139
139
|> Map . put ( :configuration , % {
140
140
aes_key: aes_key ( ) ,
141
141
encryption_key: encryption_key ( ) ,
142
142
database: "#{ name } _cloud" ,
143
143
dbuser: "#{ name } _user" ,
144
- dbpassword: Core . random_alphanum ( 30 ) ,
144
+ dbpassword: Core . random_alphanum ( 32 ) ,
145
145
subdomain: "#{ name } .cloud.plural.sh" ,
146
- jwt_secret: Core . random_alphanum ( 30 ) ,
146
+ jwt_secret: Core . random_alphanum ( 32 ) |> Base . encode64 ( ) ,
147
147
owner_name: user . name ,
148
148
owner_email: user . email ,
149
- admin_password: Core . random_alphanum ( 30 ) ,
149
+ admin_password: Core . random_alphanum ( 32 ) |> Base . encode64 ( ) ,
150
+ erlang_secret: Core . random_alphanum ( 32 ) |> Base . encode64 ( ) ,
150
151
client_id: oidc . client_id ,
151
152
client_secret: oidc . client_secret ,
152
153
plural_token: token ,
153
- kas_api: Core . random_alphanum ( 30 ) ,
154
- kas_private: Core . random_alphanum ( 30 ) ,
155
- kas_redis: Core . random_alphanum ( 30 )
154
+ kas_api: Core . random_alphanum ( 64 ) |> Base . encode64 ( ) ,
155
+ kas_private: Core . random_alphanum ( 64 ) |> Base . encode64 ( ) ,
156
+ kas_redis: Core . random_alphanum ( 64 ) |> Base . encode64 ( ) ,
156
157
} )
157
158
end
158
159
@@ -165,8 +166,8 @@ defmodule Core.Services.Cloud do
165
166
end
166
167
167
168
defp select_roach ( cloud ) do
168
- CockroachCluster . for_cloud ( cloud )
169
- |> CockroachCluster . unsaturated ( )
169
+ PostgresCluster . for_cloud ( cloud )
170
+ |> PostgresCluster . unsaturated ( )
170
171
|> Repo . all ( )
171
172
|> random_choice ( "Could not place in #{ cloud } " )
172
173
end
0 commit comments