2020-05-28 13:11:12 -06:00
|
|
|
# Pleroma: A lightweight social networking server
|
2021-01-12 23:49:20 -07:00
|
|
|
# Copyright © 2017-2021 Pleroma Authors <https://pleroma.social/>
|
2020-05-28 13:11:12 -06: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 05:38:59 -07:00
|
|
|
tags: ["Instance configuration"],
|
|
|
|
summary: "Retrieve instance configuration",
|
2020-05-28 13:11:12 -06: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 10:31:05 -06:00
|
|
|
| admin_api_params()
|
2020-05-28 13:11:12 -06:00
|
|
|
],
|
2021-02-17 10:56:13 -07:00
|
|
|
security: [%{"oAuth" => ["admin:read"]}],
|
2020-05-28 13:11:12 -06: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 05:38:59 -07:00
|
|
|
tags: ["Instance configuration"],
|
|
|
|
summary: "Update instance configuration",
|
2020-05-28 13:11:12 -06:00
|
|
|
operationId: "AdminAPI.ConfigController.update",
|
2021-02-17 10:56:13 -07:00
|
|
|
security: [%{"oAuth" => ["admin:write"]}],
|
2020-07-14 10:31:05 -06:00
|
|
|
parameters: admin_api_params(),
|
2020-05-28 13:11:12 -06:00
|
|
|
requestBody:
|
|
|
|
request_body("Parameters", %Schema{
|
|
|
|
type: :object,
|
|
|
|
properties: %{
|
|
|
|
configs: %Schema{
|
|
|
|
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 05:38:59 -07:00
|
|
|
tags: ["Instance configuration"],
|
|
|
|
summary: "Retrieve config description",
|
2020-05-28 13:11:12 -06:00
|
|
|
operationId: "AdminAPI.ConfigController.descriptions",
|
2021-02-17 10:56:13 -07:00
|
|
|
security: [%{"oAuth" => ["admin:read"]}],
|
2020-07-14 10:31:05 -06:00
|
|
|
parameters: admin_api_params(),
|
2020-05-28 13:11:12 -06: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
|