From 694c9f8c4b75f5e1d3c219dfe77317f1d2788627 Mon Sep 17 00:00:00 2001 From: jb-alvarado Date: Tue, 8 Nov 2022 15:42:17 +0100 Subject: [PATCH] fix auth example, #232 --- assets/ffplayout.service | 1 + assets/ffplayout@.service | 1 + docs/api.md | 48 ++++++++++++++++----------------- ffplayout-api/src/api/routes.rs | 48 ++++++++++++++++----------------- 4 files changed, 50 insertions(+), 48 deletions(-) diff --git a/assets/ffplayout.service b/assets/ffplayout.service index ba7cf61c..c76858f3 100644 --- a/assets/ffplayout.service +++ b/assets/ffplayout.service @@ -5,6 +5,7 @@ After=network.target remote-fs.target [Service] ExecStart=/usr/bin/ffplayout Restart=always +StartLimitIntervalSec=20 RestartSec=1 KillMode=mixed User=ffpu diff --git a/assets/ffplayout@.service b/assets/ffplayout@.service index 37a9f1a1..a790c367 100644 --- a/assets/ffplayout@.service +++ b/assets/ffplayout@.service @@ -5,6 +5,7 @@ After=network.target remote-fs.target [Service] ExecStart=/usr/bin/ffplayout %I Restart=always +StartLimitIntervalSec=20 RestartSec=1 KillMode=mixed User=ffpu diff --git a/docs/api.md b/docs/api.md index 1b65b917..07762ca5 100644 --- a/docs/api.md +++ b/docs/api.md @@ -42,7 +42,7 @@ curl -X GET 'http://127.0.0.1:8787/api/user' -H 'Content-Type: application/json' ```BASH curl -X PUT http://127.0.0.1:8787/api/user/1 -H 'Content-Type: application/json' \ --d '{"mail": "", "password": ""}' -H 'Authorization: ' +-d '{"mail": "", "password": ""}' -H 'Authorization: Bearer ' ``` **Add User** @@ -111,7 +111,7 @@ curl -X DELETE http://127.0.0.1:8787/api/channel/2 -H "Authorization: Bearer ' +curl -X GET http://127.0.0.1:8787/api/playout/config/1 -H 'Authorization: Bearer ' ``` Response is a JSON object from the ffplayout.yml @@ -120,7 +120,7 @@ Response is a JSON object from the ffplayout.yml ```BASH curl -X PUT http://127.0.0.1:8787/api/playout/config/1 -H "Content-Type: application/json" \ --d { } -H 'Authorization: ' +-d { } -H 'Authorization: Bearer ' ``` #### Text Presets @@ -131,7 +131,7 @@ Text presets are made for sending text messages to the ffplayout engine, to over ```BASH curl -X GET http://127.0.0.1:8787/api/presets/ -H 'Content-Type: application/json' \ --H 'Authorization: ' +-H 'Authorization: Bearer ' ``` **Update Preset** @@ -140,7 +140,7 @@ curl -X GET http://127.0.0.1:8787/api/presets/ -H 'Content-Type: application/jso curl -X PUT http://127.0.0.1:8787/api/presets/1 -H 'Content-Type: application/json' \ -d '{ "name": "", "text": "", "x": "", "y": "", "fontsize": 24, \ "line_spacing": 4, "fontcolor": "#ffffff", "box": 1, "boxcolor": "#000000", "boxborderw": 4, "alpha": 1.0, "channel_id": 1 }' \ --H 'Authorization: ' +-H 'Authorization: Bearer ' ``` **Add new Preset** @@ -149,14 +149,14 @@ curl -X PUT http://127.0.0.1:8787/api/presets/1 -H 'Content-Type: application/js curl -X POST http://127.0.0.1:8787/api/presets/ -H 'Content-Type: application/json' \ -d '{ "name": "", "text": "TEXT>", "x": "", "y": "", "fontsize": 24, \ "line_spacing": 4, "fontcolor": "#ffffff", "box": 1, "boxcolor": "#000000", "boxborderw": 4, "alpha": 1.0, "channel_id": 1 }' \ --H 'Authorization: ' +-H 'Authorization: Bearer ' ``` **Delete Preset** ```BASH curl -X DELETE http://127.0.0.1:8787/api/presets/1 -H 'Content-Type: application/json' \ --H 'Authorization: ' +-H 'Authorization: Bearer ' ``` ### ffplayout controlling @@ -171,7 +171,7 @@ here we communicate with the engine for: ```BASH curl -X POST http://127.0.0.1:8787/api/control/1/text/ \ --H 'Content-Type: application/json' -H 'Authorization: ' \ +-H 'Content-Type: application/json' -H 'Authorization: Bearer ' \ -d '{"text": "Hello from ffplayout", "x": "(w-text_w)/2", "y": "(h-text_h)/2", \ "fontsize": "24", "line_spacing": "4", "fontcolor": "#ffffff", "box": "1", \ "boxcolor": "#000000", "boxborderw": "4", "alpha": "1.0"}' @@ -185,14 +185,14 @@ curl -X POST http://127.0.0.1:8787/api/control/1/text/ \ ```BASH curl -X POST http://127.0.0.1:8787/api/control/1/playout/ -H 'Content-Type: application/json' --d '{ "command": "reset" }' -H 'Authorization: ' +-d '{ "command": "reset" }' -H 'Authorization: Bearer ' ``` **Get current Clip** ```BASH curl -X GET http://127.0.0.1:8787/api/control/1/media/current --H 'Content-Type: application/json' -H 'Authorization: ' +-H 'Content-Type: application/json' -H 'Authorization: Bearer ' ``` **Response:** @@ -222,14 +222,14 @@ curl -X GET http://127.0.0.1:8787/api/control/1/media/current **Get next Clip** ```BASH -curl -X GET http://127.0.0.1:8787/api/control/1/media/next/ -H 'Authorization: ' +curl -X GET http://127.0.0.1:8787/api/control/1/media/next/ -H 'Authorization: Bearer ' ``` **Get last Clip** ```BASH curl -X GET http://127.0.0.1:8787/api/control/1/media/last/ --H 'Content-Type: application/json' -H 'Authorization: ' +-H 'Content-Type: application/json' -H 'Authorization: Bearer ' ``` #### ffplayout Process Control @@ -242,7 +242,7 @@ Control ffplayout process, like: ```BASH curl -X POST http://127.0.0.1:8787/api/control/1/process/ --H 'Content-Type: application/json' -H 'Authorization: ' +-H 'Content-Type: application/json' -H 'Authorization: Bearer ' -d '{"command": "start"}' ``` @@ -252,14 +252,14 @@ curl -X POST http://127.0.0.1:8787/api/control/1/process/ ```BASH curl -X GET http://127.0.0.1:8787/api/playlist/1?date=2022-06-20 --H 'Content-Type: application/json' -H 'Authorization: ' +-H 'Content-Type: application/json' -H 'Authorization: Bearer ' ``` **Save playlist** ```BASH curl -X POST http://127.0.0.1:8787/api/playlist/1/ --H 'Content-Type: application/json' -H 'Authorization: ' +-H 'Content-Type: application/json' -H 'Authorization: Bearer ' -- data "{}" ``` @@ -269,14 +269,14 @@ A new playlist will be generated and response. ```BASH curl -X GET http://127.0.0.1:8787/api/playlist/1/generate/2022-06-20 --H 'Content-Type: application/json' -H 'Authorization: ' +-H 'Content-Type: application/json' -H 'Authorization: Bearer ' ``` **Delete Playlist** ```BASH curl -X DELETE http://127.0.0.1:8787/api/playlist/1/2022-06-20 --H 'Content-Type: application/json' -H 'Authorization: ' +-H 'Content-Type: application/json' -H 'Authorization: Bearer ' ``` ### Log file @@ -285,7 +285,7 @@ curl -X DELETE http://127.0.0.1:8787/api/playlist/1/2022-06-20 ```BASH curl -X Get http://127.0.0.1:8787/api/log/1 --H 'Content-Type: application/json' -H 'Authorization: ' +-H 'Content-Type: application/json' -H 'Authorization: Bearer ' ``` ### File Operations @@ -294,34 +294,34 @@ curl -X Get http://127.0.0.1:8787/api/log/1 ```BASH curl -X POST http://127.0.0.1:8787/api/file/1/browse/ -H 'Content-Type: application/json' --d '{ "source": "/" }' -H 'Authorization: ' +-d '{ "source": "/" }' -H 'Authorization: Bearer ' ``` **Create Folder** ```BASH curl -X POST http://127.0.0.1:8787/api/file/1/create-folder/ -H 'Content-Type: application/json' --d '{"source": ""}' -H 'Authorization: ' +-d '{"source": ""}' -H 'Authorization: Bearer ' ``` **Rename File** ```BASH curl -X POST http://127.0.0.1:8787/api/file/1/rename/ -H 'Content-Type: application/json' --d '{"source": "", "target": ""}' -H 'Authorization: ' +-d '{"source": "", "target": ""}' -H 'Authorization: Bearer ' ``` **Remove File/Folder** ```BASH curl -X POST http://127.0.0.1:8787/api/file/1/remove/ -H 'Content-Type: application/json' --d '{"source": ""}' -H 'Authorization: ' +-d '{"source": ""}' -H 'Authorization: Bearer ' ``` **Upload File** ```BASH -curl -X POST http://127.0.0.1:8787/api/file/1/upload/ -H 'Authorization: ' +curl -X POST http://127.0.0.1:8787/api/file/1/upload/ -H 'Authorization: Bearer ' -F "file=@file.mp4" ``` @@ -331,7 +331,7 @@ Import text/m3u file and convert it to a playlist lines with leading "#" will be ignore ```BASH -curl -X POST http://127.0.0.1:8787/api/file/1/import/ -H 'Authorization: ' +curl -X POST http://127.0.0.1:8787/api/file/1/import/ -H 'Authorization: Bearer ' -F "file=@list.m3u" ``` diff --git a/ffplayout-api/src/api/routes.rs b/ffplayout-api/src/api/routes.rs index ffc78ef9..93d3fc24 100644 --- a/ffplayout-api/src/api/routes.rs +++ b/ffplayout-api/src/api/routes.rs @@ -166,7 +166,7 @@ async fn get_user(user: web::ReqData) -> Result", "password": ""}' -H 'Authorization: ' +/// -d '{"mail": "", "password": ""}' -H 'Authorization: Bearer ' /// ``` #[put("/user/{id}")] #[has_any_role("Role::Admin", "Role::User", type = "Role")] @@ -332,7 +332,7 @@ async fn remove_channel(id: web::Path) -> Result' +/// curl -X GET http://127.0.0.1:8787/api/playout/config/1 -H 'Authorization: Bearer ' /// ``` /// /// Response is a JSON object from the ffplayout.yml @@ -355,7 +355,7 @@ async fn get_playout_config( /// /// ```BASH /// curl -X PUT http://127.0.0.1:8787/api/playout/config/1 -H "Content-Type: application/json" \ -/// -d { } -H 'Authorization: ' +/// -d { } -H 'Authorization: Bearer ' /// ``` #[put("/playout/config/{id}")] #[has_any_role("Role::Admin", type = "Role")] @@ -388,7 +388,7 @@ async fn update_playout_config( /// /// ```BASH /// curl -X GET http://127.0.0.1:8787/api/presets/ -H 'Content-Type: application/json' \ -/// -H 'Authorization: ' +/// -H 'Authorization: Bearer ' /// ``` #[get("/presets/{id}")] #[has_any_role("Role::Admin", "Role::User", type = "Role")] @@ -406,7 +406,7 @@ async fn get_presets(id: web::Path) -> Result /// curl -X PUT http://127.0.0.1:8787/api/presets/1 -H 'Content-Type: application/json' \ /// -d '{ "name": "", "text": "", "x": "", "y": "", "fontsize": 24, \ /// "line_spacing": 4, "fontcolor": "#ffffff", "box": 1, "boxcolor": "#000000", "boxborderw": 4, "alpha": 1.0, "channel_id": 1 }' \ -/// -H 'Authorization: ' +/// -H 'Authorization: Bearer ' /// ``` #[put("/presets/{id}")] #[has_any_role("Role::Admin", "Role::User", type = "Role")] @@ -427,7 +427,7 @@ async fn update_preset( /// curl -X POST http://127.0.0.1:8787/api/presets/ -H 'Content-Type: application/json' \ /// -d '{ "name": "", "text": "TEXT>", "x": "", "y": "", "fontsize": 24, \ /// "line_spacing": 4, "fontcolor": "#ffffff", "box": 1, "boxcolor": "#000000", "boxborderw": 4, "alpha": 1.0, "channel_id": 1 }' \ -/// -H 'Authorization: ' +/// -H 'Authorization: Bearer ' /// ``` #[post("/presets/")] #[has_any_role("Role::Admin", "Role::User", type = "Role")] @@ -443,7 +443,7 @@ async fn add_preset(data: web::Json) -> Result' +/// -H 'Authorization: Bearer ' /// ``` #[delete("/presets/{id}")] #[has_any_role("Role::Admin", "Role::User", type = "Role")] @@ -467,7 +467,7 @@ async fn delete_preset(id: web::Path) -> Result' \ +/// -H 'Content-Type: application/json' -H 'Authorization: Bearer ' \ /// -d '{"text": "Hello from ffplayout", "x": "(w-text_w)/2", "y": "(h-text_h)/2", \ /// "fontsize": "24", "line_spacing": "4", "fontcolor": "#ffffff", "box": "1", \ /// "boxcolor": "#000000", "boxborderw": "4", "alpha": "1.0"}' @@ -492,7 +492,7 @@ pub async fn send_text_message( /// /// ```BASH /// curl -X POST http://127.0.0.1:8787/api/control/1/playout/ -H 'Content-Type: application/json' -/// -d '{ "command": "reset" }' -H 'Authorization: ' +/// -d '{ "command": "reset" }' -H 'Authorization: Bearer ' /// ``` #[post("/control/{id}/playout/")] #[has_any_role("Role::Admin", "Role::User", type = "Role")] @@ -510,7 +510,7 @@ pub async fn control_playout( /// /// ```BASH /// curl -X GET http://127.0.0.1:8787/api/control/1/media/current -/// -H 'Content-Type: application/json' -H 'Authorization: ' +/// -H 'Content-Type: application/json' -H 'Authorization: Bearer ' /// ``` /// /// **Response:** @@ -548,7 +548,7 @@ pub async fn media_current(id: web::Path) -> Result' +/// curl -X GET http://127.0.0.1:8787/api/control/1/media/next/ -H 'Authorization: Bearer ' /// ``` #[get("/control/{id}/media/next")] #[has_any_role("Role::Admin", "Role::User", type = "Role")] @@ -563,7 +563,7 @@ pub async fn media_next(id: web::Path) -> Result' +/// -H 'Content-Type: application/json' -H 'Authorization: Bearer ' /// ``` #[get("/control/{id}/media/last")] #[has_any_role("Role::Admin", "Role::User", type = "Role")] @@ -584,7 +584,7 @@ pub async fn media_last(id: web::Path) -> Result' +/// -H 'Content-Type: application/json' -H 'Authorization: Bearer ' /// -d '{"command": "start"}' /// ``` #[post("/control/{id}/process/")] @@ -602,7 +602,7 @@ pub async fn process_control( /// /// ```BASH /// curl -X GET http://127.0.0.1:8787/api/playlist/1?date=2022-06-20 -/// -H 'Content-Type: application/json' -H 'Authorization: ' +/// -H 'Content-Type: application/json' -H 'Authorization: Bearer ' /// ``` #[get("/playlist/{id}")] #[has_any_role("Role::Admin", "Role::User", type = "Role")] @@ -620,7 +620,7 @@ pub async fn get_playlist( /// /// ```BASH /// curl -X POST http://127.0.0.1:8787/api/playlist/1/ -/// -H 'Content-Type: application/json' -H 'Authorization: ' +/// -H 'Content-Type: application/json' -H 'Authorization: Bearer ' /// -- data "{}" /// ``` #[post("/playlist/{id}/")] @@ -641,7 +641,7 @@ pub async fn save_playlist( /// /// ```BASH /// curl -X GET http://127.0.0.1:8787/api/playlist/1/generate/2022-06-20 -/// -H 'Content-Type: application/json' -H 'Authorization: ' +/// -H 'Content-Type: application/json' -H 'Authorization: Bearer ' /// ``` #[get("/playlist/{id}/generate/{date}")] #[has_any_role("Role::Admin", "Role::User", type = "Role")] @@ -658,7 +658,7 @@ pub async fn gen_playlist( /// /// ```BASH /// curl -X DELETE http://127.0.0.1:8787/api/playlist/1/2022-06-20 -/// -H 'Content-Type: application/json' -H 'Authorization: ' +/// -H 'Content-Type: application/json' -H 'Authorization: Bearer ' /// ``` #[delete("/playlist/{id}/{date}")] #[has_any_role("Role::Admin", "Role::User", type = "Role")] @@ -677,7 +677,7 @@ pub async fn del_playlist( /// /// ```BASH /// curl -X Get http://127.0.0.1:8787/api/log/1 -/// -H 'Content-Type: application/json' -H 'Authorization: ' +/// -H 'Content-Type: application/json' -H 'Authorization: Bearer ' /// ``` #[get("/log/{id}")] #[has_any_role("Role::Admin", "Role::User", type = "Role")] @@ -694,7 +694,7 @@ pub async fn get_log( /// /// ```BASH /// curl -X POST http://127.0.0.1:8787/api/file/1/browse/ -H 'Content-Type: application/json' -/// -d '{ "source": "/" }' -H 'Authorization: ' +/// -d '{ "source": "/" }' -H 'Authorization: Bearer ' /// ``` #[post("/file/{id}/browse/")] #[has_any_role("Role::Admin", "Role::User", type = "Role")] @@ -712,7 +712,7 @@ pub async fn file_browser( /// /// ```BASH /// curl -X POST http://127.0.0.1:8787/api/file/1/create-folder/ -H 'Content-Type: application/json' -/// -d '{"source": ""}' -H 'Authorization: ' +/// -d '{"source": ""}' -H 'Authorization: Bearer ' /// ``` #[post("/file/{id}/create-folder/")] #[has_any_role("Role::Admin", "Role::User", type = "Role")] @@ -727,7 +727,7 @@ pub async fn add_dir( /// /// ```BASH /// curl -X POST http://127.0.0.1:8787/api/file/1/rename/ -H 'Content-Type: application/json' -/// -d '{"source": "", "target": ""}' -H 'Authorization: ' +/// -d '{"source": "", "target": ""}' -H 'Authorization: Bearer ' /// ``` #[post("/file/{id}/rename/")] #[has_any_role("Role::Admin", "Role::User", type = "Role")] @@ -745,7 +745,7 @@ pub async fn move_rename( /// /// ```BASH /// curl -X POST http://127.0.0.1:8787/api/file/1/remove/ -H 'Content-Type: application/json' -/// -d '{"source": ""}' -H 'Authorization: ' +/// -d '{"source": ""}' -H 'Authorization: Bearer ' /// ``` #[post("/file/{id}/remove/")] #[has_any_role("Role::Admin", "Role::User", type = "Role")] @@ -762,7 +762,7 @@ pub async fn remove( /// **Upload File** /// /// ```BASH -/// curl -X POST http://127.0.0.1:8787/api/file/1/upload/ -H 'Authorization: ' +/// curl -X POST http://127.0.0.1:8787/api/file/1/upload/ -H 'Authorization: Bearer ' /// -F "file=@file.mp4" /// ``` #[put("/file/{id}/upload/")] @@ -781,7 +781,7 @@ async fn save_file( /// lines with leading "#" will be ignore /// /// ```BASH -/// curl -X POST http://127.0.0.1:8787/api/file/1/import/ -H 'Authorization: ' +/// curl -X POST http://127.0.0.1:8787/api/file/1/import/ -H 'Authorization: Bearer ' /// -F "file=@list.m3u" /// ``` #[put("/file/{id}/import/")]