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

chore: update swagger docs #148

Merged
merged 5 commits into from
Aug 9, 2023
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
2 changes: 1 addition & 1 deletion VERSION
Original file line number Diff line number Diff line change
@@ -1 +1 @@
0.2.26
0.2.27
2 changes: 1 addition & 1 deletion config/runtime.exs
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ alias Supavisor.Helpers, as: H

secret_key_base =
if config_env() in [:dev, :test] do
"dev_secret_key_base"
"3S1V5RyqQcuPrMVuR4BjH9XBayridj56JA0EE6wYidTEc6H84KSFY6urVX7GfOhK"
else
System.get_env("SECRET_KEY_BASE") ||
raise """
Expand Down
7 changes: 0 additions & 7 deletions lib/supavisor_web/controllers/page_controller.ex

This file was deleted.

24 changes: 24 additions & 0 deletions lib/supavisor_web/controllers/tenant_controller.ex
Original file line number Diff line number Diff line change
Expand Up @@ -174,6 +174,18 @@ defmodule SupavisorWeb.TenantController do
send_resp(conn, code, "")
end

operation(:terminate,
summary: "Stop tenant's pools and clear cache",
parameters: [
external_id: [in: :path, description: "External id", type: :string],
authorization: @authorization
],
responses: %{
204 => Empty.response(),
404 => NotFound.response()
}
)

def terminate(conn, %{"external_id" => external_id}) do
Logger.metadata(project: external_id)

Expand All @@ -192,4 +204,16 @@ defmodule SupavisorWeb.TenantController do
Logger.warning("Terminate #{external_id}: #{inspect(result)}")
render(conn, "show_terminate.json", result: result)
end

operation(:health,
summary: "Health check",
parameters: [],
responses: %{
204 => Empty.response()
}
)

def health(conn, _) do
send_resp(conn, 204, "")
end
end
35 changes: 33 additions & 2 deletions lib/supavisor_web/open_api_schemas.ex
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,8 @@
db_password: %Schema{type: :string, description: "Database password"},
pool_size: %Schema{type: :integer, description: "Pool size"},
mode_type: %Schema{type: :string, description: "Pooling mode type"},
max_clients: %Schema{type: :integer, description: "Max clients count"},
pool_checkout_timeout: %Schema{type: :integer, description: "Pool checkout timeout"},
is_manager: %Schema{
type: :boolean,
description: "The users who can be used for internal needs"
Expand All @@ -41,6 +43,7 @@
db_password: "postgres",
pool_size: 10,
is_manager: false,
max_clients: 25000,

Check warning on line 46 in lib/supavisor_web/open_api_schemas.ex

View workflow job for this annotation

GitHub Actions / Formatting Checks

Numbers larger than 9999 should be written with underscores: 25_000
mode_type: "transaction",
inserted_at: "2023-03-27T12:00:00Z",
updated_at: "2023-03-27T12:00:00Z"
Expand All @@ -62,6 +65,16 @@
db_host: %Schema{type: :string, description: "Database host"},
db_port: %Schema{type: :integer, description: "Database port"},
db_database: %Schema{type: :string, description: "Database name"},
ip_version: %Schema{type: :string, description: "auto"},
require_user: %Schema{type: :boolean, description: false},
sni_hostname: %Schema{type: :string, description: "your.domain.com"},
upstream_ssl: %Schema{type: :boolean, description: true},
upstream_verify: %Schema{type: :string, description: "none"},
enforce_ssl: %Schema{type: :boolean, description: false},
auth_query: %Schema{
type: :string,
description: "SELECT rolname, rolpassword FROM pg_authid WHERE rolname=$1"
},
users: %Schema{type: :array, items: User},
inserted_at: %Schema{type: :string, format: :date_time, readOnly: true},
updated_at: %Schema{type: :string, format: :date_time, readOnly: true}
Expand All @@ -88,6 +101,8 @@
db_user: "postgres",
db_password: "postgres",
pool_size: 10,
max_clients: 25000,

Check warning on line 104 in lib/supavisor_web/open_api_schemas.ex

View workflow job for this annotation

GitHub Actions / Formatting Checks

Numbers larger than 9999 should be written with underscores: 25_000
pool_checkout_timeout: 1000,
is_manager: false,
mode_type: "transaction",
inserted_at: "2023-03-27T12:00:00Z",
Expand Down Expand Up @@ -123,6 +138,16 @@
db_host: %Schema{type: :string, description: "Database host"},
db_port: %Schema{type: :integer, description: "Database port"},
db_database: %Schema{type: :string, description: "Database name"},
ip_version: %Schema{type: :string, description: "auto"},
require_user: %Schema{type: :boolean, description: false},
sni_hostname: %Schema{type: :string, description: "your.domain.com"},
upstream_ssl: %Schema{type: :boolean, description: true},
upstream_verify: %Schema{type: :string, description: "none"},
enforce_ssl: %Schema{type: :boolean, description: false},
auth_query: %Schema{
type: :string,
description: "SELECT rolname, rolpassword FROM pg_authid WHERE rolname=$1"
},
users: %Schema{type: :array, items: User},
inserted_at: %Schema{type: :string, format: :date_time, readOnly: true},
updated_at: %Schema{type: :string, format: :date_time, readOnly: true}
Expand All @@ -131,18 +156,24 @@
:db_host,
:db_port,
:db_database,
:users
:users,
:require_user
],
example: %{
db_host: "localhost",
db_port: 5432,
db_database: "postgres",
ip_version: "auto",
enforce_ssl: false,
require_user: true,
users: [
%{
db_user: "postgres",
db_password: "postgres",
pool_size: 10,
mode_type: "transaction"
mode_type: "transaction",
max_clients: 25000,

Check warning on line 175 in lib/supavisor_web/open_api_schemas.ex

View workflow job for this annotation

GitHub Actions / Formatting Checks

Numbers larger than 9999 should be written with underscores: 25_000
pool_checkout_timeout: 1000
}
]
}
Expand Down
8 changes: 3 additions & 5 deletions lib/supavisor_web/router.ex
Original file line number Diff line number Diff line change
Expand Up @@ -23,11 +23,6 @@ defmodule SupavisorWeb.Router do
plug(OpenApiSpex.Plug.PutApiSpec, module: SupavisorWeb.ApiSpec)
end

scope "/", SupavisorWeb do
pipe_through(:browser)
get("/", PageController, :index)
end

scope "/swaggerui" do
pipe_through(:browser)
get("/", OpenApiSpex.Plug.SwaggerUI, path: "/api/openapi")
Expand All @@ -50,6 +45,7 @@ defmodule SupavisorWeb.Router do
put("/tenants/:external_id", TenantController, :update)
delete("/tenants/:external_id", TenantController, :delete)
get("/tenants/:external_id/terminate", TenantController, :terminate)
get("/health", TenantController, :health)
end

scope "/metrics", SupavisorWeb do
Expand Down Expand Up @@ -80,6 +76,8 @@ defmodule SupavisorWeb.Router do
end
end

defp check_auth(%{request_path: "/api/health"} = conn, _), do: conn

defp check_auth(conn, secret_key) do
secret = Application.fetch_env!(:supavisor, secret_key)

Expand Down
Loading