api

package
v0.0.6-beta Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Mar 21, 2022 License: GPL-2.0 Imports: 11 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func AddSwitchPermission

func AddSwitchPermission(w http.ResponseWriter, r *http.Request)

TODO: add all request body docs Add a switchPermission to a given user, admin authentication required Request: `{"username": "x", "switch": "y"}` | Response: Response

func AddUser

func AddUser(w http.ResponseWriter, r *http.Request)

Creates a new user and gives him a provided password Request: `{"username": "x", "password": "y"}`, admin auth required

func AddUserPermission

func AddUserPermission(w http.ResponseWriter, r *http.Request)

Adds a given permission to a given user, admin authentication required If the permission is invalid, a `422` is returned Request: `{"username": "", "permission": ""}` | Response: Response

func DebugInfo

func DebugInfo(w http.ResponseWriter, r *http.Request)

Reading system debug information, admin authentication required Todo: read raspberry pi information

func DeleteAllUserNotifications

func DeleteAllUserNotifications(w http.ResponseWriter, r *http.Request)

func DeleteUser

func DeleteUser(w http.ResponseWriter, r *http.Request)

Deletes a user given a valid username This also needs to delete any data that depends on this user in terms of a foreign key Admin auth required

func DeleteUserNotificationById

func DeleteUserNotificationById(w http.ResponseWriter, r *http.Request)

Delete a given notification from the current user

func FlushAllLogs

func FlushAllLogs(w http.ResponseWriter, r *http.Request)

Triggers deletion of ALL internal server logs, admin authentication required Request: empty | Response: Response

func FlushOldLogs

func FlushOldLogs(w http.ResponseWriter, r *http.Request)

Triggers deletion of internal server logs which are older than 30 days, admin authentication required Request: empty | Response: Response

func GetNotificationCount

func GetNotificationCount(w http.ResponseWriter, r *http.Request)

Returns a uin16 that indicates the number of notifications the current user has, no authentication required

func GetNotifications

func GetNotifications(w http.ResponseWriter, r *http.Request)

Returns a list containing notifications of the current user

func GetPowerStates

func GetPowerStates(w http.ResponseWriter, r *http.Request)

Returns a list of power states, no authentication required Request: empty | Response: `[{"switchId": "x", power: false}, {...}]`

func GetSwitches

func GetSwitches(w http.ResponseWriter, r *http.Request)

Returns a list of available switches as JSON to the user, no authentication required

func GetUserDetails

func GetUserDetails(w http.ResponseWriter, r *http.Request)

Returns the user's personal data, auth required

func GetUserPermissions

func GetUserPermissions(w http.ResponseWriter, r *http.Request)

Returns a list of strings which resemble permissions of the currently logged in user, authentication required Request: empty | Response: `["a", "b", "c"]`

func GetUserRoomsWithSwitches

func GetUserRoomsWithSwitches(w http.ResponseWriter, r *http.Request)

Returns the wanted response for the frontend

func GetUserSwitches

func GetUserSwitches(w http.ResponseWriter, r *http.Request)

Only returns switches which the user has access to, authentication required

func HealthCheck

func HealthCheck(w http.ResponseWriter, r *http.Request)

Runs a healthcheck of most systems on which the appplication relies on, will be used by e.g `Uptime Kuma`, no authentication required TODO: also check the hardware nodes

func InitLogger

func InitLogger(logger *logrus.Logger)

func ListLogs

func ListLogs(w http.ResponseWriter, r *http.Request)

Returns a list of logging items in the logging table, admin authentication required

func ListUsers

func ListUsers(w http.ResponseWriter, r *http.Request)

Returns a list of users and their metadata, admin auth required

func PowerPostHandler

func PowerPostHandler(w http.ResponseWriter, r *http.Request)

API endpoint for manipulating power states and (de) activating sockets, authentication required Permission and switch permission is needed to interact with this endpoint

func RemoveSwitchPermission

func RemoveSwitchPermission(w http.ResponseWriter, r *http.Request)

TODO: split into either a submodlue or separate files, should be in a subfolder in server/api or server/routes/api and /server/routes/ui Removes a given switch permission from a given user, admin authentication required Request: `{"username": "x", "switch": "y"}` | Response: Response

func RemoveUserPermission

func RemoveUserPermission(w http.ResponseWriter, r *http.Request)

Todo: unit tests for some of the subfunction Removes a given permission from a user, admin authentication required Request: `{"username": "x", "permission": "y"}` | Response: Response

func TestImageProxy

func TestImageProxy(w http.ResponseWriter, r *http.Request)

TEST IMAGE FETCHING MODULE

Types

type AddUserRequest

type AddUserRequest struct {
	Username string `json:"username"`
	Password string `json:"password"`
}

type DeleteNotificationByIdRequest

type DeleteNotificationByIdRequest struct {
	Id uint `json:"id"`
}

type LoginRequest

type LoginRequest struct {
	Username string `json:"username"`
	Password string `json:"password"`
}

type NotificationCountResponse

type NotificationCountResponse struct {
	NotificationCount uint16 `json:"count"`
}

type PowerRequest

type PowerRequest struct {
	Switch  string `json:"switch"`
	PowerOn bool   `json:"powerOn"`
}

type RemoveUserRequest

type RemoveUserRequest struct {
	Username string `json:"username"`
}

type Response

type Response struct {
	Success bool   `json:"success"`
	Message string `json:"message"`
	Error   string `json:"error"`
}

type UserPermissionRequest

type UserPermissionRequest struct {
	Username   string `json:"username"`
	Permission string `json:"permission"`
}

type UserSwitchPermissionRequest

type UserSwitchPermissionRequest struct {
	Username string `json:"username"`
	Switch   string `json:"switch"`
}

TODO: check if `Switch` is called somewhat else in other places

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL