Add POST /process/probe endpoint

This commit is contained in:
Ingo Oppermann
2023-08-09 10:41:23 +03:00
parent d930a91cbb
commit 15d317a1cd
5 changed files with 204 additions and 6 deletions

View File

@@ -3016,6 +3016,58 @@ const docTemplate = `{
} }
} }
}, },
"/api/v3/process/probe": {
"post": {
"security": [
{
"ApiKeyAuth": []
}
],
"description": "Probe a process to get a detailed stream information on the inputs.",
"consumes": [
"application/json"
],
"produces": [
"application/json"
],
"tags": [
"v16.?.?"
],
"summary": "Add a new process",
"operationId": "process-3-probe-config",
"parameters": [
{
"description": "Process config",
"name": "config",
"in": "body",
"required": true,
"schema": {
"$ref": "#/definitions/api.ProcessConfig"
}
}
],
"responses": {
"200": {
"description": "OK",
"schema": {
"$ref": "#/definitions/api.Probe"
}
},
"400": {
"description": "Bad Request",
"schema": {
"$ref": "#/definitions/api.Error"
}
},
"403": {
"description": "Forbidden",
"schema": {
"$ref": "#/definitions/api.Error"
}
}
}
}
},
"/api/v3/process/{id}": { "/api/v3/process/{id}": {
"get": { "get": {
"security": [ "security": [
@@ -3842,7 +3894,7 @@ const docTemplate = `{
"tags": [ "tags": [
"v16.7.2" "v16.7.2"
], ],
"summary": "Probe a process", "summary": "Probe a known process",
"operationId": "process-3-probe", "operationId": "process-3-probe",
"parameters": [ "parameters": [
{ {
@@ -3871,6 +3923,12 @@ const docTemplate = `{
"schema": { "schema": {
"$ref": "#/definitions/api.Error" "$ref": "#/definitions/api.Error"
} }
},
"404": {
"description": "Not Found",
"schema": {
"$ref": "#/definitions/api.Error"
}
} }
} }
} }

View File

@@ -3008,6 +3008,58 @@
} }
} }
}, },
"/api/v3/process/probe": {
"post": {
"security": [
{
"ApiKeyAuth": []
}
],
"description": "Probe a process to get a detailed stream information on the inputs.",
"consumes": [
"application/json"
],
"produces": [
"application/json"
],
"tags": [
"v16.?.?"
],
"summary": "Add a new process",
"operationId": "process-3-probe-config",
"parameters": [
{
"description": "Process config",
"name": "config",
"in": "body",
"required": true,
"schema": {
"$ref": "#/definitions/api.ProcessConfig"
}
}
],
"responses": {
"200": {
"description": "OK",
"schema": {
"$ref": "#/definitions/api.Probe"
}
},
"400": {
"description": "Bad Request",
"schema": {
"$ref": "#/definitions/api.Error"
}
},
"403": {
"description": "Forbidden",
"schema": {
"$ref": "#/definitions/api.Error"
}
}
}
}
},
"/api/v3/process/{id}": { "/api/v3/process/{id}": {
"get": { "get": {
"security": [ "security": [
@@ -3834,7 +3886,7 @@
"tags": [ "tags": [
"v16.7.2" "v16.7.2"
], ],
"summary": "Probe a process", "summary": "Probe a known process",
"operationId": "process-3-probe", "operationId": "process-3-probe",
"parameters": [ "parameters": [
{ {
@@ -3863,6 +3915,12 @@
"schema": { "schema": {
"$ref": "#/definitions/api.Error" "$ref": "#/definitions/api.Error"
} }
},
"404": {
"description": "Not Found",
"schema": {
"$ref": "#/definitions/api.Error"
}
} }
} }
} }

View File

@@ -4980,9 +4980,13 @@ paths:
description: Forbidden description: Forbidden
schema: schema:
$ref: '#/definitions/api.Error' $ref: '#/definitions/api.Error'
"404":
description: Not Found
schema:
$ref: '#/definitions/api.Error'
security: security:
- ApiKeyAuth: [] - ApiKeyAuth: []
summary: Probe a process summary: Probe a known process
tags: tags:
- v16.7.2 - v16.7.2
/api/v3/process/{id}/report: /api/v3/process/{id}/report:
@@ -5073,6 +5077,39 @@ paths:
summary: Get the state of a process summary: Get the state of a process
tags: tags:
- v16.7.2 - v16.7.2
/api/v3/process/probe:
post:
consumes:
- application/json
description: Probe a process to get a detailed stream information on the inputs.
operationId: process-3-probe-config
parameters:
- description: Process config
in: body
name: config
required: true
schema:
$ref: '#/definitions/api.ProcessConfig'
produces:
- application/json
responses:
"200":
description: OK
schema:
$ref: '#/definitions/api.Probe'
"400":
description: Bad Request
schema:
$ref: '#/definitions/api.Error'
"403":
description: Forbidden
schema:
$ref: '#/definitions/api.Error'
security:
- ApiKeyAuth: []
summary: Add a new process
tags:
- v16.?.?
/api/v3/report/process: /api/v3/report/process:
get: get:
description: Search log history of all processes by providing patterns for process description: Search log history of all processes by providing patterns for process

View File

@@ -60,7 +60,7 @@ func (h *RestreamHandler) Add(c echo.Context) error {
} }
if !h.iam.Enforce(ctxuser, process.Domain, "process:"+process.ID, "write") { if !h.iam.Enforce(ctxuser, process.Domain, "process:"+process.ID, "write") {
return api.Err(http.StatusForbidden, "", "You are not allowed to write this process") return api.Err(http.StatusForbidden, "", "You are not allowed to write this process, check the domain and process ID")
} }
if !superuser { if !superuser {
@@ -633,8 +633,8 @@ func (h *RestreamHandler) SearchReportHistory(c echo.Context) error {
return c.JSON(http.StatusOK, response) return c.JSON(http.StatusOK, response)
} }
// Probe probes a process // Probe probes a known process
// @Summary Probe a process // @Summary Probe a known process
// @Description Probe an existing process to get a detailed stream information on the inputs. // @Description Probe an existing process to get a detailed stream information on the inputs.
// @Tags v16.7.2 // @Tags v16.7.2
// @ID process-3-probe // @ID process-3-probe
@@ -643,6 +643,7 @@ func (h *RestreamHandler) SearchReportHistory(c echo.Context) error {
// @Param domain query string false "Domain to act on" // @Param domain query string false "Domain to act on"
// @Success 200 {object} api.Probe // @Success 200 {object} api.Probe
// @Failure 403 {object} api.Error // @Failure 403 {object} api.Error
// @Failure 404 {object} api.Error
// @Security ApiKeyAuth // @Security ApiKeyAuth
// @Router /api/v3/process/{id}/probe [get] // @Router /api/v3/process/{id}/probe [get]
func (h *RestreamHandler) Probe(c echo.Context) error { func (h *RestreamHandler) Probe(c echo.Context) error {
@@ -672,6 +673,49 @@ func (h *RestreamHandler) Probe(c echo.Context) error {
return c.JSON(http.StatusOK, apiprobe) return c.JSON(http.StatusOK, apiprobe)
} }
// ProbeConfig probes a process
// @Summary Add a new process
// @Description Probe a process to get a detailed stream information on the inputs.
// @Tags v16.?.?
// @ID process-3-probe-config
// @Accept json
// @Produce json
// @Param config body api.ProcessConfig true "Process config"
// @Success 200 {object} api.Probe
// @Failure 400 {object} api.Error
// @Failure 403 {object} api.Error
// @Security ApiKeyAuth
// @Router /api/v3/process/probe [post]
func (h *RestreamHandler) ProbeConfig(c echo.Context) error {
ctxuser := util.DefaultContext(c, "user", "")
process := api.ProcessConfig{
Owner: ctxuser,
Type: "ffmpeg",
}
if err := util.ShouldBindJSON(c, &process); err != nil {
return api.Err(http.StatusBadRequest, "", "invalid JSON: %s", err.Error())
}
if !h.iam.Enforce(ctxuser, process.Domain, "process:"+process.ID, "write") {
return api.Err(http.StatusForbidden, "", "You are not allowed to probe this process, check the domain and process ID")
}
if process.Type != "ffmpeg" {
return api.Err(http.StatusBadRequest, "", "unsupported process type, supported process types are: ffmpeg")
}
config, _ := process.Marshal()
probe := h.restream.Probe(config, 20*time.Second)
apiprobe := api.Probe{}
apiprobe.Unmarshal(&probe)
return c.JSON(http.StatusOK, apiprobe)
}
// Skills returns the detected FFmpeg capabilities // Skills returns the detected FFmpeg capabilities
// @Summary FFmpeg capabilities // @Summary FFmpeg capabilities
// @Description List all detected FFmpeg capabilities. // @Description List all detected FFmpeg capabilities.

View File

@@ -611,6 +611,7 @@ func (s *server) setRoutesV3(v3 *echo.Group) {
v3.GET("/metadata/:key", s.v3handler.restream.GetMetadata) v3.GET("/metadata/:key", s.v3handler.restream.GetMetadata)
if !s.readOnly { if !s.readOnly {
v3.POST("/process/probe", s.v3handler.restream.ProbeConfig)
v3.GET("/process/:id/probe", s.v3handler.restream.Probe) v3.GET("/process/:id/probe", s.v3handler.restream.Probe)
v3.POST("/process", s.v3handler.restream.Add) v3.POST("/process", s.v3handler.restream.Add)
v3.PUT("/process/:id", s.v3handler.restream.Update) v3.PUT("/process/:id", s.v3handler.restream.Update)