Skip to content

Commit

Permalink
Support me-central-1 region for dedicated hosting
Browse files Browse the repository at this point in the history
just keep expanding based on incoming requests
  • Loading branch information
michaeljguarino committed Sep 28, 2024
1 parent 8a1f16f commit aebd1d6
Show file tree
Hide file tree
Showing 11 changed files with 90 additions and 7 deletions.
10 changes: 8 additions & 2 deletions apps/core/lib/core/schema/console_instance.ex
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,12 @@ defmodule Core.Schema.ConsoleInstance do
stack_deleted: 7

@region_map %{
aws: ~w(us-east-1)
shared: %{
aws: ~w(us-east-1)
},
dedicated: %{
aws: ~w(us-east-1 me-central-1)
}
}

schema "console_instances" do
Expand Down Expand Up @@ -134,7 +139,8 @@ defmodule Core.Schema.ConsoleInstance do

defp validate_region(cs) do
cloud = get_field(cs, :cloud)
regions = @region_map[cloud]
type = get_field(cs, :type)
regions = @region_map[type][cloud]
validate_change(cs, :region, fn :region, reg ->
case reg in regions do
true -> []
Expand Down
4 changes: 2 additions & 2 deletions apps/core/lib/core/schema/user.ex
Original file line number Diff line number Diff line change
Expand Up @@ -204,7 +204,7 @@ defmodule Core.Schema.User do
|> validate_required([:name, :email])
|> validate_length(:email, max: 255)
|> validate_length(:name, max: 255)
|> validate_length(:password, min: 10)
|> validate_length(:password, min: 10, max: 255)
|> validate_format(:email, @email_re)
|> hash_password()
|> generate_uuid(:avatar_id)
Expand Down Expand Up @@ -254,7 +254,7 @@ defmodule Core.Schema.User do
|> add_email(model)
|> validate_length(:email, max: 255)
|> validate_length(:name, max: 255)
|> validate_length(:password, min: 10)
|> validate_length(:password, min: 10, max: 255)
|> validate_format(:email, @email_re)
|> unique_constraint(:email)
|> validate_required([:name, :email])
Expand Down
1 change: 0 additions & 1 deletion apps/core/lib/core/services/cloud/workflow.ex
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
defmodule Core.Services.Cloud.Workflow do
use Core.Services.Base
alias Core.Repo
alias Core.Clients.Console
alias Core.Schema.{ConsoleInstance}
alias Core.Services.Cloud.Workflow.{Dedicated, Shared}

Expand Down
2 changes: 2 additions & 0 deletions apps/core/lib/core/services/cloud/workflow/shared.ex
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,8 @@ defmodule Core.Services.Cloud.Workflow.Shared do
alias Core.Schema.{ConsoleInstance, PostgresCluster, User}
alias Core.Repo

require Logger

@behaviour Core.Services.Cloud.Workflow

def sync(%ConsoleInstance{external_id: id} = instance) when is_binary(id) do
Expand Down
4 changes: 2 additions & 2 deletions apps/core/lib/core/services/users.ex
Original file line number Diff line number Diff line change
Expand Up @@ -715,8 +715,8 @@ defmodule Core.Services.Users do
|> when_ok(&delete_eab_key/1)
end

@decorate cache_evict(cache: Core.Cache, keys: [{:eab, c, p, u}])
def delete_eab_key(%EabCredential{user_id: u, cluster: c, provider: p} = eab),
@decorate cache_evict(cache: Core.Cache, keys: [{:eab, eab.user_id, eab.cluster, eab.provider}])
def delete_eab_key(%EabCredential{} = eab),
do: Core.Repo.delete(eab)

defp materialize_eab_key(cluster, provider, %User{id: user_id}) do
Expand Down
6 changes: 6 additions & 0 deletions apps/graphql/lib/graphql/resolvers/cloud.ex
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,12 @@ defmodule GraphQl.Resolvers.Cloud do
use GraphQl.Resolvers.Base, model: Core.Schema.ConsoleInstance
alias Core.Services.{Cloud, Clusters}

def resolve_settings(_, _) do
{:ok, %{
regions: ConsoleInstance.regions()
}}
end

def resolve_instance(%{id: id}, %{context: %{current_user: user}}),
do: Cloud.visible(id, user)

Expand Down
19 changes: 19 additions & 0 deletions apps/graphql/lib/graphql/schema/cloud.ex
Original file line number Diff line number Diff line change
Expand Up @@ -45,9 +45,28 @@ defmodule GraphQl.Schema.Cloud do
timestamps()
end

object :plural_cloud_settings do
field :regions, :plural_cloud_regions
end

object :plural_cloud_regions do
field :shared, non_null(:cloud_regions)
field :dedicated, non_null(:cloud_regions)
end

object :cloud_regions do
field :aws, list_of(:string)
end

connection node_type: :console_instance

object :cloud_queries do
field :cloud_settings, :plural_cloud_settings do
middleware Authenticated

resolve &Cloud.resolve_settings/2
end

field :console_instance, :console_instance do
middleware Authenticated
arg :id, non_null(:id)
Expand Down
1 change: 1 addition & 0 deletions apps/graphql/lib/graphql/schema/user.ex
Original file line number Diff line number Diff line change
Expand Up @@ -558,6 +558,7 @@ defmodule GraphQl.Schema.User do

field :update_user, :user do
middleware Authenticated
middleware RateLimit, limit: 10, time: 60_000
arg :id, :id
arg :attributes, non_null(:user_attributes)

Expand Down
18 changes: 18 additions & 0 deletions apps/graphql/test/queries/cloud_queries_test.exs
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,24 @@ defmodule GraphQl.CloudQueriesTest do
use Core.SchemaCase, async: true
import GraphQl.TestHelpers

describe "cloudSettings" do
test "it can list supported regions" do
{:ok, %{data: %{"cloudSettings" => settings}}} = run_query("""
query {
cloudSettings {
regions {
shared { aws }
dedicated { aws }
}
}
}
""", %{}, %{current_user: insert(:user)})

refute Enum.empty?(settings["regions"]["shared"]["aws"])
refute Enum.empty?(settings["regions"]["dedicated"]["aws"])
end
end

describe "consoleInstances" do
test "it can fetch the cloud instances in your account" do
user = insert(:user)
Expand Down
15 changes: 15 additions & 0 deletions schema/schema.graphql
Original file line number Diff line number Diff line change
Expand Up @@ -209,6 +209,8 @@ type RootQueryType {
"Get a list of clusters owned by the current account."
clusters(after: String, first: Int, before: String, last: Int): ClusterConnection

cloudSettings: PluralCloudSettings

consoleInstance(id: ID!): ConsoleInstance

consoleInstances(after: String, first: Int, before: String, last: Int): ConsoleInstanceConnection
Expand Down Expand Up @@ -644,6 +646,19 @@ type ConsoleInstance {
updatedAt: DateTime
}

type PluralCloudSettings {
regions: PluralCloudRegions
}

type PluralCloudRegions {
shared: CloudRegions!
dedicated: CloudRegions!
}

type CloudRegions {
aws: [String]
}

type ConsoleInstanceConnection {
pageInfo: PageInfo!
edges: [ConsoleInstanceEdge]
Expand Down
17 changes: 17 additions & 0 deletions www/src/generated/graphql.ts
Original file line number Diff line number Diff line change
Expand Up @@ -385,6 +385,11 @@ export enum CloudProvider {
Aws = 'AWS'
}

export type CloudRegions = {
__typename?: 'CloudRegions';
aws?: Maybe<Array<Maybe<Scalars['String']['output']>>>;
};

export type CloudShell = {
__typename?: 'CloudShell';
aesKey: Scalars['String']['output'];
Expand Down Expand Up @@ -2208,6 +2213,17 @@ export type PlatformSubscriptionLineItems = {
quantity: Scalars['Int']['output'];
};

export type PluralCloudRegions = {
__typename?: 'PluralCloudRegions';
dedicated: CloudRegions;
shared: CloudRegions;
};

export type PluralCloudSettings = {
__typename?: 'PluralCloudSettings';
regions?: Maybe<PluralCloudRegions>;
};

export type PluralConfiguration = {
__typename?: 'PluralConfiguration';
gitCommit?: Maybe<Scalars['String']['output']>;
Expand Down Expand Up @@ -3733,6 +3749,7 @@ export type RootQueryType = {
charts?: Maybe<ChartConnection>;
chat?: Maybe<ChatMessage>;
closure?: Maybe<Array<Maybe<ClosureItem>>>;
cloudSettings?: Maybe<PluralCloudSettings>;
/** Get a cluster by its ID. */
cluster?: Maybe<Cluster>;
/** Get a list of clusters owned by the current account. */
Expand Down

0 comments on commit aebd1d6

Please sign in to comment.