diff --git a/apps/core/lib/core/schema/console_instance.ex b/apps/core/lib/core/schema/console_instance.ex index 4f532dbbb..dcfeb678f 100644 --- a/apps/core/lib/core/schema/console_instance.ex +++ b/apps/core/lib/core/schema/console_instance.ex @@ -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 @@ -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 -> [] diff --git a/apps/core/lib/core/services/cloud/workflow.ex b/apps/core/lib/core/services/cloud/workflow.ex index 311871bbf..b4ba31e3a 100644 --- a/apps/core/lib/core/services/cloud/workflow.ex +++ b/apps/core/lib/core/services/cloud/workflow.ex @@ -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} diff --git a/apps/core/lib/core/services/cloud/workflow/shared.ex b/apps/core/lib/core/services/cloud/workflow/shared.ex index 1be796b43..2732f4416 100644 --- a/apps/core/lib/core/services/cloud/workflow/shared.ex +++ b/apps/core/lib/core/services/cloud/workflow/shared.ex @@ -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 diff --git a/apps/core/lib/core/services/users.ex b/apps/core/lib/core/services/users.ex index b0d765adc..6b00a5bfd 100644 --- a/apps/core/lib/core/services/users.ex +++ b/apps/core/lib/core/services/users.ex @@ -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 diff --git a/apps/graphql/lib/graphql/resolvers/cloud.ex b/apps/graphql/lib/graphql/resolvers/cloud.ex index b7703f4ee..0925fe2c9 100644 --- a/apps/graphql/lib/graphql/resolvers/cloud.ex +++ b/apps/graphql/lib/graphql/resolvers/cloud.ex @@ -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) diff --git a/apps/graphql/lib/graphql/schema/cloud.ex b/apps/graphql/lib/graphql/schema/cloud.ex index 9ae2661c1..6fb77849d 100644 --- a/apps/graphql/lib/graphql/schema/cloud.ex +++ b/apps/graphql/lib/graphql/schema/cloud.ex @@ -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) diff --git a/apps/graphql/test/queries/cloud_queries_test.exs b/apps/graphql/test/queries/cloud_queries_test.exs index 0407936fd..dbbda3540 100644 --- a/apps/graphql/test/queries/cloud_queries_test.exs +++ b/apps/graphql/test/queries/cloud_queries_test.exs @@ -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) diff --git a/schema/schema.graphql b/schema/schema.graphql index 06a0a8f2b..f4ba05270 100644 --- a/schema/schema.graphql +++ b/schema/schema.graphql @@ -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 @@ -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] diff --git a/www/src/generated/graphql.ts b/www/src/generated/graphql.ts index 449c62cb7..5ea9174a9 100644 --- a/www/src/generated/graphql.ts +++ b/www/src/generated/graphql.ts @@ -385,6 +385,11 @@ export enum CloudProvider { Aws = 'AWS' } +export type CloudRegions = { + __typename?: 'CloudRegions'; + aws?: Maybe>>; +}; + export type CloudShell = { __typename?: 'CloudShell'; aesKey: Scalars['String']['output']; @@ -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; +}; + export type PluralConfiguration = { __typename?: 'PluralConfiguration'; gitCommit?: Maybe; @@ -3733,6 +3749,7 @@ export type RootQueryType = { charts?: Maybe; chat?: Maybe; closure?: Maybe>>; + cloudSettings?: Maybe; /** Get a cluster by its ID. */ cluster?: Maybe; /** Get a list of clusters owned by the current account. */