mirror of
https://github.com/outbackdingo/firezone.git
synced 2026-03-21 07:44:03 +00:00
Why: * In previous commits, the portal code had been updated to use hard deletion rather than soft deletion of data. The fields used in the soft deletion were still kept in the DB and the code to allow for zero downtime rollout and an easy rollback if necessary. To continue with that work the portal code has now been updated to remove any reference to the soft deleted fields (e.g. deleted_at, persistent_id, etc...). While the code has been updated the actual data in the DB will need to remain for now, to once again allow for a zero downtime rollout. Once this commit has been deployed to production another PR can follow to remove the columns from the necessary tables in the DB. Related: #8187
133 lines
3.5 KiB
Elixir
133 lines
3.5 KiB
Elixir
defmodule API.PolicyController do
|
|
use API, :controller
|
|
use OpenApiSpex.ControllerSpecs
|
|
alias API.Pagination
|
|
alias Domain.Policies
|
|
|
|
action_fallback API.FallbackController
|
|
|
|
tags ["Policies"]
|
|
|
|
operation :index,
|
|
summary: "List Policies",
|
|
parameters: [
|
|
limit: [in: :query, description: "Limit Policies returned", type: :integer, example: 10],
|
|
page_cursor: [in: :query, description: "Next/Prev page cursor", type: :string]
|
|
],
|
|
responses: [
|
|
ok: {"Policy Response", "application/json", API.Schemas.Policy.ListResponse}
|
|
]
|
|
|
|
# List Policies
|
|
def index(conn, params) do
|
|
list_opts = Pagination.params_to_list_opts(params)
|
|
|
|
with {:ok, policies, metadata} <- Policies.list_policies(conn.assigns.subject, list_opts) do
|
|
render(conn, :index, policies: policies, metadata: metadata)
|
|
end
|
|
end
|
|
|
|
operation :show,
|
|
summary: "Show Policy",
|
|
parameters: [
|
|
id: [
|
|
in: :path,
|
|
description: "Policy ID",
|
|
type: :string,
|
|
example: "00000000-0000-0000-0000-000000000000"
|
|
]
|
|
],
|
|
responses: [
|
|
ok: {"Policy Response", "application/json", API.Schemas.Policy.Response}
|
|
]
|
|
|
|
# Show a specific Policy
|
|
def show(conn, %{"id" => id}) do
|
|
with {:ok, policy} <- Policies.fetch_policy_by_id(id, conn.assigns.subject) do
|
|
render(conn, :show, policy: policy)
|
|
end
|
|
end
|
|
|
|
operation :create,
|
|
summary: "Create Policy",
|
|
parameters: [],
|
|
request_body:
|
|
{"Policy Attributes", "application/json", API.Schemas.Policy.Request, required: true},
|
|
responses: [
|
|
ok: {"Policy Response", "application/json", API.Schemas.Policy.Response}
|
|
]
|
|
|
|
# Create a new Policy
|
|
def create(conn, %{"policy" => params}) do
|
|
with {:ok, policy} <- Policies.create_policy(params, conn.assigns.subject) do
|
|
conn
|
|
|> put_status(:created)
|
|
|> put_resp_header("location", ~p"/policies/#{policy}")
|
|
|> render(:show, policy: policy)
|
|
end
|
|
end
|
|
|
|
def create(_conn, _params) do
|
|
{:error, :bad_request}
|
|
end
|
|
|
|
operation :update,
|
|
summary: "Update a Policy",
|
|
parameters: [
|
|
id: [
|
|
in: :path,
|
|
description: "Policy ID",
|
|
type: :string,
|
|
example: "00000000-0000-0000-0000-000000000000"
|
|
]
|
|
],
|
|
request_body:
|
|
{"Policy Attributes", "application/json", API.Schemas.Policy.Request, required: true},
|
|
responses: [
|
|
ok: {"Policy Response", "application/json", API.Schemas.Policy.Response}
|
|
]
|
|
|
|
# Update a Policy
|
|
def update(conn, %{"id" => id, "policy" => params}) do
|
|
subject = conn.assigns.subject
|
|
|
|
with {:ok, policy} <- Policies.fetch_policy_by_id(id, subject) do
|
|
case Policies.update_policy(policy, params, subject) do
|
|
{:ok, policy} ->
|
|
render(conn, :show, policy: policy)
|
|
|
|
{:error, reason} ->
|
|
{:error, reason}
|
|
end
|
|
end
|
|
end
|
|
|
|
def update(_conn, _params) do
|
|
{:error, :bad_request}
|
|
end
|
|
|
|
operation :delete,
|
|
summary: "Delete a Policy",
|
|
parameters: [
|
|
id: [
|
|
in: :path,
|
|
description: "Policy ID",
|
|
type: :string,
|
|
example: "00000000-0000-0000-0000-000000000000"
|
|
]
|
|
],
|
|
responses: [
|
|
ok: {"Policy Response", "application/json", API.Schemas.Policy.Response}
|
|
]
|
|
|
|
# Delete a Policy
|
|
def delete(conn, %{"id" => id}) do
|
|
subject = conn.assigns.subject
|
|
|
|
with {:ok, policy} <- Policies.fetch_policy_by_id(id, subject),
|
|
{:ok, policy} <- Policies.delete_policy(policy, subject) do
|
|
render(conn, :show, policy: policy)
|
|
end
|
|
end
|
|
end
|