2020-05-28 19:11:12 +00:00
|
|
|
# Pleroma: A lightweight social networking server
|
2023-01-02 20:38:50 +00:00
|
|
|
# Copyright © 2017-2022 Pleroma Authors <https://pleroma.social/>
|
2020-05-28 19:11:12 +00:00
|
|
|
# SPDX-License-Identifier: AGPL-3.0-only
|
|
|
|
|
|
|
|
defmodule Pleroma.Web.ApiSpec.Admin.ConfigOperation do
|
|
|
|
alias OpenApiSpex.Operation
|
|
|
|
alias OpenApiSpex.Schema
|
|
|
|
alias Pleroma.Web.ApiSpec.Schemas.ApiError
|
|
|
|
|
|
|
|
import Pleroma.Web.ApiSpec.Helpers
|
|
|
|
|
|
|
|
def open_api_operation(action) do
|
|
|
|
operation = String.to_existing_atom("#{action}_operation")
|
|
|
|
apply(__MODULE__, operation, [])
|
|
|
|
end
|
|
|
|
|
|
|
|
def show_operation do
|
|
|
|
%Operation{
|
2021-02-03 12:38:59 +00:00
|
|
|
tags: ["Instance configuration"],
|
|
|
|
summary: "Retrieve instance configuration",
|
2020-05-28 19:11:12 +00:00
|
|
|
operationId: "AdminAPI.ConfigController.show",
|
|
|
|
parameters: [
|
|
|
|
Operation.parameter(
|
|
|
|
:only_db,
|
|
|
|
:query,
|
|
|
|
%Schema{type: :boolean, default: false},
|
|
|
|
"Get only saved in database settings"
|
|
|
|
)
|
2020-07-14 16:31:05 +00:00
|
|
|
| admin_api_params()
|
2020-05-28 19:11:12 +00:00
|
|
|
],
|
2021-02-17 17:56:13 +00:00
|
|
|
security: [%{"oAuth" => ["admin:read"]}],
|
2020-05-28 19:11:12 +00:00
|
|
|
responses: %{
|
|
|
|
200 => Operation.response("Config", "application/json", config_response()),
|
|
|
|
400 => Operation.response("Bad Request", "application/json", ApiError)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
end
|
|
|
|
|
|
|
|
def update_operation do
|
|
|
|
%Operation{
|
2021-02-03 12:38:59 +00:00
|
|
|
tags: ["Instance configuration"],
|
|
|
|
summary: "Update instance configuration",
|
2020-05-28 19:11:12 +00:00
|
|
|
operationId: "AdminAPI.ConfigController.update",
|
2021-02-17 17:56:13 +00:00
|
|
|
security: [%{"oAuth" => ["admin:write"]}],
|
2020-07-14 16:31:05 +00:00
|
|
|
parameters: admin_api_params(),
|
2020-05-28 19:11:12 +00:00
|
|
|
requestBody:
|
|
|
|
request_body("Parameters", %Schema{
|
|
|
|
type: :object,
|
|
|
|
properties: %{
|
Pleroma.Web.AdminAPI.ConfigController: dialyzer error
lib/pleroma/web/admin_api/controllers/config_controller.ex:162:call
The function call will not succeed.
Phoenix.Controller.render(
_conn :: %{:body_params => %{:configs => _, _ => _}, _ => _},
<<105, 110, 100, 101, 120, 46, 106, 115, 111, 110>>,
%{:configs => [any()], :need_reboot => _}
)
will never return since the success typing is:
(
%Plug.Conn{
:adapter => {atom(), _},
:assigns => %{atom() => _},
:body_params => %Plug.Conn.Unfetched{:aspect => atom(), binary() => _},
:cookies => %Plug.Conn.Unfetched{:aspect => atom(), binary() => _},
:halted => boolean(),
:host => binary(),
:method => binary(),
:owner => pid(),
:params => %Plug.Conn.Unfetched{:aspect => atom(), binary() => _},
:path_info => [binary()],
:path_params => %{binary() => binary() | [any()] | map()},
:port => char(),
:private => %{atom() => _},
:query_params => %Plug.Conn.Unfetched{
:aspect => atom(),
binary() => binary() | [any()] | map()
},
:query_string => binary(),
:remote_ip =>
{byte(), byte(), byte(), byte()}
| {char(), char(), char(), char(), char(), char(), char(), char()},
:req_cookies => %Plug.Conn.Unfetched{:aspect => atom(), binary() => binary()},
:req_headers => [{_, _}],
:request_path => binary(),
:resp_body =>
nil
| binary()
| maybe_improper_list(
binary() | maybe_improper_list(any(), binary() | []) | byte(),
binary() | []
),
:resp_cookies => %{binary() => map()},
:resp_headers => [{_, _}],
:scheme => :http | :https,
:script_name => [binary()],
:secret_key_base => nil | binary(),
:state =>
:chunked | :file | :sent | :set | :set_chunked | :set_file | :unset | :upgraded,
:status => nil | non_neg_integer()
},
atom() | binary(),
atom() | binary() | [{_, _}] | map()
) :: %Plug.Conn{
:adapter => {atom(), _},
:assigns => %{atom() => _},
:body_params => %Plug.Conn.Unfetched{:aspect => atom(), binary() => _},
:cookies => %Plug.Conn.Unfetched{:aspect => atom(), binary() => _},
:halted => boolean(),
:host => binary(),
:method => binary(),
:owner => pid(),
:params => %Plug.Conn.Unfetched{:aspect => atom(), binary() => _},
:path_info => [binary()],
:path_params => %{binary() => binary() | [any()] | map()},
:port => char(),
:private => %{atom() => _},
:query_params => %Plug.Conn.Unfetched{
:aspect => atom(),
binary() => binary() | [any()] | map()
},
:query_string => binary(),
:remote_ip =>
{byte(), byte(), byte(), byte()}
| {char(), char(), char(), char(), char(), char(), char(), char()},
:req_cookies => %Plug.Conn.Unfetched{:aspect => atom(), binary() => binary()},
:req_headers => [{_, _}],
:request_path => binary(),
:resp_body =>
nil
| binary()
| maybe_improper_list(
binary() | maybe_improper_list(any(), binary() | []) | byte(),
binary() | []
),
:resp_cookies => %{binary() => map()},
:resp_headers => [{_, _}],
:scheme => :http | :https,
:script_name => [binary()],
:secret_key_base => nil | binary(),
:state => :sent,
:status => nil | non_neg_integer()
}
and the contract is
(Plug.Conn.t(), binary() | atom(), Keyword.t() | map()) :: Plug.Conn.t()
2024-01-27 21:42:30 +00:00
|
|
|
"configs" => %Schema{
|
2020-05-28 19:11:12 +00:00
|
|
|
type: :array,
|
|
|
|
items: %Schema{
|
|
|
|
type: :object,
|
|
|
|
properties: %{
|
|
|
|
group: %Schema{type: :string},
|
|
|
|
key: %Schema{type: :string},
|
|
|
|
value: any(),
|
|
|
|
delete: %Schema{type: :boolean},
|
|
|
|
subkeys: %Schema{type: :array, items: %Schema{type: :string}}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}),
|
|
|
|
responses: %{
|
|
|
|
200 => Operation.response("Config", "application/json", config_response()),
|
|
|
|
400 => Operation.response("Bad Request", "application/json", ApiError)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
end
|
|
|
|
|
|
|
|
def descriptions_operation do
|
|
|
|
%Operation{
|
2021-02-03 12:38:59 +00:00
|
|
|
tags: ["Instance configuration"],
|
|
|
|
summary: "Retrieve config description",
|
2020-05-28 19:11:12 +00:00
|
|
|
operationId: "AdminAPI.ConfigController.descriptions",
|
2021-02-17 17:56:13 +00:00
|
|
|
security: [%{"oAuth" => ["admin:read"]}],
|
2020-07-14 16:31:05 +00:00
|
|
|
parameters: admin_api_params(),
|
2020-05-28 19:11:12 +00:00
|
|
|
responses: %{
|
|
|
|
200 =>
|
|
|
|
Operation.response("Config Descriptions", "application/json", %Schema{
|
|
|
|
type: :array,
|
|
|
|
items: %Schema{
|
|
|
|
type: :object,
|
|
|
|
properties: %{
|
|
|
|
group: %Schema{type: :string},
|
|
|
|
key: %Schema{type: :string},
|
|
|
|
type: %Schema{oneOf: [%Schema{type: :string}, %Schema{type: :array}]},
|
|
|
|
description: %Schema{type: :string},
|
|
|
|
children: %Schema{
|
|
|
|
type: :array,
|
|
|
|
items: %Schema{
|
|
|
|
type: :object,
|
|
|
|
properties: %{
|
|
|
|
key: %Schema{type: :string},
|
|
|
|
type: %Schema{oneOf: [%Schema{type: :string}, %Schema{type: :array}]},
|
|
|
|
description: %Schema{type: :string},
|
|
|
|
suggestions: %Schema{type: :array}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}),
|
|
|
|
400 => Operation.response("Bad Request", "application/json", ApiError)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
end
|
|
|
|
|
|
|
|
defp any do
|
|
|
|
%Schema{
|
|
|
|
oneOf: [
|
|
|
|
%Schema{type: :array},
|
|
|
|
%Schema{type: :object},
|
|
|
|
%Schema{type: :string},
|
|
|
|
%Schema{type: :integer},
|
|
|
|
%Schema{type: :boolean}
|
|
|
|
]
|
|
|
|
}
|
|
|
|
end
|
|
|
|
|
|
|
|
defp config_response do
|
|
|
|
%Schema{
|
|
|
|
type: :object,
|
|
|
|
properties: %{
|
|
|
|
configs: %Schema{
|
|
|
|
type: :array,
|
|
|
|
items: %Schema{
|
|
|
|
type: :object,
|
|
|
|
properties: %{
|
|
|
|
group: %Schema{type: :string},
|
|
|
|
key: %Schema{type: :string},
|
|
|
|
value: any()
|
|
|
|
}
|
|
|
|
}
|
|
|
|
},
|
|
|
|
need_reboot: %Schema{
|
|
|
|
type: :boolean,
|
|
|
|
description:
|
|
|
|
"If `need_reboot` is `true`, instance must be restarted, so reboot time settings can take effect"
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
end
|
|
|
|
end
|